
/*********************************************************************/
/*			JAVASCRIPT REUSABLE CODE		     					 */
/*********************************************************************/
/* Project 	   	  :  Innovative Recruting				     		 */
/* Program name   :  ReusableJavascript.js				     		 */
/* Version	      :  1.0.0(First Version)				     		 */
/* Author	      :  Mohanraj Jayaraman				     			 */
/* Date		      :  10/20/2001					     				 */
/*********************************************************************/
/* PLEASE MAKE AN ENTRY IN THE MODIFICATION HISTORY BOX WHENEVER     */
/*	   THIS SCRIPT IS MODIFIED	OR IF ANY NEW ADDITION IS MADE       */
/*********************************************************************/
/*  Function Name ** Description                  ** Returns         */ 
/*********************************************************************/
/*  isNumber      ** Checks for Valid Numeric     ** False, when the */
/*                ** entries.                     ** value has non   */ 
/*                **                              ** numeric entries */  
/*                **                              **                 */  
/*  isDecNumber   ** 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.         */
/*                **                              **                 */
/*  isEmpty       ** Checks for Nulls             ** Retruns false   */
/*                **                              ** when null values*/
/*                **                              ** are found       */
/*                **                              **                 */  
/*  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.        */
/*                **                              **                 */  
/*  isZipcode     ** Checks for valid Zip code    ** Returns True    */
/*                ** Number                       ** for valid zip   */
/*                **                              ** code   entered. */
/*                **                              **                 */  
/*  isFName       ** Checks for valid First       ** Returns false   */
/*                ** Name                         ** when other than */
/*                **                              ** Name is         */
/*                **                              ** entered.        */
/*  isLName       ** Checks for valid Last        ** Returns false   */
/*                ** Name                         ** when other than */
/*                **                              ** Name is         */
/*                **                              ** entered.        */
/*                **                              **                 */  
/*  isPhoneUS       ** Checks for valid Phone       ** Returns false   */
/*                ** Number                       ** when other than */
/*                **                              ** a valid Phone   */
/*                **                              ** No is entered.	 */
/*                **                              **                 */  
/*  isZipcode     ** Checks for valid Zip code    ** Returns True    */
/*                ** Number                       ** for valid zip   */
/*                **                              ** code   entered. */
/*                **                              **                 */  
/*  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.         **                 */
/*                **                              **                 */  
/*********************************************************************/
/**********************************************************************
Modifcation History 		:
-----------------------------------------------------------------------
Version			Author				 Date  			Modification 		
								(MM/DD/CCYY)		Details			
-----------------------------------------------------------------------
v.1.0.0	       Mohanraj			12/20/2000		   First Verion
v.1.0.1	       Mohanraj			01/14/2001		   IsPhone and IsZipcode
												   Functions were added
v.1.0.2	       Mohanraj			04/10/2001		   IsName function split into two
												   functions
												   isFname to  validate First Name 
												   and 
												   isLname to validate Last Name 
												   
												   isZip changed to accept 
												   with spaces , without spaces 
												   and with - .
v.1.0.2	       Mohanraj			05/16/2001		   isZip bug fixed.
												   (Was accepting 6-8 digit numbers)
v.1.0.3		   Irana			10/19/2001			Log -  IruUpd	
**********************************************************************/

/* 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 NUMERIC ENTRIES WITH DECIMAL POINTS

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 isDecNumber(formObj)
{
	var testChar  = " ";
	var objVal    = formObj.value	;
	var valLength = objVal.length	;
	var occDot 	  = 0; 
	var firstOcc  = 0;
	for (var i=0; i < valLength; i++)
	{
		//alert("i " +i);
		testChar = objVal.charAt(i);
		if(testChar == '.')
		{
			occDot++  ;
			firstOcc++ ;
			//alert("first Exec " + firstOcc);			
			if( occDot > 1 )
			{
				return false;
			}
		}
		
		if(testChar != '.' )
		{
			if (testChar < '0' || testChar > '9' ) 
			{	
				return false;
			}
			if (firstOcc > 0  )
			{
				firstOcc++ ;
				if( firstOcc > 3 )
				{
					return false;
				}
			}
		}
	}
	
	return true;
}
////////////////////////////   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.value="";
	theField.focus();
	alert(s);
	return false;
}

////////////////////////////   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);
		
		/*   Permitted chars in an Email Address */		
		
		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 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 isFName(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   //////////////////////////

function isLName(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;}
    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 != ' ') && (testChar != '-')
		   )
			{
				return false;
			}
	}
	
	return true;
}

