// JavaScript Document
/****************** Mail Sending Form Validation ******************************/
/****************** Created Date : 10-03-2011 *********************************/
/****************** Created By   :  Satheeshkumar.S ***************************/

function validation_mail_form()	{
//alert("Hi I have been calling validate_mail_form ");
	var errorstring="";
	var first_name 	= document.getElementById('first_name').value;
	var last_name 	= document.getElementById('last_name').value;
	var email 		= document.getElementById('email').value;
	var phone_no 	= document.getElementById('phone_no').value;
	var gender 		= document.getElementById('gender').value;
	//alert(gender);
	 if(trim(first_name)=='')	{
			errorstring = errorstring + " Enter Your  First Name \n";
		}
	 if(trim(last_name)=='')	{
			errorstring = errorstring + " Enter Your  Last Name \n";
		}	
		
	if(trim(email)=='')	{
			errorstring = errorstring + " Enter Your Email \n";
		}
		
	if(trim(email)!='' && checkemail((email),'')==false)		{
			errorstring = errorstring + " Enter Valid Email. \n";
		}
	if(trim(phone_no)=='')	{
			errorstring = errorstring + " Enter Your Phone No \n";
		}	
	if(trim(gender)=='')	{	
			errorstring = errorstring + " Select Your Gender \n";
	}		
	
	if(errorstring != "")
	{
		alert(errorstring);
		return false;
	}
	else
	{
		return true;
	}
		
}
function checkemail(email){
	var str=email;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str))
		return true;
	else
		return false;
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}



