function openCalendar(field){
    
		 if (field == 'arrival') {
		 		 datestr = document.search.arrival_mm.options[document.search.arrival_mm.selectedIndex].value + '/' +
		 		 			document.search.arrival_dd.options[document.search.arrival_dd.selectedIndex].value + '/' +
	 						document.search.arrival_yy.options[document.search.arrival_yy.selectedIndex].value
		}
		  else {
		 	 	 datestr = document.search.departure_mm.options[document.search.departure_mm.selectedIndex].value + '/' +
		 		 			document.search.departure_dd.options[document.search.departure_dd.selectedIndex].value + '/' +
	 						document.search.departure_yy.options[document.search.departure_yy.selectedIndex].value
		 }
	   calendar_window = window.open("/TravelPlannerColoradoBase/portal/popup.calendar.asp?fieldName=" + field + "&date=" + datestr, "calendar", "width=350,height=300, top=90, left=40, resizable=yes,scrollbars=no,toolbar=yes");
	   calendar_window.focus();
  }
	
function SetDepartureDate() {
   var ddate;
   var adate;
   var msPerDay
	 var i;
	 
	 msPerDay = 24 * 60 * 60 * 1000;
	 ddate = new Date(document.search.arrival_yy.options[document.search.arrival_yy.selectedIndex].value,document.search.arrival_mm.options[document.search.arrival_mm.selectedIndex].value-1,document.search.arrival_dd.options[document.search.arrival_dd.selectedIndex].value,12,0,0,0);
	 
	 adate = new Date(document.search.arrival_yy.options[document.search.arrival_yy.selectedIndex].value,document.search.arrival_mm.options[document.search.arrival_mm.selectedIndex].value-1,document.search.arrival_dd.options[document.search.arrival_dd.selectedIndex].value,12,0,0,0);
	 
	 var nowdate = new Date();
	 var startdate = adate;
	 
	 ddate.setMilliseconds(ddate.getMilliseconds() + 2 * msPerDay);
	 
	 //alert(ddate);
	 for (i=0; i<document.search.departure_mm.options.length; i++) {
      if (Number(document.search.departure_mm.options[i].value-1) == Number(ddate.getMonth())) {
		    document.search.departure_mm.selectedIndex = i;
			 //alert("month: " + document.search.departure_mm.options[i].value);
	 	 }
	 }
	
	 for (i=0; i<document.search.departure_dd.options.length; i++) {
		 //alert("day: " + document.search.departure_dd.options[i].value + " " + ddate.getDate());
      if (Number(document.search.departure_dd.options[i].value) == Number(ddate.getDate())) {
		    document.search.departure_dd.selectedIndex = i;
			 //alert("day: " + document.search.departure_dd.options[i].value);
	 	 }
	 }

   for (i=0; i<document.search.departure_yy.options.length; i++) {
      if (Number(document.search.departure_yy.options[i].value) == Number(ddate.getFullYear())) {
		    document.search.departure_yy.selectedIndex = i;
		    if (nowdate > startdate){
				document.search.departure_yy.selectedIndex = document.search.departure_yy.selectedIndex + 1;
				document.search.arrival_yy.selectedIndex = document.search.arrival_yy.selectedIndex + 1;
			}
			 //alert("year: " + document.search.departure_yy.options[i].value);
  	 	}
	 }	 	

}

//merge date fildes
function mergeDates() {
	document.search.Arrive.value = document.search.arrival_mm.value + '/' + document.search.arrival_dd.value + '/' + document.search.arrival_yy.value;
	document.search.Depart.value = document.search.departure_mm.value + '/' + document.search.departure_dd.value + '/' + document.search.departure_yy.value;
}
