// JavaScript Document


function checkFields() 
{
    var strName = document.contact.name.value
	var strAddress = document.contact.address.value
	var strCity = document.contact.city.value
	var strState = document.contact.state.value
	var strEmail = document.contact.email.value
	var strPhone = document.contact.phone.value
	
		
	//below checks for empty required fields
	if ((strName=='') || (strName.charAt(0)== " ")) 
	{   
		  alert("You must enter your name to proceed.");
		  document.contact.name.focus();
		  document.contact.name.select();							
		  return false;									
	}
	
	
	//below checks for empty required fields
	if ((strAddress=='') || (strAddress.charAt(0)== " ")) 
	{   
		  alert("You must enter your address to proceed.");
		  document.contact.address.focus();
		  document.contact.address.select();							
		  return false;									
	}
	
	
	if ((strCity=='') || (strCity.charAt(0)== " ")) 
	{   
		  alert("You must enter your city to proceed.");
		  document.contact.city.focus();
		  document.contact.city.select();							
		  return false;									
	}
	
	
	if (document.contact.state.selectedIndex==0) 
	{   
		  alert("You must choose your state to proceed.");							
		  return false;									
	}
	
	if ((strEmail=='') || (strEmail.charAt(0)== " "))
	{   
		  alert("You must enter your email address to proceed.");
		  document.contact.email.focus();
		  document.contact.email.select();							
		  return false;									
	}
	
	
	
	//below verifies the email address for correct email format
	if (document.contact.email.value.indexOf("@") == -1					// Checks if location of @ exists 
			|| document.contact.email.value.indexOf(".") == -1)			// or if location of . exists
		{alert("You have entered an invalid email address!")
		 document.contact.email.focus();
		document.contact.email.select();
		 return false;
		}
		
	if ((strPhone=='') || (strPhone.charAt(0)== " "))
	{   
		  alert("You must enter your telephone number to proceed.");
		  document.contact.phone.focus();
		  document.contact.phone.select();							
		  return false;									
	}
	
	
	//below is the phone number validation
	  var num = new Array();
	  var p = /(\d{3})\D*(\d{3})\D*(\d{4})/;	// \d means any digit, {3} means 3 of them, \D* means any amount 
	  num = document.contact.phone.value.match(p);	// of non-digit characters
	  if (num != null) 
	   {
		document.contact.phone.value="(" + num[1] + ") "+num[2]+ "-" +num[3]
		}
	  else 
	   { 
		alert(" Invalid telephone number:\n Enter 3 digit area code and 7 digit number")
		document.contact.phone.focus();
		document.contact.phone.select();
		return false;
	   }	

	return true;
} 


var myimages=new Array()
function preloadimages()
{
	for (i=0;i<preloadimages.arguments.length;i++)
	{
		myimages[i]=new Image()
		myimages[i].src=preloadimages.arguments[i]
	}
}
preloadimages("/images/tabs2.gif","/images/tabr2.gif","/images/tab2.gif");


