// JavaScript Document
// Created By: Odlan
// Last Modified: 08/18/2007
var error_color = "#ffffcc";
// This string prototype will trim whitespace
String.prototype.trim = function () {
    return this.replace(/^\s*|\s*$/,"");
}
// This function will trim any value entered and determined if its empty
// Uses: textboxes, textareas
function IsEmpty(inVal){
    return (inVal.trim() == "")? 1 : 0;
}
// This function will check a value and determine if its empty
// Uses: select boxes
function IsNotSelected(objName){
    return (objName.options[objName.selectedIndex].value == "")? 1 : 0;
}
// This function checks for valid email addresses
function IsValidEmail(inVal) {
   return (inVal.indexOf(".") > 2) && (inVal.indexOf("@") > 0);
}

// This function prepares the divs display and the alert messages during errors
function ShowFormError(objName, msg){
    msg = 'ERROR!\n' + msg + '\n';
    alert(msg);
    objName.style.background = error_color;
    objName.focus();
}
// This function encompasses all the necessary checks prior to form submission
function CheckForm(f){
    if (true) { // Toggle on/off form checking
        if (IsEmpty(f.moi.value.trim())) { ShowFormError(f.moi,'Contact Name Required.'); return false; }
        if (IsEmpty(f.addy.value.trim()) || !IsValidEmail(f.addy.value.trim())) { ShowFormError(f.addy,'Contact Email Required. Please make sure it is a valid email address.'); return false; }
        if (IsEmpty(f.v_code.value.trim())) { ShowFormError(f.v_code,'Please enter the Verify Code .'); return false; }
       //if (IsNotSelected(f.element7)) { ShowFormError(f.element7,'Requestor Location Required.'); return false; }
    }
    return true;
}