function init_dateSelector ()	// could probably include a bunch of the other calendar setup code
{
	var ht = $('datesel_hotel_type');
	var rn = $('datesel_room_num');
	var hy = $('datesel_hotel_yes');
	var hn = $('datesel_hotel_no');
	
	if ($chk(hy) && $chk(hn)) {
		hy.addEvent('click', function () {	
			ht.disabled = false;
			rn.disabled = false;		
		});
		
		hn.addEvent('click', function () {
			ht.disabled = true;
			rn.disabled = true;
		});
	}
	
}
womAdd("init_dateSelector();");

var today;
var next_date;
var dep_cal;
var arr_cal;

	today=new Date();
	next_date = today.getFullYear() + "-" + (today.getMonth()+1) + "-" + today.getDate();
	
	dep_cal = new CalendarPopup("dep_caldiv");
	dep_cal.setReturnFunction("setMultipleValues_dep");	
	dep_cal.addDisabledDates(null,next_date);
	dep_cal.offsetX = 18;
	dep_cal.offsetY = 0;	
		 
	arr_cal = new CalendarPopup("arr_caldiv");
	arr_cal.setReturnFunction("setMultipleValues_arr");
	arr_cal.addDisabledDates(null,next_date);
	arr_cal.offsetX = 18;
	arr_cal.offsetY = 0;

function init_calendarDates ()
{

	today=new Date();
	next_date = today.getFullYear() + "-" + (today.getMonth()+1) + "-" + today.getDate();
	
	dep_cal = new CalendarPopup("dep_caldiv");
	dep_cal.setReturnFunction("setMultipleValues_dep");	
	dep_cal.addDisabledDates(null,next_date);
	dep_cal.offsetX = 18;
	dep_cal.offsetY = 0;	
		 
	arr_cal = new CalendarPopup("arr_caldiv");
	arr_cal.setReturnFunction("setMultipleValues_arr");
	arr_cal.addDisabledDates(null,next_date);
	arr_cal.offsetX = 18;
	arr_cal.offsetY = 0;
}
womAdd("init_calendarDates();");

function setMultipleValues_dep(y,m,d) {
	document.det_form.dept_date_year.value=y;
	document.det_form.dept_date_month.selectedIndex=m;
	for (var i=0; i<document.det_form.dept_date_date.options.length; i++) {
		if (document.det_form.dept_date_date.options[i].value==d) {
			document.det_form.dept_date_date.selectedIndex=i;
		}
	}
}

function setMultipleValues_arr(y,m,d) {
	
	 new_date = y + '-' + m + '-' + d;
	 dep_cal.disabledDatesExpression = "";
	 dep_cal.addDisabledDates(null,new_date);
	
	 document.det_form.arrival_date_year.value=y;
	 document.det_form.arrival_date_month.selectedIndex=m;
	 for (var i=0; i<document.det_form.arrival_date_date.options.length; i++) {
		  if (document.det_form.arrival_date_date.options[i].value==d) {
			   document.det_form.arrival_date_date.selectedIndex=i;
		   }
	  }	
	if (document.det_form.dept_date_year.value == '' || document.det_form.dept_date_year.value < y) {
		document.det_form.dept_date_year.value=y;
		document.det_form.dept_date_month.selectedIndex=m;
		for (var i=0; i<document.det_form.dept_date_date.options.length; i++) {
			if (document.det_form.dept_date_date.options[i].value==d) {
				document.det_form.dept_date_date.selectedIndex=i;
			}
		}
	}
	else if (document.det_form.dept_date_year.value == y) {
		if (document.det_form.dept_date_month.selectedIndex == 0 || document.det_form.dept_date_month.selectedIndex < m) {
			document.det_form.dept_date_month.selectedIndex=m;
			for (var i=0; i<document.det_form.dept_date_date.options.length; i++) {
				if (document.det_form.dept_date_date.options[i].value==d) {
					document.det_form.dept_date_date.selectedIndex=i;
				}
			}
		}
		else if (document.det_form.dept_date_month.selectedIndex == m) {
			if (document.det_form.dept_date_date.selectedIndex == 0 || document.det_form.dept_date_date.selectedIndex < document.det_form.arrival_date_date.selectedIndex) {
				for (var i=0; i<document.det_form.dept_date_date.options.length; i++) {
					if (document.det_form.dept_date_date.options[i].value==d) {
						document.det_form.dept_date_date.selectedIndex=i;
					}
				}
			}
		}
	}	
 }


function getDateString(y_obj,m_obj,d_obj) {
	 var y = y_obj.options[y_obj.selectedIndex].value;
	 var m = m_obj.options[m_obj.selectedIndex].value;
	 var d = d_obj.options[d_obj.selectedIndex].value;
	 if (y=="" || m=="") { return null; }
	 if (d=="") { d=1; }
	 return str= y+'-'+m+'-'+d;
	 }
	 
function changeRoomsState (el) {
	 if (el.value == "1") {
		document.det_form.room_num.disabled = true;
		document.det_form.room_num.selectedIndex = 0;
	 }
	 else {
		 document.det_form.room_num.disabled = false;
	 }
}

function updateRoomCount ()
{
	var form = $('det_form');
	var grp_size = form.group_size.value;
	if (grp_size != '--')
	{
		form.room_num.selectedIndex = Math.ceil(grp_size / 2);
	}
}