﻿_spBodyOnLoadFunctionNames.push('disableBusControls');
_spBodyOnLoadFunctionNames.push('disablePhoneControls');

function disablePhoneControls() {
    var entry = document.getElementById(pnlEntry);
    if (entry != null) {
        ValidatorEnable(document.getElementById(reqcountryhome), false);
        ValidatorEnable(document.getElementById(reqnumberHome), false);
        ValidatorEnable(document.getElementById(reqcountrywork), false);
        ValidatorEnable(document.getElementById(reqnumberwork), false);
        ValidatorEnable(document.getElementById(reqcountryfax), false);
        ValidatorEnable(document.getElementById(reqnumberfax), false);
    }
}

function changeterms() {
    var hidden = document.getElementById(hiddenTerms);
    if (hidden.value == 'false')
        hidden.value = 'true';
    else
        hidden.value = 'false';
}

function PhoneValidatorManger(phonetype) {
    var homecountry = document.getElementById(ddlhomecountries);
    var homenumber = document.getElementById(tbHome);
    var homepreferred = document.getElementById(rbhomephone);
    var homecountryvalid = document.getElementById(reqcountryhome);
    var homenumbervalid = document.getElementById(reqnumberHome);

    var workcountry = document.getElementById(ddlworkcountries);
    var worknumber = document.getElementById(tbwork);
    var workpreferred = document.getElementById(rbwork);
    var workcountryvalid = document.getElementById(reqcountrywork);
    var worknumbervalid = document.getElementById(reqnumberwork);

    var faxcountry = document.getElementById(ddlfaxcountries);
    var faxnumber = document.getElementById(tbFax);
    var faxpreferred = document.getElementById(rbFax);
    var faxcountryvalid = document.getElementById(reqcountryfax);
    var faxnumbervalid = document.getElementById(reqnumberfax);

    var countryvalue;
    var numbervalue;
    var preferredvalue;
    var countryvalid;
    var numbervalid;

    countryvalue = homecountry.value;
    numbervalue = homenumber.value;
    preferredvalue = homepreferred.checked;
    countryvalid = homecountryvalid;
    numbervalid = homenumbervalid;
    if (countryvalue != '-1' || numbervalue != '' || preferredvalue) {
        ValidatorEnable(countryvalid, true);
        ValidatorEnable(numbervalid, true);
    }
    else {
        ValidatorEnable(countryvalid, false);
        ValidatorEnable(numbervalid, false);
    }


    countryvalue = workcountry.value;
    numbervalue = worknumber.value;
    preferredvalue = workpreferred.checked;
    countryvalid = workcountryvalid;
    numbervalid = worknumbervalid;
    if (countryvalue != '-1' || numbervalue != '' || preferredvalue) {
        ValidatorEnable(countryvalid, true);
        ValidatorEnable(numbervalid, true);
    }
    else {
        ValidatorEnable(countryvalid, false);
        ValidatorEnable(numbervalid, false);
    }


    countryvalue = faxcountry.value;
    numbervalue = faxnumber.value;
    preferredvalue = faxpreferred.checked;
    countryvalid = faxcountryvalid;
    numbervalid = faxnumbervalid;
    if (countryvalue != '-1' || numbervalue != '' || preferredvalue) {
        ValidatorEnable(countryvalid, true);
        ValidatorEnable(numbervalid, true);
    }
    else {
        ValidatorEnable(countryvalid, false);
        ValidatorEnable(numbervalid, false);
    }


}


function clearHobby(myvalue) {
    if (myvalue == 'Other') {
        //Change class of the textbox to the text not dimmed
        document.getElementById(tbOtherHobby).value = '';
    }
}

function fillHobby(myvalue) {
    if (myvalue == '') {
        //Change class of the textbox to the text dimmed
        document.getElementById(tbOtherHobby).value = 'Other';
    }
}

function clearTitle(myvalue) {
    if (myvalue == 'Other') {
        //Change class of the textbox to the text not dimmed
        document.getElementById(tbOtherTitle).value = '';
    }
}

function fillTitle(myvalue) {
    if (myvalue == '') {
        //Change class of the textbox to the text dimmed
        document.getElementById(tbOtherTitle).value = 'Other';
    }
}

