//code to check dates

    var today = new Date();
    var year  = y2k(today.getYear());
    var month = today.getMonth();
    var months = new array("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER");
    var years = new yearArray("2002", "2015") ;
    var w_cal ;
	var thisDay   = today.getDate();
 	var thisMonth = today.getMonth();
 	var thisYear  = y2k(today.getYear());

	function showCalendarHelp(aFrame, page) {
		aFrame.document.location.replace(server_path + "/Ibe/" + page);
		return;
	}

  // Checks if browser is Netscape 2.0x since the options array properties don't work with Netscape 2.0x
  function isBrowserSupp() {
      // Get the version of the browser
      version =  parseFloat( navigator.appVersion );

      if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
          return false;
      }
      else {
  	return true;
      }

  return true;
  }

function  browserSupport() {
       Netscape4 = (document.layers);
       IExplorer4 = (document.all);
       version4 = (Netscape4 || IExplorer4);
       if (version4 != null)
		return true ;
       else
		return false ;
}

  function isLeapYear(yr) {
      if (((yr % 4 == 0) && (yr % 100 != 0)) || (yr % 400 == 0))
           return true ;
      else
           return false ;
  }


  function getDaysInMonth(mthIdx, YrStr)
  {
  // all the rest have 31
  var maxDays=31
  // expect Feb. (of course)
  if (mthIdx==1)
  	{
  	if (isLeapYear(YrStr))
  		{
  		maxDays=29;
  		}
  	else
  		{
  		maxDays=28;
  		}
  	}
  // thirty days hath...
  if (mthIdx==3 || mthIdx==5 || mthIdx==8 || mthIdx==10)
  	{
  	maxDays=30;
  	}
  return maxDays;
  }

  //the function which does some magic to the date fields
  // return non-zero if it is the last day of the month
  // just because the Return (DROP_DAY) has an additional element ("NONE" [--]), it has to act special

  function adjustReturnDate(mthIdx, Dt, Yr) {
	  var value=0;
	  var numDays=getDaysInMonth(mthIdx, Yr.options[Yr.options.selectedIndex].text);

	  if (Dt.options.selectedIndex < numDays) {
	  	return ;
	  } else {
	  	Dt.options.selectedIndex=numDays;
	  }
  }

  //the function which does some magic to the date fields
  // return non-zero if it is the last day of the month
  function adjustDate(mthIdx, Dt, Yr) {
	  var value=0;
	  var numDays=getDaysInMonth(mthIdx, Yr.options[Yr.options.selectedIndex].text);

	  if (mthIdx==1) {
	  	if (Dt.options.selectedIndex + 1 < numDays) {
	  		return 0;
	  	} else {
	  		Dt.options.selectedIndex=numDays - 1;
	  		//check for leap year
	  		if (numDays==29) {
	  			return 99;
	  		} else {
	  			return 1;
	  		}
	  	}
	  }
	  if (Dt.options.selectedIndex + 1 < numDays) {
	  	value=0;
	  } else {
		  if (Dt.options.selectedIndex + 1 > numDays) {
		  		Dt.options.selectedIndex--;
		  		value=3;
		  }	else {
		  	   //index is 31 or 30
		  	    value=2;
		  }
	  }
	  return value;
  }

  //changes departure month when arrival month is changed
  function amadChange(inM,inD,inY,outM,outD,outY)
  {
        if ( !isBrowserSupp() ) {

                return;
        }

        var res = adjustDate(inM.options.selectedIndex, inD,inY);

        if ( res != 0 ) {
                outD.options.selectedIndex=0;
                outM.options.selectedIndex = inM.options.selectedIndex + 1;
        } else {
                outM.options.selectedIndex = inM.options.selectedIndex;
				// commented as auto increment of drop day not required
                // outD.options.selectedIndex = inD.options.selectedIndex + 1;
        }

        // Set the out year to the same as the in year
        outY.options.selectedIndex = inY.options.selectedIndex;

        var currentMonth = ( new Date() ).getMonth();

        // If the in date is 12/31/?? set the out date to 01/01/??
        if ( ( inM.options.selectedIndex == 11 ) && ( inD.options.selectedIndex == 30 ) ) {
                outM.options.selectedIndex=0;
                outY.options.selectedIndex++;
        }

        // If the selected month is before the current month, increment the in year.
        if ((inM.options.selectedIndex < currentMonth)) {

                // First make sure it is a valid selection
                if ( inY.selectedIndex < ( inY.options.length - 1 ) )
                        inY.options.selectedIndex++;

                // Now set the out year to the same as the in year
                outY.options.selectedIndex = inY.options.selectedIndex;
        }
	else
	{
		inY.options.selectedIndex++;
		outY.options.selectedIndex = inY.options.selectedIndex;
	}

        return;
  }

  function dmddChange(outM,outD,outY)  {
	  if (!isBrowserSupp()) {
	  		return;
	  }
  	  adjustReturnDate(outM.options.selectedIndex,outD, outY);
  	  return;
  }

  function setInitialCurrentDate() {
		// alert("day: " + thisDay + "\nmonth: " + thisMonth + "\nyear: " + thisYear) ;
		// Set current date only on first request
		if (parent.frames['form'].document.RentalInfo.DROP_DAY.options.selectedIndex == 0) {
			setCurrentDate() ;
		}
  }

  function setCurrentDate() {
		parent.frames['form'].document.RentalInfo.PICK_DAY.options.selectedIndex = thisDay - 1 ;
		parent.frames['form'].document.RentalInfo.PICK_MONTH.options.selectedIndex = thisMonth ;
		parent.frames['form'].document.RentalInfo.PICK_YEAR.options.selectedIndex = getYearIndex(thisYear) ;
		parent.frames['form'].document.RentalInfo.DROP_MONTH.options.selectedIndex = thisMonth ;
		parent.frames['form'].document.RentalInfo.DROP_YEAR.options.selectedIndex = getYearIndex(thisYear) ;
  }