/////////////////////////   end   //////////////////////////

/*checks for a valid phone number

Function Name :  isPhoneUS

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. 

Return Value : This returns false for an invalid Phone number

*/
function isPhoneUS(formObj)
{
	 var respc = /^[\s]+$/
	 var renum=/(^[0-9]+)\-+([0-9]+)\-+([0-9]+)$/	 

     if (respc.test(formObj.value) == true)
		 {return false;}
	
     if (renum.test(formObj.value) == false)
		 {return false;}

	 var testChar  = " ";
	 var objVal    = formObj.value;
	 var valLength = objVal.length;
	 
	 if((valLength ==  0 ) || (valLength > 12 )|| (valLength < 12 ) )
	 	{ return false; }

	 for (var i=0; i < valLength; i++)
	 {	testChar = objVal.charAt(i);
		if(i != 3 || i != 7 )
		{	if ((testChar < 0 || testChar > 9 ))
			{return false;}
		}
		else
		{	if ((testChar != '-' ))
			{return false;}
		}
	 }
	
	 return true;
}

///////////////////////////    end     ////////////////////

/*checks for a valid phone number

Function Name :  isZipUS

Short Description :

This function checks for  a valid Zip Code.
The  input is the form object  which is to be validated 
for vaid Zip codes.This also checks for blank spaces. 

Return Value : This returns false for an invalid Phone number

*/
function isZipUS(formObj)
{
	/*
	 var respc = /^[\s]+$/
	 
    if (respc.test(formObj.value) == true)
	 {return false;}
	*/
	
	 var testChar  = " ";
	 var objVal    = formObj.value;
	 var valLength = objVal.length;
	 
	 if((valLength ==  0)  || (valLength > 10) )
	 { return false; }

	 //alert(valLength);
	 if(valLength ==  9 || valLength ==  5)
	 	{
			var renum1 = /(^[0-9]+)$/	;
		    if (renum1.test(formObj.value) == false)
				{return false;}
			return true;
		}
	 
	 if	(valLength > 5)
		{	
			if(valLength != 10  )
				{return false;}			
			//alert(valLength);
		    if(valLength == 10  )
			{
				if(objVal.charAt(5) != '-')
					{	
						if(objVal.charAt(5) != ' ')
						{
							return false;
						}
					}
				if(objVal.charAt(5) == '-')			
				{
					var renum2 =/(^[0-9]+)\-([0-9]+)$/	;
				    if (renum2.test(formObj.value) == false)
					{
						return false;
					}
				}
				if(objVal.charAt(5) == ' ')			
				{
					var renum3 =/(^[0-9]+)\s([0-9]+)$/	;
				    if (renum3.test(formObj.value) == false)
					{return false;}
				}
			}
		}
	 else
		{	
			var renum = /[0-9]/		
		    if (renum.test(formObj.value) == false)
				{return false;}
			if (valLength < 5 )
			    {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.

*/
var reDate=/(^[0-9]+)\/+([0-9]+)\/+([0-9]+)$/


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 
    } 
  }
} 

//Added by Iranna - 10/19/01    // Log - IruUpd 

function validate(){
	return confirm("Are you sure?  This action cannot be undone.");
	}

