function CountryCheck() {
        var ddCountry = $('ddCountry');
        var ddStateUSA = $('ddStateUSA'); var ddStateCanada = $('ddStateCanada'); var ddStateOthers = $('ddStateOthers');
        var divIRSSSN1 = $('divIRSSSN1'); var divIRSSSN2 = $('divIRSSSN2');

        if (ddCountry != null && typeof(ddCountry) != 'undefined' && ddCountry.value == "US") {    
        ddStateOthers.style.visibility = "hidden"; ddStateOthers.style.display = "none";
        ddStateCanada.style.visibility = "hidden"; ddStateCanada.style.display = "none";
        ddStateUSA.style.visibility = "visible"; ddStateUSA.style.display = "inline";
                if (divIRSSSN1 != null && typeof(divIRSSSN1) != 'undefined' && divIRSSSN2 != null && typeof(divIRSSSN2) != 'undefined') {
                        divIRSSSN1.style.visibility = 'visible';
                        divIRSSSN1.style.display = 'inline';
                        divIRSSSN2.style.visibility = 'visible';
                        divIRSSSN2.style.display = 'inline';                                    
                }                                       
        return;
    }
    if (ddCountry != null && typeof(ddCountry) != 'undefined' && ddCountry.value == "CA") {
        ddStateUSA.style.visibility = "hidden"; ddStateUSA.style.display = "none";
        ddStateOthers.style.visibility = "hidden"; ddStateOthers.style.display = "none";
        ddStateCanada.style.visibility = "visible"; ddStateCanada.style.display = "inline";
                if (divIRSSSN1 != null && typeof(divIRSSSN1) != 'undefined' && divIRSSSN2 != null && typeof(divIRSSSN2) != 'undefined') {
                        divIRSSSN1.style.visibility = 'hidden';
                        divIRSSSN1.style.display = 'none';
                        divIRSSSN2.style.visibility = 'hidden';
                        divIRSSSN2.style.display = 'none';                                      
                }                                       
        return;
    } else {
        ddStateUSA.style.visibility = "hidden"; ddStateUSA.style.display = "none";
        ddStateOthers.style.visibility = "visible"; ddStateOthers.style.display = "inline";
        ddStateCanada.style.visibility = "hidden"; ddStateCanada.style.display = "none";
                if (divIRSSSN1 != null && typeof(divIRSSSN1) != 'undefined' && divIRSSSN2 != null && typeof(divIRSSSN2) != 'undefined') {
                        divIRSSSN1.style.visibility = 'hidden';
                        divIRSSSN1.style.display = 'none';
                        divIRSSSN2.style.visibility = 'hidden';
                        divIRSSSN2.style.display = 'none';                                      
                }                                       
        return;
    }
}

function IrsSsnInit(data) {
        var ddIRS_SSN = $('ddIRS_SSN');
        if (ddIRS_SSN != null && typeof(ddIRS_SSN) != 'undefined') {
                ddIRS_SSN.selectedIndex = parseInt(data);    
        }
}
function CountryInit(country) {
        var ddCountry = $('ddCountry');
        if (ddCountry != null && typeof(ddCountry) != 'undefined' && country != null && typeof(country) != 'undefined') {       
                for (x = 0; x < ddCountry.options.length; x++) {
                        if (ddCountry.options[x].value == country.toString()) {
                                ddCountry.selectedIndex = x;    
                        }
                }
        }
}

function StateInit(state) {
        var ddStateUSA = $('ddStateUSA'); var ddStateCanada = $('ddStateCanada');

        if (ddStateUSA != null && typeof(ddStateUSA) != 'undefined' && ddStateCanada != null && typeof(ddStateCanada) != 'undefined') { 
                for (s = 0; s < ddStateCanada.options.length; s++) {
                        if (ddStateCanada.options[s].value == state.toString()) {
                                ddStateCanada.selectedIndex = s;    
                        }
                }
                for (t = 0; t < ddStateUSA.options.length; t++) {
                        if (ddStateUSA.options[t].value == state.toString()) {
                                if (divIRSSSN1 != null && typeof(divIRSSSN1) != 'undefined' && divIRSSSN2 != null && typeof(divIRSSSN2) != 'undefined') {
                                        divIRSSSN1.style.visibility = 'visible';
                                        divIRSSSN1.style.display = 'inline';
                                        divIRSSSN2.style.visibility = 'visible';
                                        divIRSSSN2.style.display = 'inline';                                    
                                }
                                ddStateUSA.selectedIndex = t;    
                        }
                }  
        }       
}

function cancelRegistration() {
    top.location="./index.php";
}
function returnToHome() {
    top.location="./index.php";
}


