// JavaScript Document
function trim(inputStr)
{
	if(typeof inputStr != "string")
	{
		return inputStr;
	}
	
	var retVal = inputStr;
	var ch = retVal.substring(0,1);
	while(ch==" ")
	{
		retVal = retVal.substring(1,retVal.length);
		ch = retVal.substring(0,1);
	}
	
	ch = retVal.substring(retVal.length-1, retVal.length);
	while(ch==" ")
	{
		retVal = retVal.substring(0,retVal.length-1);
		ch = retVal.substring(retVal.length-1, retVal.length);
	}
	
	return retVal;
}
function checkemail(str)
{
	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 enterNumerics(e)
{
	//alert("in nummerics")
	if (!e) var e = window.event;
	// e gives access to the event in all browsers
	if(!e.which) key = e.keyCode; // This is used store the keycode(IE Only) 
	else key = e.which; // This is used store the keycode(Netscape Only)

	if((key>=48)&&(key<=57)||key==8||key==9){
		key=key;
		return true;
	 }
	 else{
		 
	   key=0;
	  // alert("Please enter only numerics");
	   return false;
	 }
     
}
function validate()
{

	var errors=""
	var Cust_Name = trim(document.getElementById('Cust_Name').value)
	var Cust_ContactNo = trim(document.getElementById('Cust_ContactNo').value)
	var Cust_MailID = trim(document.getElementById('Cust_MailID').value)
	//var Cust_State = trim(document.getElementById('Cust_State').value)
	var Cust_Place = trim(document.getElementById('Cust_Place').value)
	var Mail = trim(document.getElementById('Mail').checked)
	var Phone = trim(document.getElementById('Phone').checked)
	var Cust_Details = trim(document.getElementById('Cust_Details').value)
	
	
	if(Cust_Name=="")
	{
		errors += "Please enter name.\n"
	}
	if(Phone)
	{
		if(Cust_ContactNo=="")
		{
			errors += "Please enter your contact number.\n"
		}
	}
	if(Mail)
	{
		if(Cust_MailID == "")
		{
			errors += "Please enter your email id.\n"
		}
		else if(!checkemail(Cust_MailID))
		{
			errors += "Your email id is invalid.\n"
		}
	}
	if(!Mail && Cust_MailID!="")
	{
		if(!checkemail(Cust_MailID))
		{
			errors += "Your email id is invalid.\n"
		}
	}	
	if(Cust_Place=="")
	{
		errors += "Please enter your city/place/location.\n"
	}
	if(!(Mail || Phone))
	{
		errors += "Please select Contact me through.\n"
	}	
	if(Cust_Details=="")
	{
		errors += "Please enter Description.\n"
	}
	
	if(errors=="")
		return true;
		
	alert(errors);
	return false;
}