function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
/****************************/
function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
 		 return true					
	}
/*******************************/

function check_date(field){
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var seperator = ".";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = DateField;
   //alert(DateValue);
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   //alert(DateValue);
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
  	/*  alert (day);
	  alert (month);
 	  alert (year);*/
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err != 0) {
return false;
}
return true;
}

/**************************/
function form_validator(f)
{
	var xdat;
	if ( trim(f.name.value)  == "" )
	{
		alert("Name must enter ");
		f.name.value="";
		f.name.focus();
		return false;
	}
	if ( trim(f.profileid.value)  == "" )
	{
		alert("Profile Id should not blank ");
		f.profileid.value="";
		f.profileid.focus();
		return false;
	}
	if ( trim(f.profileid.value).length<4 ){
		alert("Profileid should have atleast 4 chars");
		f.profileid.focus();
		return false;
	}	
	/************************************/
	
	/********************************/
	var letters=" :;\"<>,?/`~!@#$%^&*)_-\\=+|.";
	for(ij=0;ij<=letters.length-1;ij++)
	{
	if (trim(f.profileid.value).indexOf(letters.substr(ij,1))>=0 ){
		alert("Invalid Profileid");
		f.profileid.focus();		
		return false;
	}
	}
	
	if ( trim(f.email.value)  == "" )
	{
		alert("email Id should not blank ");
		f.email.value="";
		f.email.focus();
		return false;
	}
	if ( trim(f.retypeemail.value)  == "" )
	{
		alert("retype email Id should not blank ");
		f.retypeemail.value="";
		f.retypeemail.focus();
		return false;
	}
	/********************************/
	if ((f.email.value==null)||(f.email.value=="")){
		alert("Please Enter your Email ID");
		f.email.focus();
		return false;
	}
	if (echeck(f.email.value)==false){
		f.email.value="";
		alert("Invalid  email id ");
		f.email.focus();
		return false;
	}
	/*********************************/
	/********************************/
	if ((f.retypeemail.value==null)||(f.retypeemail.value=="")){
		alert("Please Enter your Email ID");
		f.retypeemail.focus();
		return false;
	}
	if (echeck(f.retypeemail.value)==false){
		f.retypeemail.value="";
		alert("Invalid  email id ");
		f.retypeemail.focus();
		return false;
	}
	/*********************************/
	/********************************/
	if (f.retypeemail.value!=f.email.value){
		alert("Retype email id is not matching");
		f.retypeemail.focus();
		return false;
	}
	/*********************************/
	if ( trim(f.password.value)=="" ){
		alert("Enter a password");
		f.password.value="";
		f.password.focus();
		return false;
	}
	if ( trim(f.password.value).length<4 ){
		alert("Password should have atleast 4 chars");
		f.password.value="";
		f.password.focus();
		return false;
	}
	if ( trim(f.retypepassword.value)=="" ){
		alert("Enter retype password");
		f.retypepassword.value="";
		f.retypepassword.focus();
		return false;
	}
	if (f.password.value!=f.retypepassword.value){
		alert("Retype password not match");
		f.retypepassword.focus();
		return false;
	}
	/***************************************/
		if (f.relationship.value=="0" ){
		alert("Select one from 'Profile created by'");
		f.relationship.focus();
		return false;
	}
	if ( f.day.value=="0"){
		alert("Select a day ");
		f.day.focus();
		return false;
	}
	if ( f.month.value=="0" ){
		alert("Select a month");
		f.month.focus();
		return false;
	}
	if ( f.year.value=="0" ){
		alert("Select Year");
		f.year.focus();
		return false;
	}
	var abc1;
	var abc2;
	var xx1,xx2;
	xx1=("0"+f.day.value).length-2;
	xx2=("0"+f.month.value).length-2;
	if (xx1<=0 ) xx1=0;
	if(xx2<=0) xx2=0;
	abc1=("0"+f.day.value).substr(xx1,2);
	abc2=("0"+f.month.value).substr(xx2,2);
	xdat=abc1+"-"+abc2+"-"+f.year.value;
	//alert(xdat);
	if ( !check_date(xdat) )
	{
		alert ("Choose a valid date");
		return false;
	}
	
	if ( f.maritalstatus.value=="0" ){
		alert("Select a status");
		f.maritalstatus.focus();
		return false;
	}
	if ( f.complexion.value=="0" ){
		alert("Select a complexion");
		f.complexion.focus();
		return false;
	}
	if ( f.motounge.value=="0" ){
		alert("Select a Mother Tounge");
		f.motounge.focus();
		return false;
	}
	/************************************************/
	
  if (f.Religion.selectedIndex < 0)
  {
    alert("Please select one of the \"Religion\" options.");
    f.Religion.focus();
    return (false);
  }

  if (f.Religion.selectedIndex == 0)
  {
    alert("The first \"Religion\" option is not a valid selection.  Please choose one of the other options.");
    f.Religion.focus();
    return (false);
  }
  if (f.subcaste.selectedIndex < 0)
  {
    alert("Please select one of the \"Sub Caste\" options.");
    f.subcaste.focus();
    return (false);
  }

  if (f.subcaste.selectedIndex == 0)
  {
    alert("The first \"Sub Caste\" option is not a valid selection.  Please choose one of the other options.");
    f.subcaste.focus();
    return (false);
  }
	
	/***************************************************/
	if ( f.occupation.value=="0" ){
		alert("Select a Occupation");
		f.occupation.focus();
		return false;
	}
	if ( f.country.value=="0" ){
		alert("Select a Country");
		f.country.focus();
		return false;
	}
	if ( f.state.value=="0" ){
		alert("Select a State");
		f.state.focus();
		return false;
	}
	if ( f.abtdosth.value=="" ){
		alert("Select an option for 'Where you find WedIndia.com'");
		f.abtdosth.focus();
		return false;
	}
	if ( trim(f.title.value)=="" ){
		alert("Enter a good title");
		f.title.value="";
		f.title.focus();
		return false;
	}
		if ( trim(f.title.value).length<50 ){
		alert("Enter title with minimum 50 characters");
		//f.title.value="";
		f.title.focus();
		return false;
	}
	if ( trim(f.title.value).length>500 ){
		alert("Maximum 500 characters Allowed ");
		//f.aboutyourself.value="";
		f.title.focus();
		return false;
	}
	
	for(ij=0;ij<=f.title.value.length-1;ij++)
	{
	if ((f.title.value.substr(ij,1)==f.title.value.substr(ij+1,1)) && (f.title.value.substr(ij,1)==f.title.value.substr(ij+2,1))){
		alert("Invalid Title");
		f.title.focus();		
		return false;
	}
	}

	if ( trim(f.aboutyourself.value)=="" ){
		alert("Type something about yourself ");
		f.aboutyourself.value="";
		f.aboutyourself.focus();
		return false;
	}
	
		if ( trim(f.aboutyourself.value).length<50 ){
		alert("Minimum 50 characters required ");
		//f.aboutyourself.value="";
		f.aboutyourself.focus();
		return false;
	}
		if ( trim(f.aboutyourself.value).length>900 ){
		alert("Maximum 900 characters Allowed ");
		//f.aboutyourself.value="";
		f.aboutyourself.focus();
		return false;
	}
	for(ij=0;ij<=f.aboutyourself.value.length-1;ij++)
	{
	if ((f.aboutyourself.value.substr(ij,1)==f.aboutyourself.value.substr(ij+1,1)) && (f.aboutyourself.value.substr(ij,1)==f.aboutyourself.value.substr(ij+2,1))){
		alert("Invalid Description");
		f.aboutyourself.focus();		
		return false;
	}
	}
	if ( !f.agree.checked) {
		alert ("You should agree with the terms and conditions");
		return false;
	}
	return true;
}


