/*********************************************************************/
/*  Function Name ** Description                  ** Returns         */ 
/*********************************************************************/
/*                **                              **                 */
/*  isBlank       ** Checks for embedded blank    ** False, when the */
/*                ** Spaces.                      ** value has blank */ 
/*                **                              ** Spaces. Else    */   
/*                **                              ** True            */
/*                **                              **                 */  
/*  isNumber      ** Checks for Valid Numeric     ** False, when the */
/*                ** entries.                     ** value has non   */ 
/*                **                              ** numeric entries */  
/*                **                              **                 */  
/*  trimtxt       ** Trims leading/trailing       ** Trimmed text    */
/*                ** spaces.                      **                 */
/*                **                              **                 */
/*  Remove_Suc_Spaces_InString                    ** Removed white   */
/*                **  Removes in between          ** Spaces within   */
/*                **  whitespaces in the string   ** the string      */
/*                **  leaving one. This is also   **                 */
/*                **  applicable to Text Area     **                 */  
/*                **                              **                 */  
/*  ErrMsg        **  Alerts an message  set the  ** Returns false   */
/*                **  focus in the form object    ** Always.         */
/*                **                              **                 */                                   
/*  isdateDMY     **  Checks for valid date in    ** Returns True    */
/*                **  DD/MM/CCYY format.          ** when date is    */
/*                **                              ** valid, else     */
/*                **                              ** will return     */
/*                **                              ** false.          */
/*                **                              **                 */  
/*  isdateMDY     **  Checks for valid date in    ** Returns True    */
/*                **  MM/DD/CCYY format.          ** when date is    */
/*                **                              ** valid, else     */
/*                **                              ** will return     */
/*                **                              ** false.          */
/*                **                              **                 */  
/*  dateval       ** Checks for valid date.       ** Return false    */
/*                ** can accept the format as     ** when invalid    */
/*                ** the input parameter.         ** date is entered */
/*                ** Default is MM/DD/CCYY format **                 */
/*                **                              **                 */  
/*  DateCmp       ** Compares two dates.          ** Return  0:Equal */
/*                ** Also checks for the validity ** Return -1:Less  */
/*                ** of the input dates.          ** Return 1:Greater*/
/*                ** Alerts an error message if   **                 */
/*                ** i/p date is invalid.         **                 */
/*                **                              **                 */  
/*  isEmpty       ** Checks for Nulls             ** Retruns false   */
/*                **                              ** when Nulls.     */
/*                **                              **                 */
/*                **                              **                 */  
/*  isAlpha       ** Checks for valid Alphabets   ** Returns false   */
/*                **                              ** when other than */
/*                **                              ** Alphabets is    */
/*                **                              ** entered.        */
/*                **                              **                 */  
/*  isAlphaNumeric** Checks for valid Alphabets   ** Returns false   */
/*                ** and numbers                  ** when other than */
/*                **                              ** Alphabets or    */
/*                **                              ** Number is       */
/*                **                              ** entered         */
/*                **                              **                 */    
/*  isEmail       ** Checks for valid Email       ** Returns false   */
/*                ** Entry                        ** when other than */
/*                **                              ** Email is        */
/*                **                              ** entered.        */
/*                **                              **                 */  
/*  isPhone       ** Checks for valid Phone       ** Returns false   */
/*                ** Number                       ** when other than */
/*                **                              ** Phone No is     */
/*                **                              ** entered.        */
/*                **                              **                 */  
/*                **                              **                 */  
/*  isMobile      ** Checks for valid Mobile      ** Returns True    */
/*                ** Number                       ** for valid mobile*/
/*                **                              ** Number entered. */
/*                **                              **                 */  
/*  isPager       ** Checks for valid Mobile      ** Returns True    */
/*                ** Number                       ** for valid Pager */
/*                **                              ** Number entered. */
/*                **                              **                 */  
/*  isZipcode     ** Checks for valid Zip code    ** Returns True    */
/*                ** Number                       ** for valid zip   */
/*                **                              ** code   entered. */
/*                **                              **                 */  
/*                **                              **                 */  
/*  isName        ** Checks for valid Name        ** Returns false   */
/*                **                              ** when other than */
/*                **                              ** Name is         */
/*                **                              ** entered.        */
/*********************************************************************/
/*********************************************************************/



/* Check for Embedded Blank field 

Function Name :  isBlank

Short Description :

This function checks for embedded blank spaces.
The  input is the form object which is to be validated for
embedded blanks.

N.B.This function does not check for full blanks

Return Value :This function returns false if  embedded
blanks are present.

*/


function isBlank(formObj)		
{
	var objVal    = formObj.value;
	var valLength = objVal.length;

	if (valLength == 0)
		return true; 
	if(objVal != "")
 	  {
		for (var i= 0; i < valLength; i++)
		{
			if (objVal.charAt(i) == ' ' || objVal.charAt(i) == '\t'
				|| objVal.charAt(i) == '\r' || objVal.charAt(i) == '\n')
			{
				return false;
			}
		}
	}
	return true;
}

////////////////////// END  //////////////////////////////////


/* THIS FUNCTION CHECKS FOR NON NUMERIC ENTRIES

Function Name :  isNumber

Short Description :

This function checks for Non numeric entries.
The  input is the form object which is to be validated for
Non numeric entries.

Return Value :This function returns false if  Non numeric 
entries are present.

*/

function isNumber(formObj)
{
	var testChar  = " ";
	var objVal    = formObj.value;
	var valLength = objVal.length;
	for (var i=0; i < valLength; i++)
	{
		testChar = objVal.charAt(i);
		if (testChar < '0' || testChar > '9') 
		{
			return false;
		}
	}
	
	return true;
}
////////////////////////////   END  /////////////////////////////

/* THIS FUNCTION CHECKS FOR NON FLOAT ENTRIES

Function Name :  isFloat

Short Description :

This function checks for Non float entries.
The  input is the form object which is to be validated for
Non float entries.

Return Value :This function returns false if  Non float 
entries are present.

*/