// Is the upload field empty and can?
function isFormComplete(which){
var pass=true

for (i=0;i<which.length;i++){
	var tempobj=which.elements[i]
	if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value==''&&tempobj.name.substring(0,4)!="Copy"&&tempobj.name.substring(0,5)!="Copy2"&&tempobj.name.substring(0,5)!="Copy3"&&tempobj.name.substring(0,5)!="Copy4"&&tempobj.name.substring(0,5)!="Copy5"&&tempobj.name.substring(0,5)!="Copy6"&&tempobj.name.substring(0,5)!="Copy7"&&tempobj.name.substring(0,5)!="Copy8"&&tempobj.name.substring(0,12)!="txt_aff_add2"&&tempobj.name.substring(0,12)!="txt_aff_nam2"&&tempobj.name.substring(0,13)!="txt_aff_add12"&&tempobj.name.substring(0,13)!="txt_aff_add22"&&tempobj.name.substring(0,12)!="txt_aff_cit2"&&tempobj.name.substring(0,12)!="txt_aff_stt2"&&tempobj.name.substring(0,12)!="txt_aff_zip2"&&tempobj.name.substring(0,12)!="txt_aff_phn2"&&tempobj.name.substring(0,12)!="txt_aff_nam3"&&tempobj.name.substring(0,13)!="txt_aff_add13"&&tempobj.name.substring(0,13)!="txt_aff_add23"&&tempobj.name.substring(0,12)!="txt_aff_cit3"&&tempobj.name.substring(0,12)!="txt_aff_stt3"&&tempobj.name.substring(0,12)!="txt_aff_zip3"&&tempobj.name.substring(0,12)!="txt_aff_phn3"&&tempobj.name.substring(0,12)!="txt_aff_nam4"&&tempobj.name.substring(0,13)!="txt_aff_add14"&&tempobj.name.substring(0,13)!="txt_aff_add24"&&tempobj.name.substring(0,12)!="txt_aff_cit4"&&tempobj.name.substring(0,12)!="txt_aff_stt4"&&tempobj.name.substring(0,12)!="txt_aff_zip4"&&tempobj.name.substring(0,12)!="txt_aff_phn4"&&tempobj.name.substring(0,6)!="Title2"&&tempobj.name.substring(0,6)!="Title3"&&tempobj.name.substring(0,6)!="Title4"&&tempobj.name.substring(0,6)!="Title5"&&tempobj.name.substring(0,6)!="Title6")||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
		pass=false
		break
		}
	}
	
	if (!pass){
	alert("One or more of the required elements are not completed. Please complete them, then submit again!")
	return false
	}
	else
	return true
}
	

// Is the upload field empty and can?
function isNewPhysicianOK(which){
var pass=true

for (i=0;i<which.length;i++){
	var tempobj=which.elements[i]
	if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
		pass=false
		break
		}
	}
	
	if (!pass){
	alert("One or more of the required elements are not completed. Please complete them, then submit again!")
	return false
	}
	else
	return true
}

// Is the upload field empty and can?
function checkEmptyUpload(txtfld,namefld){
		if (txtfld == ""){
			alert("You must enter something into the "+namefld+" field.");
			return false;
			}
		else {
			return true;
			}
	}

// Is the field empty?
function checkEmpty(txtfld,namefld){
	if (txtfld == ""){
		alert("You must enter something into the "+namefld+" field.");
		}
	}
	
// Is it a phone number?
function isPhone(elmstr) {
    if (elmstr.length != 12){
		alert("You must enter a phone number in the fomat of XXX-XXX-XXXX");
		return false;
	}
    for (var i = 0; i < elmstr.length; i++) {
        if ((i < 3 && i > -1) ||
            (i > 3 && i < 7) || 
            (i > 7 && i < 12)) {
            if (elmstr.charAt(i) < "0" || 
                elmstr.charAt(i) > "9") {
				alert("You have entered a character that is not a number.");
				return false;
				}
        }
        else if (elmstr.charAt(i) != "-") {
				alert("Please seperate the phone number using '-' dashes.");
				return false;
				}
    }        
return true;
}

// Is it a zip code?
function isZip(elmstr) {
    if (elmstr.length != 5){
		alert("You must enter a zip code in the fomat of XXXXX");
		return false;
	}
    for (var i = 0; i < elmstr.length; i++) {
        if (elmstr.charAt(i) < "0" || 
            elmstr.charAt(i) > "9") {
			alert("You have entered a character that is not a number.");
			return false;
			}
	    }        
	return true;
}

function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//////////////////////  END   //////////////////

