/* ======================================================================
DESC: This script is used to validate the login page which takes the user id, password

PLATFORMS: Windows/Linux

USAGE NOTES: 
====================================================================== */

/* ======================================================================
FUNCTION: 	formValidate

INPUT:		It calls several other functions like isUid,isPassword
				
RETURNS:		This function returns true if all the inputs in the form are valid or returns false

DESC:			This function is called before submitting the form whose true/false 
				would let the form from being submitted or not.				
====================================================================== */

/* ======================================================================
FUNCTION: 	formUValidate

INPUT:		It calls several other functions like isUid,isPassword
				
RETURNS:		This function returns true if all the inputs in the form are valid or returns false

DESC:			This function is called before submitting the form whose true/false 
				would let the form from being submitted or not.				
====================================================================== */

/* ======================================================================
FUNCTION: 	isUid

INPUT:		It reads the value from the form's user id text field 
				
RETURNS:		This function returns true if the user id is valid with respect to specs or returns false

DESC:			This function checks the userid to be a minimum of 4 chars & max of 15 chars.
				No special symbols are also allowed except for '_'.Can have alphabets & numbers.
====================================================================== */

/* ======================================================================
FUNCTION: 	isPassword

INPUT:		It reads the value from the form's user password & confirm password fields 
				
RETURNS:		This function returns true if the user id password is valid with respect to specs or returns false

DESC:			This function checks the password to be a minimum of 4 chars & max of 50 chars.
				No spaces are also allowed.Can have alphabets & numbers. Cannot be same as user id.
====================================================================== */

/* ======================================================================
FUNCTION: 	isEmail

INPUT:		It reads the value from the form's user email id field 
				
RETURNS:		This function returns true if the email id is valid with respect to specs or returns false

DESC:			This function checks the email id with '@' and '.' symbols No spaces are also allowed.
					Initial letter must be an alphabet.Accepts only "_" in the Id
====================================================================== */

/* ======================================================================
FUNCTION: 	isNamesValid

INPUT:		It reads the value from the form's First Name & Last Name fields 
				
RETURNS:		This function returns true if the First Name & Last Name is valid with respect to specs or returns false

DESC:			This function checks the First Name & Last Name that no spaces are also allowed.
====================================================================== */

/* ======================================================================
FUNCTION: 	isPhone

INPUT:		It reads the value from the form's Area Code & Number & Extension fields 
				
RETURNS:		This function returns true if the Area Code & Number & Extension is valid with respect to specs or returns false

DESC:			This function checks the Area Code is numeric and Number entered is in given format and Extension is numeric.
====================================================================== */

/* ======================================================================
FUNCTION: 	isAddress

INPUT:		It reads the value from the form's Address fields 
				
RETURNS:		This function returns true if the Address is valid with respect to specs or returns false

DESC:			This function checks the Address is not empty and First letter is an alphabet.
====================================================================== */

/* ======================================================================
FUNCTION: 	isStateZipValid

INPUT:		It reads the value from the form's State & ZipCode fields 
				
RETURNS:		This function returns true if the State & ZipCode is valid with respect to specs or returns false

DESC:			This function checks the State & ZipCode are not empty and  ZipCode is Numeric
====================================================================== */

/* ======================================================================
FUNCTION: 	isCity

INPUT:		It reads the value from the form's city fields 
				
RETURNS:		This function returns true if the city is valid with respect to specs or returns false

DESC:			This function checks the city is not empty and first letter is an alphabet
====================================================================== */

/* ======================================================================
FUNCTION: 	isHint

INPUT:		It reads the value from the form's hint question and hint answer fields 
				
RETURNS:		This function returns true if the hint question and hint answer is valid with respect to specs or returns false

DESC:			This function checks the hint question and hint answer is not empty and hint answer is not same as password
====================================================================== */

/* ======================================================================
FUNCTION: 	isBlank

INPUT:		It reads the value from the form's field 
				
RETURNS:		This function returns true if the field is valid with respect to specs or returns false

DESC:			This function checks whether the form field is empty
====================================================================== */

/* ======================================================================
FUNCTION: 	isCPassword

INPUT:		It reads the value from the form's current password, new password and confirm password fields
				
RETURNS:		This function returns true if the current password, new password and confirm password fields is valid with respect to specs or returns false

DESC:			This function checks the password to be a minimum of 4 chars & max of 50 chars.
				No spaces are also allowed.Can have alphabets & numbers. Cannot be same as user id. New password cannot be same as current password.
====================================================================== */

/* ======================================================================
FUNCTION: 	putSTDCode

INPUT:		It reads the value from the form's area code field of phone number
				
RETURNS:		This function returns true if the area code field of phone number is valid with respect to specs or returns false

DESC:			This function automatically inputs the area code of phone number field in to the area code of mobile number and fax number fields as they are keyd in.
====================================================================== */

/* ======================================================================
FUNCTION: 	keyCheckN

INPUT:		It reads the value from the form's fields values
				
RETURNS:		This function returns true if valid with respect to specs or returns false

DESC:			This function checks the type of browser and KeyedIn value is numeric and blocks the function of delete key
====================================================================== */

/* ======================================================================
FUNCTION: 	keyCheck

INPUT:		It reads the value from the form's fields values
				
RETURNS:		This function returns true if valid with respect to specs or returns false

DESC:			This function checks the type of browser and blocks the function KeyedIn value if it is numeric and blocks the function of delete key
====================================================================== */

