//--------------------------------------------------------------------------
// Function    : validateSignUpForm(form,mode,cbJobTitle, gvManagement,txtFirstName,txtLastName,txtEmail,txtOther,errControl)
// Description : This function validates SignUp Form
//             : Updated on 08/28/2009 by HMK
//--------------------------------------------------------------------------
function validateSignUpForm(form, mode, cbJobTitle, gvManagement, txtFirstName, txtLastName, txtEmail, txtOther, errControl) {
    var isCheckedOther = false;

    if (txtOther != null) {
        if (txtOther.value == "")
            isCheckedOther = false;
        else
            isCheckedOther = true;
    }

    var isValidated = ValidateForm(form, mode);
    var isDateValidatedJobList = CheckDate(document.getElementById(GetClientId("gvJobList")));
    var isDateValidatedManagementJob = CheckDate(document.getElementById(GetClientId("gvManagementJob")));

    var resultOrganization = ValidateOrganization(document.getElementById(GetClientId("rbOrganizationSelect")).checked, document.getElementById(GetClientId("rcbOrganization")), document.getElementById("errRcbOrganization"));
    var resultSupervisor = ValidateSupervisor(document.getElementById(GetClientId("rbSupervisorSelect")).checked, document.getElementById(GetClientId("rcbSupervisor")), document.getElementById("errRcbSupervisor"));

    var org = document.getElementById(GetClientId("rcbOrganization_Input"));
    var sup = document.getElementById(GetClientId("rcbSupervisor_Input"));

    if (isValidated && resultOrganization && resultSupervisor && isDateValidatedJobList && isDateValidatedManagementJob) {
        return true;
    }
    else {
        if (txtFirstName.value == "") {
            txtFirstName.focus();
        }
        else if (txtLastName.value == "") {
            txtLastName.focus();
        }
        else if (txtEmail.value != undefined && (txtEmail.value == "" || !(checkEmail(txtEmail.value)))) {
            txtEmail.focus();
        }

        else if (!org.isDisabled && !resultOrganization) {
            org.focus();
        }
        else if (!sup.isDisabled && !resultSupervisor) {
            sup.focus();
        }
        return false;
    }
}

//--------------------------------------------------------------------------
// Function    : ValidateSignInForm(frm,mode,errorControl)
// Description : This function validates SignUp Form
//--------------------------------------------------------------------------
function ValidateSignInForm(frm, mode, errorControl) {
    if (errorControl != "undefined") {
        errorControl.style.visibility = "hidden";
        errorControl.innerHTML = '';
    }

    memberId = document.getElementById(GetClientId("txtMemberId")).value;
    password = document.getElementById(GetClientId("txtPassword")).value;

    var result = true;

    // check user name
    if (memberId == '') {
        errorControl.innerHTML = 'Please enter Member ID';
        result = false;
    }
    else if (!checkAlphanumeric(memberId)) {

        errorControl.innerHTML = "<br/>Please enter valid Member ID";
        result = false;
    }

    // check password
    if (password == '') {
        errorControl.innerHTML += '<br/>Please enter Password';
        result = false;

    }
    else if (!checkAlphanumeric(password)) {
        errorControl.innerHTML += '<br/>Please enter valid password';
        result = false;
    }

    if (!result) {
        if (errorControl != "undefined") {
            errorControl.style.visibility = 'visible';
            window.location = '#ancTopLock';
        }
    }

    return result;
}

//--------------------------------------------------------------------------
// Function    : CheckDate(obj) 
// Description : Check the dates and validate the RadDatePicker
//--------------------------------------------------------------------------

function CheckDate(obj) 
{
    var result = true;
    var joblist = obj;
    var index = 2;
    var cbJobType = null;
    var errStartDate = null;
    var date = null;

    for (index; index <= joblist.rows.length; index++) {

        if (index < 10) {
            cbJobType = document.getElementById(joblist.id + "_ctl0" + index + "_cbJobType");
            errStartDate = document.getElementById(joblist.id + "_ctl0" + index + "_errStartDate");
            date = document.getElementById(joblist.id + "_ctl0" + index + "_rdpStartDate_dateInput_text");
        }
        else {
            cbJobType = document.getElementById(joblist.id + "_ctl" + index + "_cbJobType");
            errStartDate = document.getElementById(joblist.id + "_ctl" + index + "_errStartDate");
            date = document.getElementById(joblist.id + "_ctl" + index + "_rdpStartDate_dateInput_text");
        }
        
        if (cbJobType == undefined || date == undefined || date == null || cbJobType == null) continue;

        if (cbJobType.checked == true && date.value.trim() == "") {
            errStartDate.innerHTML = "Please select date";
            date.focus();
            result = false;
        }
        else 
        {
            errStartDate.innerHTML = "";
        }
    }
    return result;
}