function CheckForm(theForm) {
    var why = "";
    why += checkFullName(theForm.txtFullName.value);
    why += checkJobTitle(theForm.txtJobTitle.value);
    why += checkOrganization(theForm.txtOrganization.value);
    why += checkWebSite(theForm.txtWebSite.value);
    why += checkEmail(theForm.txtEMail.value);
    why += checkPhone(theForm.txtPhone.value);
    why += checkTimeFrame(theForm.ddlTimeFrame.value);
    why += checkHidden1(theForm.Hidden1.value);
    why += checkHidden2(theForm.Hidden2.value);
    why += checkCurrentProgram(theForm.txtOtherInfo.value);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

// Full Name is required
function checkFullName (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your Full Name. Full Name is required.\n";
}
return error;
}
// Current Program is required 
function checkCurrentProgram (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your current program. Current Program field is required.\n";
}
return error;
}

// Job Title is required
function checkJobTitle (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your Job Title. Job Title is required.\n";
}
return error;
}

// Organization is required
function checkOrganization (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your Organization's name. Organization is required.\n";
}
return error;
}

// Web Site is required
function checkWebSite (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your Web Site address. Web Site is required.\n";
}
return error;
}

// EMail is required & EMail format is invalid
function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address. EMail is required.\n";
   return error;
}
    var emailFilter=/^.+@.+\..{2,4}$/;
    if (!(emailFilter.test(strng))) {
       error = "Please enter a valid email address. EMail format is invalid.\n";
    }
    else {
	//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters. EMail format is invalid.\n";
       }
    }
return error;
}

// Phone is required
function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a phone number. Phone is required.\n";
   return error;
}
else{
	//test Phone Number for illegal characters
	var stripped = strng.replace(/[\(\)\.\-\ \+]/g, ''); //strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.\n";
    }
    else {
	    if (!(isInteger(stripped))) {
		   error = "The phone number contains illegal characters.\n";
		}
		else {
			if (stripped.length < 10) {
				error = "The phone number is the wrong length. Make sure you included an area code.\n";
			}
	    return error;
		}
	}
    return error;
  }
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


// Time Frame is required
function checkTimeFrame (strng) {
var error = "";
if (strng == "" || strng == "Select a purchase time frame") {
   error = "You didn't select a purchase Time Frame. Time Frame is required.\n";
}
return error;
}


// Hidden1 should not be populated
function checkHidden1 (strng) {
var error = "";
strng = trim(strng);
if (strng != "") {
   error = ""; //This is a bot
}
return error;
}


// Hidden2 should not be populated
function checkHidden2 (strng) {
var error = "";
strng = trim(strng);
if (strng != "") {
   error = ""; //This is a bot
}
return error;
}


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