/* ======================================================================
FUNCTION: 	chk_4num

INPUT:		It reads the value from the form's fields values
				
RETURNS:		This function returns true if valid with respect to specs or returns false

DESC:			This function checks whether keyedin value is a number
====================================================================== */

/* ======================================================================
FUNCTION: 	isvalid

INPUT:		It reads the value from the form's field 
				
RETURNS:		This function returns true if the field is valid with respect to specs or returns false

DESC:			This function checks whether the form field contains any special characters as specified
====================================================================== */

/* ======================================================================
FUNCTION: 	textLimit

INPUT:		It reads the value from the form's field 
				
RETURNS:		This function returns true if the field is valid with respect to specs or returns false

DESC:			This function checks the characters are fixed to the max length of the control
====================================================================== */

// This function checks the validity of the necessay functions
function formValidate()
{	
	if(isUid() && isPassWord() && isEmail(document.frm_personal_info.txt_user_email) && isNamesValid() && isPhone('Phone',document.frm_personal_info.txt_ContPhone_std_code,document.frm_personal_info.txt_ContPhone_phone,document.frm_personal_info.txt_ContPhone_exn,1) && isComp() && isAddress() && isCity()  && isStateZipValid() && isPhone('Fax',document.frm_personal_info.txt_f_std_code,document.frm_personal_info.txt_f_fax_no,document.frm_personal_info.txt_fPhone_exn,0) &&  isHint(1))
	{
		return true;
	}
	else
	{
		return false;
	}
}

// This function checks the validity of the necessay functions
function formUValidate()
{	
	if(isUid() && isEmail(document.frm_personal_info.txt_user_email) && isNamesValid() && isPhone('Phone',document.frm_personal_info.txt_ContPhone_std_code,document.frm_personal_info.txt_ContPhone_phone,document.frm_personal_info.txt_ContPhone_exn,1) && isComp() && isAddress() && isCity()  && isStateZipValid() && isPhone('Fax',document.frm_personal_info.txt_f_std_code,document.frm_personal_info.txt_f_fax_no,document.frm_personal_info.txt_fPhone_exn,1) && isPhone('Mobile',document.frm_personal_info.txt_m_std_code,document.frm_personal_info.txt_m_mob_no,document.frm_personal_info.txt_mPhone_exn,0) && isHint(1))	
	{
		return true;
	}
	else
	{
		return false;
	}
}

