var xmlHttp;
var div;

function getDiv(xmlHttp, div)
{
    if(div == undefined)
    {
        document.getElementById("content").innerHTML=xmlHttp.responseText;
    }
    else
    {
        document.getElementById(div).innerHTML=xmlHttp.responseText;
    }
}

function getPage(str)
{
    //alert(str);
    if(str!='none')
    {
        xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request")
            return true;
        } 
 
        //var str = str.split("_");    
        var url="/tpl/album_ss/inc/main.inc.php";
        xmlHttp.onreadystatechange=stateChanged;
        xmlHttp.open("POST",url,true);
        xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset=UTF-8;');
        xmlHttp.send('folderid='+str);
    } else {
        return true;
    }
}


function checkUsername(str, div, inc)
{
    if(str!='none')
    {
        xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request")
            return true;
        } 

        if(inc != undefined)
        {
            var url= '/tpl/album_lof/inc/'+inc+'.inc.php';
        }
        else
        {
            var url= '/tpl/album_lof/inc/main.inc.php';
        }

        xmlHttp.onreadystatechange = function() { 
                                       if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
                                                getDiv(xmlHttp, div);
                                     }
        xmlHttp.open("POST",url,true);
        xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset=UTF-8;');
        xmlHttp.send('action=check_username&username='+str);
    } else {
        return true;
    }
}

function checkValue(str, div, inc, act)
{
    if(str!='none')
    {
        xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request")
            return true;
        } 

        if(inc != undefined)
        {
            var url= '/tpl/album_lof/inc/'+inc+'.inc.php';
        }
        else
        {
            var url= '/tpl/album_lof/inc/main.inc.php';
        }

        xmlHttp.onreadystatechange = function() { 
                                       if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
                                                getDiv(xmlHttp, div);
                                     }
        xmlHttp.open("POST",url,true);
        xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset=UTF-8;');
        xmlHttp.send('action='+act+'&value='+str);
    } else {
        return true;
    }
}

function checkPassword(str1, str2, div, inc)
{
    if(str1!='none' && str2!='none')
    {
        xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request")
            return true;
        } 

        if(inc != undefined)
        {
            var url= '/tpl/album_lof/inc/'+inc+'.inc.php';
        }
        else
        {
            var url= '/tpl/album_lof/inc/main.inc.php';
        }

        xmlHttp.onreadystatechange = function() { 
                                       if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
                                                getDiv(xmlHttp, div);
                                     }
        xmlHttp.open("POST",url,true);
        xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset=UTF-8;');
        xmlHttp.send('action=check_password&password='+str1+'&password_verify='+str2);
    } else {
        return true;
    }
}

function getForm(str)
{ 
    if(str!='none')
    {
        xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request")
            return
        } 
    var url="inc/"+document.getElementById("form_name").value+".form.php";
    xmlHttp.onreadystatechange=stateChanged(div);
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset=UTF-8;');
    xmlHttp.send('contact_id='+str);
    }
}

function stateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        document.getElementById("content").innerHTML=xmlHttp.responseText;
    }
}

function GetXmlHttpObject()
{ 
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
}

function toggle_item (element) {
    for (var i = 0; i < document.getElementsByName(element).length; i++) {
        if(document.getElementsByName(element)[i].style.display == "none") {
            document.getElementsByName(element)[i].style.display = "";
        } else {
            document.getElementsByName(element)[i].style.display = "none";
        }
    } 
}

function open_player(url) {
    playerWindow = window.open(url, "player", "background-color=black,width=316,height=350,toolbar=no,status=no,scrollbars=no,resizeable=no,menubar=no");
    playerWindow.focus();
}
