//Form validation code
function Validate(WebToLeadForm){   
  if (!isProper(WebToLeadForm.name.value))      { alert("Please enter your name"); WebToLeadForm.name.focus(); return false;}
  if (!isValidEmail(WebToLeadForm.email.value))   { alert("Please enter your email address properly"); WebToLeadForm.email.focus(); return false; }
  if (!isValidPhone(WebToLeadForm.phone.value))   { alert("Please enter your telephone number properly"); WebToLeadForm.phone.focus(); return false; }
  if (!isProper(WebToLeadForm.inquiry.value))   { alert("Please enter some details so we may assist you better"); WebToLeadForm.inquiry.focus(); return false; }
  if (WebToLeadForm.inquiry.value.length > 250) { alert("Please limit your inquiry to 250 characters"); return false; }
  
  return true;
}

function isValidEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {return true;}
    else { return false; }
}

function isValidPhone(string) {
    if (string.removeNonDigits().search(/^[0-9]{7,}$/) != -1) {return true;}
    else { return false; }
}

function isProper(string) {
	if (string.search(/^\w(.+)$/) != -1) {return true;}
    else { return false; }
}

String.prototype.removeNonDigits = function() {
	filteredValues = "1234567890";     // Characters stripped out
	var returnString = "";
	for (var i = 0; i < this.length; i++) {  // Search through string and append to unfiltered values to returnString.
		var c = this.charAt(i);
		if (filteredValues.indexOf(c) != -1) returnString += c;
	}
	return returnString;
}

//Form validation code