function IsAllSpace(strValue) {
    var re = /^\s*$/;
    return re.test(strValue);
}

function IsNumber(strValue) {
    var re = /^\d*$/;
    return re.test(strValue);
}
function IsAllZero(s){
    var i;
    var counter = 0;
    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (c == "0") {
          counter++;
        }
    }
    if (counter >= s.length) {
       return true;
    }
    return false;
}
function isEmailValid(emailAddress) {
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,8}|[0-9]{1,3})(\\]?)$");
    return (!r1.test(trim(emailAddress)) && r2.test(trim(emailAddress)));
}
function trim(inputString) {
    // Removes leading and trailing spaces from the passed string. Also removes
    // consecutive spaces and replaces it with one space. If something besides
    // a string is passed in (null, custom object, etc.) then return the input.
    if (typeof inputString != "string") {
        return inputString;
    }
    var retValue = inputString;
    var ch = retValue.substring(0, 1);
    while (ch == " ") { // Check for spaces at the beginning of the string
        retValue = retValue.substring(1, retValue.length);
        ch = retValue.substring(0, 1);
    }
    ch = retValue.substring(retValue.length - 1, retValue.length);
    while (ch == " ") { // Check for spaces at the end of the string
        retValue = retValue.substring(0, retValue.length - 1);
        ch = retValue.substring(retValue.length - 1, retValue.length);
    }
    while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
        retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length); // Again, there are two spaces in each of the strings
    }
    return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function
// Validate location information from a form
function validateCustomerInput() {
    if (IsAllSpace(document.form1.Name.value)) {
        document.form1.Name.focus();
        alert("Please enter Your First Name.")
        return false;
    }
    if (isEmailValid(document.form1.email.value) == false) {
		document.form1.email.focus();
        alert("Your email address is not properly formed.  Please change it and try again.");
        return false;
    }
     return true;
}
function validateFreeTourInput() {
    if (IsAllSpace(document.form2.fname.value)) {
        document.form2.fname.focus();
        alert("Please enter Your First Name.")
        return false;
    }
    if (isEmailValid(document.form2.email.value) == false) {
		document.form2.email.focus();
        alert("Your email address is not properly formed.  Please change it and try again.");
        return false;
    }
	    // Phone number check
    if (!IsNumber(document.form2.CTNAreaCode.value) || document.form2.CTNAreaCode.value.length != 3) {
        document.form2.CTNAreaCode.focus();
        alert("Please enter valid Phone Number.")
        return false;
    }

    if (!IsNumber(document.form2.CTNPrefix.value) || document.form2.CTNPrefix.value.length != 3) {
        document.form2.CTNPrefix.focus();
        alert("Please enter valid Phone Number.")
        return false;
    }

	if (!IsNumber(document.form2.CTNNumber.value) || document.form2.CTNNumber.value.length != 4) {
        document.form2.CTNNumber.focus();
        alert("Please enter valid Phone Number.")
        return false;
    }
	    if (IsAllZero(document.form2.CTNAreaCode.value) &&
        IsAllZero(document.form2.CTNPrefix.value) &&
        IsAllZero(document.form2.CTNNumber.value)) {
        document.form2.CTNAreaCode.focus();
        alert("Phone Number cannot be zero.")
        return false;
    }

     return true;
}