function isFloat(formObj)
{
	var testChar  = " ";
	var objVal    = formObj.value;
	var valLength = objVal.length;
	for (var i=0; i < valLength; i++)
	{
		testChar = objVal.charAt(i);
		if ((testChar < '0' || testChar > '9') && (testChar != '.')) 
		{
			return false;
		}
	}
	
	return true;
}
////////////////////////////   END  /////////////////////////////
/* THIS FUNCTION CHECKS FOR NON TIME ENTRIES

Function Name :  isTime

Short Description :

This function checks for Non time entries.
The  input is the form object which is to be validated for
Non time entries.

Return Value :This function returns false if  Non time 
entries are present.

*/

function isTime(formObj)		
{
	var objVal    = formObj.value;
	var valLength = objVal.length;

	if (valLength == 0)
		return true; 
	
	if(objVal != "")
 	{
		
		for (var i=0; i < valLength; i++)
		{
			if ((objVal.charAt(i) < '0' || objVal.charAt(i) > '9') && (objVal.charAt(i) != ':')) 
			{
				return false;
			}
			if ((i == 0 && objVal.charAt(i) == ':') || (i == valLength-1 && objVal.charAt(i) == ':')) 
			{
				return false;
			}
		}
		
		ary = new Array();
		ary = objVal.split(":")
	
		if (ary[0] < 1 || ary[0] > 24) 
		{
			return false;
		}
		if (ary[1] < 0 || ary[1] > 59)
		{
			return false;
		}
	 }	
return true;
}
////////////////////////////   END  /////////////////////////////
////////////////////////////   END  /////////////////////////////

/* TRIMS LEADING AND TRAILING SPACES

Function Name :  trimtxt

Short Description :

This function trims leading and trailing spaces.
The  input is the form object whose value is to be trimmed.

Return Value : This returns the trimmed text.

*/

	
	
function trimtxt(formobj)
 {
 	var txtval = formobj.value;
	var txtlen = txtval.length;
	var firstindex = -1;
	var lastindex = -1;
	var finaltxt = "";
		
	for (i=0;i<txtlen;i++)
	{
		if (txtval.charAt(i) == " ")
		{	continue ;}
		else
		{ 
			firstindex = i;
			break;
		}
	}
		
	for (i=txtlen-1;i>=0;i--)
	{
		if (txtval.charAt(i) == " ")
		{ 	continue ;}
		else
		{ 
			lastindex = i;
			break;
		}
     } 

	 if (firstindex < 0 && lastindex < 0)
	 {
	 		return "";
	 }
	
	   
	 finaltxt = txtval.substring(firstindex,lastindex+1); 
	 return finaltxt;
}

////////////////////////////   END  /////////////////////////////

/* THIS FUNCTION REMOVES in between white spaces WHICH APPEAR IN STRING S LEAVING ONE.

Function Name :  Remove_Suc_Spaces_InString

Short Description :

THIS FUNCTION Removes in between white spaces which appear in string s leaving one.
The  input is the form object value. 

Return Value :This function returns the String which is stripped off.

*/

function Remove_Suc_Spaces_InString (s)
{   
	var i;
    var whitespace = " \t\n\r";
	var returnString = "";
	var check=0;
	

    // Search through string's characters one by one.
    // If character is not in WhiteSpace, append to returnString.
	
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) 
			{
				returnString += c;
				check=0;
			}
		else if (check==0)
				{
		    		returnString += c;
					check=1;	
				}	
     }

    return returnString;
}


////////////////////////////   END  /////////////////////////////

/* THIS FUNCTION ALERT THE USER AN ERROR MESSAGE, SELECTS AND SET FOCUS IN IT.

Function Name :  ErrMsg

Short Description :

	Notify user that contents of field theField are invalid.
 	String s describes expected contents of theField.value.
 	String s is the Error Message Which will be Displayed in the Alert Box.
 	Put select theField, put focus in it, and return false.
*/

function ErrMsg (theField, s)
{   
	theField.focus();
///    theField.select();  *** select on fields removed.
    alert(s);
    return false;
}

////////////////////////////   END  /////////////////////////////

/* function for date validations.

Function Name :  isDateDMY

Short Description :

This function checks for a valid date in DD/MM/CCYY format.
The  input is the form object for which date validation is required.

Date between 1900A.D and 9999 A.D will be accepted.

Input Parameters : Date

Return Value : This returns false in case of an 
invalid date.

*/
var reDate=/(^[0-9]+)\/+([0-9]+)\/+([0-9]+)$/

