﻿function popitup() {
    window.alert("I’m sorry without this documentation we are unable to offer you employment.")
}

function isEmailAddr(s) {
    var rv = false
    if ((s == null) || (s.length == 0)) {
        rv = false;
    } else {
        var reEmail = /([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        //reEmail = /.+\@.+\..+$/

        rv = reEmail.test(s)
    }
    if (rv) {
        return rv
    } else {
        return false
    }
}

function IsNumeric(strString)
//  check for valid numeric strings	
{
    var strValidChars = "0123456789.- ";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}


function validateRadio(theRadio) {
    // set var radio_choice to false
    var radio_choice = false;

    // Loop from zero to the one minus the number of radio button selections
    for (counter = 0; counter < theRadio.length; counter++) {
        // If a radio button has been selected it will return true
        // (If not it will return false)
        if (theRadio[counter].checked) {
            radio_choice = true;
            strRadioValue = theRadio[counter].value;
        }
    }
    if (!radio_choice) {
        return (false);
    }
    return (true);
}

function validation(theForm) {
    /*
    if (!IsNumeric(theForm.home_phone_number.value)) {
        alert("Please check your home phone number. Make sure they are all numbers.");
        theForm.home_phone_number.focus();
        return (false);
    }

    if (!IsNumeric(theForm.work_phone_number.value)) {
        alert("Please check your work phone number. Make sure they are all numbers.");
        theForm.work_phone_number.focus();
        return (false);
    }

    if (!IsNumeric(theForm.mobile_phone_number.value)) {
        alert("Please check your mobile phone number. Make sure they are all numbers.");
        theForm.mobile_phone_number.focus();
        return (false);
    }

    if (!isEmailAddr(theForm.email_from.value)) {
        alert("Please check your email address. Make sure it is like example@domain.co.nz");
        theForm.email_from.focus();
        return (false);
    }
    */
    if (!validateRadio(theForm.NZ_Citizen)) {
        alert("Sorry, since you do not have the right legal documentation, you can not proceed with the application.");
        theForm.NZ_Citizen[0].focus();
        return (false);
    }

    if (theForm.NZ_Citizen[0].checked && (!validateRadio(theForm.have_evidence_of_citizenship) || theForm.have_evidence_of_citizenship[1].checked)) {
        alert("Sorry, since you do not have the right legal documentation, you can not proceed with the application.");
        theForm.have_evidence_of_citizenship[0].focus();
        return (false);
    }

    if (theForm.NZ_Citizen[1].checked && !validateRadio(theForm.have_perm_residence_or_work_visa)) {
        alert("Sorry, since you do not have the right legal documentation, you can not proceed with the application.");
        theForm.have_perm_residence_or_work_visa[0].focus();
        return (false);
    }

    if (theForm.NZ_Citizen[1].checked && theForm.have_perm_residence_or_work_visa[1].checked) {
        alert("Sorry, since you do not have the right legal documentation, you can not proceed with the application.");
        theForm.NZ_Citizen[0].focus();
        return (false);
    }
    if (theForm.NZ_Citizen[1].checked && theForm.have_perm_residence_or_work_visa[0].checked && theForm.work_permit_expiry_date.value == "") {
        alert("Sorry, since you do not have the right legal documentation, you can not proceed with the application.");
        theForm.work_permit_expiry_date.focus();
        return (false);
    }

    return (true);
}