function isValidEmail(emailid)	// Email Validation
{		
var email=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	return email.test(emailid);
}

//Phone Validation
function isValidPhoneNo(strng)
{
//strip out acceptable non-numeric characters
var stripped = strng.replace(/[\(\)\.\+\-\ ]/g, '');
	return !isNaN(stripped);
}


//  this function checks the given string is empty or not
//  and return true or false accordingly.
	function is_empty(str)
	{
  		 str=trim(str);
		 if ((str.length==0)||(str==null))
			return true;
		 return false;
	}
// End of is_empty Function
	
	function trim(inputString) 
	{
	   // Removes leading and trailing spaces from the passed string. Also removes
	   // consecutive spaces and replaces it with one space. If something besides
	   // a string is passed in (null, custom object, etc.) then return the input.
	   if (typeof inputString != "string") { return inputString; }
	   var retValue = inputString;
	   var ch = retValue.substring(0, 1);
	   while (ch == " ") { // Check for spaces at the beginning of the string
		  retValue = retValue.substring(1, retValue.length);
		  ch = retValue.substring(0, 1);
	   }
	   ch = retValue.substring(retValue.length-1, retValue.length);
	   while (ch == " ") { // Check for spaces at the end of the string
		  retValue = retValue.substring(0, retValue.length-1);
		  ch = retValue.substring(retValue.length-1, retValue.length);
	   }
	   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
		  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	   }
	   return retValue; // Return the trimmed string back to the user
	} // Ends the "trim" function

function validate()   // sensis contact form validation
{
if(is_empty(document.getElementById('name').value))
 { 
	 alert("Please enter your name.");
	 document.getElementById('name').value="";
	 document.getElementById('name').focus();
	 return false;
 }

 if(document.getElementById('email').value=="")
 { 
	 alert("Please enter your email address.");
	 document.getElementById('email').focus();
	 return false;
 }

 if(!isValidEmail(document.getElementById('email').value))
 { 
	 alert("Please enter a valid email address.");
	 document.getElementById('email').focus();
	 return false;
 }


 if(document.getElementById('telephone').value=="")
 { 
	 alert("Please enter your telephone number.");
	 document.getElementById('telephone').focus();
	 return false;
 }

 if(!isValidPhoneNo(document.getElementById('telephone').value))
 { 
	 alert("Please enter a valid telephone number.");
	 document.getElementById('telephone').focus();
	 return false;
 }

  if(document.getElementById('contact-message').value=="")
	 { 
		 alert("Please enter your message.");
		 document.getElementById('contact-message').focus();
		 return false;
	 }

  if(document.getElementById('spampro').value !="c3vt4i")
	 { 
		 alert("Please enter correct spam protection code.");
		 document.getElementById('spampro').value="";
		 document.getElementById('spampro').focus();
		 return false;
	 }

}