function isDateDMY(text)
 {
  var sun = text.value;
  var i;
  var a = new Array();
  var b,c;
  var x=0;

  if (reDate.test(text.value))                           // Code to split the value entered
         { newstr = sun.split(reDate,"$1,$2,$3");        // into DD/MM/YYYY using
           var dd_from1=RegExp.$1;                       // Regular Expressions
           var mm_from1=RegExp.$2;
           var yy_from1=RegExp.$3;
         }
  else
    { 
	//text.select();  ** select on fields removed.
	text.focus(); return false; }   	// If Date entered is invalid
 
  if(yy_from1  < 1900 )
  {//text.select(); select on field removed.
  text.focus();return false;}			// If CC field is not entered

  if(!reDate.test(text.value))
  {//text.select(); ** select on fields removed
  text.focus();return false;}
  else
	{													// Following piece of code is to 
    for(i=0;i<text.value.length;i++)					// Pad '0's before when single 
    { 													// digit is entered for dd/mm fields.
	  if (text.value.charAt(i) == " ")
	  {//text.select(); ** select on fields removed
	  text.focus();return false;}
	  else
     {a[i] = text.value.charAt(i); if (a[i] == '/') {x++;} }
    }
	if (x > 2)
	{//text.select();  ** select on fields removed.
	text.focus();return false;} 
	else if (((a[1] == '/')  || (a[2] == '/')) && ((a[3] == '/')  || (a[4] == '/') || (a[5] == '/')))  
	{
   if ((a[1] == '/') && (a[3] == '/'))
    {
	   if ((a[6] != null) && (a[7] != null))
      {text.value=("0"+a[0]+a[1]+"0"+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]);}
	   else if (a[5] == null) {//text.select();  ** select on fields removed
	                           text.focus();return false;} 
	   else if ((((a[6] == null) && (a[7] == null)) || ((a[6] == "") && (a[7] == ""))) && (a[4] < 4))
	   {text.value=("0"+a[0]+a[1]+"0"+a[2]+a[3]+"20"+a[4]+a[5]);}
	   else if ((((a[6] == null) && (a[7] == null)) || ((a[6] == "") && (a[7] == ""))) && (a[4] >= 4))
	   {text.value=("0"+a[0]+a[1]+"0"+a[2]+a[3]+"19"+a[4]+a[5]);}	   
	   else
	   {//text.select();  ** select on fields removed.
	   text.focus();return false;}
	 }
	 
  else if ((a[2] == '/') && (a[4] == '/'))
    {
	   if ((a[7] != null) && (a[8] != null))
      {text.value=(a[0]+a[1]+a[2]+"0"+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]);}
	   else if (a[6] == null){//text.select(); ** select on fields removed
	                           text.focus();return false;} 	   
	   else if ((((a[7] == null) && (a[8] == null)) || ((a[7] == "") && (a[8] == ""))) && (a[5] < 4))
	   {text.value=(a[0]+a[1]+a[2]+"0"+a[3]+a[4]+"20"+a[5]+a[6]);}
	   else if ((((a[7] == null) && (a[8] == null)) || ((a[7] == "") && (a[8] == ""))) && (a[5] >= 4))
      {text.value=(a[0]+a[1]+a[2]+"0"+a[3]+a[4]+"19"+a[5]+a[6]);}
	   else
	   {//text.select(); ** select on fields removed
	   text.focus();return false;}
	 } 
  else if ((a[2] == '/') && (a[5] == '/'))
   {
	   if ((a[8] != null) && (a[9] != null))
      {text.value=(a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9]);}     
	   else if (a[7] == null) {//text.select(); ** select on fields removed
	                             text.focus();return false;} 	   
	   else if ((((a[8] == null) && (a[9] == null)) || ((a[8] == "") && (a[9] == ""))) && (a[6] < 4))
 {text.value=(a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+"20"+a[6]+a[7]);}
	   else if ((((a[8] == null) && (a[9] == null)) || ((a[8] == "") && (a[9] == ""))) && (a[6] >= 4))
	   {text.value=(a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+"19"+a[6]+a[7]);}
	   else
	   { //text.select(); ** select on fields removed
	        text.focus();return false;}
   } 
 else if ((a[1] == '/') && (a[4] == '/'))
   {
	   if ((a[7] != null) && (a[8] != null))
      {text.value=("0"+a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]);}
	   else if (a[6] == null) {//text.select(); ** select on fields removed
	                          text.focus();return false;} 	   
	   else if ((((a[7] == null) && (a[8] == null)) || ((a[7] == null) && (a[8] == null))) && (a[5] < 4))
	   {text.value=("0"+a[0]+a[1]+a[2]+a[3]+a[4]+"20"+a[5]+a[6]);}
	   else if ((((a[7] == null) && (a[8] == null)) || ((a[7] == null) && (a[8] == null))) && (a[5] >= 4))
	   {text.value=("0"+a[0]+a[1]+a[2]+a[3]+a[4]+"19"+a[5]+a[6]);}
	   else
	   {//text.select(); ** select on fields removed
	     text.focus();return false;}
	} 
  else {//text.select(); ** select on fields removed
           text.focus();return false;} 	

  var dd = text.value.substring(0,2);
  var mm = text.value.substring(3,5);
  var yy = text.value.substring(6,10);

 if ((dd == "") || (dd == 0) || (dd > 31))
  {//text.select();** select on fields removed
    text.focus();return false;}
 else if((mm == "") || (mm == 0) || (mm > 12))
  {//text.select();** select on fields removed
  text.focus();return false;}
 else if (((yy % 100) == 0) && (mm == 2) && (dd == 29))			// Leap year Check
           { if (((yy %400) == 0) && (mm == 2) && (dd == 29))
		        return true; 
	         else
			 {//text.select();** select on fields removed
			 text.focus();return false;} }
	  else if (((yy % 4) == 0) && (mm == 2) && (dd == 29))
		   return true;  
//  ((((yy % 4) == 0) || ((yy % 100) == 0) || ((yy %400) == 0)) && (mm == 2) && (dd == 29))
//   {return true;}
 else if (((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11)) && (dd > 30)) 
  { //text.select(); ** select on fields removed
  text.focus();return false;}
 else if ((mm == 2) && (dd > 28)) 
  {//text.select(); ** select on fields removed
  text.focus();return false;}   
 else if ((mm == 2) && (dd > 29) && (((yy % 4) != 0) || ((yy % 100) != 0) || ((yy %400) != 0)))
  { // text.select(); ** select on fields removed
  text.focus();return false;}
 else if (yy < 1900)
  {//text.select(); ** select on fields removed
  text.focus();return false;}
   
 }
 else
 {//text.select(); ** select on fields removed
 text.focus();return false;}
}
return true;
}

