﻿//Contact-US Validation

function checksubmit()
	{
	 if (document.email_contact.contact_name.value == "")
		{	alert("Please enter your name."); document.email_contact.contact_name.focus(); return false;	}
	 if (document.email_contact.phone.value == "")
		{	alert("Please enter your phone number."); document.email_contact.phone.focus(); return false; }
	 if (document.email_contact.email.value == "")
		{	alert("Please enter your email address.");	document.email_contact.email.focus(); return false;	}
		else 
			{
			 tmp = new String(document.email_contact.email.value);
			 tmp2 = tmp.split("@")
			 if (tmp2.length != 2)
				{	alert("Not a valid email address!"); document.email_contact.email.focus(); return false;}
			 if (tmp2[0] == '')
				{	alert("Not a valid email address!"); document.email_contact.email.focus(); return false;}
				tmp3 = tmp2[1].split('.')
				if (tmp3.length < 2)
					{	alert("Not a valid email address!"); document.email_contact.email.focus(); return false;}
				i = tmp3.length
				  for (j = 0; j<i ;j++)
					{
				 	 if (tmp3[j] =="")
				 	 {	alert("Not a valid email address!"); document.email_contact.email.focus(); return false;}
			}
				 
		 }
	 if (document.email_contact.confirm_email.value != document.email_contact.email.value)
		{	alert("Your email address does not match.");	document.email_contact.email.focus(); return false;	}
	 if (document.email_contact.subject.value == "select")
		{	alert("Please enter a subject for your message."); document.email_contact.subject.focus(); return false; }
	 if (document.email_contact.textarea.value == "")
		{	alert("Please enter your message."); document.email_contact.textarea.focus(); return false; }
	 document.email_contact.submit();
	}

//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 + theString.charAt(i);
			else if (theString.charAt(i) == "(" || theString.charAt(i) == ") " || theString.charAt(i) == "-" || theSt == ") " || theString.charAt(i) == "-" || theString.charAt(i) == " ")

			{

				

			}

			else 

			{

				return ("");

			}

		}

		return(newString);

	}

	function checkValidPhone(control)

	{

		var temp = elimChars(control.value);

		if (temp.length != 10)

		{

			alert("Invalid Phone Number \n Please Enter a Valid Phone Number");

			control.focus();

			control.select();

		}

		else

		{

			control.value = "(" + 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); 

		}

	}
