﻿
function validate(field) {
    var valid = "0123456789-() "
    var ok = "yes";
    var temp;
    for (var i = 0; i < field.value.length; i++) {
        temp = "" + field.value.substring(i, i + 1);
        if (valid.indexOf(temp) == "-1") ok = "no";
    }
    if (ok == "no") {
        return 1;
    }
    if (!(exists(field.value))) {
        return 1;
    }
}

function exists(userEntry) {

    var aCharExists = 0;
    var entry = userEntry;

    if (entry) {
        for (var i = 0; i < entry.length; i++) {
            if (entry.charAt(i) != "") {
                aCharExists = 1;
            }
        }
    }

    if (!aCharExists) {
        return 0;
    }

    return 1;
}

function isLongerThan11(field) {
    if (field.substr(0, 7) == 'http://') {
        if (field.length < 11) {
            return 0;
        }
    }
    else {
        if (field.length < 4) {
            return 0;
        }
    }
    return 1;
}

function isChecked(field) {
    if (field.checked) {
        return 1;
    }
    return 0;
}

function multiSelectCheck(field) {
    var selectCount = 0;

    for (var i = 0; i < field.length; i++) {
        if (field.options[i].selected == true) {
            selectCount++;
        }
    }

    if (selectCount > 5) {
        return 0;
    }
    return 1;
}

function multiSelectCheck3(field) {
    var selectCount = 0;

    for (var i = 0; i < field.length; i++) {
        if (field.options[i].selected == true) {
            selectCount++;
        }
    }

    if (selectCount > 3) {
        return 0;
    }
    return 1;
}

//////////////////////////////////////////////////////////////////////
// validateForm() function:
// Validates input of entire form.
//////////////////////////////////////////////////////////////////////



function validateUpload() {

    var fixThis = "";

    if (!(exists(document.addregistration.name.value))) {
        fixThis += "Please input your Name.\n"
    }

    if (!(exists(document.addregistration.emailaddress.value))) {
        fixThis += "Please input a valid Email Address.\n"
    }

    if (!(exists(document.addregistration.password.value))) {
        fixThis += "Please enter a Password.\n"
    }

    if (!(exists(document.addregistration.passwordcheck.value))) {
        fixThis += "Please confirm the Password.\n"
    }

    if (!(document.addregistration.password.value == document.addregistration.passwordcheck.value)) {
        fixThis += "The passwords you entered did not match.\n"
    }


    if (fixThis != "") {
        alert(fixThis);

    } else {

        document.addregistration.submit();
    }
}


function validateLogon() {

    var fixThis = "";

    if (!(exists(document.logon.email.value))) {
        fixThis += "Please enter your email address.\n"
    }

    if (!(exists(document.logon.password.value))) {
        fixThis += "Please enter your password.\n"
    }

    if (fixThis != "") {
        alert(fixThis);

    } else {

        document.logon.submit();
    }
}

function validateData(objForm) {
    var fixThis = "";

    var selectBox = document.forms[0].location;
    user_input = selectBox.options[selectBox.selectedIndex].value

    if ((user_input == 0) || (objForm.keywords.value == "")) {
        fixThis = "Please select a location and keyword to setup your new job alert"
    }


    if (fixThis != "") {
        alert(fixThis);

    }
    else {
        objForm.submit();
    }
}