// This function validates the valid characters
function isvalid(str,chars)
{	
	var bool_valid = true;	
	var validchars = chars;
	for (var int_i=0; int_i < str.length; int_i++) 
	{
		var letter = str.charAt(int_i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
		{	
			alert("Invalid character: " + letter +"\n" + "The following characters are not accepted : "+ chars);
			bool_valid=false;
			break;
		}
	}
	return bool_valid;
}

// This function checks the validity of the city field
function isCity()
{
   bool_citystatevalid=true;
   //This is to check if City has been provided with any value or not
   if (Trim(document.frm_personal_info.txt_comp_city.value)=="")
   {
     alert ("City must not be blank");
     bool_citystatevalid=false;     
   }
   //Checks whether the city field starts with an alphabet
   if (bool_citystatevalid == true)
   {
	    var ch=Trim(document.frm_personal_info.txt_comp_city.value).substring(0,1);
		if( (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) )  
		{
 			alert ("First letter of City must be an alphabet");
 			bool_citystatevalid=false;			
		}
   }
   // Checks whether city contains invalid chars
   if(bool_citystatevalid==true)
	{	
		bool_citystatevalid = isvalid(Trim(document.frm_personal_info.txt_comp_city.value),"~!@#$%^&*()-+=`{}|[]\\/<>:\";,?_")
	}
	//This is to focus on the city text field if any criterion has been violated
	if (bool_citystatevalid==false)
	{
		document.frm_personal_info.txt_comp_city.select();
		document.frm_personal_info.txt_comp_city.focus();
	}
   // Returns the status of City Validity
   return bool_citystatevalid;
}

// This function checks the validity of the company field
function isComp()
{
   bool_comp=true;
   //This is to check if company has been provided with any value or not
   if (Trim(document.frm_personal_info.txt_comp_name.value)=="")
   {
     alert ("Company name must not be blank");
     bool_comp=false;     
   }
   //Checks whether the company field starts with an alphabet
   if (bool_comp == true)
   {
	    var ch=Trim(document.frm_personal_info.txt_comp_name.value).substring(0,1);
		if( (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) )  
		{
 			alert ("First letter of Comapny name must be an alphabet");
 			bool_comp=false;			
		}
   }
   // Checks whether company contains invalid chars
   if(bool_comp == true)
	{	
		bool_comp = isvalid(Trim(document.frm_personal_info.txt_comp_name.value),"~!@#$%^&*()-+=`{}|[]\\/<>:\";,?_")
	}
	//This is to focus on the company text field if any criterion has been violated
	if (bool_comp==false)
	{
		document.frm_personal_info.txt_comp_name.select();
		document.frm_personal_info.txt_comp_name.focus();
	}
   // Returns the status of company Validity
   return bool_comp;
}

// This function checks the validity of the address field
function isAddress()
{
	var bool_address=true;
	//This is to check if the Company Address has been provided with any value or not	
	if (Trim(document.frm_personal_info.txt_comp_address.value)=="")
	{
		alert ("Address must not be blank");	
		bool_address=false;
		document.frm_personal_info.txt_comp_address.focus();
		document.frm_personal_info.txt_comp_address.select();
	}
	if(bool_address==true)
	{
		var ch = Trim(document.frm_personal_info.txt_comp_address.value).substring(0,1);
		//This is to check if the first character of the Address given is an alphabet or not
		if (	((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != '_')) 
		{
			alert ("First letter of Address must be an alphabet");
 			bool_address=false;
			document.frm_personal_info.txt_comp_address.focus();
			document.frm_personal_info.txt_comp_address.select();
		}			
	}
	if(bool_address==true && Trim(document.frm_personal_info.txt_comp_address.value).length > 100)
	{
		alert ("Address must not exceed 100 characters");
 		bool_address=false;
		document.frm_personal_info.txt_comp_address.focus();
		document.frm_personal_info.txt_comp_address.select();		
	}
	// Returns the status of Address validity
	return bool_address;
}

// This function checks the validity of the userid field
function isUid ()
{
 var bool_uidvalid=true;
 var txt_uid=document.frm_personal_info.txt_user_id.value;
 //This is to check if the user id has been provided with any value or not
 if (txt_uid=="")
 {
	bool_uidvalid=false;
    alert ("User Id must not be blank");
 } 
 //This is to check if length of user id is min 4 chars 
 else if (txt_uid.length<4)
 {
    bool_uidvalid=false;
    alert ("User Id must have minimum 4 characters.");
 }
 /*This is to check if length of user id is more than max 15 chars*/
 else if (txt_uid.length>15)
 {
    bool_uidvalid=false;
    alert ("User Id must not exceed 15 characters");
 } 
 /*This is to check if the first charecter of the user id given is an alphabet or not*/
 if(bool_uidvalid==true)
 {
   var ch=txt_uid.substring(0,1);
   if( (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) )  
   {
 	  alert ("First letter of User Id must be an alphabet");
 	  bool_uidvalid=false;
   }
 }
 //This is to check whether all the charecters in the user id are valid charecters
  if(bool_uidvalid==true)
 {
 for (var int_i = 1; int_i < txt_uid.length; int_i++) 
	{
		var ch = txt_uid.substring(int_i, int_i + 1);
		if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != '_')) 
		{
			alert("User Id field accepts A-Z, a-z, 0-9, '_'");
 			bool_uidvalid=false;
			break;
		}
	}
  }
  //This is to check whether all the charecters in the user id are valid charecters 
 if(bool_uidvalid==true)
 {	
	bool_uidvalid = isvalid(txt_uid,"~!@#$%^&*()-+=`{}|[]\\/<>:\";',?")
 }
  //This is to check whether "_" are repeated for 3 times and contains spaces
 if(bool_uidvalid==true)
 {
	var kount;
	var skount;
	kount = 0
	skount = 0
	for (var int_i = 1; int_i < txt_uid.length; int_i++) 
	{
		var ch = txt_uid.substring(int_i, int_i + 1);
		if (ch == '_') 
		{
			kount = kount + 1;
		}
		if (ch == " ")
		{			
			skount = skount + 1;
		}
		if (kount > 3)
		{
			alert("User Id should not contain more than 3 '_' characters");
 			bool_uidvalid=false;
			break;
		}
		if (skount > 0)
		{
			alert("User Id should not contain spaces");
 			bool_uidvalid=false;
			break;
		}
	}
  }
  //This is to focus on the user id text field if any criterion has been violated
  if (bool_uidvalid==false) 
  {
	 document.frm_personal_info.txt_user_id.select();
	 document.frm_personal_info.txt_user_id.focus();
  }
  //Return the status of the user id validity
  return bool_uidvalid;
}

// This function checks the validity of the password field
function isPassWord() 
{
var txt_pwd=document.frm_personal_info.pss_user_pwd.value;
var txt_cnfp=document.frm_personal_info.pss_conf_pwd.value;
var bool_pwdvalid=true;
var bool_cpwdvalid=true;

//Checks whether the password is empty
if ( txt_pwd=="" ) 
{
    alert ("Password must not be blank");
    bool_pwdvalid=false;
}
//Checks whether the password length is less than 6 chars
else if (txt_pwd.length < 6 ) 
{
    alert ("Password must have minimum 6 characters");
    bool_pwdvalid=false;
}
//Checks whether the password length exceeds 50 characters
else if (txt_pwd.length > 50)
{
    alert ("Password must not exceed 50 characters");
    bool_pwdvalid=false; 
}
//Checks whether the password is same as user id
else if (txt_pwd==document.frm_personal_info.txt_user_id.value)
{
    alert ("Password must not be same as User Id");
    bool_pwdvalid=false; 
} 
//Checks if the password has any spaces in it
if ( bool_pwdvalid==true ) 
{
   for(var int_i=0;int_i<txt_pwd.length;int_i++)
   {
     var ch=txt_pwd.substring(int_i,int_i+1)
     if ( ch==" " ) 
     {
     	alert ("Password must not contain space");
       	bool_pwdvalid=false;
	    break;
     }
	}
}
//Checks whether the password contains valid characters
if(bool_pwdvalid==true)
 {	
	bool_pwdvalid = isvalid(txt_pwd,"~!@#$%^&*()-+=`{}|[]\\/<>:\";',?")
 }
//Check whether the Confirm password is entered
if ((bool_pwdvalid==true) && (txt_cnfp == ""))
{
	alert("Confirm Password must not be blank");
	bool_cpwdvalid = false;
}
//Checks if the confirm password has any spaces in it
if ( bool_pwdvalid==true && bool_cpwdvalid==true ) 
{
   for(var int_i=0;int_i<txt_cnfp.length;int_i++)
   {
     var ch=txt_cnfp.substring(int_i,int_i+1)
     if ( ch==" " ) 
     {
     	alert ("Confirm Password must not contain space");
       	bool_cpwdvalid=false;
	    break;
     }
   }
}
//Checks whether the confirm password contains valid characters
if ( bool_pwdvalid==true && bool_cpwdvalid==true ) 
 {	
	bool_cpwdvalid = isvalid(txt_cnfp,"~!@#$%^&*()-+=`{}|[]\\/<>:\";',?")
 }
//Check whether the password entered both the times are same   
if (((bool_pwdvalid==true) && (bool_cpwdvalid==true)) && (txt_pwd!=txt_cnfp))
{
   alert("Password and Confirm Password do not match");
   bool_pwdvalid=false
}

//If the password is not satisfying all criterion then the focus is set on the password field
if ( bool_pwdvalid==false ) 
{
   document.frm_personal_info.pss_user_pwd.select()
   document.frm_personal_info.pss_user_pwd.focus()
}
//If the confirm password is not satisfying all criterion then the focus is set on the confirm password field
if ( bool_cpwdvalid==false )
{
   document.frm_personal_info.pss_conf_pwd.select()
   document.frm_personal_info.pss_conf_pwd.focus()
   bool_pwdvalid = false
}
// Returns the status of the password validity
return bool_pwdvalid
}

