function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
		alert(fieldLabel);
		formField.focus();
		result = false;
	}
	
	return result;
}
// Email Validation
function checkEmail(myForm,mess)
{
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,5})+$/.test(myForm.value))
 {
	return (true)
 }
	alert(mess);
	myForm.focus();
	return (false)
}

function isNotNumeric(str){
		for (var i = 0; i < str.length; i++)
		{
				var ch = str.substring(i, i + 1);
				if((ch < '0' || '9' < ch)) 
				{
					if(ch == "+" || ch == "-" || ch == "." || ch == ")" || ch == "("  || ch == " ") continue;
					return true;
				}
		}
		return false;
}
function isNotAlphabets(str){
		for (var i = 0; i < str.length; i++)
		{
				re = / /gi				//Replace the space between words with no space
				str = str.replace(re,"");
			
				var ch = str.substring(i, i + 1);
				
				if((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) 
				{
					return true;
				}
		}
		return false;
}

function contact_form(nForm) {
		
		 if(!validRequired(document.ChronoContact_contact_form.first_name,"Please enter your First Name"))
			return false;
		 if(isNotAlphabets(document.ChronoContact_contact_form.first_name.value))
		 {
			alert("Invalid characters in First Name.");
			document.ChronoContact_contact_form.first_name.focus();
			return false;
		 }
		if(!validRequired(document.ChronoContact_contact_form.last_name,"Please enter your Last Name"))
			return false;
		 if(isNotAlphabets(document.ChronoContact_contact_form.last_name.value))
		 {
			alert("Invalid characters in Last Name.");
			document.ChronoContact_contact_form.last_name.focus();
			return false;
		 }
		 if(!validRequired(document.ChronoContact_contact_form.company,"Please enter your Company"))
			return false;
		if (!checkEmail(document.ChronoContact_contact_form.email,"Please enter valid Email"))
			return false;
		if (!validRequired(document.ChronoContact_contact_form.phone,"Please enter your Phone Number"))
			return false;			
						
	 if(isNotNumeric(document.ChronoContact_contact_form.phone.value))
	 {
		alert("Invalid characters in phone.");
		document.ChronoContact_contact_form.phone.focus();
		return false;
	 }				
		if (!validRequired(document.ChronoContact_contact_form.message,"Please enter your Message"))
			return false;
return true;
}
function validatePhoneNumberWithAreaCode(elementValue){   
	var phoneNumberPattern = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;   
	return phoneNumberPattern.test(elementValue);   
} 
function validatePhoneNumber(elementValue){   
	var phoneNumberPattern = /^(\d{3})[- ]?(\d{4})$/;   
	return phoneNumberPattern.test(elementValue);   
}  
function validateBankRoutingNumber(value)
{
  var i, n, t;

  t = "";
  for (i = 0; i < value.length; i++)
  {
		c = parseInt(value.charAt(i), 10);
		if (c >= 0 && c <= 9)
			  t = t + c;
  }
  if (t.length != 9)
  {
	return false;
  }
  n = 0;
  for (i = 0; i < t.length; i += 3)
  {
    n += parseInt(t.charAt(i),     10) * 3
      +  parseInt(t.charAt(i + 1), 10) * 7
      +  parseInt(t.charAt(i + 2), 10);
  }
  if (!(n != 0 && n % 10 == 0))
  {
	return false;
  }
  return true;
}
