// JavaScript Document

function validateForm(form)
{ 	
	
	var firstname = form.firstname.value; 
	var lastname = form.lastname.value;
	var email = form.email.value;
	var phone = form.phone.value;
	var cellphone = form.cellphone.value;
	var message = form.message.value;
	
		
	if(firstname == "")
	{ 
		
		alert("Please enter your first name."); 
		form.firstname.focus(); 
		return false; 
		
	}
	
	if(lastname == "")
 	{ 
		
		alert("Please enter your last name.");
		form.lastname.focus(); 
		return false; 
		
	}
	

	
	

	if(email == "")
	{ 
		alert("Please enter your email.");
		form.email.focus(); 
		return false; 
			
	}
	if(email != "")
	{
		var okEmail = form.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
		if (okEmail)
		{
			ok = true;
		} 
		else 
		{
		   alert("Please enter a valid email address.");
		   form.email.focus();
		   form.email.select();
		   ok = false;
		   return false;
		}  
	}

	if(phone == "" && cellphone == "")
	{ 
		alert("Please enter a phone number where you can be reached.");
		form.cellphone.focus();	
		return false; 
	}	
	if(phone != "")
	{
		//alert("Please enter your phone.");
		//phonechar = phone.charAt(0); 
		//alert(phonechar);
		if(phone.length < 10)
		{ 
			alert("Please enter your phone number in the following format. (505) 555-1111"); 
			form.phone.focus(); 
			return false; 
		}
					
		for(var i = 0; i != phone.length; i++)
		{
			var phonechar = phone.substring(i, i + 1); 
			//alert(phonechar); 
			//
			if(phonechar < "0" || phonechar > "9" )
			{ 
				if (phonechar != "(" && phonechar != " " && phonechar != ")" && phonechar != "-")
				{
					//alert(phonechar); 
					alert("Please enter your phone number in the following format. (505) 555-1111"); 
					form.phone.focus(); 
					return false; 
				}
			}
			//)
		}
			
	}
	
	if(cellphone != "")
	{
		//alert("Please enter your phone.");
		//phonechar = phone.charAt(0); 
		//alert(phonechar);
		if(cellphone.length < 10)
		{ 
			alert("Please enter your cell phone number in the following format. (505) 555-1111"); 
			form.cellphone.focus(); 
			return false; 
		}
					
		for(var i = 0; i != cellphone.length; i++)
		{
			var phonechar = cellphone.substring(i, i + 1); 
			if(phonechar < "0" || phonechar > "9" )
			{ 
				if (phonechar != "(" && phonechar != " " && phonechar != ")" && phonechar != "-")
				{
					//alert(phonechar); 
					alert("Please enter your cell phone number in the following format. (505) 555-1111"); 
					form.cellphone.focus(); 
					return false; 
				}
			}
		}
			
	}
		
	
	
	
}
