﻿
var aStateOptions = new Array();

function getSelectedList(e)
{
    var sTemp = "";
    
    if(e.options.length==0) return "";
    
    for(var i=0;i<e.options.length;i++)
    {
        if(e.options[i].selected) sTemp+=","+e.options[i].value;
    }
    
    return sTemp.substring(1);
}

function selCountry_onchange(sCountryList,sStateList,sStateText)
{
    var bFirst=false;
    var oCountry = e("selCountry");
    var oState = e("selState");
    var oStateText = e("txtState");
    
    if(sCountryList) oCountry = e(sCountryList);
    if(sStateList) oState = e(sStateList);
    if(!oCountry) return;
    
    if(aStateOptions.length==0)
    {
        for(var i=0;i<oState.options.length;i++)
        {
            aStateOptions[aStateOptions.length] = new Object();
            aStateOptions[aStateOptions.length-1].option = oState.options[i];
            aStateOptions[aStateOptions.length-1].countryid = oState.options[i].getAttribute("countryid");
            oState.options[i] = null;
            i--;
        }
    }

    if(oCountry.value == "1" || oCountry.value == "2" || oCountry.value == "98")
    {
        oState.style.display = "";
        oStateText.style.display = "none";
        
        for(var i=0;i<oState.options.length;i++)
        {
            oState.options[i] = null;
            i--;
        }
        
        for(var i=0;i<aStateOptions.length;i++)
        {
            if(aStateOptions[i].countryid == oCountry.value)
            {
                oState.options[oState.options.length] = aStateOptions[i].option;
            }
        }
        oState.options[0].selected = true;
    }
    else
    {
        oState.style.display = "none";
        oStateText.style.display = "";
    }
}



function selCompanyCountry_onchange()
{
    var oCountry = e("selCompanyCountry");
    var oState = e("selCompanyState");
    var oStateText = e("txtCompanyState");
    
    if(!oCountry) 
    {
        return;
    }
    
    if (aStateOptions.length==0)
    {
        for (var i=0;i<oState.options.length;i++)
        {
            aStateOptions[aStateOptions.length] = new Object();
            aStateOptions[aStateOptions.length-1].option = oState.options[i];
            aStateOptions[aStateOptions.length-1].countryid = oState.options[i].getAttribute("countryid");
            oState.options[i] = null;
            i--;
        }
    }
    
    if(oCountry.value == "1" || oCountry.value == "2" || oCountry.value == "98")
    {
        oState.style.display = "";
        oStateText.style.display = "none";
        oStateText.Value = "";
        
        for (var i=0;i<aStateOptions.length;i++)
        {
            if (aStateOptions[i].countryid == oCountry.value)
            {
                oState.options[oState.options.length] = aStateOptions[i].option;
            }
        }
        
        oState.options[0].selected = true;
    }
    else
    {
        oState.style.display = "none";
        oStateText.style.display = "";
    }
}

function btnTopLogin_onclick()
{
    var oForm;
    var oInput;
    
    oForm = document.createElement('form');
    oForm.action = '/Site/Login.aspx';
    oForm.method='post';
    
    oInput = document.createElement('input');
    oInput.name = 'txtLogin';
    oInput.value = e('txtTopLogin').value;
    oForm.appendChild(oInput);
    
    oInput = document.createElement('input');
    oInput.name = 'txtPassword';
    oInput.value = e('txtTopPassword').value;
    oForm.appendChild(oInput);
    
    e('btnTopLogin').disabled=true;
    
    document.getElementsByTagName("div")[0].appendChild(oForm);
    oForm.submit();
}

function btnSignUp_onclick()
{
    var sUrl="/Site/SignUp.aspx?";
    
    if(e("txtReturnUrl")) sUrl+="ReturnUrl="+escape(e("txtReturnUrl").value);
    if(e("txtSignUpType")) sUrl+="&UserType="+e("txtSignUpType").value;
    
    
    window.location = sUrl;
}

function openResult(a,b,c)
{
    if(c != undefined && c > 0)
    {
        return true;
    }
    else
    {
        window.open("JobDescription.aspx?a=" + a + "&b=" + b);
        return false;
    }
}


function getObjectFromXml(sXml)
{
    var oObject;
    var oDOMParser;
    
    if (typeof ActiveXObject != "undefined" && typeof GetObject != "undefined")
    {
        oObject = new ActiveXObject("Microsoft.XMLDOM");
        oObject.loadXML(sXml);
    }
    else if (typeof DOMParser != "undefined")
    {  
        oDOMParser = new DOMParser();
        oObject = oDOMParser.parseFromString(sXml, "application/xml");
    } 
    
    return oObject;
}