//**********************************************************
// this java script coding checks acts as a basic form 
// validator with several kind of checks .
//**********************************************************
//COPYRIGHT HOLDER:  ATUL SEHGAL @ REAL TIME.  
//**********************************************************

function regformvalidator(RegForm)
{

//----------------------------------------------------------------------------------------------

	  if (RegForm.Title.selectedIndex==-1)
	  {
			alert("Please Select Title!");
			RegForm.Title.focus();
			return false;
	  }
     
//----------------------------------------------------------------------------------------------

	if (RegForm.FirstName.value=="")
	{
			alert("First Name cannot be null");
			RegForm.FirstName.focus();
			return (false);
	}
	
	if (RegForm.FirstName.value.length < 2)
	{
		alert("Please enter at least 2 characters in the \"FirstName\" field.");
		RegForm.FirstName.focus();
		return (false);
	}		

		var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .";
		var checkStr =RegForm.FirstName.value;
		var allValid = true;
		for (i = 0;  i < checkStr.length;  i++)
		{
		  ch = checkStr.charAt(i);
		  for (j = 0;  j < checkOK.length;  j++)
		    if (ch == checkOK.charAt(j))
		      break;
		  if (j == checkOK.length)
		  {
		    allValid = false;
		    break;
		  }
		}
		if (!allValid)
		{
		  alert("Please enter only valid entries in the \"First Name\" field.");
		  RegForm.FirstName.focus();
		  allValid = true;
		  return (false);
		}

//----------------------------------------------------------------------------------------------
    
     if (RegForm.LastName.value=="")
     {
			alert("LastName cannot be null");
			RegForm.LastName.focus();
			return false;
	 }

	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .";
	var checkStr = RegForm.LastName.value;
	var allValid = true;
		for (i = 0;  i < checkStr.length;  i++)
		{
		  ch = checkStr.charAt(i);
		  for (j = 0;  j < checkOK.length;  j++)
		    if (ch == checkOK.charAt(j))
		      break;
		  if (j == checkOK.length)
		  {
		    allValid = false;
		    break;
		  }
		}
	 if (!allValid)
	 {
	  alert("Please enter only valid entries in the \"Last Name\" field.");
	  RegForm.LastName.value="";
	  RegForm.LastName.focus();
	  allValid = true;
	  return (false);
	 }


//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
 //if (RegForm.date.value=="")
     //{
			//alert("Select a valid date");
			//RegForm.date.focus();
			//return false;
	 //}

//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
 //if (RegForm.month.value=="")
     //{
			//alert("Month Name should be selected");
			//RegForm.month.focus();
			//return false;
	 //}

//----------------------------------------------------------------------------------------------

 //if (RegForm.year.value=="")
     //{
			//alert("Year should be selected");
			//RegForm.year.focus();
			return false;
	 //}



//----------------------------------------------------------------------------------------------
// block for validating date
//var sDob=RegForm.date.value +"/"+ RegForm.month.value+"/"+ RegForm.year.value;
 //if (!isdate(sDob))
//	{
//	alert (sDob);
//	return false;	
//}
//----------------------------------------------------------------------------------------------

 //if (RegForm.Age.value=="")
	 //{
	  //alert("Age cannot be null");
	  //RegForm.Age.focus();
	  //return false;
	 //} 
	 //&&(RegForm.Age.value > 120)
	 //if  ( (isNaN(RegForm.Age.value)==true)||(RegForm.Age.value < 1) )
	 //{
	   //alert("Enter the Age in Positive Numbers");
	   //RegForm.Age.focus();
	   //return false;
	 //} 
     
     //if (RegForm.Age.value >120  )
	//{
	   //alert("Enter the Age Less Than 120");
	   //RegForm.Age.focus();
	   //return false;
	//}

//----------------------------------------------------------------------------------------------

//if (RegForm.Institution.value=="")
  //{
		//alert("School or Workplace field cannot be null");
		//RegForm.Institution.focus();
		//return false;
  //} 


//-----------------------------------------------------------------------------------------------
  
if (RegForm.Address.value=="")
  {
		alert("Mailing Address cannot be blank");
		RegForm.Address.focus();
		return false;
  } 

  var checkadd = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 -/,.#";
  var checkStr = RegForm.Address.value;
  var allValid = true;
  
  	for (i = 0;  i < checkStr.length;  i++)
		{
		  ch = checkStr.charAt(i);
		  for (j = 0;  j < checkadd.length;  j++)
		    if (ch == checkadd.charAt(j))
		      break;
		  if (j == checkadd.length)
		  {
		    allValid = false;
		    break;
		  }
		}
  if (!allValid)
  {
    alert("Please enter only valid entries in the \"Mailing Address\" field.");
    RegForm.Address.value="";
    RegForm.Address.focus();
    allValid = true;
    return (false);
  }
  
  
//----------------------------------------------------------------------------------------------

  var checkadd = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 -/,.#";
  var checkStr = RegForm.Address1.value;
  var allValid = true;
  	for (i = 0;  i < checkStr.length;  i++)
		{
		  ch = checkStr.charAt(i);
		  for (j = 0;  j < checkadd.length;  j++)
		    if (ch == checkadd.charAt(j))
		      break;
		  if (j == checkadd.length)
		  {
		    allValid = false;
		    break;
		  }
		}
	if (!allValid)
	{
	  alert("Please enter only valid entries in the \"Mailing Address \" field.");
	  RegForm.Address1.value="";
	  RegForm.Address1.focus();
	  allValid = true;
	  return (false);
	}


//----------------------------------------------------------------------------------------------


 if (RegForm.City.value=="")
  {
		alert("City cannot be null");
		RegForm.City.focus();
		return false;
  }
  
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .";
  var checkStr = RegForm.City.value;
  var allValid = true;
  
  for (i = 0;  i < checkStr.length;  i++)
		{
		  ch = checkStr.charAt(i);
		  for (j = 0;  j < checkOK.length;  j++)
		    if (ch == checkOK.charAt(j))
		      break;
		  if (j == checkOK.length)
		  {
		    allValid = false;
		    break;
		  }
		}
   if (!allValid)
   {
    alert("Please enter only valid entries in the \"City\" field.");
    RegForm.City.value="";
    RegForm.City.focus();
    allValid = true;
    return (false);
   }


//----------------------------------------------------------------------------------------------


if (RegForm.State.value=="")
  {
		alert("State cannot be null");
		RegForm.State.focus();
		return false;
  }
   var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .";
   var checkStr = RegForm.State.value;
   var allValid = true;
   
   for (i = 0;  i < checkStr.length;  i++)
		{
		  ch = checkStr.charAt(i);
		  for (j = 0;  j < checkOK.length;  j++)
		    if (ch == checkOK.charAt(j))
		      break;
		  if (j == checkOK.length)
		  {
		    allValid = false;
		    break;
		  }
		}

  if (!allValid)
   {
     alert("Please enter only valid entries in the \"State\" field.");
     RegForm.State.value="";
     RegForm.State.focus();
     allValid = true;
     return (false);
   }

//----------------------------------------------------------------------------------------------

 
   if (RegForm.PinCode.value=="")
  {
		alert("PinCode cannot be null");
		RegForm.PinCode.focus();
		return false;
  }
  
   //CHECK FOR CORRECT LENGTH
   if(RegForm.PinCode.value.length<5)
   { 
		alert("PIN \ ZIP Code cannot be less than 5 no's");
		RegForm.PinCode.focus();
		return false;
   }
   
  var checkpc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 -";
  var checkStr = RegForm.PinCode.value;
  var allValid = true;
  
      for (i = 0;  i < checkStr.length;  i++)
		{
		  ch = checkStr.charAt(i);
		  for (j = 0;  j < checkpc.length;  j++)
		    if (ch == checkpc.charAt(j))
		      break;
		  if (j == checkpc.length)
		  {
		    allValid = false;
		    break;
		  }
		}

  
  if (!allValid)
  {
    alert("Please enter only valid entries in the \"PinCode\" field.");
    RegForm.PinCode.value="";
    RegForm.PinCode.focus();
    allValid = true;
    return (false);
  }


//----------------------------------------------------------------------------------------------

 
  if ((RegForm.Country.selectedIndex==-1)||(RegForm.Country.selectedIndex==0))
  {
		alert("Please Select Your Country!");
		RegForm.Country.focus();
		return false;
  }

  
  
//----------------------------------------------------------------------------------------------
  
  if (RegForm.CountryCode.value=="")
  {
   alert("Country Code cannot be null");
   RegForm.CountryCode.focus();
   return false;
  }
  
 // CHECK FOR NOT A NUMBER and positive number
	if ((isNaN(RegForm.CountryCode.value)==true)||(RegForm.CountryCode.value < 1))
	{
	   alert("Enter the Country Code in Positive Numbers");
	   RegForm.CountryCode.focus();
	   return false;
	} 
	
  
//----------------------------------------------------------------------------------------------
  
  if (RegForm.CityCode.value=="")
  {
   alert("CityCode cannot be null");
   RegForm.CityCode.focus();
   return false;
  }
  
  // CHECK FOR NOT A NUMBER and positive number
	if ((isNaN(RegForm.CityCode.value)==true)||(RegForm.CityCode.value < 1))
	{
	   alert("Enter the City Code in Positive Numbers");
	   RegForm.CityCode.focus();
	   return false;
	} 
  
  
  
//----------------------------------------------------------------------------------------------
  
	//if (RegForm.Phone.value=="")
		 //{
		  //alert("Phone cannot be null");
		  //RegForm.Phone.focus();
		  //return false;
		 //}

	    //var checkOK = "oOrRmM()0123456789 .-";
		//var checkStr =RegForm.Phone.value;
		//var allValid = true;
		//for (i = 0;  i < checkStr.length;  i++)
		//{
		  //ch = checkStr.charAt(i);
		  //for (j = 0;  j < checkOK.length;  j++)
		    //if (ch == checkOK.charAt(j))
		      //break;
		  //if (j == checkOK.length)
		  //{
		    //allValid = false;
		    //break;
		  //}
		//}
		//if (!allValid)
		//{
		  //alert("Please enter only valid entries in the \"Phone\" field.");
		  //RegForm.Phone.focus();
		  //allValid = true;
		  //return (false);
		//}

	//if (RegForm.Phone.value.length < 5)
	//{
	   //alert("Enter atleast Five digits Phone Number");
	   //RegForm.Phone.focus();
	   //return false;
	//}
	
//----------------------------------------------------------------------------------------------

	    var checkOK = "oOrRmM()0123456789 .-+";
		var checkStr =RegForm.Fax.value;
		var allValid = true;
		for (i = 0;  i < checkStr.length;  i++)
		{
		  ch = checkStr.charAt(i);
		 for (j = 0;  j < checkOK.length;  j++)
		    if (ch == checkOK.charAt(j))
		      break;
		  if (j == checkOK.length)
		  {
		    allValid = false;
		    break;
		  }
		}
		if (!allValid)
		{
		  alert("Please enter only valid entries in the \"Cell No.\" field.");
		  RegForm.Fax.focus();
		  allValid = true;
		  return (false);
		}
	
	if (RegForm.Fax.value.length > 0)
	{
		if (RegForm.Fax.value.length < 10)
		{
		   alert("Enter atleast Ten digits Cell Number");
		   RegForm.Fax.focus();
		   return false;
		}
	}
//----------------------------------------------------------------------------------------------
   
	
//----------------------------------------------------------------------------------------------
  
  if (RegForm.Email.value=="")
  {
		alert("Email cannot be null");
		RegForm.Email.focus();
		return false;
  }
  
  var checkEmail = "@.";
  var checkStr = RegForm.Email.value;
  var EmailValid = false;
  var EmailAt = false;
  var EmailPeriod = false;
  
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkEmail.length;  j++)
    {
      if (ch == checkEmail.charAt(j) && ch == "@")
        EmailAt = true;
      if (ch == checkEmail.charAt(j) && ch == ".")
        EmailPeriod = true;
	  if (EmailAt && EmailPeriod)
		break;
	  if (j == checkEmail.length)
		break;
     }
                          // if both the @ and . were in the string
    if (EmailAt && EmailPeriod)
    {
		EmailValid = true
		break;
    }
  }
  if (!EmailValid)
  {
    alert("The \"Email\" field has invalid entry");
    RegForm.Email.focus();
    return (false);
  }

  var checkpc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.@-";
  var checkStr = RegForm.Email.value;
  var allValid = true;
  
      for (i = 0;  i < checkStr.length;  i++)
		{
		  ch = checkStr.charAt(i);
		  for (j = 0;  j < checkpc.length;  j++)
		    if (ch == checkpc.charAt(j))
		      break;
		  if (j == checkpc.length)
		  {
		    allValid = false;
		    break;
		  }
		}
  if (!allValid)
  {
    alert("Please enter only valid entries in the \"Email\" field.");
    RegForm.Email.value="";
    RegForm.Email.focus();
    allValid = true;
    return (false);
  }

  if(RegForm.Email.value.length<7)
  {
		alert("Email address can not be less than Seven chars");
		RegForm.Email.focus();
		return false;
  }