// This function checks the validity of the email field
function isEmail(emlfield)
{
   var str_emladd=emlfield.value;
   var bool_emlvalid=true;
   var chat=str_emladd.indexOf("@");
   var chdot=str_emladd.indexOf(".");
   var chdot_nxt=str_emladd.charAt(chdot+1);
   var str_fstchar=str_emladd.charAt(0);

   // Checks whether Email Id is blank
   if (str_emladd == "")
   {
	   alert("E-mail address must not be blank");
	   bool_emlvalid=false;
       emlfield.select();
       emlfield.focus();
   }
   // Checks whether Email Id entered is a valid Id
   else if((str_emladd.indexOf("@")!=str_emladd.lastIndexOf("@"))||(str_emladd.indexOf(".")<str_emladd.indexOf("@"))||(str_emladd.indexOf(".")==-1)||(str_emladd.indexOf(" ")!=-1)||(str_emladd=="")||(chat==-1))
   {
      alert("Please enter valid e-mail address");
      bool_emlvalid=false;
      emlfield.select();
      emlfield.focus();
   } 
   // Checks whether first character of Email Id is an alphabet
   else if((str_fstchar<'A' || str_fstchar >'Z') && (str_fstchar < 'a' || str_fstchar > 'z'))
   {
      alert("First letter of e-mail address must be an alphabet");
      bool_emlvalid=false;
      emlfield.select();
      emlfield.focus();
   }
 /*  else
   {
      for(var i=0;i<str_emladd.length;i++)
      {
        var ch=str_emladd.substring(i,i+1);
		// Checks whether EmailId contains invalid characters
        if ( (ch <"A" || ch > "Z") && (ch <"a" || ch >"z")  && (ch!="@") && (ch!=".") && (ch!="_") && (ch < "0" || ch >"9"))
        {
          alert("Email Address Cannot Have invalid Characters.");
          bool_emlvalid=false;
		  emlfield.select();
   		  emlfield.focus();
   		  break;
        }
      }
   }*/
   // Checks whether Email Id contains any invalid characters
   else
   {
      var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@._-";
	  for (var i=0; i < str_emladd.length; i++) 
	  {
			var letter = str_emladd.charAt(i).toLowerCase();
			if (validchars.indexOf(letter) != -1)
			continue;
			alert("Invalid character: " + letter);
			bool_emlvalid=false;
			emlfield.select();
			emlfield.focus();
			break;
	  }	
   }
   // Checks whether EmailId contains "." before the domain name
   if ((bool_emlvalid==true) && (chat+1==chdot))
   {
      alert("Please enter valid e-mail address");
   	  bool_emlvalid=false;
      emlfield.focus();
      emlfield.select();
   }
   // Checks whether EmailId contains the domain name
   if ((bool_emlvalid==true) && ((chdot_nxt <"A" || chdot_nxt > "Z") && (chdot_nxt <"a" || chdot_nxt >"z") && (chdot_nxt < "0" || chdot_nxt >"9")))
   {
	  alert("Please enter correct domain name in the e-mail address");
	  bool_emlvalid=false;
	  emlfield.select();
	  emlfield.focus();
	}
	//Return the status of the email id validity
    return bool_emlvalid;
}   

// This function checks the for the keyedin value is a number
function chk_4num(msrc,dst)
{
	var str_value,str_resvalue,i,ch;
	str_resvalue=new String();
	str_value=msrc.value;

	for (i=0;i < str_value.length;i++)
	{
	   ch=str_value.charAt(i);
	   if (!(ch >='0' && ch <='9'))
	   {	
			str_resvalue+=str_value.substring(i,i+1);			
	   }	
	}
	dst.value=str_resvalue;
}	

