 function validation()
{
 			var ft;
			ft=valphone(document.cont.phone.value);	
			var eemail1= document.cont.ea.value;
			var result=trim(document.cont.ea.value);
			fts=valphone(document.cont.guests.value);	
 
  	if (document.cont.name.value=="")
  		{
  		alert ("Please enter your Name");	
  		document.cont.name.focus();
  		return false;
  		}
  	if(!(document.cont.name.value==""))
  		{
  			var cardno="";
  			val_name=document.cont.name.value;
  			len=document.cont.name.value.length;
  			if(val_name.substring(0,1)== " ")
  				{
  				alert("Enter valid name");
  				document.cont.name.select();
  				return false;
  				} 
  			else
  				{
  				if(!(val_name.match(/^[a-zA-Z ]+$/)))
  					 {
  						alert("Please enter valid Name");
  						document.cont.name.select();
  						return false;
  					 }
  				}	
  		}
	
	
	
    	if (document.cont.phone.value=="")
    	{
    		alert ("Please enter the Phone Number");
    		document.cont.phone.focus();
    		document.cont.phone.select();
    		return false;
    	}
	
    	if(ft==1)
    	{
    		alert("Please enter valid Phone number")
    		document.cont.phone.focus();
    		document.cont.phone.select();
    		return false;
    	}
    	if (document.cont.phone.value.length < 5)
    	{
    		alert ("Phone number should be more than 5 numbers");
    		document.cont.phone.focus();
    		document.cont.phone.select();
    		return false;
    	}
	
    	if(document.cont.ea.value == "")  
    	 {
    	 	alert("Please enter the Email address");
    	 	document.cont.ea.select();
    	 	return false;
    	 }
	 
    	 if (result == "")
    	 {
    	 	alert("Please enter a valid E-mail address");
    		document.cont.ea.select();
    		return false;
    	 }
      if(!verif_mail())
      	{
      	return false;
      	}
				
				
			var selObj = document.getElementById('event');
	    var selIndex = selObj.selectedIndex;
	    var event=selObj.options[selIndex].value;	
			if(event == "")  
    	 {
    	 	alert("Please select a Event");
    	 	return false;
    	 }
			
			if (document.cont.date.value=="")
    	{
    		alert ("Please enter the event date");
    		document.cont.date.focus();
    		document.cont.date.select();
    		return false;
    	}
    	if (document.getElementById('date').value!="")
    	{
			newv=Date.isValid(document.getElementById('date').value,'MMM d,yyyy');
			//alert(newv)
    	 	 if (newv == false)
				 {
				 alert("enter a valid date");
         document.getElementById('date').select();
         return false;
				 }
								 
      }
				
    			
			if (document.cont.guests.value=="")
    	{
    		alert ("Please enter the no. of guests");
    		document.cont.guests.focus();
    		document.cont.guests.select();
    		return false;
    	}
    	
    	
    	if(fts==1)
    	{
    		alert("Please enter valid numeric value")
    		document.cont.guests.focus();
    		document.cont.guests.select();
    		return false;
    	}
			
			
			
			
}


function verif_mail() 
{
	var id = document.cont.ea.value;
	if(id == "")  
	{
	alert("Enter the Email ID");
	document.cont.ea.select();
	return false;
	}
	  
	var apos=id.indexOf("@");
	var lpos=id.lastIndexOf("@");
	var dotpos=id.lastIndexOf(".");
	var id_len=id.length;
	//alert(dotpos);
	var dif=id_len-dotpos;
	//alert(dif);
	
	
	if(dif<3 || dif>5)
	{
	alert("Enter Valid Email Id");
	document.cont.ea.select();
	return false;
	}
	
	if(apos!=lpos)
	{
	alert("Enter Valid Email Id");
	document.cont.ea.select();
	return false;
	}
	
	if (apos<1||dotpos-apos<2) 
	  {
		alert("Enter Valid Email ID");
		document.cont.ea.select();
		return false;
	  }
	  
	for(i=0;i<=dotpos;i++)
	{
		var str=id;
		var ch=str.substring(i,i+1);
		
		if(ch==' ' || ch==';' || ch==',' || ch=='!' || ch=='#' || ch=='$' || ch=='%' || ch=='^' || ch=='&' || ch=='*' )
		{
			alert("Enter Valid Email ID");
			document.cont.ea.select();
			return false;
		}
		return true;
	}
	
	var str=id.substring(dotpos+1,id_len);
	//alert(str);
	
		for (var i = 0; i < str.length; i++) 
		{
			var ch = str.substring(i, i + 1);
		//alert(ch)
			//if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch == '.')) 
			if(ch==1 || ch==2 || ch==3 || ch==4 || ch==5 || ch==6 || ch==7 || ch==8 || ch==9 || ch==0 || ch==';' || ch=='$' || ch=='@' || ch=='*' || ch=='^' || ch=='&' || ch=='%' ||ch=='#')
			//if((ch < "0" || "9" < ch))
			{
				alert("Enter Valid Email ID");
				document.cont.ea.select();
				return false;
			}
		}
	}


function valphone(vp)
{
	var frvar=0;
	var fvarphone="1234567890-";
	var ii;
	flenphone=vp.length;
	for(ii=0; ii < flenphone ;ii++)
	{
		if(fvarphone.indexOf(vp.charAt(ii))<0)
		{
			frvar=1;
			break;
		}
	}
	return frvar;
}


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