function isDateDMYValue(text)
 {
  var sun = text.value;
  var i;
  var a = new Array();
  var b,c;
  var x=0;

  if (reDate.test(text.value))                           // Code to split the value entered
         { newstr = sun.split(reDate,"$1,$2,$3");        // into DD/MM/YYYY using
           var dd_from1=RegExp.$1;                       // Regular Expressions
           var mm_from1=RegExp.$2;
           var yy_from1=RegExp.$3;
         }
  else
    { 
	return false; }   	// If Date entered is invalid
 
  if(yy_from1  < 1900 )
  {return false;}			// If CC field is not entered

  if(!reDate.test(text.value))
  {return false;}
  else
	{													// Following piece of code is to 
    for(i=0;i<text.value.length;i++)					// Pad '0's before when single 
    { 													// digit is entered for dd/mm fields.
	  if (text.value.charAt(i) == " ")
	  {return false;}
	  else
     {a[i] = text.value.charAt(i); if (a[i] == '/') {x++;} }
    }
	if (x > 2)
	{return false;} 
	else if (((a[1] == '/')  || (a[2] == '/')) && ((a[3] == '/')  || (a[4] == '/') || (a[5] == '/')))  
	{
   if ((a[1] == '/') && (a[3] == '/'))
    {
	   if ((a[6] != null) && (a[7] != null))
      {text.value=("0"+a[0]+a[1]+"0"+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]);}
	   else if (a[5] == null) {//text.select();  ** select on fields removed
	                           text.focus();return false;} 
	   else if ((((a[6] == null) && (a[7] == null)) || ((a[6] == "") && (a[7] == ""))) && (a[4] < 4))
	   {text.value=("0"+a[0]+a[1]+"0"+a[2]+a[3]+"20"+a[4]+a[5]);}
	   else if ((((a[6] == null) && (a[7] == null)) || ((a[6] == "") && (a[7] == ""))) && (a[4] >= 4))
	   {text.value=("0"+a[0]+a[1]+"0"+a[2]+a[3]+"19"+a[4]+a[5]);}	   
	   else
	   {return false;}
	 }
	 
  else if ((a[2] == '/') && (a[4] == '/'))
    {
	   if ((a[7] != null) && (a[8] != null))
      {text.value=(a[0]+a[1]+a[2]+"0"+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]);}
	   else if (a[6] == null){//text.select(); ** select on fields removed
	                           text.focus();return false;} 	   
	   else if ((((a[7] == null) && (a[8] == null)) || ((a[7] == "") && (a[8] == ""))) && (a[5] < 4))
	   {text.value=(a[0]+a[1]+a[2]+"0"+a[3]+a[4]+"20"+a[5]+a[6]);}
	   else if ((((a[7] == null) && (a[8] == null)) || ((a[7] == "") && (a[8] == ""))) && (a[5] >= 4))
      {text.value=(a[0]+a[1]+a[2]+"0"+a[3]+a[4]+"19"+a[5]+a[6]);}
	   else
	   {return false;}
	 } 
  else if ((a[2] == '/') && (a[5] == '/'))
   {
	   if ((a[8] != null) && (a[9] != null))
      {text.value=(a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9]);}     
	   else if (a[7] == null) {//text.select(); ** select on fields removed
	                             text.focus();return false;} 	   
	   else if ((((a[8] == null) && (a[9] == null)) || ((a[8] == "") && (a[9] == ""))) && (a[6] < 4))
 {text.value=(a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+"20"+a[6]+a[7]);}
	   else if ((((a[8] == null) && (a[9] == null)) || ((a[8] == "") && (a[9] == ""))) && (a[6] >= 4))
	   {text.value=(a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+"19"+a[6]+a[7]);}
	   else
	   { return false;}
   } 
 else if ((a[1] == '/') && (a[4] == '/'))
   {
	   if ((a[7] != null) && (a[8] != null))
      {text.value=("0"+a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]);}
	   else if (a[6] == null) {//text.select(); ** select on fields removed
	                          text.focus();return false;} 	   
	   else if ((((a[7] == null) && (a[8] == null)) || ((a[7] == null) && (a[8] == null))) && (a[5] < 4))
	   {text.value=("0"+a[0]+a[1]+a[2]+a[3]+a[4]+"20"+a[5]+a[6]);}
	   else if ((((a[7] == null) && (a[8] == null)) || ((a[7] == null) && (a[8] == null))) && (a[5] >= 4))
	   {text.value=("0"+a[0]+a[1]+a[2]+a[3]+a[4]+"19"+a[5]+a[6]);}
	   else
	   {return false;}
	} 
  else {return false;} 	

  var dd = text.value.substring(0,2);
  var mm = text.value.substring(3,5);
  var yy = text.value.substring(6,10);

 if ((dd == "") || (dd == 0) || (dd > 31))
  {return false;}
 else if((mm == "") || (mm == 0) || (mm > 12))
  {return false;}
 else if (((yy % 100) == 0) && (mm == 2) && (dd == 29))			// Leap year Check
           { if (((yy %400) == 0) && (mm == 2) && (dd == 29))
		        return true; 
	         else
			 {return false;} }
	  else if (((yy % 4) == 0) && (mm == 2) && (dd == 29))
		   return true;  
//  ((((yy % 4) == 0) || ((yy % 100) == 0) || ((yy %400) == 0)) && (mm == 2) && (dd == 29))
//   {return true;}
 else if (((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11)) && (dd > 30)) 
  { return false;}
 else if ((mm == 2) && (dd > 28)) 
  {return false;}   
 else if ((mm == 2) && (dd > 29) && (((yy % 4) != 0) || ((yy % 100) != 0) || ((yy %400) != 0)))
  { return false;}
 else if (yy < 1900)
  {return false;}
   
 }
 else
 {return false;}
}
return true;
}

////////////////////////////   END  /////////////////////////////

/* function for date validations.

Function Name :  isDateMDY

Short Description :

This function checks for a valid date in MM/DD/CCYY format.
The  input is the form object for which date validation is required.

Date between 1900A.D and 9999 A.D will be accepted.

Input Parameters : Date

Return Value : This returns false in case of an 
invalid date.

*/

