		var theDay = 0;
		var theMonth = 0;      // set to 0 to initialize as integer variables
		var theYear = 0;
		
		//var theDate = '';
		//var txDate1 = '';
		//var txDate2 = '';

		// ***** verifyDate()     ******************************************
		// This function accepts three numbers that represent a date. month,
		// day and year. It verifies whether the date is a valid one. This
		// function callse isMonthOK(), isDayOK(), and isYearOK().
		// if this function is called with only one parameter (a whole date
		// string like 1/27/1998), this function will call seperateDates()
		// and will function properly.
		// This function's return values are as follows:
		//      RETURN 0 - THE DATE IS VALID
		//      RETURN 1 - THE MONTH IS NOT VALID
		//      RETURN 2 - THE DAY IS NOT VALID
		//      RETURN 3 - THE YEAR IS NOT VALID
		//		RETURN 4 - THE DATE IS UNREADABLE

		function verifyDate(enteredDay, enteredMonth, enteredYear) {
		   retVal = 0;

		   theDay = enteredDay;
		   theMonth = enteredMonth;
		   theYear = enteredYear;

		   if(enteredMonth == null && enteredYear == null)
		      retVal = seperateDateString(enteredDay);
		   else if (isMonthOK() == 0)
		      retVal = 1;
		   else if (isDayOK() == 0)
		      retVal = 2;
		   else if (isYearOK() == 0)
		      retVal = 3;

		   return retVal;
		}


		// ***** seperateDateString()     *******************************************
		// This function is called by verifyDate() when it is passed only one
		// parameter. It seperates the date mm/dd/yyyy into it's individual date
		// components and then re-calls verifyDate() with the three date parameters.

		function seperateDateString(dateString) {
		    var retVal = 0;
		    var slash1 = 0;     //character index of 1st slash
		    var slash2 = 0;     //character index of 2nd slash
		    var numSlashes = 0; //make sure there are two slashes
		    
		    for (slash1; slash1 < dateString.length && numSlashes == 0; slash1++) {
		        if (dateString.charAt(slash1) == '/' || dateString.charAt(slash1) == '-')
		            numSlashes++;
		    }
		    
		    for (slash2 = slash1; slash2 < dateString.length && numSlashes == 1; slash2++) {
		        if (dateString.charAt(slash2) == '/' || dateString.charAt(slash2) == '-')
		            numSlashes++;
		    }
		    
		    if (numSlashes == 2) {
		    
				theDay   = dateString.substring(0, slash1 - 1);
		        theMonth = dateString.substring(slash1, slash2 - 1);
		        theYear = dateString.substring(slash2, dateString.length);
		        
		        retVal = verifyDate(theDay, theMonth, theYear);
		    }
		    else
		        retVal = 4;
		    
		    theDate = theDay + '/' + theMonth + '/' + theYear;
		    //theDate = theYear + '/' + theMonth + '/' + theDay;
		    
			return retVal;
		}


		// ***** isMonthOK()     *******************************************
		// This function checks theMonth variable set by verifyDate(). It
		// returns 0 if the month is invalid, 1 if the month IS valid.
		// This function should only be called by verifyDate()
		function isMonthOK() {
		    var retVal = 0;

		    if(theMonth <= 12 && theMonth != 0)
		        retVal = 1;
		    else
		        retVal = 0;

		    return retVal;
		}

		// ***** isDayOK()     *********************************************
		// This function checks theDay variable set by verifyDate(). It
		// returns 0 if the day is invalid, 1 if the day IS valid.
		// theMonth variable is considered because there are different number
		// of days in each month. Leap-year is also considered (divisible by 4).
		// This function should only be called by verifyDate()
		function isDayOK() {
		    var retVal = 0;
		    
		    if(theMonth == 1 || theMonth == 3 || theMonth == 5 || theMonth == 7
		        || theMonth == 8 || theMonth == 10 || theMonth == 12) {
		    if (theDay >= 1 && theDay <= 31)
		        retVal = 1;
		    else
		        retVal = 0;
		    }
		    else if (theMonth == 2) {
		        if (theDay >= 1 && theDay <=28)
		            retVal = 1;
 else			if (theDay == 29 && ((theYear % 4) == 0 && (theYear % 100)) || 0 && (theYear % 400) == 0)
		            retVal = 1;  // valid leap-year
		        else if (theDay == 29 && (theYear % 4) != 0)
		            retVal = 0;
		        else
		            retVal = 0;
		    }
		    else {
		        if (theDay >= 1 && theDay <= 30)
		            retVal = 1;
		        else
		            retVal = 0;
		    }
		    return retVal;
		}

		// ***** isYearOK()     ****************************************************
		// This function checks theYear variable set by verifyDate(). It
		// returns 0 if the year is invalid, 1 if the year IS valid.
		// This function should only be called by verifyDate()
		function isYearOK() {
		   var retVal = 0;

		   if (theYear >= 1900 && theYear <= 2050)
		      retVal = 1;
		   else
		      retVal = 0;

		   return retVal;
		}
		
		// ***** composeNewDate()     ****************************************************
		// This function checks if theDay and theMonth length is < 2. If it is 1 
		//add a zero and then compose the string mm/dd/yyyy into tmpNewDate variable.
		function composeNewDate(txDate)
		{
			var tmpNewDate;
			
			seperateDateString(txDate);
			
			if (theMonth.length < 2)
				theMonth = "0" + theMonth;
				
			if (theDay.length < 2)
				theDay = "0" + theDay;
		
			tmpNewDate = '' + theYear + '' + theMonth + '' + theDay;
		
			return tmpNewDate; 
		}
		
		// ***** compDate()     ****************************************************
		// This function compare two dates set by composeNewDate(). It
		// returns '0' if tmpNewDate1 < tmpNewDate2, '1' if tmpNewDate1 > tmpNewDate2,
		// '2' if tmpNewDate1 = tmpNewDate2.
		function compDate(txNewDate1, txNewDate2)
		{
			var tmpNewDate1 = "";
			var tmpNewDate2 = "";
			var result = "";
			
			result = 0;
			
			tmpNewDate1 = composeNewDate(txNewDate1);
			tmpNewDate2 = composeNewDate(txNewDate2);
			
			if (tmpNewDate1 > tmpNewDate2)
			{
				result = 1;
			}
			else
			{
				if (tmpNewDate1 == tmpNewDate2)
					result = 2;
			}
			
			return result;
		}