// This function checks the validity of the first name and last name fields
function isNamesValid()
{	
   var str_fnm=Trim(document.frm_personal_info.txt_cont_fname2.value)
   var str_lnm=Trim(document.frm_personal_info.txt_cont_lname.value)
   var bool_remvalid=true;
   // Checks whether First Name is empty
   if(str_fnm=="")
   {
     alert("First Name should be provided");
     bool_remvalid=false;
     document.frm_personal_info.txt_cont_fname2.select();
     document.frm_personal_info.txt_cont_fname2.focus();
   }
   // Checks whether Last Name is empty
   else if(str_lnm=="")
   {
     alert("Last Name should be provided");
     bool_remvalid=false;
     document.frm_personal_info.txt_cont_lname.select();
     document.frm_personal_info.txt_cont_lname.focus();
   }
   // Checks whether First Name contains an alphabet
   if (bool_remvalid == true)
   {
	    var ch=str_fnm.substring(0,1);
		if( (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) )  
		{
 			alert ("First letter of First Name must be an alphabet");
 			bool_remvalid=false;
			document.frm_personal_info.txt_cont_fname2.select();
			document.frm_personal_info.txt_cont_fname2.focus();
		}
   }
   // Checks whether first name contains special characters
   if ((bool_remvalid == true) && (isvalid(str_fnm,"~!@#$%^&*()-+=`{}|[]\\/<>:\";,?") == false))
   {	
		bool_remvalid=false;
		document.frm_personal_info.txt_cont_fname2.select();
		document.frm_personal_info.txt_cont_fname2.focus();
   }
	// Checks whether first name can contain a single quote and ' _'
   if (bool_remvalid == true)
   {
	    var qkount;
		var ukount;
		var skount;
		qkount = 0
		ukount = 0
		skount = 0
		for (var i=0;i<str_fnm.length;i++)
	    {
			var ch=str_fnm.substring(i,i+1);
			if( (ch == "_")  )
			{
 				ukount = ukount + 1
			}
			if (ch == "'")
			{
				qkount = qkount + 1
			}
			if (ch == " ")
			{
				skount = skount + 1
			}
			if ((ukount > 1) || (qkount > 1))
			{			
				alert ("First Name can contain a single quote and ' _'");
 				bool_remvalid=false;
				document.frm_personal_info.txt_cont_fname2.select();
				document.frm_personal_info.txt_cont_fname2.focus();
				break;
			}
			if ((bool_remvalid==true) && (skount > 2))
			{
				alert ("More than 2 spaces are not allowed in First Name");
 				bool_remvalid=false;
				document.frm_personal_info.txt_cont_fname2.select();
				document.frm_personal_info.txt_cont_fname2.focus();
				break;
			}
	    }		
   }
   // Checks whether Last Name contains an alphabet
   if (bool_remvalid == true)
   {
	    var ch=str_lnm.substring(0,1);
		if( (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) )  
		{
 			alert ("First letter of Last Name must be an alphabet");
 			bool_remvalid=false;
			document.frm_personal_info.txt_cont_lname.select();
			document.frm_personal_info.txt_cont_lname.focus();
		}
   }
   // Checks whether last name contains any special characters
   if ((bool_remvalid == true) && (isvalid(str_lnm,"~!@#$%^&*()-+=`{}|[]\\/<>:\";,?") == false))
   {	
		bool_remvalid=false;
		document.frm_personal_info.txt_cont_lname.select();
			document.frm_personal_info.txt_cont_lname.focus();
   }
   // Checks whether last name can contain a single quote and ' _'
   if (bool_remvalid == true)
   {
	    var qkount;
		var ukount;
		var skount;
		qkount = 0
		ukount = 0
		skount = 0
		for (var i=0;i<str_lnm.length;i++)
	    {
			var ch=str_lnm.substring(i,i+1);
			if( (ch == "_")  )
			{
 				ukount = ukount + 1
			}
			if (ch == "'")
			{
				qkount = qkount + 1
			}
			if (ch == " ")
			{
				skount = skount + 1
			}
			if ((ukount > 1) || (qkount > 1))
			{			
				alert ("Last Name can contain a single quote and ' _'");
 				bool_remvalid=false;
				document.frm_personal_info.txt_cont_lname.select();
				document.frm_personal_info.txt_cont_lname.focus();
				break;
			}
			if ((bool_remvalid==true) && (skount > 2))
			{
				alert ("More than 2 spaces are not allowed in Last Name");
 				bool_remvalid=false;
				document.frm_personal_info.txt_cont_lname.select();
				document.frm_personal_info.txt_cont_lname.focus();
				break;
			}
	    }		
   }
   //Return the status of the Name validity
   return bool_remvalid;
}