function isDateMDY(text)
 {
  var sun = text.value;
 
  var i;
  var a = new Array();
  var b,c;
  var x=0;

  if (reDate.test(text.value))							// Check whether the value entered is
         { newstr = sun.split(reDate,"$1,$2,$3");       // in the format specified
           var mm_from1=RegExp.$1;						// using Regular Expressions.
           var dd_from1=RegExp.$2;
           var yy_from1=RegExp.$3;
         }
   else
     { //text.select(); ** select on fields removed
	  text.focus(); return false; }		// Say Invalid date if not in the format
 														// specified.
  if(yy_from1  < 1900 )
     {// text.select();** select on fields removed
	  text.focus(); return false; }

  if(!reDate.test(text.value))
     {// text.select();** select on fields removed
	  text.focus(); return false; }
  else
	{
    for(i=0;i<text.value.length;i++)
    { 
	  if (text.value.charAt(i) == " ")
	  { //text.select();** select on fields removed
	   text.focus(); return false; }
	  else
     {a[i] = text.value.charAt(i); if (a[i] == '/') {x++;} }
    }
	if (x > 2)											// Following piece of code is to pad '0's
	  { //text.select();
	     text.focus(); return false; }	// when single digit is entered for dd/mm
	else if (((a[1] == '/')  || (a[2] == '/')) && ((a[3] == '/')  || (a[4] == '/') || (a[5] == '/')))  
	{
   if ((a[1] == '/') && (a[3] == '/'))
    {
	   if ((a[6] != null) && (a[7] != null))
      {text.value=("0"+a[0]+a[1]+"0"+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]);}
	   else if (a[5] == null) { //text.select(); ** select on fields removed
	                             text.focus(); return false; } 
	   else if ((((a[6] == null) && (a[7] == null)) || ((a[6] == "") && (a[7] == ""))) && (a[4] < 4))
	   {text.value=("0"+a[0]+a[1]+"0"+a[2]+a[3]+"20"+a[4]+a[5]);}
	   else if ((((a[6] == null) && (a[7] == null)) || ((a[6] == "") && (a[7] == ""))) && (a[4] >= 4))
	   {text.value=("0"+a[0]+a[1]+"0"+a[2]+a[3]+"19"+a[4]+a[5]);}	   
	   else
	   { //text.select(); ** select on fields removed
	   text.focus(); return false; }
	 }
	 
  else if ((a[2] == '/') && (a[4] == '/'))
    {
	   if ((a[7] != null) && (a[8] != null))
      {text.value=(a[0]+a[1]+a[2]+"0"+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]);}
	   else if (a[6] == null) { //text.select();** select on fields removed
	    text.focus(); return false; } 	   
	   else if ((((a[7] == null) && (a[8] == null)) || ((a[7] == "") && (a[8] == ""))) && (a[5] < 4))
	   {text.value=(a[0]+a[1]+a[2]+"0"+a[3]+a[4]+"20"+a[5]+a[6]);}
	   else if ((((a[7] == null) && (a[8] == null)) || ((a[7] == "") && (a[8] == ""))) && (a[5] >= 4))
      {text.value=(a[0]+a[1]+a[2]+"0"+a[3]+a[4]+"19"+a[5]+a[6]);}
	   else
	   { //text.select();   ** select on fields removed
	    text.focus(); return false; }
	 } 
  else if ((a[2] == '/') && (a[5] == '/'))
   {
	   if ((a[8] != null) && (a[9] != null))
      {text.value=(a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9]);}     
	   else if (a[7] == null) {// text.select();** select on fields removed
	                text.focus(); return false; } 	   
	   else if ((((a[8] == null) && (a[9] == null)) || ((a[8] == "") && (a[9] == ""))) && (a[6] < 4))
 {text.value=(a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+"20"+a[6]+a[7]);}
	   else if ((((a[8] == null) && (a[9] == null)) || ((a[8] == "") && (a[9] == ""))) && (a[6] >= 4))
	   {text.value=(a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+"19"+a[6]+a[7]);}
	   else
	   { //text.select(); ** select on fields removed
	   text.focus(); return false; }
   } 
 else if ((a[1] == '/') && (a[4] == '/'))
   {
	   if ((a[7] != null) && (a[8] != null))
      {text.value=("0"+a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]);}
	   else if (a[6] == null) {// text.select();** select on fields removed
	    text.focus(); return false; } 	   
	   else if ((((a[7] == null) && (a[8] == null)) || ((a[7] == null) && (a[8] == null))) && (a[5] < 4))
	   {text.value=("0"+a[0]+a[1]+a[2]+a[3]+a[4]+"20"+a[5]+a[6]);}
	   else if ((((a[7] == null) && (a[8] == null)) || ((a[7] == null) && (a[8] == null))) && (a[5] >= 4))
	   {text.value=("0"+a[0]+a[1]+a[2]+a[3]+a[4]+"19"+a[5]+a[6]);}
	   else
	   {// text.select(); ** select on fields removed
	   text.focus(); return false; }
	} 
  else { //text.select();** select on fields removed
   text.focus(); return false; } 	

  var mm = text.value.substring(0,2);
  var dd = text.value.substring(3,5);
  var yy = text.value.substring(6,10);

 if ((dd == "") || (dd == 0) || (dd > 31))
  { //text.select(); ** select on fields removed
  text.focus(); return false; }
 else if((mm == "") || (mm == 0) || (mm > 12))
  { //text.select(); ** select on fields removed
  text.focus(); return false; }
 else if (((yy % 100) == 0) && (mm == 2) && (dd == 29))			// Leap Year Check
           { if (((yy %400) == 0) && (mm == 2) && (dd == 29))
		        return true; 
	         else
			 { //text.select(); ** select on fields removed
			 text.focus(); return false; } }
	  else if (((yy % 4) == 0) && (mm == 2) && (dd == 29))
		   return true;  
//  ((((yy % 4) == 0) || ((yy % 100) == 0) || ((yy %400) == 0)) && (mm == 2) && (dd == 29))
//   {return true;}
 else if (((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11)) && (dd > 30)) 
  { //text.select();** select on fields removed
   text.focus(); return false; }
 else if ((mm == 2) && (dd > 28)) 
  { //text.select(); ** select on fields removed
  text.focus(); return false; }   
 else if ((mm == 2) && (dd > 29) && (((yy % 4) != 0) || ((yy % 100) != 0) || ((yy %400) != 0)))
  {// text.select();** select on fields removed
   text.focus(); return false; }
 else if (yy < 1900)
  { //text.select(); ** select on fields removed
  text.focus(); return false; }
   
 }
 else
 {// text.select(); ** select on fields removed
 text.focus(); return false; }
}
return true;
}

