/* Checks form and runs through every function listed */
function checkWholeForm(theForm) {
    var why = "";
    why += checkName(theForm.Name.value);
    why += checkEmail(theForm.Email.value);
    why += checkPhone(theForm.Phone.value);
    why += checkPostcode(theForm.House.value);
    why += checkIam(theForm.iam.selectedIndex);
    why += checkEnquiry(theForm.textarea.value);

    if (why != "") { alert(why); return false; }
    return true;
}


/* Name function */
function checkName (strng) {
  var error="";
  if (strng == "") 
  { 
  	error = "- Name is required *\n"
    	document.theForm.Name.focus(); 
  }
    	return error;
}

/* Email function */
function checkEmail (strng) 
{
  var error="";
  if (strng == "") 
  { 
  	error = "- Email Address is required *\n";
  	document.theForm.Email.focus(); 
  }

  var emailFilter=/^.+@.+\..{2,3}$/;
  if (!(emailFilter.test(strng))) 
  { 
  	error = "- Email Address is required *\n";
  	document.theForm.Email.focus(); 
  }
  else
  {
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
    if (strng.match(illegalChars)) 
    { 
    	error = "- Invalid E-Mail Address *\n";
    	document.theForm.Email.focus(); 
    }
  }
  return error;    
}

/* Phone function */
function checkPhone (strng) {
  var error="";
  if (strng == "") 
  { 
  	error = "- Phone is required *\n"
    	document.theForm.Phone.focus(); 
  }
    	return error;
}


/* Message function */
function checkPostcode (strng)
{ 
   var error="";
   if (strng == "")
   {
      error = "- Postcode is required *\n";
      document.theForm.House.focus();
   }
   return error;
}

/* How you would like to be contacted function */
function checkIam (choice) 
{
   var error = "";
   if (choice == 0) 
   { 
   	error = "- I am seeking - required *\n"; 
   }    
   return error;
}    

function checkSelect (choice) 
{
   var error = "";
   if (choice == 0) 
   { 
   	error = "- How you heard about us? *\n"; 
   }    
   return error;
}    



/* Message function */
function checkEnquiry (strng)
{ 
   var error="";
   if (strng == "")
   {
      error = "- Enquiry is required *\n";
      document.theForm.textarea.focus();
   }
   return error;
}