function submitRegistration() {
    var form = $("registration");
    if (form != undefined && form != null) {
                if (form.txtEmailAddress.value.length <= 0 || form.txtEmailAddress.value.length > 320) { alert(_PSA_LG_REGISTER_001); form.txtEmailAddress.focus(); form.txtEmailAddress.select(); return 0; }
                if (form.txtPassword.value.length <= 5 || form.txtPassword.value.length > 32) { alert(_PSA_LG_REGISTER_002); form.txtPassword.focus(); form.txtPassword.select(); return 0; }    
                if (form.txtPassword.value != form.txtPassword2.value) { alert(_PSA_LG_REGISTER_003); form.txtPassword.focus(); form.txtPassword.select(); return 0; }      
                if (form.txtBusinessName.value.length <= 0 || form.txtBusinessName.value.length > 250) { alert(_PSA_LG_REGISTER_004); form.txtBusinessName.focus(); form.txtBusinessName.select(); return 0; }       
                if (form.txtFirstName.value.length <= 0 || form.txtFirstName.value.length > 250) { alert(_PSA_LG_REGISTER_005); form.txtFirstName.focus(); form.txtFirstName.select(); return 0; } 
        if (form.txtLastName.value.length <= 0 || form.txtLastName.value.length > 250) { alert(_PSA_LG_REGISTER_006); form.txtLastName.focus(); form.txtLastName.select(); return 0; } 
        if (form.txtAddressLine1.value.length <= 0 || form.txtAddressLine1.value.length > 250) { alert(_PSA_LG_REGISTER_007); form.txtAddressLine1.focus(); form.txtAddressLine1.select(); return 0; } 
        if (form.txtAddressLine2.value.length > 250) { alert(_PSA_LG_REGISTER_008); form.txtAddressLine2.focus(); form.txtAddressLine2.select(); return 0;}    
        if (form.txtCity.value.length <= 0 || form.txtCity.value.length > 250) { alert(_PSA_LG_REGISTER_009); form.txtCity.focus(); form.txtCity.select(); return 0; } 
        if (form.ddCountry.options[form.ddCountry.selectedIndex].value.length <= 0) { alert(_PSA_LG_REGISTER_010); form.ddCountry.focus(); return 0; }  
        if (form.ddCountry[form.ddCountry.selectedIndex].value.toLowerCase() == "ca") { if ((form.ddStateCanada.selectedIndex == -1) || (form.ddStateCanada.selectedIndex == 0)) { alert(_PSA_LG_REGISTER_011); form.ddStateCanada.focus(); return 0; } }
        if (form.ddCountry[form.ddCountry.selectedIndex].value.toLowerCase()=="us") { if ((form.ddStateUSA.selectedIndex == -1) || (form.ddStateUSA.selectedIndex == 0)) { alert(_PSA_LG_REGISTER_012); form.ddStateUSA.focus(); return 0; } }
        if ((!form.ddCountry[form.ddCountry.selectedIndex].value.toLowerCase()=="ca") && (!form.ddCountry[form.ddCountry.selectedIndex].value.toLowerCase() == "us")) { if (form.ddStateOthers.value.length <= 0 || form.ddStateOthers.value.length > 250) { alert(_PSA_LG_REGISTER_013); form.ddStateOthers.focus(); form.ddStateOthers.select(); return 0; } }
        if (parseInt(_PSA_OPTION_IRSNAS_MANDATORY) == parseInt(1)) {
                        if (form.ddCountry.options[form.ddCountry.selectedIndex].value.toLowerCase() == "us") { if (form.ddIRS_SSN.options[form.ddIRS_SSN.selectedIndex].value.length <= 0 || form.txtIRS_SSN.value.length <= 0) { alert(_PSA_LG_REGISTER_014); return 0; } }
                }
        if (form.txtPostalCode.value.length <= 0 || form.txtPostalCode.value.length > 10) { alert(_PSA_LG_REGISTER_015); form.txtPostalCode.focus(); form.txtPostalCode.select(); return 0; }      
        if (form.txtPhone.value.length <= 0 || form.txtPhone.value.length > 50) { alert(_PSA_LG_REGISTER_016); form.txtPhone.focus(); form.txtPhone.select(); return 0; }     
        if (form.txtCell.value.length > 50) { alert(_PSA_LG_REGISTER_017); form.txtCell.focus(); form.txtCell.select(); return 0; }      
        if (form.txtPage.value.length > 50) { alert(_PSA_LG_REGISTER_018); form.txtPage.focus(); form.txtPage.select(); return 0; }       
        if (form.txtFax.value.length > 50) { alert(_PSA_LG_REGISTER_019); form.txtFax.focus(); form.txtFax.select(); return 0; }   
        if (!form.chkTermsOfUse.checked) { alert(_PSA_LG_REGISTER_020); form.chkTermsOfUse.focus(); return 0; }        
        if (form.txtImageCode.value.length != 8) { alert(_PSA_LG_REGISTER_021); form.txtImageCode.focus(); form.txtImageCode.select(); return 0; }                      
        form.submit();
    }
}
