// JavaScript Document
//Javascript main functions BOF
function trimSpace(x)
{
	var emptySpace = / /g;
	var trimAfter = x.replace(emptySpace,"");
	return(trimAfter);
}

function ValidateEmail(str)
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID");
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID");
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail ID");
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail ID");
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail ID");
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail ID");
	    return false;
	 }

	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail ID");
	    return false;
	 }

	 return true;
}


function validform()
{
 if(trimSpace(document.frmform.fname.value).length==0 )
 {
  alert("Please enter first name.");
  document.frmform.fname.focus();
  return false;
 } 
 if(trimSpace(document.frmform.lname.value).length==0 )
 {
  alert("Please enter last name.");
  document.frmform.lname.focus();
  return false;
 }
 if(trimSpace(document.frmform.Dphone1.value).length==0 || trimSpace(document.frmform.Dphone2.value).length==0 || trimSpace(document.frmform.Dphone3.value).length==0 )
 {
  alert("Please enter correct Daytime phone.");
  document.frmform.Dphone1.focus();
  return false;
 }
 if(trimSpace(document.frmform.email.value).length==0 )
 {
  alert("Please enter email.");
  document.frmform.email.focus();
  return false;
 } 
    if ((ValidateEmail(document.frmform.email.value)==false))
	{
		document.frmform.email.focus();
		return false;
	}
	
 if(trimSpace(document.frmform.date_event.value).length==0 )
 {
  alert("Please enter date of event.");
  document.frmform.date_event.focus();
  return false;
 }
 if(trimSpace(document.frmform.description.value).length==0 )
 {
  alert("Please enter description.");
  document.frmform.description.focus();
  return false;
 }
 
}