// This function checks the validity of the phone/fax/mobile number field
function isPhone(msg,stdfield,phonefield,extfield,compulsory)
{  
   var str_std=Trim(stdfield.value)
   var str_pno=Trim(phonefield.value)	
   var str_ext=Trim(extfield.value)
   var bool_phonevalid=true;
   
   //Checks if the area code is empty
   if ((compulsory!=1 && str_std.length==0) && ((str_pno.length!=0) || (str_ext.length!=0)))
   {
	   alert(msg + " Area code must not be blank.");
	   bool_phonevalid=false;
       stdfield.select();
       stdfield.focus();
   }	
   //Checks if the country code is Valid
   else if (((compulsory==1)&&(str_std==""))||(str_std < 0)||(isNaN(str_std)))
   {
      alert("Please enter valid " + msg + " Area Code");
      bool_phonevalid=false;
      stdfield.select();
      stdfield.focus();
   }
   // Checks whether areacode contains all Zeros
	else if ((compulsory==1) && (str_std == "000" ))
	{		
		alert("Please enter valid " + msg + " Area Code");
		bool_phonevalid=false;
		stdfield.select();
		stdfield.focus();
	}
   //Checks if the areacode length is 3
   else if ((compulsory==1) && (str_std.length<3))
	{
	  alert(msg + " Area code should be 3 characters length.");
      bool_phonevalid=false;
      stdfield.select();
      stdfield.focus();
	}
   //Checks if the Phone No is valid   
   else if ((compulsory==1) && (str_pno=="") )
   {
      alert("Phone/Fax/Mobile number must not be blank");
      bool_phonevalid=false;
      phonefield.select();
      phonefield.focus();
   }
	//Checks if the Phone No is exceeds maximum length
   if ((bool_phonevalid==true) && (compulsory==1 && str_pno.length<8))
	{
	  alert("Please enter valid Phone/Fax/Mobile Number");
      bool_phonevalid=false;	  
      phonefield.select();
      phonefield.focus();
	}  
	// Checks for "-" and value entered is a number
	if (bool_phonevalid==true)
    {
	   for(var int_i=0;int_i<str_pno.length;int_i++)
	   {
			var ch = str_pno.substring(int_i, int_i + 1);			
			if ((isNaN(parseInt(ch)) || (parseInt(ch) < 0 && parseInt(ch) > 9)) && (int_i!=3))
			{
			   alert("Please enter valid Phone/Fax/Mobile Number(Ex. 999-9999)");
			   bool_phonevalid=false;
	  		   phonefield.value = "";
			   phonefield.select();
			   phonefield.focus();
   			   break;
			}
			if (((int_i!=3) && (ch=="-")) || ((int_i==3) && (ch!="-")))
			{
			   alert("Please enter valid Phone/Fax/Mobile Number(Ex. 999-9999)");
			   bool_phonevalid=false;
			   phonefield.value = "";
	  		   phonefield.select();
			   phonefield.focus();
			   break;
			}
       }
   }
   // Checks for a valid phone number
   if ((bool_phonevalid == true) && (str_pno == "000-0000"))
   {
	   alert("Please enter valid Phone/Fax/Mobile Number(Ex. 999-9999)");
	   bool_phonevalid=false;
	   phonefield.select();
	   phonefield.focus();   	
   }
   // Checks for a valid extension number   
   if (((bool_phonevalid==true) && (str_ext != "")) && ((isNaN(str_ext)) || (str_ext < 0)))
   {
	   alert("Please enter a valid " + msg + " extension number");
	   bool_phonevalid=false;			   
	   extfield.select();
	   extfield.focus();
   }
   // Checks if the extension contains all Zeros
   if ((bool_phonevalid==true) && (str_ext != ""))
   {
	   var exists = 0
	   for (j=0;j<str_ext.length;j++)
	   {
		   var ch = str_ext.substring(j, j+1)
		   if (ch != 0)
		   {
				exists = 1
				break;
		   }
	   }	   
	   if (exists == 0)
	   {
			alert("Please enter a valid " + msg + " extension number");
			bool_phonevalid=false;			   
			extfield.select();
			extfield.focus();
	   }	   
   }
     //Return the status of the Phone Number or Fax Number or Mobile Number validity
   return bool_phonevalid
}

/*function putCountryCode()
{
   document.frm_personal_info.txt_f_country_code.value = document.frm_personal_info.txt_ContPhone_country_code.value
   document.frm_personal_info.txt_m_country_code.value = document.frm_personal_info.txt_ContPhone_country_code.value
} */  

// To key in the Area Code when it is keyed in for Phone Number
function putSTDCode()
{
   document.frm_personal_info.txt_f_std_code.value = document.frm_personal_info.txt_ContPhone_std_code.value
   document.frm_personal_info.txt_m_std_code.value = document.frm_personal_info.txt_ContPhone_std_code.value
}