//----------------------------------------------------------------------------------------------

  
  if (RegForm.UserId.value=="")
  {
   alert("User Id cannot be null");
   RegForm.UserId.focus();
   return false;
  }
  
   var checkuid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
   var checkStr = RegForm.UserId.value;
   var allValid = true;
   
      for (i = 0;  i < checkStr.length;  i++)
		{
		  ch = checkStr.charAt(i);
		  for (j = 0;  j < checkuid.length;  j++)
		    if (ch == checkuid.charAt(j))
		      break;
		  if (j == checkuid.length)
		  {
		    allValid = false;
		    break;
		  }
		} 
   if (!allValid)
   {
     alert("Please enter only valid entries in the \"User-Id\" field.");
     RegForm.UserId.value="";
     RegForm.UserId.focus();
     allValid = true;
     return (false);
   }
  
   if(RegForm.UserId.value.length<3)
   {
    	alert("UserId must contain atleast 3 characters");
	    RegForm.UserId.focus();
		return false;				
   }



//----------------------------------------------------------------------------------------------

  
  if (RegForm.Password.value=="")
  {
   alert("Password cannot be null");
   RegForm.Password.focus();
   return false;
  }	
  
  
   var checkpwd = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
   var checkStr = RegForm.Password.value;
   var allValid = true;
   
   for (i = 0;  i < checkStr.length;  i++)
		{
		  ch = checkStr.charAt(i);
		  for (j = 0;  j < checkpwd.length;  j++)
		    if (ch == checkpwd.charAt(j))
		      break;
		  if (j == checkpwd.length)
		  {
		    allValid = false;
		    break;
		  }
		} 
   if (!allValid)
   {
     alert("Please enter only valid entries in the \"Password\" field.");
     RegForm.Password.value="";
     RegForm.Password.focus();
     allValid = true;
     return (false);
   }

	if(RegForm.Password.value.length<6)
	{
	  	alert("Password must contain atleast 6 characters");
		RegForm.Password.focus();
		return false;				
	}