////////////////////////   END  /////////////////////////////////

/* function for date validations.

Function Name :  dateval

Short Description :

This function checks for a valid date.
The  input is the form object for which date 
validation is required.

This function will call either isDateDMY or isDateMDY
based on the second parameter. If 'DMY' is passed in the second 
parameter, Date will be validated for "DD/MM/CCYY" format.
If 'MDY' is passed in the second parameter, Date will be validated
for "MM/DD/CCYY" format. 

If Nothing is passed, "MM/DD/CCYY" format is assumed.

Date between 1900A.D and 9999 A.D will be accepted.

Input Parameters : Date, Format 

Format : Two formats are currently available
1. MM/DD/CCYY
2. DD/MM/CCYY
Default : MM/DD/CCYY

Return Value : This returns false in case of an 
invalid date.
*/


function dateval(form,format)
{
switch (format) {
case "MDY" : { return (isDateMDY (form)) }
				  
case "DMY" : { return (isDateDMY (form)) }

default    : { return (isDateMDY (form)) } }
}

//////////////////////  END   //////////////////

/* THIS FUNCTION DateCmp Compares 2 Dates.

Function Name :  DateCmp

Short Description :

Primarily this function compares two dates.The  inputs are the form objects. This function will also checks for a valid date  either in DD/MM/CCYY or MM/DD/CCYY format.This function will call dateval to check for the validitity of the Date.

Date between 1900A.D and 9999 A.D will be accepted.

Input Parameters : Date,Date

Return Value : 
	This will return 1  if Date1 > Date2.
	This will return -1 if Date1 < Date2.
	This will return 0 if Date1 = Date2.
	This will return false and alerts an Error Message in case of an 
		invalid date.


*/


function DateCmp(formObj1,formObj2,format)
{

	var chk = 0;
	switch (format) 

	{
	case "MDY" :if (dateval(formObj1,'MDY') == false)
			 		return ErrMsg(formObj1,"Invalid Date");
                 else  if (dateval(formObj2) == false)	 
			    	return ErrMsg(formObj2,"Invalid Date");
			
 	break;	
	case "DMY" :if (dateval(formObj1,'DMY') == false)
			 		return ErrMsg(formObj1,"Invalid Date");
             	else  if (dateval(formObj2,'DMY') == false)	 
			    	return ErrMsg(formObj2,"Invalid Date");
			 	chk=1;
			 	break;	
	default : 
				if (dateval (formObj1) == false)
			 		return ErrMsg(formObj1,"Invalid Date");
             	else  if (dateval(formObj2) == false)	 
			    	return ErrMsg(formObj2,"Invalid Date");

	}
   	
	var objVal11=	formObj1.value;
   	var objVal12=	formObj2.value;
   	var newstr = objVal11.split(reDate,"$1,$2,$3"); 
   	var yy_from1=RegExp.$3;
	
	if (chk==1)
		{
			var dd_from1=RegExp.$1;
   			var mm_from1=RegExp.$2;
		}	
   	else
		{	
			var dd_from1=RegExp.$2;
			var mm_from1=RegExp.$1;
		}	

	var newstr = objVal12.split(reDate,"$1,$2,$3"); 
	var yy_from2=RegExp.$3;	
	if (chk==1)
		{
			var dd_from2=RegExp.$1;
			var mm_from2=RegExp.$2;
		}	
   	else
		{	
			var dd_from2=RegExp.$2;
			var mm_from2=RegExp.$1;
		}	
	if (yy_from1 > yy_from2)
		return 1;
	else if (yy_from1 < yy_from2)
		return 	-1
    else {
			if (mm_from1 > mm_from2)
				return 1
			else if (mm_from1 < mm_from2)
				return -1
			else {
					if (dd_from1 > dd_from2)
						return 1
					else if (dd_from1 < dd_from2)	
							return -1
					else
							return 0	
				}	
		}
}	

//////////////////////  END   //////////////////


/* for a must enter field

Function Name :  isEmpty

Short Description :

This function checks for  null value.
The  input is the form object for which Nulls
are to be validated.

N.B. This function does not check for special characters.
 
Return Value : This returns false in case of Nulls
or spaces.

*/


function isEmpty(formObj)
{
   var reWhitespace = /^\s+$/
   var s=formObj.value;
   if ((s == null) || (s.length == 0) || (reWhitespace.test(s)) )
       return false;
   else
       return true;
}

///////////////////////    end  /////////////////////////

/*checks for a valid alphabets

Function Name :  isAlpha

Short Description :

This function checks for  Valid Alphabets.
The  input is the form object for which Alphabets are to be validated.
The function also checks for blank spaces.This function also 
trims the leading and trailing spaces of the form object value.

Return Value : This returns false for non alphabetic entries
and spaces.

*/

function isAlpha(formObj)
{
    var objValm =trimtxt(formObj);   	
	var respc = /^[\s]+$/

	if (respc.test(formObj.value) == true)
	{return false;}

	formObj.value = objValm;
	var testChar  = " ";
	var objVal    = objValm;
	var valLength = objVal.length;
	
    if (objVal == "")
	{return true;}	
	
	
	for (var i=0; i < valLength; i++)
	{
		testChar = objVal.charAt(i);
		
		if ((testChar < 'a' || testChar > 'z') &&
			(testChar < 'A' || testChar > 'Z'))
		{
			return false;
		}
	}
	
	return true;
}

//////////////////////////   end  ////////////////////////