// This function checks the validity of the state and zip code fields
function isStateZipValid()
{
   var bool_valid=true;
   var str_State=Trim(document.frm_personal_info.txt_comp_state.value)
   var str_Zip=Trim(document.frm_personal_info.txt_comp_zip.value)
   var str_ZipExt=Trim(document.frm_personal_info.txt_comp_zipext.value)

   // Checks whether State is empty
   if(str_State=="")
   {
		 alert("State should be provided");
	     bool_valid=false;
		 document.frm_personal_info.txt_comp_state.select();
	     document.frm_personal_info.txt_comp_state.focus();
	}	
   //Checks whether the state starts with an alphabet
   if (bool_valid == true)
   {
	    var ch=str_State.substring(0,1);
		if( (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) )  
		{
 			alert ("First letter of State must be an alphabet");
 			bool_valid=false;
			document.frm_personal_info.txt_comp_state.select();
			document.frm_personal_info.txt_comp_state.focus();
		}
   }
  // Checks whether state contains any special characters
   if ((bool_valid == true) && (isvalid(str_State,"~!@#$%^&*()-+=`{}|[]\\/<>:\";,?_") == false))
   {	
		bool_valid=false;
		document.frm_personal_info.txt_comp_state.select();
		document.frm_personal_info.txt_comp_state.focus();
   }
	// Checks whether ZipCode is empty
	if(bool_valid == true && str_Zip=="")
	{
		 alert("Zip code must be provided");
	     bool_valid=false;
		 document.frm_personal_info.txt_comp_zip.select();
	     document.frm_personal_info.txt_comp_zip.focus();
	}
	// Checks whether ZipCode consists of 5 characters
	if ((bool_valid == true) && (str_Zip.length < 5))
	{
		alert("ZipCode should be 5 characters length");
		bool_valid = false;
		document.frm_personal_info.txt_comp_zip.select();
	    document.frm_personal_info.txt_comp_zip.focus();
	}
	// Checks whether zip code is numeric
	if (((bool_valid == true) && (str_Zip != "")) && ((isNaN(str_Zip)) || (str_Zip < 0)))
	{
		alert("Please enter a valid zip code");
		bool_valid = false
		document.frm_personal_info.txt_comp_zip.select();
	    document.frm_personal_info.txt_comp_zip.focus();
	}
	// Checks whether ZipCode contains all Zeros
	if (bool_valid == true && str_Zip == "00000")
	{
		alert("Please enter a valid ZipCode");
		bool_valid = false;
		document.frm_personal_info.txt_comp_zip.select();
		document.frm_personal_info.txt_comp_zip.focus();		
	}
	// Checks whether zip extension is numeric
	if (((bool_valid == true) && (str_ZipExt != "")) && ((isNaN(str_ZipExt)) || (str_ZipExt < 0)))
	{
		alert("Please enter a valid zip extension");
		bool_valid = false;
		document.frm_personal_info.txt_comp_zipext.select();
	    document.frm_personal_info.txt_comp_zipext.focus();
	}
	if ((bool_valid == true) && (str_ZipExt != "") && (str_ZipExt.length < 4))
	{
		alert("Zip Extension should be 4 characters length");
		bool_valid = false;
		document.frm_personal_info.txt_comp_zipext.select();
	    document.frm_personal_info.txt_comp_zipext.focus();
	}
	// Checks whether ZipCode contains all Zeros
	if (bool_valid == true && str_ZipExt != "" && str_ZipExt == "0000")
	{		
		alert("Please enter a valid Zip Extension");
		bool_valid = false;
		document.frm_personal_info.txt_comp_zipext.select();
		document.frm_personal_info.txt_comp_zipext.focus();		
	}
	  //Return the status of the State and ZipCode validity
	return bool_valid;
}

// This function checks the keyed in value is not a number
function keyCheck(eventObj, obj)
{
	var keyCode
	// Check For Browser Type
	if (document.all){ 
		keyCode=eventObj.keyCode
	}
	else{
		keyCode=eventObj.which
	}
	var str=obj.value
	// blocks the functioning of delete key
	if(keyCode==46)
	{ 
		if (str.indexOf(".")>0)
		{
			return false
		}
	}
	if((keyCode >=48 && keyCode <58)   &&   (keyCode != 46))
	{ // Allow only integers and decimal points
		return false
	}
	return true
}

// This function checks the validity of the current password, new password and confirm password field
function isCPassWord() 
{
var txt_cpwd=document.frm_personal_info.pss_user_cpwd.value;
var txt_pwd=document.frm_personal_info.pss_user_pwd.value;
var txt_cnfp=document.frm_personal_info.pss_conf_pwd.value;
var txt_uid=document.frm_personal_info.txt_user_id.value;
var bool_opwdvalid=true;
var bool_pwdvalid=true;
var bool_cpwdvalid=true;

//Checks whether the old password is empty
if ( txt_cpwd=="" ) 
{
    alert ("Current Password must not be blank");
    bool_opwdvalid=false;
}
//Checks whether the old password length is less than 6 chars
else if (txt_cpwd.length < 6 ) 
{
    alert ("Current Password must have minimum 6 characters");
    bool_opwdvalid=false;
}
//Checks whether the old password length exceeds 50 chars
else if (txt_cpwd.length > 50)
{
    alert ("Current Password must not exceed 50 characters");
    bool_opwdvalid=false; 
}
// Checks whether the current password contains all spaces
if ( bool_opwdvalid==true ) 
{
   for(var int_i=0;int_i<txt_cpwd.length;int_i++)
   {
	 var ch=txt_cpwd.substring(int_i,int_i+1)
	 if ( ch==" " ) 
	 {
		alert ("Current Password must not contain space");
		bool_opwdvalid=false;
		break;
	 }
   }
}
// checks whether if password contain special characters
if(bool_opwdvalid==true)
 {	
	bool_opwdvalid = isvalid(txt_cpwd,"~!@#$%^&*()-+=`{}|[]\\/<>:\";',?")
 }
if (bool_opwdvalid == true)
{
	//Checks whether the New password is empty
	if ( txt_pwd=="" ) 
	{
		alert ("New Password must not be blank");
		bool_pwdvalid=false;
	}
	//Checks whether the password length is less than 6 chars
	else if (txt_pwd.length < 6 ) 
	{
		alert ("New Password must have minimum 6 characters");
		bool_pwdvalid=false;
	}
	//Checks whether the password length exceeds 50 chars
	else if (txt_pwd.length > 50)
	{
		alert ("New Password must not exceed 50 characters");
		bool_pwdvalid=false; 
	}
	//Checks whether the new password is same as current password
	else if (txt_pwd==document.frm_personal_info.pss_user_cpwd.value)
	{
		alert ("New Password must not be same as Old Password");
		bool_pwdvalid=false; 
	}  
	//Checks whether new password is same as userid
	else if (txt_pwd == txt_uid)
	{
		alert ("New Password must not be same as User Id");
		bool_pwdvalid=false; 
	}
	//Checks if the password has any spaces in it
	if ( bool_pwdvalid==true ) 
	{
	   for(var int_i=0;int_i<txt_pwd.length;int_i++)
	   {
		 var ch=txt_pwd.substring(int_i,int_i+1)
		 if ( ch==" " ) 
		 {
			alert ("New Password must not contain space");
			bool_pwdvalid=false;
			break;
		 }
		}
	}
	// checks whether if password contain special characters
	if(bool_pwdvalid==true)
	 {	
		bool_pwdvalid = isvalid(txt_pwd,"~!@#$%^&*()-+=`{}|[]\\/<>:\";',?")
	 }
	//Check whether the Confirm password is entered
	if ((bool_pwdvalid==true) && (txt_cnfp == ""))
	{
		alert("Confirm Password must not be blank");
		bool_cpwdvalid = false;
	}

	//Checks if the confirm password has any spaces in it
	if ( bool_cpwdvalid==true ) 
	{
	   for(var int_i=0;int_i<txt_cnfp.length;int_i++)
	   {
		 var ch=txt_cnfp.substring(int_i,int_i+1)
		 if ( ch==" " ) 
		 {
			alert ("Confirm Password must not contain space");
			bool_cpwdvalid=false;
			break;
		 }
	   }
	}
	// checks whether if password contain special characters
	if(bool_cpwdvalid==true)
	 {	
		bool_cpwdvalid = isvalid(txt_cnfp,"~!@#$%^&*()-+=`{}|[]\\/<>:\";',?")
	 }
	//Check whether the password entered both the times are same   
	if (((bool_pwdvalid==true) && (bool_cpwdvalid==true)) && (txt_pwd!=txt_cnfp))  
	{
	   alert("Password and Confirm Password do not match");
	   bool_pwdvalid=false
	}
}
//If the new password is not satisfying all criterion then the focus is set on the new password field
if ( bool_pwdvalid==false )
{
   document.frm_personal_info.pss_user_pwd.select()
   document.frm_personal_info.pss_user_pwd.focus()
}

//If the confirm password is not satisfying all criterion then the focus is set on the confirm password field
if ( bool_cpwdvalid==false )
{
   document.frm_personal_info.pss_conf_pwd.select()
   document.frm_personal_info.pss_conf_pwd.focus()
   bool_pwdvalid = false
}

//If the current password is not satisfying all criterion then the focus is set on the current password field
if (bool_opwdvalid == false)
{
   document.frm_personal_info.pss_user_cpwd.select()
   document.frm_personal_info.pss_user_cpwd.focus()
   bool_pwdvalid = false
}
//Return the status of the Password validity
return bool_pwdvalid
}