//----------------------------------------------------------------------------------------------

   if (RegForm.ConfirmPassword.value=="")
  {
		alert("Confirm Password cannot be null");
		RegForm.ConfirmPassword.focus();
		return false;
  }
  
    pass=RegForm.Password.value;
    confpass=RegForm.ConfirmPassword.value;
    if((pass)!=(confpass))
    {
       alert("Password and Confirm Password are not Identical");
       RegForm.ConfirmPassword.value="";
       RegForm.ConfirmPassword.focus();
       return false;
    }
  
//----------------------------------------------------------------------------------------------
  
 //if (RegForm.Question.value=="")
  //{
   //alert("Password Question cannot be null");
   //RegForm.Question.focus();
   //return false;
  //}

   //var checkq = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ._?";
   //var checkStr = RegForm.Question.value;
   //var allValid = true;
   //for (i = 0;  i < checkStr.length;  i++)
		//{
		  //ch = checkStr.charAt(i);
		  //for (j = 0;  j < checkq.length;  j++)
		    //if (ch == checkq.charAt(j))
		      //break;
		  //if (j == checkq.length)
		  //{
		    //allValid = false;
		    //break;
		  //}
		//} 
   //if (!allValid)
   //{
     //alert("Please enter only valid entries in the Question field.");
     //RegForm.Question.value="";
     //RegForm.Question.focus();
     //allValid = true;
     //return (false);
   //}



//----------------------------------------------------------------------------------------------
  
  //if (RegForm.Answer.value=="")
  //{
   //alert("Password Answer cannot be null");
   //RegForm.Answer.focus();
   //return false;
  //}
  
   //var checkq = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ._?-";
   //var checkStr = RegForm.Answer.value;
   //var allValid = true;
   //for (i = 0;  i < checkStr.length;  i++)
		//{
		  //ch = checkStr.charAt(i);
		  //for (j = 0;  j < checkq.length;  j++)
		    //if (ch == checkq.charAt(j))
		      //break;
		  //if (j == checkq.length)
		  //{
		    //allValid = false;
		    //break;
		  //}
		} 
   //if (!allValid)
   //{
     //alert("Please enter only valid entries in the Answer field.");
     //RegForm.Answer.value="";
     //RegForm.Answer.focus();
     //allValid = true;
     //return (false);
   //}
  
//----------------------------------------------------------------------------------------------
//ENDING REGFORM VALIDATOR   

}