function enableBusControls() {
    var entry = document.getElementById(pnlEntry);
    if (entry != null) {
        if (document.getElementById(rbseaman).checked) {
            document.getElementById('astJobTitle').className = "Enable";
            document.getElementById('divtxtJobTitle').className = "Enable";
            document.getElementById('astDepartment').className = "Enable";
            document.getElementById('divtxtDepartment').className = "Enable";
            document.getElementById('astCompany').className = "Enable";
            document.getElementById('divtxtCompany').className = "Enable";


            ValidatorEnable(document.getElementById(valJobTitle), true);
            ValidatorEnable(document.getElementById(valDepartment), true);
            ValidatorEnable(document.getElementById(valCompany), true);
            var jobt = document.getElementById(tbJobTitle);
            jobt.disabled = false;
            var dep = document.getElementById(tbDepartment);
            dep.disabled = false;
            var comp = document.getElementById(tbCompany);
            comp.disabled = false;
            var buscategory = document.getElementById(ddlBusCategory);
            buscategory.disabled = false;
        }
    }
}

function disableBusControls() {
    var entry = document.getElementById(pnlEntry);
    if (entry != null) {
        if (!document.getElementById(rbseaman).checked) {
            document.getElementById('astJobTitle').className = "Disable";
            document.getElementById('divtxtJobTitle').className = "Disable";
            document.getElementById('astDepartment').className = "Disable";
            document.getElementById('divtxtDepartment').className = "Disable";
            document.getElementById('astCompany').className = "Disable";
            document.getElementById('divtxtCompany').className = "Disable";

            ValidatorEnable(document.getElementById(valJobTitle), false);
            ValidatorEnable(document.getElementById(valDepartment), false);
            ValidatorEnable(document.getElementById(valCompany), false);
            var jobt = document.getElementById(tbJobTitle);
            jobt.value = '';
            jobt.disabled = true;
            var dep = document.getElementById(tbDepartment);
            dep.value = '';
            dep.disabled = true;
            var comp = document.getElementById(tbCompany);
            comp.value = '';
            comp.disabled = true;
            var buscategory = document.getElementById(ddlBusCategory);
            buscategory.selectedIndex = 0;
            buscategory.disabled = true;
        }
    }
}
function validateBirthDate(source, clientside_arguments) {
    var birthtb = document.getElementById(tbBirth);
    var birthdate = birthtb.value;
    var birthday = birthdate.substr(0, 2) * 1;
    var birthmon = birthdate.substr(3, 2) * 1;
    birthmon = birthmon - 1;
    var birthyear = birthdate.substr(6, 4) * 1;
    var bdate = new Date();
    bdate.setFullYear(birthyear, birthmon, birthday);
    var maxdate = new Date();
    maxdate.setYear(maxdate.getFullYear() - 2);
    bdate.setHours(0, 0, 0, 0);
    maxdate.setHours(0, 0, 0, 0);
    if (bdate > maxdate)
        clientside_arguments.IsValid = false;
    else
        clientside_arguments.IsValid = true;
}

function validateExpiryDate(source, clientside_arguments) {
    var issuedate = document.getElementById(tbPassIssue);
    if (issuedate.value == '')
        clientside_arguments.isValid = false;
    else {
        var exptb = document.getElementById(tbPassExpiry);
        var expdate = exptb.value;
        var expday = expdate.substr(0, 2) * 1;
        var expmon = expdate.substr(3, 2) * 1;
        expmon = expmon - 1;
        var expyear = expdate.substr(6, 4) * 1;
        var edate = new Date();
        edate.setFullYear(expyear, expmon, expday);
        edate.setHours(0, 0, 0, 0);

        var issdate = issuedate.value;
        var issday = issdate.substr(0, 2) * 1;
        var issmon = issdate.substr(3, 2) * 1;
        issmon = issmon - 1;
        var issyear = issdate.substr(6, 4) * 1;
        var idate = new Date();
        idate.setFullYear(issyear, issmon, issday);
        idate.setHours(0, 0, 0, 0);

        var maxdate = new Date();
        maxdate.setFullYear(issyear + 10, issmon, issday);
        maxdate.setHours(0, 0, 0, 0);

        if (edate <= idate || edate > maxdate)
            clientside_arguments.IsValid = false;
        else
            clientside_arguments.IsValid = true;
    }
}

//ResetControls
function ResetControls() {
    document.forms[0].reset();
    unvalidate();
    disableBusControls();
}


function unvalidate() {
    var myValidators = Page_Validators;
    if ((typeof (myValidators) != "undefined") && (myValidators != null)) {
        for (i = 0; i < myValidators.length; i++) {
            var myValidator = myValidators[i];
            if (myValidator.style.visibility.length > 0 && myValidator.style.display.length == 0) {
                myValidator.style.visibility = 'hidden';
            }
            else if (myValidator.style.display.length > 0 && myValidator.style.visibility.length == 0) {
                myValidator.style.display = 'none';
            }
        }
    }
}
