// JavaScript Document
//DESIGN: DIGITALTURTLE.CO.UK
//AUTHOR: MATT BENTLEY
//EMAIL: MATT@DIGITALTURTLE.CO.UK

document.onload = validationSetUp;

function validationSetUp()
{
	if(document.getElementById)
	{
		var contactForm = document.getElementById("contact_form");
		input.onSubmit = function(){ 
                return verify();
            }

	}
}

function IsEmpty(aTextField) 
{
   if ((aTextField.value.length==0) || (aTextField.value==null)) 
      return true;
   else 
   	return false;
}

function verify() 
{
	var themessage = "Please tell us ";
	var emailCheck = document.contactForm.email.value;
	var goodEmail = emailCheck.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.biz)|(\.info)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	
	if (IsEmpty(contactForm.wherehear)) 
		themessage = themessage + "- how you heard about us ";
	if (!goodEmail) 
		themessage = themessage + " - your email address";
		
	//alert if fields are empty and cancel form submit
	if (themessage == "Please tell us ") 
			return true;
	else 
	{
		alert(themessage);
		return false;
	}
}