// This function is to check the validity of hint question and hint answer
function isHint(from_status) 
{
var txt_ques=document.frm_personal_info.cmb_hint_ques.selectedIndex 
var txt_ans=Trim(document.frm_personal_info.pss_hint_ans.value)
var bool_hintqvalid=true
var bool_hintavalid=true

// Checks whether Hint Question is selected
if (txt_ques==0) 
{
  alert ("Hint question must be selected.");
  bool_hintqvalid=false;
}
// Checks whether Hint Answer is blank
else if (bool_hintqvalid==true && txt_ans=="")
{
  alert("Hint answer must not be blank");
  bool_hintavalid=false; 
}
// Checks whether hint answer is of atleast 3 chars
else if (bool_hintqvalid==true && txt_ans.length < 3)
{
  alert("Hint Answer must be minimum of 3 characters");
  bool_hintavalid=false; 
}
// Checks whether hint answer is same as password
if(from_status==1 && bool_hintavalid==true  && bool_hintqvalid==true && document.frm_personal_info.pss_user_pwd.value==txt_ans)
{
   alert ("Hint Answer must not be same as password");
   bool_hintavalid=false;
}
// Checks whether hint answer is same as userid
if(from_status==1 && bool_hintavalid==true  && bool_hintqvalid==true && document.frm_personal_info.txt_user_id.value==txt_ans)
{
   alert ("Hint Answer must not be same as userid");
   bool_hintavalid=false;
}
//If the hint question is not satisfying all criterion then the focus is set on the hint question field
if (bool_hintqvalid==false)
{
   document.frm_personal_info.cmb_hint_ques.focus();
}
//If the hint answer is not satisfying all criterion then the focus is set on the hint answer field
if (bool_hintavalid==false)
{
   document.frm_personal_info.pss_hint_ans.select();
   document.frm_personal_info.pss_hint_ans.focus();
}
//Return the status of the hint question ans hint answer validity
if (bool_hintqvalid==false || bool_hintavalid==false)
{
  return false;
}
else
{
  return true;
}    
}

//This function checks whether the field is blank
function isBlank(inField,Msg)
{	
   bool_blank=true;
   if (inField.value=="")
   {
     alert (Msg);
     bool_blank=false;
     inField.select();
     inField.focus();
   }
   // Returns the status of the validity of the field
   return bool_blank;
}      

//This function is to check whether the keyed in value is a number
function keyCheckN(eventObj, obj)
{
	var keyCode
	// Check For Browser Type
	if (document.all){ 
		keyCode=eventObj.keyCode
	}
	else{
		keyCode=eventObj.which
	}	
	var str=obj.value
	if(keyCode==46)
	{ 
		if (str.indexOf(".")>0)
		{
			return false
		}
	}	
	// Allow only integers and decimal points
	if(((keyCode >47 && keyCode <58) && (keyCode != 46)) || (keyCode == 13))	
	{	
		return true 
	}		
	else
	{
		return false
	}	
	return true
}

// This function limits the characters to the length specified
function textLimit(field, maxlen) 
{	
	if (field.value.length > maxlen)
	field.value = field.value.substring(0, maxlen);
}