/*
		CAVU Corp JavaScript Data Handling Routines
		CAVUDataRoutines.JS
		© Copyright 1996-1999
		® All Rights Reserved
		CAVU Corporation, Raleigh NC
		
		07/17/2002 RCS added SetFieldManditoryFlag( Field, Options )
		08/31/2002 RCS fixed a field validation problem with range checking of type=10 fields
		10/17/2002 RCS added code to prevent 5 digit year 
		10/31/2002 Srini DevTrack# 1398 
					Items selected in multiple-selectboxes not highlighted when focus
					changed to another box. 		
*/

  var ShowHelpMsgs = 1; //set to false if the system does not show help prompting msgs

	var validstreetNum  = "0123456789 -";
	var ValidNum		= "0123456789-.";
	var NumsOnly		= "0123456789";
	var ValidReal		= "0123456789-,.";
	var ValidPercnt	    = "0123456789-,.";
	var ValidInt		= "0123456789-,";
	var ValidPhone	    = "0123456789-()Xx ";
	var ValidZip		= "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
	var ValidDate		= "0123456789/.";
	var ValidSSN		= "0123456789";
	var ValidAlphaOnly	= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var UpperAlphaOnly	= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var validTime	    = "0123456789:.";
	var PhoneZipPunct	= "()-/";
	var ErrorFlag		= false;
	var ErrorTimer;
	var FieldFlag;

	var ManditoryOK		 = 'green' ;  // green - manditory field that is completed
	var ManditoryBoxOK	 = '' //'lightgreen' ; // '#d7FFd7' ;  // green - manditory field that is completed
	var ManditoryWarning = 'tomato' ;  // red - manditory field that must be completed
	var ManditoryCaution = 'yellow' ;  // yellow - manditory field initial setting if empty

// define formatting styles for dates
var aDaysInMonth	 = Array (31,0,31,30,31,30,31,31,30,31,30,31);

var cMM_DD_YYYY		 = 1000;	//puts date into mm/dd/yyyy format
var cYYYYMMDD		 = 1001;
var cMMDDYYYY		 = 1002;

//--- perform browser check on load
//----------------------------------------------------------
var BrowserIE		 = 0;
var BrowserNS		 = 0;
var BrowserDOM		 = 0;

//var IsBrowserNetscape = false;

if (document.all) {BrowserIE=1;fShow="visible";fHide="hidden";}
if (document.getElementById&&!document.all)	{BrowserDOM=1;fShow="visible";fHide="hidden";}
if (document.layers) {BrowserNS=1;fShow="show";fHide="hide";}

//----------------------------------------------------------
/*
	This can be used in a field onEntry to select the entire field (like most MS software)
	It is selective and will only select the entire field, for password, text and textarea fields
*/

//-----------------------------------------------------------------------------------------------------------------------------------------
function SelectContents( Caller )
{
	if ((Caller.type == "password") || (Caller.type == "text") || (Caller.type == "textarea"))
	{
		Caller.select();
	}
}


