var xmlHttp

function showSuppliers(subCatID, subCatName)
{
    if(subCatID !='')
    {
        var url="Control.php";
        url=url+"?action=showSuppliers";
        url=url+"&subCatID="+subCatID;
        url=url+"&subCatName="+subCatName;
        location.href=url;
    }
}
function addSubCategoryToAccount(subCatID, accountid)
{
    if(subCatID !='')
    {
        var url="Control.php";
        url=url+"?action=addSubCategoryToAccount";
        url=url+"&subCatID="+subCatID;
        url=url+"&accountID="+accountid;
        location.href=url;
    }
}
function getAccount(str)
{     
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="Control.php"
    url=url+"?AccountID="+str
    url=url+"&action=showEditAccount"
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}
function showReport(name)
{
    var url= 'Control.php?action=showReport&reportName='+name;
    document.getElementById('report').src=url;
    return false;
}
function setAccountActive(accountid, active)
{     
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="Control.php";
    url=url+"?AccountID="+accountid;
    url=url+"&Active="+active;
    url=url+"&action=activate";
    xmlHttp.onreadystatechange=accountActivestateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

function getAvailableSubCategoriesForAccount(accountID, catID)
{     
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="../Logic/AccountCategoryLogic.php";
    url=url+"?catID="+catID;
    url=url+"&accountID="+accountID;
    url=url+"&action=GetAvailableSubCategoriesForAccount";
    xmlHttp.onreadystatechange=subCategoryStateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

function getSubCatagoriesForAccount(accountID)
{     
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="../Logic/AccountCategoryLogic.php";
    url=url+"?accountID="+accountID;
    url=url+"&action=GetSubsForAccount";
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

function addSubToAccount(accountID, subid, admin)
{
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="../Logic/AccountCategoryLogic.php";
    url=url+"?accountID="+accountID;
    url=url+"&subCatID="+subid;
    url=url+"&action=AddSubCategoryToAccount";
    location.href=url;
}
function getAccountCategoryMgnt(accountID)
{
    var url="Control.php";
    url=url+"?action=showAssignSubCategories&accountID="+accountID;
    document.getElementById('view').src=url;
    return false;
}
function refresh()
{
    window.location.reload( false );
}
function validatePwd(form)
{
    var invalid = " "; // Invalid character is a space
    var minLength = 6; // Minimum length
    var pw1 = form.password.value;
    var pw2 = form.confirm_password.value;
    // check for a value in both fields.
    if (pw1 == '' || pw2 == '')
    {
        alert('Please enter your password twice.');
        return false;
    }
    // check for minimum length
    if (form.password.value.length < minLength)
    {
        alert('Your password must be at least ' + minLength + ' characters long. Try again.');
        return false;
    }
    // check for spaces
    if (form.password.value.indexOf(invalid) > -1)
    {
        alert("Sorry, spaces are not allowed.");
        return false;
    }
    else
    {
        if (pw1 != pw2)
        {
            alert ("You did not enter the same new password twice. Please re-enter your password.");
            return false;
        }
        else
        {
            return true;
        }
    }
}
function accountActivestateChanged() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
//alert(xmlHttp.responseText);
} 
}
function stateChanged() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
        document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
    } 
}
function subCategoryStateChanged() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
        document.getElementById("txtSubs").innerHTML=xmlHttp.responseText;
    } 
}
function addSubCatStateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
//alert(xmlHttp.responseText);
}
}
function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        //Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}
