jQuery(document).ready(function() {
//$('#contactp2 #theName').bind("blur",chkname);
//$('#contactp2 #theCompany').bind("blur",chkcompany);
//$('#contactp2 #title').bind("blur",chktitle);
//$('#contactp2 #theEmail').bind("blur",chkmail);
//$('#contactp2 #theEmail').bind("blur",chkmail);
$('#contactp2 #button').bind("click",chksubmit);
});
var errlg='';
function chkname()
{
	if ($.trim($('#contactp2 #theName').val()) == "")
	{
	 //$('#errormaincontact').html('Please check name');
	 errlg='Name';
	 return true;
	}
	else
	{
	return false;
	}
}
function chkcompany()
{	
	if ($.trim($('#contactp2 #theCompany').val()) == "")
	{	
	// $('#errormaincontact').html('Please check company');
	 errlg=errlg+'Company';
	 return true;
	}
	else
	{
	return false;
	}
}
function chktitle()
{
	if ($.trim($('#contactp2 #title').val()) == "")
	{
	// $('#errormaincontact').html('Please check name');
	 errlg=errlg+'Title';
	 return true;
	}
	else
	{
	return false;
	}
	
}
function chkmail()
{
	if ($.trim($('#contactp2 #theEmail').val()) == "")
	{
	// $('#errormaincontact').html('Please check name');
	 errlg=errlg+'Email';
	 return true;
	}
	else
	{
		 var emails = $.trim($("#contactp2 #theEmail").val());	
		 if(isValidEmailAddress(emails))
		 {
		 return false;
		 }
		 else
		 {
		 errlg=errlg+'Invalid email address';
		 return true;
		 }
	}	
}

function isValidEmailAddress(emailAddress) {
 		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
 		return pattern.test(emailAddress);
	} 

function chkphone()
{
	if ($.trim($('#contactp2 #thePhone').val()) == "")
	{
	// $('#errormaincontact').html('Please check name');
	 errlg=errlg+'Phone';
	 return true;
	}
	else
	{
		var phoneExp = /^[0-9\.\s\-\(\)\*\+]+$/;		
		if($("#contactp2 #thePhone").val().match(phoneExp)){
		//alert('ok');
		
		return false;
		}
		else
		{
		//alert('not');
		errlg=errlg+'Invalid phone number';
		return true;
		}
	}	
}

function chktime()
{
	if ($.trim($('#contactp2 #theTime').val()) == "")
	{
	// $('#errormaincontact').html('Please check name');
	 errlg=errlg+'Time';
	 return true;
	}
	else
	{
	return false;
	}
}

function chksubmit()
{
	errlg='';
	if(chkname()==false && chkcompany()==false && chktitle()==false && chkphone()==false && chkmail()==false && chktime()==false)
	{
	//chkname();
	//chkcompany();
	//chktitle();
	//alert("sss");
	//alert('no error');
	return true;	
	}
	else
	{
	$('#errormaincontact').html('Please check '+ errlg);
	return false;
	}
}