//-----------------------------------------------------------------------------------------------------------------------------------------
function CheckForm( iform ) 
{
	//JES:03/02/2004: revised and made more generic
	var fieldNum, k, v, returnFlag, firstField;
	var errorField;
	var errorFlag=false;
	var returnFlag=true;
	var firstField=-10;
	var missingFieldnames = '';
	var objElement;
		
	for( fieldNum=0; fieldNum < iform.elements.length; fieldNum++ )
	{
		objElement = iform.elements[fieldNum];
		
		if( (objElement.CType != "undefined") && (objElement.CType != null) )
		{  
			if( (objElement.COptions==10) || (objElement.COptions==11) )
			{
				if (objElement.value == "" )
				{
					if (firstField==-10)
					{
						firstField = fieldNum;
					}
					if ( objElement.CType == 99 )	//select box
					{
					    if (BrowserIE||BrowserDOM)
							objElement.style.backgroundColor=ManditoryWarning;
					}
					else
					{
					    if (BrowserIE||BrowserDOM)
							objElement.style.borderColor=ManditoryWarning;
					}
					
					missingFieldnames = missingFieldnames + '    ' + objElement.CFieldName + "\n"
					returnFlag = false;			//to prevent browser from submiting
				}
			}
			
			if (errorFlag == false && objElement.CType != 99 )		//not a select box
			{
				var FieldName = objElement.CFieldName
				var Type = objElement.CType
				var Options = objElement.COptions
				var Min = objElement.CMin
				var Max = objElement.CMax
				var Reformat = objElement.CReformat
				
				//var rc = Validate( iform.elements[fieldNum], FieldName, Type, Options, Min, Max, Reformat )
			
				rc = CheckField( objElement, Type, FieldName )
				if( rc != true )
				{
					return false;
					errorFlag = true; //to prevent browser from submiting
				}
			}
		}
	}
	
	if ( errorFlag == true ) 
	{
		alert("Some fields are in error.\nPlease correct resubmit the page");
		return false;
	}
	else if ( returnFlag != true ) 
	{ 
		missingFieldnames += ' ' 
		missingFieldnames = missingFieldnames.replace( '<BR>', ' - ' );
		var alertMsg = "The following mandatory fields in the page do not have values.\n"
					 + "They have been highlighted in red.\nPlease enter values in these fields and resubmit the page\n"
					 + missingFieldnames;
		alert( alertMsg );
		return false;
	}
	else
	{
		return true;
	}
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function Ltrim( InputString )
{
	var i;
	var outStr = "";
	var l = InputString.length;
	for (i = 0; i < l; i++)
		if (InputString.charAt(i)!=' ')
		break;
	for (i; i < InputString.length; i++)
		outStr += InputString.charAt(i);
		return outStr;
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function Rtrim( InputString )
{
	var j;
	var outStr = "";
	var i = (InputString.length) - 1;
	for (i; i >= 0; i--)
		if (InputString.charAt(i) != ' ' )
		break;
	for (j = 0; j <= i; j++)
		outStr += InputString.charAt(j);
		return outStr ;
}
    
//-----------------------------------------------------------------------------------------------------------------------------------------
function LRtrim( InputString )
{
	return Ltrim( Rtrim( InputString ) );    
}
    
//-----------------------------------------------------------------------------------------------------------------------------------------
function CalcDec( InputString )
{
	var i
	var s = LRtrim( InputString );    
	for( i=0; i < s.length; i++) {
		if( s.charAt(i) == '.' )
		break;    
	}
	if( i == s.length )
		return 0;    
	else
		return (s.length - i - 1);    
	}

//-----------------------------------------------------------------------------------------------------------------------------------------
function CheckString( InputString, ValidString )
{
	var i, j, ch2
	var l = InputString.length;
	var cl = ValidString.length;
	for (i = 0; i < l; i++)
	{
		ch2 = InputString.charAt(i);
		for (j = 0; j < cl; j++)
		{
			if ( ch2 == ValidString.charAt(j) )
				break;
		}
		if( j >= cl )
			return ch2;
	}
	return "-1";
}


//-----------------------------------------------------------------------------------------------------------------------------------------
function CheckNumber( InputString )
    {
      var i, ch3
      var str = LRtrim( InputString );
      var l  = str.length;
      var numDec = 0;
      var numMin = 0;
	  for (i = 0; i < l; i++)
      {
        ch3 = str.charAt(i);     // fixed 1/19/97 RCS
        if (ch3 == '-')
        {
    	if( i != 0 )
               return 1;
            numMin++;
        }
        else if(  ch3 == '.')
            numDec++;    
      }
      if( numDec > 1 )
        return 2;
      if( numMin > 1 )
        return 3;
      return 0;
	      }

//-----------------------------------------------------------------------------------------------------------------------------------------
function CheckValidString( InputString, ValidString, FieldName, InputField )
{
	var ch1 = CheckString( InputString, ValidString )
	if( ch1 != "-1"  )
	{
		var msg = "This field only accepts the characters '" + ValidString + "'  ";
		msg += "\nYou entered the character '" + ch1 + "' which is invalid.";
		AlertMsg( InputField, FieldName, msg );
		return false;
	}
	return true;
}
    


//-----------------------------------------------------------------------------------------------------------------------------------------
function CheckNumberString( InputString, ValidString, FieldName, InputField )
    { 
      var chx;
      if( CheckValidString( InputString, ValidString, FieldName, InputField ) == false )
         return false;    
      chx = CheckNumber( InputString )
      if( chx != 0 )
      {
        var msg = "Numeric field input error.";    
        if( chx == 1 )
           msg += "The minus sign must be the first character.";    
        else if( chx == 2 )
           msg += "There can only be one decimal point.";    
        else if( chx == 3 )
           msg += "There can only be one minus sign.";    
        AlertMsg( InputField, FieldName, msg );    
        return false;    
      }
      return true;    
    }

//-----------------------------------------------------------------------------------------------------------------------------------------
function CheckField( InputField, Type, FieldName )
    {
    var InputString = InputField.value
    InputString = LRtrim( InputString );
       
    var ch;    
    
    if( InputString.length == 0 )
      return true;     // can't check blank field
    
    if( Type == 0 )
    { 
		//T4655 SLC 02282005  If Min or Max are defined, they should be checked.
		if ( InputField.CMin != null && (InputField.value).length < InputField.CMin )
		{
  			AlertMsg( InputField, FieldName, "Please enter at least " + InputField.CMin + " characters.");
	  		return false;
		}

		if ( InputField.CMax != null && (InputField.value).length > InputField.CMax )
		{
  			AlertMsg( InputField, FieldName, "The field has a maximum size of " + InputField.CMax + " characters.");
	  		return false;
		}

    }
    else if( Type >= 1 && Type <= 3) // alpha only  
    {
      ch=CheckString( InputString, ValidAlphaOnly );    
      if( ch != "-1"  )
      {
       var msg = "This field only accepts the characters A-Z and a-z."
       msg += "\nYou entered the character '" + ch + "' which is invalid.";    
       AlertMsg( InputField, FieldName, msg );    
       return false;    
      }
    }
    else if( Type >= 4 && Type <= 5 ) // alpha num
    {  //Ignore this
	}
	else if( Type == 6 )
	{
		if( CheckValidString (InputString, NumsOnly, FieldName, InputField) == false)
			return false;
    }
	else if( Type == 7 )
	{
		if( CheckValidString (InputString, validstreetNum, FieldName, InputField) == false)
			return false;
    }
    else if( Type == 8 ) // First Letter UpperCase
    { // ignore this
//		if( CheckValidString( InputString, UpperAlphaOnly, FieldName, InputField ) == false )
//			return false;
    }
    else if( Type >= 10 && Type <= 11 ) // integer
    {
      if( CheckNumberString( InputString, ValidInt, FieldName, InputField ) == false)
        return false;
      // Juhi 16Oct2002 An integer with only one char '-' is not a valid integer    
      if( (InputString.charAt(0) == '-') && (InputString.length == 1) )
      {
		var msg = "Please enter a valid integer"    
        AlertMsg( InputField, FieldName, msg );
		return false;
      }          
    }
    else if( Type >= 20 && Type <= 21 ) // real
    {
      if( CheckNumberString( InputString, ValidReal, FieldName, InputField ) == false)
        return false;    
    }
    else if( Type >= 30 && Type <= 31 ) // dollars.cents
    {
      if( CheckNumberString( InputString, ValidReal, FieldName, InputField ) == false)
        return false;    
	  // check # of decimal points
      var j = CalcDec( InputString );    
      if( 2 < j )
      { 
       var msg = "Too many decimals have been entered for this field.  Only 2 decimals are allowed, and "
       msg += j + " were entered."
       AlertMsg( InputField, FieldName, msg );    
       return false;
      }
    }
    else if( Type >= 40 && Type <= 49 ) // percent
    {
      if( CheckNumberString( InputString, ValidPercnt, FieldName, InputField ) == false )
        return false;    
      // check # of decimal points
      var j = CalcDec( InputString );    
      var MaxDec = Type % 10;    
      if( MaxDec < j )
      {
       var msg = "Too many decimals have been entered for this field.  Only "
       msg += MaxDec + " decimals are allowed, and " + j + " were entered.";    
       AlertMsg( InputField, FieldName, msg );    
       return false;    
      }
    }
	else if( Type == 50 ) { // US phone #
		
	    if(InputString.charAt(0) == '-'){
		   AlertMsg( InputField, FieldName, "A valid Phone Number cannot start with a '-'");
	       return false;
	    }
		if( CheckValidString( InputString, ValidPhone, FieldName, InputField ) == false )
			return false;
	}
    else if( Type == 51 ) // zip code
    {
	  if(InputString.charAt(0) == '-'){
		 AlertMsg( InputField, FieldName, "A valid Zip code cannot start with a '-'");
	     return false;
	   }      	
	  
	  if( CheckValidString( InputString, ValidZip, FieldName, InputField ) == false )
        return false;
    
       if ( CheckString(InputString, PhoneZipPunct) != -1)
	   return true;
	 
      var str = GetClearString( InputString, ValidZip);    
      var len = str.length; 
      if( (len < 5) || (len > 10) )
      {
         AlertMsg( InputField, FieldName, "Wrong number of digits entered.  A valid Zip code has minimum 5 and maximum 10 digits.");    
         return false;      // zip code must be between 5 to 10 digits (included)
      }
    } 
    else if( Type == 52 ) // date
    {
      if( CheckValidString( InputString, ValidDate, FieldName, InputField ) == false )
        return false;    
    }
    else if( Type == 53 ) // SSN
	{
		if( InputString.length != 9)
		{
			AlertMsg( InputField, FieldName, "Wrong number of digits entered.  A valid TaxID is 9 digits. Please remove any dashes if necessary.");    
			return false;      // SSN must be 9 digits
		}

		if( CheckValidString (InputString, ValidSSN, FieldName, InputField) == false)
			return false;
    }
    else if( Type == 54 ) // EMAIL
	{   // ADDED 3/7/02 RCS
		var rc = isEmailValid( InputString );
		if( rc != 0 )
		{
			var errorMsg = "";
			switch( rc )
			{
				case 1:
					errorMsg = "Invalid character found in address";
					break;
					
				case 5:
					errorMsg = "Domain Name Missing";
					break;
					
				case 2:
				case 4:
				case 7:
				case 6:
					errorMsg = "Domain Name Error";
					break;
					
				case 3:
				case 8:
					errorMsg = "User Name Missing";
					break;
					
				default:
					errorMsg = "Unknown error code:" + rc ;
					break;
			}
  			AlertMsg( InputField, FieldName, "Invalid e-mail address entered. \n" + errorMsg );
  			return false;
		}
    }
    else if (Type ==55)
    {
    	if( CheckValidString (InputString, ValidZip, FieldName, InputField) == false){
			return false;
		}
    }
    else if (Type >=60 && Type <= 69)
	{
		
		
		var InputString = InputField.value;
		
		var aryDate;
		var YYYY;
		var MM;
		var DD;
		//First Check for invalid characters
		if(CheckValidString( InputString, ValidDate, FieldName, InputField ) == false)
		{
  			AlertMsg( InputField, FieldName, "Invalid date entered.  Please enter a valid date in the format MM/DD/YYYY.");
  			return false;
  		}
		
	   	var len = InputField.value.length
		if ( len > 0 )
		{
			while( InputField.value.indexOf(".",0) >= 0 )
			{
				InputField.value = InputField.value.replace( '.', '/' );
				s = InputField.value;
			}
			
			//Count the no. of slashes for a valid date
			var i;
			var cntSlash = 0;
			//reassign the inputstring to reflect the '/' replacements
			InputString = InputField.value;
      
			// check for proper date formatting
			aryDate = InputString.split("/");
			if (aryDate.length == 3)	// should have 3 date elements
			{
				MM		= aryDate[0];
				DD		= aryDate[1];
				YYYY	= aryDate[2];
			} else {
			
				if (aryDate.length == 1)		// to catch dates like '0202002'
				{
					if (InputField.value.length != 6 && InputField.value.length != 8){
						AlertMsg( InputField, FieldName, "Invalid date entered.  Please enter a valid date in the format MM/DD/YYYY.");
						return false;
					}
				} else {
					AlertMsg( InputField, FieldName, "Invalid date entered.  Please enter a valid date in the format MM/DD/YYYY.");
					return false;
				}
			}
			
			if( InputField.value.indexOf("/",0) == -1  &&  InputField.value.length >= 6 )
			{
				// InputField is unformated, try to format it
				var tStr
				tStr = InputField.value.substring( 0, 2 ) 
					 + '/'
					 + InputField.value.substring( 2, 4 )
					 + '/'
					 + InputField.value.substring( 4 );
				InputField.value = tStr;
				s = InputField.value;
				len = InputField.value.length
			}
						
			InputField.value = NormalizeDate(InputField.value);
			Today = new Date();
			Today.setHours(0);
			Today.setMinutes(0);
			Today.setSeconds(0);
			InputDate = new Date(InputField.value);
						
			//var InputDay = InputField.value.substring(3,5);
			//var InputMonth = InputField.value.substring(0,2);
			//var DateYearStr = LRtrim( "" + InputField.value.substring(6,10) ); 

			aryDate			= InputField.value.split("/");
			var InputMonth	= aryDate[0];
			var InputDay	= aryDate[1];
			var DateYearStr	= aryDate[2];

			//Error if 3 digit year
			if( DateYearStr.length == 3) 
			{
				AlertMsg( InputField, FieldName, "Invalid date entered. Please enter a valid date.");
				return false;
			}
			DateYear = parseInt (DateYearStr,10);
			//var ThisYear = "" + Today.getYear(); // getYear() is a depricated method use getFullYear();
			var ThisYear = "" + Today.getFullYear();
			
			if( ThisYear == "100" && BrowserNS )
			{ // fix netscape Y2K bug
				ThisYear = "2000"
			}
			if( ThisYear == "101" && BrowserNS )
			{ // fix netscape Y2K bug
				ThisYear = "2001"
			}

			var ThisDecade;
			var YearCompare;
			
			//Error if 3 digit year
			if( DateYearStr.length == 3) 
			{
				AlertMsg( InputField, FieldName, "Invalid date entered. Please enter a valid date.");
				return false;
			}
								
			//Juhi[16Sep02] - Check to catch and format a single digit year 
			//Make it a 2 digit year and rest of the code handles it 
			if( DateYearStr.length == 1) //Single digit for the year, the add 0 before it and let it go through the formatting for 2 digit years
			{
				DateYearStr = "0" + DateYearStr;
			}
								
			if( DateYearStr.length == 2 ) // then lets modify the date by adding the decade
			{
				if (ThisYear.length == 2)  //determine current decade
				{	
					ThisDecade = 1900;
					ThisYear = parseInt(ThisYear, 10);
					ThisYear += 1900;
				}
				else
				{
					ThisDecade = ThisYear.substring(0, 2);
					ThisDecade *= 100;
				}
				ThisDecade = parseInt(ThisDecade, 10);
				if (DateYear >= 100)
				{
					if (DateYear < 1800 || DateYear > 2200)
					{
						AlertMsg( InputField, FieldName, "Invalid date entered. Please enter a valid date.");
						return false;
					}
					else
					{
						//return true;
					}
				}
				else
				{
					DateYear += ThisDecade;
				}
				//InputField.value=DateYear + "--" + ThisYear;
				
				// deals only with formatting, not validation of date
				switch (Type)
				{
					case 60:   //dates from current date and after
						if (DateYear < ThisYear)
						{
							DateYear += 100;
						}
						else if (DateYear == ThisYear)
						{
							if (InputMonth < (Today.getMonth() + 1) )
							{
								DateYear += 100;
							}
						else if (InputMonth == (Today.getMonth() + 1) )					
							 {
								if (InputDay < Today.getDate() )
								{
									DateYear += 100;
								}
							  }
						}
						break;
					case 61:   //dates from last year and after
						if ((ThisYear - ThisYear % 100) != ((ThisYear - 1) - (ThisYear - 1) % 100))
						{     //if previous and current years in different decades, move date to earlier decade
							DateYear -= 100;
						}
						if (DateYear < (ThisYear - 1) && DateYear != 2000)
						{      //if date from year before last year, add 100 to year
							DateYear += 100;
						}
						break;
					case 62:   //dates from last year and before
						if (DateYear > ThisYear)
						{      //if date from year after last year, subtract 100 from year
							DateYear -= 100;
						}
						break;
						case 63:   //dates within 50 years of the current year
	  					if (DateYear < (ThisYear - 50))
						{      //if date from year more than 50 years in past, add 100 to year
  							DateYear += 100;
  						}
						else 
							if (DateYear > (ThisYear -0 + 50))
							{      //if date from year more than 50 years in future, subtract 100 from year
							DateYear -= 100;
							}
						break;
				}//end-switch
				
				var ModifiedDate;
				ModifiedDate = InputMonth + "/" + InputDay + "/" + DateYear;  //add modified year to date value
				InputField.value = ModifiedDate;
						
			} // end-if year.len == 2
			
			// 02/24/2004 RCS added the following date checking
			// JES:03/02/2004:fixed prob on min
			
	  		// check dates against min and max
	  		if (InputField.CMax != null && InputField.CMax.length >= 8 )
			{
				var testDate = returnYYYYMMDDDate( InputField.value )
				var MaxDate = returnYYYYMMDDDate( InputField.CMax )

				if( testDate > MaxDate )
				{
  					AlertMsg( InputField, FieldName, "Date Entered is greater than allowed.  Please enter a date that is not greater than " + InputField.CMax  );
	  				return false;
				}
			}
	  		if (InputField.CMin != null && InputField.CMin.length >= 8 )
			{
				var testDate = returnYYYYMMDDDate( InputField.value )
				var MinDate = returnYYYYMMDDDate( InputField.CMin )
				if( testDate < MinDate )
				{
  					AlertMsg( InputField, FieldName, "Date Entered is less than allowed.  Please enter a date that is not less than " + InputField.CMin  );
	  				return false;
				}
			}


			/* -----------------------------------------------------------------*/
			// perform validation if there are not min/max values on date fields
			// assuming todays date for comparison

			var enteredDate = returnYYYYMMDDDate( InputField.value )
			var cToday = new Date();
			var mm = cToday.getMonth() + 1;
			var dd = cToday.getDate();
			var yyyy = cToday.getFullYear();
			var checkDate = NormalizeDate(mm + '/' + dd + '/' + yyyy ) ;

			/* -------------- TURN OFF ----------------------------
			switch (Type)		// Date types only
			{
				case 60:   //dates greater than or equal to today
					if (enteredDate < returnYYYYMMDDDate(checkDate) && InputField.CMin == null)
					{
		  				AlertMsg( InputField, FieldName, "Date Entered is less than allowed.  Please enter a date that is not less than " + checkDate  );
	  					return false;
					}
					break;

				case 61:   //dates greater than 1 year from today
					if (InputField.CMin == null)
					{
						var cDate = new Date(cToday.setYear(yyyy - 1));
						var checkDate = NormalizeDate((cDate.getMonth()+1) + "/" + cDate.getDate() + "/" + cDate.getFullYear());

						if (enteredDate < returnYYYYMMDDDate(checkDate) )
						{
		  					AlertMsg( InputField, FieldName, "Date Entered is less than allowed.  Please enter a date that is not less than " + checkDate  );
	  						return false;
						}
					}
				
					break;
				
				case 62:   //dates less than today
					if (enteredDate > returnYYYYMMDDDate(checkDate) && InputField.CMax == null )
					{
  						AlertMsg( InputField, FieldName, "Date Entered is greater than allowed.  Please enter a date that is not greater than " + checkDate );
	  					return false;
					}
					break;
				
				case 63:   //dates within 50 years of the current year
					
					if (InputField.CMax == null && InputField.CMax == null)
					{
						var past50		= new Date(cToday.setYear(yyyy - 50));
						var future50	= new Date(cToday.setYear(yyyy + 50));
						var past50n		= NormalizeDate((past50.getMonth()+1) + "/" + past50.getDate() + "/" + past50.getFullYear());
						var future50n	= NormalizeDate((future50.getMonth()+1) + "/" + future50.getDate() + "/" + future50.getFullYear());
				
						if (enteredDate > returnYYYYMMDDDate(future50n) )
						{
  							AlertMsg( InputField, FieldName, "Date Entered is more than 50 years in the future.  Please enter a date that is less than " + future50n );
	  						return false;
						}

						if ( enteredDate < returnYYYYMMDDDate(past50n))
						{
  							AlertMsg( InputField, FieldName, "Date Entered is more than 50 years in the past.  Please enter a date that is greater than " + past50n );
	  						return false;
	  					}
					}
				
					break;

			}  //end-switch
			
			-------------- END OF TURN OFF ---------------------------- */
			
			/*----------------------------------------------------------------- */
		} //end-if len > 0  
	      
	    //Check the date against leap years or wrong date for a month (31st April), wrong year (3 digit year) etc
		InputString = InputField.value;
           
		if ( TestDate(InputString) == -1)
		{
  		    AlertMsg( InputField, FieldName, "Invalid date entered.  Please enter a valid date in the format MM/DD/YYYY.");
	  	    return false;
	  	}
  	  
    } /* --- end-if type = date --- */
    else if (Type >=70 && Type <= 79)
	{ // TOD TIME OF DAY FUNCTIONS
	
		if( CheckValidString (InputString, validTime, FieldName, InputField) == false)
			return false;
		
		var timeReturn = testTime( InputString, Type );
		var timeChar = timeReturn.charAt(0);
	
		if( timeChar == 'E' )
		{
			AlertMsg( InputField, FieldName, timeReturn );
		}
		else
		{
			InputField.value = timeReturn;
		}
	
	
	}
	else
    {
      var msg = "This field has an HTML error. Invalid Type Specified '" + Type + "'. ";    
      AlertMsg( InputField, FieldName, msg );    
    }
    
    return true;    
}
    

//-----------------------------------------------------------------------------------------------------------------------------------------
function isEmailValid (str)
{
	var invalidChars = " /':;()?!#$%^&*+=<>\[]{}";

	if (str == "") return 11;

	for (i=0; i < invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i);
		if (str.indexOf(badChar) > -1) return 1;
	}

	iLocAT = str.indexOf("@",0);
	if (iLocAT == -1) return 5;
	if (iLocAT == 0) return 8;
	
	var idot = str.indexOf(".",0);
	if (idot == -1) return 2;
	if (idot == 0) return 7;
	
	if (str.indexOf("@",iLocAT+1) > -1) return 3;

	iLocPeriod = str.indexOf(".",iLocAT+1);
	iLoc2ndPeriod = str.indexOf(".",iLocPeriod+1);
	if (iLocPeriod == -1) return 4;
	var tooClose = iLocPeriod - iLocAT;
	if (tooClose < 2) return 5;
	if (str.lastIndexOf(".")+ 3 > str.length) return 6;
	
	return 0;
}


//-----------------------------------------------------------------------------------------------------------------------------------------
function GetClearString( InputString, ValidString )
    {
      var i, j
      var outStr = "";    
      var l = InputString.length;    
      var cl = ValidString.length;    
      for (i = 0; i < l; i++)
      {
        ch = InputString.charAt(i);    
        for (j = 0; j < cl; j++)
          if (ch == ValidString.charAt(j))
          {
    		outStr += ch;    
    		break;    
          }
      }
      return outStr;    
    }
    

//-----------------------------------------------------------------------------------------------------------------------------------------

function GetInt( InputString )
    {
      var x = parseInt(GetClearString( InputString, "0123456789-." ), 10);    
      if( isNaN( x ) )
        return 0;
      else
        return x;
    }
    

//-----------------------------------------------------------------------------------------------------------------------------------------

function GetReal( InputString )
    {
      var x = parseFloat(GetClearString( InputString, "0123456789-." ));
      if( isNaN( x ) )
        return 0;
      else
        return x;
    }

//-----------------------------------------------------------------------------------------------------------------------------------------
function FormatNumber( Number )
    {
     var j
     var s = "";
     var x = Math.floor( Math.abs( Number ) );
     var d = 0;
     while( x > 0 )
     {
       j = Math.floor(x % 10);
       x = Math.floor(x / 10);
       if( d == 3 )
       {
          s = ',' + s;
          d=0;
       }
       s = j + s;
       d++;
     }
     if( Number < 0 )
       s = '-' + s;
     return s;
    }
    


//-----------------------------------------------------------------------------------------------------------------------------------------
function FormatDecimal( Number, DecimalPoints )
    {
     var j
     var i
     if( DecimalPoints < 0 )
       return "";
     var mult = Math.pow( 10, DecimalPoints );    
     var x = Math.round( Math.abs(Number) * mult) % mult;    
     var s = "";
     for(i=0; i<DecimalPoints; i++)
     {
       j = Math.floor(x % 10);    
       x = Math.floor(x / 10);    
       s = j + s;
     }
     s = '.' + s;
     return s;
    }

//-----------------------------------------------------------------------------------------------------------------------------------------
function ReFormatField( InputField, Type )
{
	var s = "";
	if( Type == 99 ) 
	{
	  return;
	}
	else if( Type == 2 || Type == 4) // upper case
	{
		InputField.value = InputField.value.toUpperCase();
	}
	else if( Type == 3 || Type == 5) // lower case 
	{
		InputField.value = InputField.value.toLowerCase();
	}
	else if( Type == 6 )
	{
		//No reformatting for this field
	}
	else if( Type == 7 )
	{
		//No reformatting for this field
	}
	else if( Type == 8 )
	{
		var BreakOut = 0;
		var Count, InnerCount, NewString, Upper, TestChr;
		var InputString = InputField.value;
		for( Count = 0; Count < InputString.length; Count++ ) {
			for( InnerCount = 0; InnerCount < UpperAlphaOnly.length; InnerCount++ ) {
				if( InputString.charAt( Count ) == UpperAlphaOnly.charAt( InnerCount ) )
					BreakOut = 1;
			}
		}
		if( BreakOut == 0 ) {
			NewString = InputString.charAt( 0 ).toUpperCase();
			for( Count = 1; Count < InputString.length; Count++ ) {
			    TestChr = InputString.charAt( Count )
				if( TestChr == " "
				 || TestChr == "\n"
				 ) {
					NewString = NewString + TestChr + InputString.charAt( Count + 1 ).toUpperCase();
					Count++;
				}
				else {
					NewString = NewString + TestChr;
				}
			}

			InputField.value = NewString;
		}
	}
	else if( Type == 10 ) // -dddd
	{
		InputField.value = GetInt( InputField.value );
	}
	else if( Type == 11 ) // -d,ddd
	{
		var x
		x = GetInt( InputField.value ) 
		if( x == 0 )
			InputField.value = "0"
		else
			InputField.value = FormatNumber( x )
	}
	else if (Type == 20)  // -dddd.cccc
	{	
		var String;
		var DecimalPlaces
		DecimalPlaces = FindDecimalPlaces(InputField.value);
		String = GetClearString(InputField.value, ValidNum);
		//InputField.value = FormatNumber( String) + FormatDecimal( String, DecimalPlaces )
		//InputField.value = FormatNumber( String) + FormatDecimal( String, DecimalPlaces )
		InputField.value = GetInt( String ) + FormatDecimal( String, DecimalPlaces )

	}
	else if( Type == 21 ) // -d,ddd.ccccc (real)
	{
		var DecimalPlaces
		var x = GetReal( InputField.value );    
		if( x == 0 )
			InputField.value = "0"
		else
		{
			DecimalPlaces = FindDecimalPlaces(InputField.value);
			InputField.value = FormatNumber( x ) + FormatDecimal( x, DecimalPlaces );
		}
	}
	else if( Type == 30 ) // -dddd.cc
	{
		var w = GetReal( InputField.value );
		var x = Math.abs( w );
		var d = Math.floor( x );
		s = FormatDecimal( w, 2 );
		//if( w < 0 )
		//	d = '-' + d;
		if( w == 0 )
			s = "0.00"
		InputField.value = d + s;
	}
	else if( Type == 31 ) // -d,ddd.cc
	{
		var x = GetReal( InputField.value );
		var d = FormatNumber( x );
		//if( x < 0 )
		//	d = '-' + d;
		var s = FormatDecimal( x, 2 );
			if( x == 0 )
			s = "0.00"
		InputField.value = d + s;
	}
	else if( Type >= 40 && Type <=49 ) // nnn.dddd
	{
		var n = Type % 10;
		var w = GetReal( InputField.value );
		var x = Math.abs( w );
		var d = Math.floor( x );
		var s = FormatDecimal( w, n );
		//if( w < 0 )
		//	d = '-' + d;
		if( w == 0 )
			InputField.value = "0"
		else
       InputField.value = d + s;
	}
	else if( Type == 50 ) { // phone
		var String = InputField.value;
		var Length = String.length;
		var Count, InnerCount, BreakOut;

		for( Count = 0; Count < Length; Count++ ) {
			for( InnerCount = 0; InnerCount < PhoneZipPunct.length; InnerCount++ ) {
				if( String.charAt( Count ) == PhoneZipPunct.charAt( InnerCount ) )
					BreakOut = 1;
			}
		}
	
		if( BreakOut != 1 ) {
			if( Length == 7 || Length == 10 ) {
				if( Length == 7 ) {
					var i = String.substring(0,3)
					var j = String.substring(3,7)
					InputField.value = i + "-" + j
				}
				else if( Length == 10 ) {
					var i = String.substring(0,3)
					var j = String.substring(3,6)
					var k = String.substring(6,11)
					InputField.value = "(" + i + ") " + j + "-" + k
				}
			}
		}
	}
	else if( Type == 51 ) { // zip code
		var String = InputField.value;
		var Length = String.length;
		var Count, InnerCount, BreakOut;

		for( Count = 0; Count < Length; Count++ ) {
			for( InnerCount = 0; InnerCount < PhoneZipPunct.length; InnerCount++ ) {
				if( String.charAt( Count ) == PhoneZipPunct.charAt( InnerCount ) )
					BreakOut = 1;
			}
		}
	
		if( BreakOut != 1 ) {
			if( Length == 5 || Length == 9 ) {
				if( Length == 9 ) {
					var i = String.substring(0,5)
					var j = String.substring(5,9)
					InputField.value = i + "-" + j
				}
			}
		}
	}
	else if( Type == 53 ) // SSN
	{
		var Count, Innercount, NewString = "";
		var InputString = InputField.value;

		InputString = InputString.replace(/[\-]/g,"")
		if( InputString.length == 9 ) {
			for( Count = 0; Count < InputString.length; Count++ ) {
				for( InnerCount = 0; InnerCount < ValidSSN.length; InnerCount++ ) {
					if( InputString.charAt( Count ) == ValidSSN.charAt( InnerCount ) ) {
						NewString += InputString.charAt( Count );
					}
				}
			}
			InputField.value  = NewString.substring(0,3) + '-';
			InputField.value += NewString.substring(3,5) + '-';
			InputField.value += NewString.substring(5,9);
		}
	}
	else if( Type == 54 ) // EMAIL
	{   // ADDED 3/7/02 RCS
		// NO REFORMATING AT THIS TIME
	}
	else if( Type == 55 ) // Fein
	{
		var Count, Innercount, NewString = "";
		var InputString = InputField.value;
		
		InputString = InputString.replace(/[\-]/g,"")
		
		NewString = InputString; 
		
		if (InputString.charAt(2) != "-"){
			InputField.value  = NewString.substring(0,2) + '-';
			InputField.value += NewString.substring(2,InputString.length);
		}
	}
}
    

//-----------------------------------------------------------------------------------------------------------------------------------------
function FindDecimalPlaces( InputString )
	{
	  var FieldLength = InputString.length
	  var DecimalLoc = InputString.indexOf(".", 0)
      var x = GetReal( InputString );    
      if( x == 0 )
        return( 0 )
      else
	  {
		if (DecimalLoc == -1 ){
			return 1;
		}
		else {
			return (FieldLength - (DecimalLoc + 1));
		}
	  }
	}
	 


//-----------------------------------------------------------------------------------------------------------------------------------------
function AlertMsg( Field, FieldName, Message )
    {
		if (ErrorFlag)
		{
			return;
		}
		else
		{
		
			if( confirm( "Error in input field: " + FieldName + ". \n" + Message + "\nOK to Correct, Cancel to Ignore." ) )
			{
				ToggleErrorFlag();
				if ((FieldFlag == FieldName + Field.value) && (BrowserNS))
					Field.value = "";
				Field.focus();
				ErrorTimer = setTimeout("ToggleErrorFlag()", 500);
				FieldFlag = FieldName + Field.value;
			}
			else
			{
				Field.value = ""
			}
		}
    }
    

//-----------------------------------------------------------------------------------------------------------------------------------------
function AlrtMsg( Field, FieldName, Message )
{
	if (ErrorFlag)
	{
		return;
	}
	else
	{
		if( confirm( "Error in input field: " + FieldName + ". \n" + Message + "\nOK to Correct, Cancel to Ignore." ) )
		{
				ToggleErrorFlag();
				if ((FieldFlag == FieldName + Field.value) && (BrowserNS))
					Field.value = "";
				Field.focus();
				ErrorTimer = setTimeout("ToggleErrorFlag()", 500);
				FieldFlag = FieldName + Field.value;
		}
	}
}
    

//-----------------------------------------------------------------------------------------------------------------------------------------
function ToggleErrorFlag()
{
	if (ErrorFlag)
	{
		ErrorFlag = false;
	}
	else
	{
		ErrorFlag = true;
	}
}
//-----------------------------------------------------------------------------------------------------------------------------------------
function setFieldProperties( Field, FieldName, Type, Options, Min, Max, Reformat )
{
xSV( Field, FieldName, Type, Options, Min, Max, Reformat )
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function xSetFieldManditoryFlag( Field, Options )
{
	Field.COptions = Options;
	if ( BrowserIE||BrowserDOM )
	{ 
		setBackgroundBorderColor (Field, Options);	
	}
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function setBackgroundBorderColor (Field, Options)
{
	Type = Field.CType;
	if ( Options > 9 )
	{ 
	  	var s = LRtrim( Field.value );
	    if( s.length > 0 )
	    {
			if( Type == 99 )
			{
			    Field.style.backgroundColor=ManditoryBoxOK;
			}
			else
			{
			    Field.style.borderColor=ManditoryOK;
			}
	    }
	    else
	    {
			if( Type == 99 )
			{
			    Field.style.backgroundColor=ManditoryCaution;
			}
			else
			{
			    Field.style.borderColor=ManditoryCaution;
			}
		}
	}
	else
	{
		if( Type == 99 )
		{
		    Field.style.backgroundColor="";
		}
		else
		{
		    Field.style.borderColor="";
		}
	}
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function xSetFormatType( Field, Options ) {
	Field.CType = Options; 
}


//-----------------------------------------------------------------------------------------------------------------------------------------
function xSV( Field, FieldName, Type, Options, Min, Max, Reformat )
{
	Field.CField = Field;
	Field.CFieldName = FieldName;
	Field.CType = Type;
	Field.COptions = Options;
	Field.CMin = Min;
	Field.CMax = Max;
	Field.CReformat = Reformat;
	if ( BrowserIE||BrowserDOM )
	{ 
		setBackgroundBorderColor (Field, Options);	
	}

	/*
		if ( Options > 9 )		//if Manditory field and IE, show input box border as yellow.
		{ 
		  	var s = LRtrim( Field.value );
		    if( s.length > 0 )
		    {
				if( Type == 99 )
				{
				    Field.style.backgroundColor=ManditoryBoxOK;
				}
				else
				{
				    Field.style.borderColor=ManditoryOK;
				}
		    }
		    else
		    {
				if( Type == 99 )
				{
				    Field.style.backgroundColor=ManditoryCaution;
				}
				else
				{
				    Field.style.borderColor=ManditoryCaution;
				}
			}
		}
		else
		{
			if( Type == 99 )
			{
			    Field.style.backgroundColor="";
			}
			else
			{
			    Field.style.borderColor="";
			}
		}
	}
	*/
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function xSV2( Field, FieldName, Type, Options, Min, Max, Reformat )
{
	Field.CField = Field;
	Field.CFieldName = FieldName;
	Field.CType = Type;
	Field.COptions = Options;
	Field.CMin = Min;
	Field.CMax = Max;
	Field.CReformat = Reformat;
	Field.onblur = onFieldBlur;
	Field.onfocus = onFieldEntry;
	if ( BrowserIE||BrowserDOM )
	{ 
		setBackgroundBorderColor (Field, Options);	
	}

	/*
	if( BrowserIE||BrowserDOM ) 
	{
		if( Options > 9 )		 //if Manditory field and IE, show input box border as yellow.
		{
		  	var s = LRtrim( Field.value );    
		    if( s.length > 0 )
		    {
				if( Type == 99 )
				    Field.style.backgroundColor=ManditoryBoxOK;
				else
				    Field.style.borderColor=ManditoryOK;
		    }
		    else
		    {
				if( Type == 99 )
				    Field.style.backgroundColor=ManditoryCaution;
				else
				    Field.style.borderColor=ManditoryCaution;
		    }
		}
		else
		{
			if( Type == 99 )
			{
			    Field.style.backgroundColor="";
			}
			else
			{
			    Field.style.borderColor="";
			}
		}
	}		// BrowserIE||BrowserDOM
	*/
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function onFieldBlur()
{
	xV( this )
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function onFieldEntry()
{
	EnableMessage( this.Cmsg )
}
    
//-----------------------------------------------------------------------------------------------------------------------------------------
function xEF( Field )
{
	EnableMessage( Field.Cmsg )
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function xV( Field )
{
	var FieldName = Field.CFieldName
	var Type = Field.CType
	var Options = Field.COptions
	var Min = Field.CMin
	var Max = Field.CMax
	var Reformat = Field.CReformat
	return Validate( Field, FieldName, Type, Options, Min, Max, Reformat )
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function Validate( Field, FieldName, Type, Options, Min, Max, Reformat )
{
	if( Type == 99 && BrowserNS  ) // select box
	   return true;
	   
	// trim field before anything else
	if (Type != 99) // 10/31/02 - srini - DevTrack# 1398
		Field.value = LRtrim( Field.value );

	// check Manditory Option
	var s = Field.value;   
	 
	if( BrowserIE||BrowserDOM )
	{
		if( Options == 10 || Options == 11 )
	    {
	        if(  s.length > 0 ) 
	        {
				if( Type == 99)
					Field.style.backgroundColor=ManditoryBoxOK;
				else
					Field.style.borderColor=ManditoryOK;
	        }   
	        else
	        {
				if( Type == 99)
					Field.style.backgroundColor=ManditoryCaution;
				else
					Field.style.borderColor=ManditoryCaution;
	        }   
	    }
	}
	
	if( Type == 99) // select box
	   return true;

	if(CheckField( Field, Type, FieldName )==false)
	   return false;
	   
	/* 8/31/2002 RCS fixed a field validation by changing <= 10 to < 10 on following stmt */
	if( ( Type >= 0 && Type < 10) || Type == 50 || Type == 53 || Type == 54 || Type==55) // string, Phone, SSN, email
	{
		var len = Field.value.length
		if( Min > 0 && Min > len && len != 0 )
		{  // don't issue the message if field is empty
			var msg = "You must enter at least " + Min + " characters in this field.";
			AlertMsg( Field, FieldName, msg );
			return false;
		}
		if( Max > 0 && Max < len )
		{
			//truncate the field if here!    
			Field.value = Field.value.substring( 0, Max )
			var msg = "You have entered too many characters into the field. "
			msg += "This field will only accept " + Max + " characters. "
			msg += "\nThe field has been truncated to fit."
			AlrtMsg( Field, FieldName, msg );
			return false;
		}
	}
	else if( Type >= 10 && Type <= 49)  // numbers
	{
		var len = Field.value.length
		var x = GetReal( Field.value );
		if( Min != null && Min > x && len != 0 )
		{
			var msg = "You have entered a value that is too small. "
			msg += "This field requires a value of at least " + Min + ".";
			AlertMsg( Field, FieldName, msg );
			return false;
		}
		if( Max != null && Max < x )
		{
			var msg = "You have entered a value that is too large. "
			msg += "This field requires a value no larger than " + Max + ".";
			AlertMsg( Field, FieldName, msg );
			return false;
		}
	}
	else if (Type >= 60 && Type <= 69)   //dates
	{
		//All checks in the function Checkfield		
	} // if (Type >= 60 && Type <= 69)   //dates

    // reformat as requested
    if( Reformat != false && Field.value.length > 0 )
        ReFormatField( Field, Type );
    
    // check must fill field option - this can be taken care of by min length!
    if( false )
    {
     var s = Field.value;
     if( s.length != Field.size )
     {
     if( Options == 1 || Options == 11 )
      {
      // **** TO DO issue error msg, field is not completely filled in
      //   return false;
      }
     }
    // check field length for overflow (HTML coding error)
     if( s.length > Field.size )
     {
     // **** TO DO issue error msg, too many chars for field, HTML error
     }
    } // endif false 
    
    //ClearMsg();
      return true;
	}

//-----------------------------------------------------------------------------------------------------------------------------------------
function returnYYYYMMDDDate (in_date)
{
	// assumption that date coming in is mm/dd/yyyy format

	var str = "";
	var aryDate;
	var YYYY;
	var MM;
	var DD;

	//if (!out_style) out_style = cMM_DD_YYYY;
	
	if (in_date.indexOf("/") > 0)		// check for valid 
	{
		aryDate	= in_date.split("/");
		if (aryDate.length == 3)		// make sure 3 date elements
		{
			MM		= aryDate[0];
			DD		= aryDate[1];
			YYYY	= aryDate[2];
			
			// final test to see if really converts to date.
			var testDate = new Date(in_date);
			if (testDate.getMonth()+1 == MM)
			{
				if (MM.length == 1) MM = '0' + MM;
				if (DD.length == 1) DD = '0' + DD;
				str = YYYY + MM + DD;
			}
		}
	}

	return str;
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function NormalizeDate (in_date)
{
	// always returns date as mm/dd/yyyy format
	var str = "";
	var YYYY;
	var MM;
	var DD;

	var aryDate	= in_date.split("/");	// assume has 3 elements
	MM		= aryDate[0];
	DD		= aryDate[1];
	YYYY	= aryDate[2];

	if (MM.length == 1) MM = '0' + MM;
	if (DD.length == 1) DD = '0' + DD;

	str = MM + "/" + DD + "/" + YYYY;
		
	return str;
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function TestDate( InputString )
{
  
  /******************testDate function*******************************
  *Variables:  DateYear- stores the year value of the input date
  *  DateMonth- stores the month value of the input date
  *  DateDay- stores the day value of the input date
  *  relYear- defines range of valid dates if input is in MM/DD/YY form
  *  YearCheck- used to check input form used
  *  IsLeapYear- used to indicate if a year is a leap year
  *Input:  date value of form MM/DD/YY or MM/DD/YYYY
  *Output:  0 for valid date, -1 for invalid date, 1 for empty string
  *Operation:  if date is of form MM/DD/YY, year is set at 20YY if YY <= relYear,
  *  19YY if YY > relYear
  *  checks month value to ensure a number between 1 and 12 was entered
  *  checks date value to ensure it is correct based on month ahd year entered
  *Tolerances:  Any string of numbers with correct month, day, and 4-digit year
  *  values will be accepted as a correct date.
  */
  
      var DateYear  //stores the year value of the input date
      var DateMonth  //stores the month value of the input date
      var DateDay  //stores the day value of the input date
      var relYear=30  //defines range of valid dates if input is in MM/DD/YY form
      var YearCheck  //used to check input form used
      var IsLeapYear = false  //used to indicate if a year is a leap year
  
      	
  		DateYear=InputString.substring(InputString.lastIndexOf("/")+1,InputString.length)
  
  		//check DateYear for null value to differentiate between null and "00"
  		DateYear=parseInt(DateYear, 10);
  		
  		if ( isNaN(DateYear) ) {
  			return -1;
  		}
  	  		
  		DateYear=parseInt(DateYear, 10);
  		DateMonth=InputString.substring(0,InputString.indexOf("/") );
  		DateMonth=parseInt(DateMonth,10);
  		DateDay=InputString.substring(InputString.indexOf("/")+1,InputString.lastIndexOf("/"));
  		DateDay=parseInt(DateDay,10);
  
		if ( isNaN(DateMonth) ) {
  			return -1;
  		}
  		
  		if ( isNaN(DateDay) ) {
  			return -1;
  		}
		  
		YearCheck =(DateYear / 100 )
  
		//determine if 2 or 4 digit year value is used
		if (YearCheck < 1)
		{
   			//if 2 digit value is used, set year to 4 digit value relative to relYear
  			if (DateYear <= relYear){
  				DateYear = DateYear + 2000
  			}
  			else{
  				DateYear = DateYear + 1900
  			}
  		}
  		else if (YearCheck < 10 )
  		{
  			return -1; // 3 digit year is unacceptable
  		}
  		// added 10/17/02 rcs to prevent 5 digit year
  		else if (YearCheck > 99 )
  		{
  			return -1; // 5 digit year is unacceptable
  		}
  
		//check month value to ensure it is between 1 and 12
		if (( DateMonth < 1) || (DateMonth > 12)){
  			return -1
  		}
  
		//determine if year input is a leap year and set IsLeapYear accordingly
		if (Math.round(DateYear / 4) == (DateYear / 4))
		{
  			IsLeapYear = true
  			if ( (Math.round(DateYear / 100) == (DateYear / 100)) && (Math.round(DateYear / 400) != (DateYear /400)) ){
  				IsLeapYear = false
  			}
  		}
  
		//check input date value for validity based on input month and year values
		if ( (DateDay > 31) || (DateDay < 1) || ((IsLeapYear == false) && (DateMonth == 2) && (DateDay > 28)) ||((IsLeapYear == true) && (DateMonth == 2) && (DateDay > 29)) || ( ((DateMonth == 4) || (DateMonth == 6) || (DateMonth == 9) || (DateMonth == 11)) && (DateDay > 30))){
  			return -1
  		}
  		else 
		{
  			return 0
  		}
        
  }//end function

//-----------------------------------------------------------------------------------------------------------------------------------------
function FieldEntry( Field )
{
	// on entry remove the field justification, then select all of the data
	Field.value = LRtrim( Field.value )
	Field.select()
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function PutFormatedField( Field, Value, Type )
{
	Field.value = Value;
	ReFormatField( Field, Type );
}
    
//-----------------------------------------------------------------------------------------------------------------------------------------
function xPutFormatedField( Field, Value )
{
	var Type = Field.CType
	Field.value = Value;    
	ReFormatField( Field, Type );
}




// *****************************************************************************************************************************
// ******************************************** FIELD PROMPTING STUFF **********************************************************
// *****************************************************************************************************************************
    
    var msgTimer;
    var msgText;
    var msgFlag = false
    

//-----------------------------------------------------------------------------------------------------------------------------------------
function ClearMsg()
{
	var temp;
	temp  = AddHeader();
	temp += "</body></html>";
	EnableMessage( temp )
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function AddHeader()
{
	var temp;
	temp  = '<html>\n'
		  + '<head>\n'
		  + ' <title>Help Frame</title>\n'
		  + '</head>\n'
		  + '<body bgcolor="#E0F0FF" marginheight="2" marginwidth="2" topmargin="2" leftmargin="2">\n'
		  + '<font face="Arial, Verdana, Helvetica" size="-1">\n';

	return temp;
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function SetMsgBoxColor( color )
{
    helpMsgColor = color;
}


//-----------------------------------------------------------------------------------------------------------------------------------------
function xSM( Field, Message )
{
	var temp;
	temp  = AddHeader()
		  + '<b>' + Field.CFieldName + ':</b><br>\n'
		  + Message
		  + '</body>\n'
		  + '</html>\n';
		  
	Field.Cmsg = temp;
}


//-----------------------------------------------------------------------------------------------------------------------------------------
function EnableMessage( Message )
{
	if( ShowHelpMsgs )
	{
	     if( msgFlag == true )
	       clearTimeout( msgTimer );    
	     msgTimer = setTimeout("WriteMessage()", 700); // short .7 second delay
	     msgText = Message;
	     msgFlag = true;
	}
}


//-----------------------------------------------------------------------------------------------------------------------------------------
function GetHelpFrame()
{	
	var helpFrameAddress;
	helpFrameAddress = top.help;
        return( helpFrameAddress );
}

//-----------------------------------------------------------------------------------------------------------------------------------------
function WriteHelpMsg( Message )
{
	var temp;
	temp = AddHeader()
		  + Message
		  + '</body>'
		  + '</html>';
	var helpFrameAddress = GetHelpFrame();
	if( helpFrameAddress != null )
	{
	    helpFrameAddress.document.open();
	    helpFrameAddress.document.write( temp );
	    helpFrameAddress.document.close();
        }

}

//-----------------------------------------------------------------------------------------------------------------------------------------
function WriteMessage()
    {
    if( msgFlag == true )
     {
	var helpFrameAddress = GetHelpFrame();
	if( helpFrameAddress != null )
	{
	    helpFrameAddress.document.open();
	    helpFrameAddress.document.write( msgText );
	    helpFrameAddress.document.close();
        }
     }
    msgFlag = false;
    }

//-----------------------------------------------------------------------------------------------------------------------------------------
function DropDown() {
	var Items, Length, Display, Number, layerRef, styleSwitch;

	if ( navigator.appName == "Netscape" ) {
		var layerRef="document.layers";
		var styleSwitch="";
	}
	else
	{
		var layerRef="document.all";
		var styleSwitch=".style";
	}
	
	Length = document.all.length;
	Number = window.event.srcElement.sourceIndex + 1;
	if ( window.event.srcElement.className == "DropBox" ) {
		eval( layerRef + '[window.event.srcElement.sourceIndex]' + '.className = \'DropBoxDown\'' );
		while( Number < Length && eval( layerRef + '[' + Number + ']' + '.className' ) != "DropBox" && eval( layerRef + '[' + Number + ']' + '.className' ) != "DropBoxDown" ) {
			eval( layerRef + '[Number]' + '.className = \'MenuBoxDown\'' );
			Number++;
		}
	}
	else {
		eval( layerRef + '[window.event.srcElement.sourceIndex]' + '.className = \'DropBox\'' );
		while( Number < Length && eval( layerRef + '[' + Number + ']' + '.className' ) != "DropBox" && eval( layerRef + '[' + Number + ']' + '.className' ) != "DropBoxDown" ) {
			eval( layerRef + '[Number]' + '.className = \'MenuBox\'' );
			Number++;
		}
	}
}

function testTime( item, formatTag ) 
{ 
	var strTest;
	strTest = LRtrim( item );
	var l = strTest.length;
	
	var i;
	var hours, minutes, tag;
	hours = '';
	minutes = '';
	tag = '';
	for (i = 0; i < l; i++)
	{
		var chrTest = strTest.charAt(i);
		if( chrTest==':' || chrTest=='.' )
		{
			if( tag != '' )
			{ // error more than one tag character
				return( 'Error - more than one tag character' )
			}
			else
			{
				tag = ':';
			}
		} 
		else
		{
			if( tag != '' )
			{ 
				minutes += chrTest;
			}
			else
			{
				hours += chrTest;
			}
		}
	}
	
	if( minutes == '' ) 
	{
		minutes = '0';
		tag = ':';
	}
	
	if( parseInt(minutes) > 59 ) return 'Error - value entered for minutes exceeds 59 '
	
	if( formatTag == 79 ) // HH:MM
	{
		// no error 
	}
	else if( formatTag >= 75 ) // use 24 hour time scale
	{
		if( parseInt(hours) > 24 ) 
			return 'Error - value entered for hours exceeds 24';
	}
	else // formatTag < 75 use 12 hour time scale
	{
		if( parseInt(hours) > 12 ) 
			return 'Error - value entered for hours exceeds 12';
	}
	
	if( formatTag == 71 || formatTag == 76 )
	{
		if( parseInt(minutes) == 0 
			|| parseInt(minutes) == 15  
		    || parseInt(minutes) == 30 
		    || parseInt(minutes) == 45 ) 
		{
		}
		else
		{
			return 'Error - value entered for minutes must be 00, 15, 30, or 45. '
		}
	}
	
	if( formatTag == 72 || formatTag == 77 )
	{
		if( parseInt(minutes) == 0 
			|| parseInt(minutes) == 30 )
		{
		}
		else
		{
			return 'Error - value entered for minutes must be 00, or 30 '
		}
	}
	
	hours = '00' + hours;
	l = hours.length;
	hours = hours.substring( l-2, 100 );
	
	minutes = '00' + minutes;
	l = minutes.length;
	minutes = minutes.substring( l-2, 100 );
	
	return hours + tag + minutes;
	
}