/*checks for valid alphanumeric characters

Function Name :  isAlphaNumeric

Short Description :

This function checks for  Valid Alphanumeric characters.
The  input is the form object for which Alphanumerics characters
are to be validated.The function also checks for blank spaces.
This function also trims the leading and trailing spaces of 
the form object value.

Return Value : This returns false for non alphanumeric entries
and spaces.

*/


	function isAlphaNumeric(formObj)
{
	var objValk = trimtxt(formObj)
	var respc = /^[\s]+$/

	if (respc.test(formObj.value) == true)
	{return false;}

	
	formObj.value = objValk;
	var testChar  = " ";
	var objVal 	  = objValk;
	var valLength = objVal.length;
	
	if (objVal == "")
	{return true;}
	
	for (var i=0; i < valLength; i++)
	{
		testChar = objVal.charAt(i);
		
		if ( (testChar < '0' || testChar > '9') &&
			 (testChar < 'a' || testChar > 'z') &&
			 (testChar < 'A' || testChar > 'Z'))

		{
			return false;
		}
	}
	
	return true;
}
///////////////////////  end     /////////////////////////

/*checks for a valid email id

Function Name :  isEmail

Short Description :

This function checks for  a valid e mail address.
The  input is the form object  which is to be validated 
for email entries.This also checks for blank spaces. This 
function also trims the leading and  trailing spaces of 
the form object value.

Return Value : This returns false for an invalid email address

*/

function isEmail(formObj)
{
   var evaluem = trimtxt(formObj)  

   var respc = /^[\s]+$/      
   if (respc.test(formObj.value)==true)
   {return false;}

   formObj.value = evaluem;
   var evalue = evaluem;
   var elength = evalue.length;
   var echeck =  /^.+\@.+\..+$/
   var a = new Array();
   var i=0;
   var j=0;  
   var b=0;
   var c =0;
   var testchar;
   
   if (evalue=="")
   {return true;}
   
   for (var i=0; i < elength; i++)
	{
		testChar = evalue.charAt(i);
		
		if ( (testChar < '0' || testChar > '9') &&
			 (testChar < 'a' || testChar > 'z') &&
			 (testChar < 'A' || testChar > 'Z') &&
			 (testChar != '@') && (testChar != '.') &&
			 (testChar != '_') && (testChar != '-'))
		{
			return false;
		}
	}
	
   
   
   for(i=0; i < elength; i++)
   {
    a[i] = evalue.charAt(i);	  

    if (a[i] == '@')  
    {b=b+1;}
    }
	
    if(b>1){return false;}   
   
    for(i=0; i < elength; i++)
    {
    a[i] = evalue.charAt(i);	  
	j = evalue.charAt(i+1);
    if((a[i] == '.') && (j == '.'))
    {  return false;}
    }
	
 
    for(i=0; i < elength; i++)
    {
    a[i] = evalue.charAt(i);	  
	j = evalue.charAt(i+1);
    if((a[i] == '@') && (j == '.'))
    {  return false;}
    }
   
    for(i=0; i < elength; i++)
    {
    a[i] = evalue.charAt(i);	  
	j = evalue.charAt(i+1);
    if((a[i] == '.') && (j == '@'))
    {  return false;}
    }
	

   for(i=0; i < elength; i++)
   {
    a[i] = evalue.charAt(i);	  
    var b = evalue.charAt(elength-1);	  
    if ((a[i] == ' ') || (b == '.'))
    	{  return false;}
    }
    
    for (var i=0; i < elength; i++)
	{
		a[i] = evalue.charAt(i);

		if ((a[i] == '+') || (a[i] == '#'))
		{
			 return false;
		}
	}
	
   
  if (echeck.test(evalue) == false)
  	 {return false;} 
  else return true;
 }


/////////////////////////  end     ///////////////////////

/*checks for a valid phone number

Function Name :  isPhone

Short Description :

This function checks for  a valid Phone number.
The  input is the form object  which is to be validated 
for vaid phone numbers.This also checks for blank spaces. This 
function also trims the leading and  trailing spaces of 
the form object value.

Return Value : This returns false for an invalid Phone number

*/

