  // returns array with days in the months
    function arrayOfDaysInMonths(adm_isLeapYear) {
      this[0] = 31;
      this[1] = 28;
      // if Leap Year there is 29 days in Feb
        if (adm_isLeapYear)
          this[1] = 29;
      this[2] = 31;
      this[3] = 30;
      this[4] = 31;
      this[5] = 30;
      this[6] = 31;
      this[7] = 31;
      this[8] = 30;
      this[9] = 31;
      this[10] = 30;
      this[11] = 31;
    }
		
 // Returns the days in the given month and year
   function daysInMonth(dim_month,dim_year) {
     // Check for leap year
       var dim_isLeapYear = (((dim_year % 4 == 0) && ( dim_year % 100 != 0)) || (dim_year % 400 == 0));
     // Create array of days in each month
       var dim_monthDays = new arrayOfDaysInMonths(dim_isLeapYear);
     // Return the days in month
       return dim_monthDays[dim_month];
   }
	
  	// Validates date on onBlur of date field
	function ValidateDate(obj,strDate,MonthDefault,DayDefault,YearDefault) {
		arryDate = strDate.split('/');		// Split the date up into a month day year array
		if (strDate.length  && (isNaN(parseInt(arryDate[2])) || isNaN(parseInt(arryDate[0])) || arryDate[2] >2100|| arryDate[2] < 1900 ||arryDate[0] > 12 || arryDate[0] <1 || isNaN(parseInt(arryDate[1])) || arryDate[1] <1 ||arryDate[1] > daysInMonth(arryDate[0] - 1,arryDate[2]))) {
			arryDate[0] = MonthDefault;
			arryDate[1] = DayDefault;
			arryDate[2] = YearDefault;
		}
    obj.value = arryDate.join('/');
	}			
  
	// Make sure date being processed is valid if not, set date to today
	function isValidDate(dateObj,MonthDefault,DayDefault,YearDefault) {
		if (isNaN(parseInt(dateObj[0])) || isNaN(parseInt(dateObj[1])) || isNaN(parseInt(dateObj[2]))) {
			arryDate[0] = MonthDefault;
			arryDate[1] = DayDefault;
			arryDate[2] = YearDefault;
		}
		return (dateObj);
	}				
		
  function nextDay(obj,n,MonthDefault,DayDefault,YearDefault) {
		currDate = obj.value;
		arryDate = currDate.split('/');		// Split the date up into a month day year array
		arryDate = isValidDate(arryDate,MonthDefault,DayDefault,YearDefault);
		daysinCurrMonth = daysInMonth(parseInt(arryDate[0])-1,parseInt(arryDate[2]));		// Get the number of days in the current month
		arryDate[1] = parseInt(arryDate[1]) + n;		// Add one to the day
		// Check for day value to be more than days in the month
		if (arryDate[1] > daysinCurrMonth) {
			nextMonth = parseInt(arryDate[0]) + 1;
			if (nextMonth > 12) {
				arryDate[0] = 1;
				arryDate[2] = parseInt(arryDate[2]) + 1;
			}
			else
				arryDate[0] = nextMonth;
			      arryDate[1] = 1;
		}
		obj.value = arryDate.join('/');
  }    
  function previousDay(obj,n,MonthDefault,DayDefault,YearDefault) {
		currDate = obj.value;
		arryDate = currDate.split('/');
		arryDate = isValidDate(arryDate,MonthDefault,DayDefault,YearDefault);
		daysinPrevMonth = daysInMonth(parseInt(arryDate[0])-2,parseInt(arryDate[2]));
		arryDate[1] = parseInt(arryDate[1]) - n;
		// Check for day of zero
		if (arryDate[1] < 1) {
			prevMonth = parseInt(arryDate[0]) - 1;
			if(prevMonth == 0) {
				arryDate[0] = 12;
				arryDate[2] = parseInt(arryDate[2]) - 1;
				arryDate[1] = 31;
			}
			else {
				arryDate[0] = prevMonth;
				arryDate[1] = daysinPrevMonth;
			}
		}
		obj.value = arryDate.join('/');
  }

  function y2k(number)    { return (number < 1000) ? number + 1900 : number; }
  
  var today = new Date();
  var day   = today.getDate();
  var month = today.getMonth();
  var year  = y2k(today.getYear());
  var activeDateField;
  
function restart() {
    activeDateField.value = '' + (month - 0 + 1) + '/' + day + '/' + year;
    mywindow.close();
}
  
  function newWindow(DateField) {
      if (DateField.value != ''){
        currDate = DateField.value
    		arryDate = currDate.split('/');
        month = parseInt(arryDate[0])-1
        year = parseInt(arryDate[2])
        day = parseInt(arryDate[1])
      }
      else {
        day   = today.getDate();
        month = today.getMonth();
        year  = y2k(today.getYear());      
      }
	  currentDay=day;
	  currentMonth=month;
	  currentYear=year;
      activeDateField = DateField;
      mywindow=open('cal.htm?menuoff=1','ActiveCalendar','resizable=no,width=250,height=200');
      if (mywindow.opener == null) mywindow.opener = self;
  }


