// JavaScript Document
function validate(contact){
	
	var st=document.contact.email.value;
	
	if(document.contact.name.value== "")
	{
	alert("Please enter your first name");
	document.contact.name.focus();
	document.contact.name.select();
	return false;
	}
	
	if(document.contact.surname.value== "")
	{
	alert("Please enter your surname");
	document.contact.surname.focus();
	document.contact.surname.select();
	return false;
	}
	
	if(document.contact.dob.value== "")
	{
	alert("Please enter your date of birth");
	document.contact.dob.focus();
	document.contact.dob.select();
	return false;
	}
	
	if(document.contact.email.value=="")
	{
		alert("Please enter your email");
		document.contact.email.focus();
		document.contact.email.select();
		return false;
	}
	else
	{			
		if(checkEmail(st)!=true)
		{
			alert("Invalid E-Mail  \n"+st);
			document.contact.email.focus();
			document.contact.email.select();
			return false; 
		 }
	}
	
	//code for phone
	
	if( document.contact.phone.value == "" ||
           isNaN( document.contact.phone.value ))
   {
     alert( "Phone number should be digit." );
     document.contact.phone.focus() ;
	 document.contact.phone.select();
     return false;
   }
}

function checkEmail(str)
{
	if((str.indexOf("@")==-1))
	{
		fstr="Please Enter @ or .";
		return false;
	}
	else
	{
	if((str.indexOf("@") == 0) )
	{
		fstr="@  Cannot Be first";
		alert(fstr);
		return false;
	}
	if((str.indexOf("@") == (str.length-1)))
	{
		fstr="@ Cannot Be Last";
		return false;
	}

	
	if((str.indexOf("@")+1) == str.indexOf("."))
	{
		fstr="@. IS Invalid Email";
		return false;
	}
	}
	var cp=0;					
	if(cp==2)
	{
		fstr="@ cannnot be repeated";
		return false;
	}
	return true;
}