function isPhone(formObj)
{
	
	var objValk = Remove_Suc_Spaces_InString(trimtxt(formObj))
	var respc = /^[\s]+$/
	
	var renum = /[0-9]/

    if (respc.test(formObj.value) == true)
	{return false;}

    if (renum.test(formObj.value) == false)
	{return false;}

	
	formObj.value = objValk;
	var testChar  = " ";
	var objVal    = objValk;
	var valLength = objVal.length;
	var a = new Array();
	var i=0;
	var j=0;
    var n=0;
	var y=0;
    var z=0;
	
	
    if((objVal.charAt(valLength-1)== '-') || (objVal.charAt(valLength-1)== '+'))
      {return false;}  	
	  
	if (objVal.charAt(0)== '-') 
      {return false;}  	
	  
	

  
    if (valLength == 1)	
    	{return false;}  	
    
    for(var m=0; m < valLength; m++)
	{
	a[m] = objVal.charAt(m);
	if (a[m] == '(')	 
	{y=y+1;
		if ((objVal.charAt(m+1) < '0' || objVal.charAt(m+1) > '9')   &&
			(objVal.charAt(m+1) != '(') &&  (objVal.charAt(m+1) != ')') &&
			(objVal.charAt(m+1) != '-')  &&  (objVal.charAt(m+1) != '+')  && (objVal.charAt(m+1) != ' '))
		{
			return false;
		}
    }
	}
	
	for(var m=0; m < valLength; m++)
	{
	a[m] = objVal.charAt(m);
	if (a[m] == ')')	  
	{z=z+1; 
		if ((objVal.charAt(m-1) < '0' || objVal.charAt(m-1) > '9')   &&
			(objVal.charAt(m-1) != '(') &&  (objVal.charAt(m-1) != ')') &&
			(objVal.charAt(m-1) != '-')  &&  (objVal.charAt(m-1) != '+')  && (objVal.charAt(m-1) != ' '))
		{
			return false;
		}
    }

	}

	if(y!=z)
        {return false;}  	

	if (y == z)
	{	
	var sw = 0;
		for(var m=0; m < valLength; m++)
		{
			 if (objVal.charAt(m) == ')')	  
			   { for (var i=m; i >= 0; i--)
			        if (objVal.charAt(i) == '(')
				      { var sw = 1;
					    break;
					  }
				if (sw != 1)
				   return false;
				}
		}
	}
		 
    for(var m=0; m < 2; m++)
	{
	a[m] = objVal.charAt(m);
	if (a[m] == '+')	  
	{n=n+1;}
	} 
       	if (n>1){return false;}
	
    
	for(i=0; i < valLength; i++)
    {
    a[i] = objVal.charAt(i);	  
	j = objVal.charAt(i+1);
	k = objVal.charAt(i+2);
    if((a[i] == '(') && (j == ' ') && (k == ')'))
    {  return false;}
    }

	if (objVal.charAt(2) == '+') 	
	    {
		
		 if (!isNaN(objVal.charAt(1)) || !isNaN(objVal.charAt(0)))
		    if ((objVal.charAt(1) != ' ') && (objVal.charAt(0) != '('))
	         return false;
	    }
		
	for(i=3; i < valLength; i++)
    {
    if(objVal.charAt(i) == '+') 
      return false;
	}

	for(i=0; i < valLength; i++)
    {
    a[i] = objVal.charAt(i);	  
	j = objVal.charAt(i+1);
    if((a[i] == '(') && (j == '('))
    {  return false;}
    }
    
   	for(i=0; i < valLength; i++)
    {
    a[i] = objVal.charAt(i);	  
	j = objVal.charAt(i+1);
    if((a[i] == '(') && (j == ')'))
    {  return false;}
    }

	for(i=0; i < valLength; i++)
    {
    a[i] = objVal.charAt(i);	  
	j = objVal.charAt(i+1);
    if((a[i] == ')') && (j == ')'))
    {  return false;}
    }

	for(i=0; i < valLength; i++)
    {
    a[i] = objVal.charAt(i);	  
	j = objVal.charAt(i+1);
    if((a[i] == '-') && (j == '-'))
    {  return false;}
    }

	for(i=0; i < valLength; i++)
    {
    a[i] = objVal.charAt(i);	  
	j = objVal.charAt(i+1);
    if((a[i] == '+') && (j == '+'))
    {  return false;}
    }

	for(i=0; i < valLength; i++)
    {
    a[i] = objVal.charAt(i);	  
	j = objVal.charAt(i+1);
    if((a[i] == '+') && (j == '-'))
    {  return false;}
    }

	for(i=0; i < valLength; i++)
    {
    a[i] = objVal.charAt(i);	  
	j = objVal.charAt(i+1);
    if((a[i] == '-') && (j == '+'))
    {  return false;}
    }

/****	for(i=0; i < valLength; i++)  [ allows (-91) ]
    {
    a[i] = objVal.charAt(i);	  
	j = objVal.charAt(i+1);
    if((a[i] == '(') && (j == '-'))
    {  return false;}
    } ****/
	
	for(i=0; i < valLength; i++)
    {
    a[i] = objVal.charAt(i);	  
	j = objVal.charAt(i+1);
    if((a[i] == '-') && (j == ')'))
    {  return false;}
    }

    
	
	for (var i=0; i < valLength; i++)
	{
		testChar = objVal.charAt(i);
		
		if ((testChar < '0' || testChar > '9')   &&
			(testChar != '(') &&  (testChar != ')') &&
			(testChar != '-')  &&  (testChar != '+')  && (testChar != ' '))
		{
			return false;
		}
	}
	
	return true;
}
///////////////////////////    end     ////////////////////



/*checks for a valid mobile number

Function Name :  isMobile
Short Description :

This function checks for  a valid Mobile number.
The  input is the form object  which is to be validated 
for valid Mobile numbers. 

Return Value : This returns true for a valid Mobile number

*/



function isMobile(formObj)
{
var objValk = Remove_Suc_Spaces_InString(trimtxt(formObj));
formObj.value=objValk;
var retval=true;
return retval;
}

///////////////////////////    end     ////////////////////


/*checks for a valid Pager number

Function Name :  isPager

Short Description :

This function checks for  a valid Pager number.
The  input is the form object  which is to be validated 
for valid Pager numbers. 

Return Value : This returns true for a valid Pager number

*/

function isPager(formObj)
{
var objValk = Remove_Suc_Spaces_InString(trimtxt(formObj));
formObj.value=objValk;
var retval=true;
return retval;
}


///////////////////////////    end     ////////////////////

/*checks for a valid Zip Code
Function Name :  isZipcode

Short Description :

This function checks for  a valid Zip Code.
The  input is the form object  which is to be validated 
for valid Zip Code.

Return Value : This returns true for a valid Zip Code.
*/

function isZipcode(formObj)
{
var objValk = Remove_Suc_Spaces_InString(trimtxt(formObj));
formObj.value=objValk;
var retval=true;
return retval;
}

///////////////////////////    end     ////////////////////




//checks for a valid name

function isName(formObj)
{
    var objValk = Remove_Suc_Spaces_InString(trimtxt(formObj));
	var respc = /^[\s]+$/
	
	if (respc.test(formObj.value) == true)
	{return false;}
	
	formObj.value = objValk;
	var testChar  = " ";
	var objVal    = objValk
	var valLength = objVal.length;
    var a = new Array;	
	var i = 0;
	var j = 0;
    
	
	 
	for (var i=0; i < valLength; i++)
	{
	a[i] = objVal.charAt(i);	  
	j = objVal.charAt(i+1);
    if((a[i] == '.') && (j == '.'))
    {  return false;}
   	}
	
		
	for (var i=0; i < valLength; i++)
	{
		testChar = objVal.charAt(i);
		
		if ((testChar < 'a' || testChar > 'z') &&
			(testChar < 'A' || testChar > 'Z') &&
			(testChar != ' ') && (testChar != '.'))
		{
			return false;
		}
	}
	
	return true;
}

/////////////////////////   end   //////////////////////////
