//**********************************************************
// this java script coding checks acts as a basic form 
// validator with several kind of checks .
//**********************************************************
//COPYRIGHT HOLDER:  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.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.Address.value=="")
  {
		alert("Address 1 cannot be null");
		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 \"Address 1\" 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 \"Address 2\" 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.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;
  }
  
  // CHECK FOR NOT A NUMBER and positive number
	if ((RegForm.Phone.value == "")||(RegForm.Phone.value < 1))
	{
	   alert("Please Enter the Phone Number");
	   RegForm.Phone.focus();
	   return false;
	} 
	
	if (RegForm.Phone.value.length < 5)
	{
	   alert("Enter atleast Five digits Phone Number");
	   RegForm.Phone.focus();
	   return false;
	}
	
	checkOK="0123456789,()OR -";
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 numbers,spaces & hyphen, (O),(R) in the \"CONTACT NO.\" field.");
    RegForm.Phone.focus();
    allValid = true;
    return (false);
  }

	
	
//----------------------------------------------------------------------------------------------

	
	// CHECK FOR NOT A NUMBER and positive number
	

	if (RegForm.Fax.value!="")
	{
		if (RegForm.Fax.value.length < 5)
		{
			alert("Enter atleast Five digits Fax Number");
			RegForm.Fax.value="";
			RegForm.Fax.focus();
			return false;
		}
	}	
	checkOK="0123456789,()OR -";
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 numbers,spaces & hyphen, (O),(R) in the \"Fax Num.\".");
    RegForm.Fax.focus();
    allValid = true;
    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);
  }

  if(RegForm.Email.value.length<7)
  {
		alert("Email address can not be less than Seven chars");
		RegForm.Email.focus();
		return false;
  }

  
  
//----------------------------------------------------------------------------------------------

//********************************************************************************

  var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  var alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  
  var charnum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 -,.&()/\:";
  var checkOK1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .-";
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .";
  var checkwell = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
  var checknum = "0123456789 ";
  var checknumber = "0123456789";
  var blank=true;
//*****************************************************************

  if (RegForm.maiden_name.value == "")
  {
      RegForm.maiden_name.value ="";
  }
//******************************************************************
if (RegForm.maiden_name.value != "")
{
  var checkStr = RegForm.maiden_name.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 \"maiden_name\" field.");
    RegForm.maiden_name.focus();
    allValid = true;
    return (false);
  }
  }
//********************************************************************

  if (RegForm.spousename.value == "")
  {
     RegForm.spousename.value ="";
  }
  //*****************************************************************
  
  if (RegForm.spousename.value != "")
  {
  var checkStr = RegForm.spousename.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkwell.length;  j++)
      if (ch == checkwell.charAt(j))
        break;
    if (j == checkwell.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only alphabets and/or blanks in the \"Spouse Name\" field.");
    RegForm.spousename.focus();
    allValid = true;
    return (false);
  }
  }
//*****************************************************************
 /* if (RegForm.spousecollege.value == "")
  {
     RegForm.spousecollege.value ="";
  }*/
//****************************************************************  
 /*if (RegForm.spousecollege.value != "")
 {
  var checkOKay = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .,"; 
  var checkStr = RegForm.spousecollege.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOKay.length;  j++)
      if (ch == checkOKay.charAt(j))
        break;
    if (j == checkOKay.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only alphabets,dot and/or blanks in the \"Spouse College\" field.");
    RegForm.spousecollege.focus();
    allValid = true;
    return (false);
  }
  }*/
//*******************************************************************

if (RegForm.noofkids.value == "" || RegForm.noofkids.value == 0)
{
    RegForm.noofkids.value =0;
}

// ********************allows ONLY numbers and spaces*******************************
if (RegForm.noofkids.value != "" && RegForm.noofkids.value != 0)
{
  var checknumber = "0123456789"; 
  var checkStr = RegForm.noofkids.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checknumber.length;  j++)
      if (ch == checknumber.charAt(j))
        break;
    if (j == checknumber.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Invalid Entries in 'No. of Kids',Only a number is allowed.");
    RegForm.noofkids.focus();
    allValid = true;
    return (false);
  }
}
//*******************************************************************

//*******************************************************************  
var strdate = RegForm.date.value;
var strmonth= RegForm.month.value;
var stryear = RegForm.year.value;

currentDate=new Date();
var curDate = currentDate.getDate();
var curMonth= currentDate.getMonth()+1;
var curYear = currentDate.getYear();

   //************************************************
}



 
//----------------------------------------------------------------------------------------------
//ENDING REGFORM VALIDATOR   