//end code to check dates

//Passes month and year to the Calendar browser

    function y2k(number) {
		return (number < 1000) ? number + 1900 : number;
    }

    function getMonthAsNumber(month) {
		var i=0 ;
		for (; i<12; i++) {
			if (months[i] == month)
				break ;
		}
		return i ;
    }

	// get the index of the year value
	function getYearIndex(year) {
		var i=0 ;
		//years.length
		for (; i<15; i++) {
			if (years[i] == year)
				break ;
		}
		return i ;
	}

    function array(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11)
    {
		this.length = 12 ;
        this[0] = m0; this[1] = m1; this[2]  = m2;  this[3]  = m3;
        this[4] = m4; this[5] = m5; this[6]  = m6;  this[7]  = m7;
        this[8] = m8; this[9] = m9; this[10] = m10; this[11] = m11;
    }

    function yearArray(y0, y1) {
		this.length = 2 ;
		this[0] = y0 ;
		this[1] = y1 ;
    }

    function openCalendar(n) {
		if (n == 1) {
			parent.frames["form"].document.RentalInfo.locType.value = "Pickup" ;
			year = document.RentalInfo.PICK_YEAR.options[document.RentalInfo.PICK_YEAR.selectedIndex].value ;
			month = getMonthAsNumber(document.RentalInfo.PICK_MONTH.options[document.RentalInfo.PICK_MONTH.selectedIndex].value) ;
	    } else {
			parent.frames["form"].document.RentalInfo.locType.value = "Return" ;
			year = document.RentalInfo.DROP_YEAR.options[document.RentalInfo.DROP_YEAR.selectedIndex].value ;
			month = getMonthAsNumber(document.RentalInfo.DROP_MONTH.options[document.RentalInfo.DROP_MONTH.selectedIndex].value) ;
		}
		showCalendarHelp(parent.frames["info"], "Calendar.html") ;
    }


//builds the Date objsect for the pick-up rental info
    function buildPickUpDate() {
	year= document.RentalInfo.PICK_YEAR.options[document.RentalInfo.PICK_YEAR.selectedIndex].value;
	month=document.RentalInfo.PICK_MONTH.selectedIndex;
	day= document.RentalInfo.PICK_DAY.options[document.RentalInfo.PICK_DAY.selectedIndex].value;
	time = document.RentalInfo.PICK_TIME.options[document.RentalInfo.PICK_TIME.selectedIndex].value;
	timeStrings = time.split(":");		// split the time int ot 2 strings at the colon
	hour = timeStrings[0];			// assign the first substring to the hour
	min = timeStrings[1];			// assign the second substring to the min

	// if the PM radio button is checked and the hour is less than 12
	//  add 12 to the hour.
	if ((!document.RentalInfo.PICK_MERIDIAN[0].checked) && (hour < 12)) {
		hour = new Number(hour);
		hour = (hour + 12);
	}

	//if the AM radio button is checked and the hour is 12, set the hour to 00
	//  So the Date object does not increment the day by one.
	if ((document.RentalInfo.PICK_MERIDIAN[0].checked) && (hour == 12)) {
			hour = 00;
	}

	//if the AM radio button is checked and the hour is 12 and the min is 30,
	//set the hour to 00 and the min to 30.  So the Date object does not increment the day by one.
	if ((document.RentalInfo.PICK_MERIDIAN[0].checked) && (hour == 12) && (min == 30)) {
			hour = 00;
			min = 30;
	}

   return (new Date(year,month,day,hour,min));
   }

//builds the Date object for the return rental info
   function buildDropDate() {
	year= document.RentalInfo.DROP_YEAR.options[document.RentalInfo.DROP_YEAR.selectedIndex].value;
	month=document.RentalInfo.DROP_MONTH.selectedIndex;
	if (document.RentalInfo.DROP_DAY.selectedIndex > 0) {
		day= document.RentalInfo.DROP_DAY.options[document.RentalInfo.DROP_DAY.selectedIndex].value;
	} else {
		return null ;
	}
	time = document.RentalInfo.DROP_TIME.options[document.RentalInfo.DROP_TIME.selectedIndex].value;
	timeStrings = time.split(":");
	hour = timeStrings[0];
	min = timeStrings[1];

	// if the PM radio button is checked and the hour is less than 12
	//  add 12 to the hour.
	if ((!document.RentalInfo.DROP_MERIDIAN[0].checked) && (hour < 12)) {
		hour = new Number(hour);
		hour = (hour + 12);
	}

	//if the AM radio button is checked and the hour is 12, set the hour to 00
	//  So the Date object does not increment the day by one.
	if ((document.RentalInfo.DROP_MERIDIAN[0].checked) && (hour == 12)) {
			hour = 00;
	}

	//if the AM radio button is checked and the hour is 12 and the min is 30,
	// set the hour to 00 and the min to 30.  So the Date object does not increment the day by one.
	if ((document.RentalInfo.DROP_MERIDIAN[0].checked) && (hour == 12) && (min == 30)) {
			hour = 00;
			min = 30;
	}

   	return (new Date(year,month,day,hour,min));
   }


// END