﻿//Contact-US Validation

function checksubmit()
	{
	 if (document.contact.contact_name.value == "")
		{	alert("Please enter your name."); document.contact.contact_name.focus(); return false;	}
	 if (document.contact.phone.value == "")
		{	alert("Please enter your phone number."); document.contact.phone.focus(); return false; }
	 if (document.contact.email.value == "")
		{	alert("Please enter your email address.");	document.contact.email.focus(); return false;	}
		else 
			{
			 tmp = new String(document.contact.email.value);
			 tmp2 = tmp.split("@")
			 if (tmp2.length != 2)
				{	alert("Not a valid email address!"); document.contact.email.focus(); return false;}
			 if (tmp2[0] == '')
				{	alert("Not a valid email address!"); document.contact.email.focus(); return false;}
				tmp3 = tmp2[1].split('.')
				if (tmp3.length < 2)
					{	alert("Not a valid email address!"); document.contact.email.focus(); return false;}
				i = tmp3.length
				  for (j = 0; j<i ;j++)
					{
				 	 if (tmp3[j] =="")
				 	 {	alert("Not a valid email address!"); document.contact.email.focus(); return false;}
			}
				 
		 }
	 if (document.contact.confirm_email.value != document.contact.email.value)
		{	alert("Your email address does not match.");	document.contact.email.focus(); return false;	}
	 if (document.contact.subject.value == "select")
		{	alert("Please enter a subject for your message."); document.contact.subject.focus(); return false; }
	 if (document.contact.textarea.value == "")
		{	alert("Please enter your message."); document.contact.textarea.focus(); return false; }
	 document.contact.submit();
	}
	
	function checksubmit_contactother()
	{
	 if (document.contact.contact_name.value == "")
		{	alert("Please enter your name."); document.contact.contact_name.focus(); return false;	}
	 if (document.contact.phone.value == "")
		{	alert("Please enter your phone number."); document.contact.phone.focus(); return false; }
	 if (document.contact.email.value == "")
		{	alert("Please enter your email address.");	document.contact.email.focus(); return false;	}
		else 
			{
			 tmp = new String(document.contact.email.value);
			 tmp2 = tmp.split("@")
			 if (tmp2.length != 2)
				{	alert("Not a valid email address!"); document.contact.email.focus(); return false;}
			 if (tmp2[0] == '')
				{	alert("Not a valid email address!"); document.contact.email.focus(); return false;}
				tmp3 = tmp2[1].split('.')
				if (tmp3.length < 2)
					{	alert("Not a valid email address!"); document.contact.email.focus(); return false;}
				i = tmp3.length
				  for (j = 0; j<i ;j++)
					{
				 	 if (tmp3[j] =="")
				 	 {	alert("Not a valid email address!"); document.contact.email.focus(); return false;}
			}
				 
		 }
	 if (document.contact.confirm_email.value != document.contact.email.value)
		{	alert("Your email address does not match.");	document.contact.email.focus(); return false;	}
	 if (document.contact.Subject.value == "")
		{	alert("Please enter a subject for your message."); document.contact.Subject.focus(); return false; }
	 if (document.contact.message.value == "")
		{	alert("Please enter your message."); document.contact.message.focus(); return false; }
	 document.contact.submit();
	}
	
	//Check Numeric

function IsNumeric(sText)

	{
		var ValidChars = "0123456789";
		var IsNumber=true;
		var Char;

		for (i = 0; i < sText.length && IsNumber == true; i++) 
			{ 
				Char = sText.charAt(i); 
				if (ValidChars.indexOf(Char) == -1) 
					{
						IsNumber = false;
					}
			}
		return IsNumber;
	}


//Phone Validation

	function elimChars(theString)
	{
		var newString = new String("");
		for (var i = 0; i < theString.length; i++)
		{
			if (theString.charAt(i) >= "0" && theString.charAt(i) <= "9")
				newString = newString + String(theString.charAt(i));
			else if (theString.charAt(i) == "(" || theString.charAt(i) == ")" || theString.charAt(i) == "-" || theString.charAt(i) == "-" || theString.charAt(i) == " ")
			{
			}
			else 
				return ("");
			
		}

		return(newString);
	}

	function checkValidPhone(control)
	{
		var temp = new String("");
		temp = elimChars(control.value);
		if (temp.length != 10)
		{
			alert("Invalid Phone Number \n Please Enter a Valid Phone Number");
			control.focus();
			control.select();
		}
		else
		{
			temp = "(" + temp.charAt(0)+ temp.charAt(1)+ temp.charAt(2) +") "+ temp.charAt(3)+ temp.charAt(4)+ temp.charAt(5) + "-"+ temp.charAt(6)+ temp.charAt(7)+ temp.charAt(8)+ temp.charAt(9);
			control.value = temp; 
		}

	}