var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var today = new Date();
function daysInMonth(year, month) {return 32 - new Date(year, month, 32).getDate();}
function updateMonth(selectMonth) {
	selectMonth.options.length = 12;
	var y=today.getFullYear();
	var m=today.getMonth();
	for(var n=0;n<=11;n++) {
		m++;
		selectMonth.options[n].text = months[m-1]+' - '+y;
		selectMonth.options[n].value = y+'-'+m;
		if(m==12){y=y+1;m=0}
	}
}
function updateDaysInMonth(selectMonth, selectDay) {
	selectDay.options.length = daysInMonth(selectMonth.value.split('-')[0], selectMonth.value.split('-')[1]-1);
	for (var i=selectDay.options.length-1; i>=0; i--) {
		var date = new Date(selectMonth.value.split('-')[0], selectMonth.value.split('-')[1]-1, i+1);
		if(date >= new Date(today.getFullYear(), today.getMonth(), today.getDate())) {
			selectDay.options[i].text = i+1;
			selectDay.options[i].value = i+1;
		}else{
			selectDay.options[i] = null;
		}
	}
	selectDay.selectedIndex=0;
}
function updateArrival(selectArrMonth, selectArrDay, selectDeptMonth, selectDeptDay) {

}
function updateDeparture(selectArrMonth, selectArrDay, selectDeptMonth, selectDeptDay) {			
	updateMonth(selectDeptMonth);
	for (var i=selectDeptMonth.options.length-1; i>=0; i--) {
		var arrDate = new Date(selectArrMonth.options[selectArrMonth.selectedIndex].value.split('-')[0], selectArrMonth.options[selectArrMonth.selectedIndex].value.split('-')[1]-1, selectArrDay.options[selectArrDay.selectedIndex].value);
		var deptDate = new Date(selectDeptMonth.options[i].value.split('-')[0], selectDeptMonth.options[i].value.split('-')[1]-1, daysInMonth(selectDeptMonth.options[i].value.split('-')[0], selectDeptMonth.options[i].value.split('-')[1]-1));
		if (deptDate <= arrDate) {selectDeptMonth.options[i] = null;}
	}
	
	updateDaysInMonth(selectDeptMonth, selectDeptDay);
	for (var i=selectDeptDay.options.length-1; i>=0; i--) {
		var arrDate = new Date(selectArrMonth.options[selectArrMonth.selectedIndex].value.split('-')[0], selectArrMonth.options[selectArrMonth.selectedIndex].value.split('-')[1]-1, selectArrDay.options[selectArrDay.selectedIndex].value);
		var deptDate = new Date(selectDeptMonth.options[selectDeptMonth.selectedIndex].value.split('-')[0], selectDeptMonth.options[selectDeptMonth.selectedIndex].value.split('-')[1]-1, selectDeptDay.options[i].value);
		if (deptDate <= arrDate) {selectDeptDay.options[i] = null;}
	}
	if(self.gfPop)gfPop.updateHidden(selectDeptMonth)
}