// Copyright: DWL Software Systems
// This is the configuration of the format for the calendar in the form.
// This javascript can not be used generally and is only compatible with a form with the following parameters:
// necessary form id: add id="calendar_form" into the form containing calendar. You not need to change the form name. 
// necessary form elements: x_date, calendar_id, both with type hidden

var formName = document.getElementById("calendar_form").name;
var calendar = new calendar(document.forms[formName].elements['x_date']);

function openCalendar(form, calendarID) {
	switch(calendarID){
		case "depart":
			xDate=form.elements["yeardepart"].value+"-"+
				form.elements["monthdepart"].value+"-"+
				form.elements["daydepart"].value;
			doPopup=1;
			break;
		case "return":
			xDate=form.elements["yearreturn"].value+"-"+
				form.elements["monthreturn"].value+"-"+
				form.elements["dayreturn"].value;
			doPopup=1;
			break;
		default:
			alert("Error!");
			doPopup=0;
			break;
	}
	if(doPopup) {
		form.elements["x_date"].value=xDate;
		form.elements["calendar_id"].value=calendarID;

		calendar.popup();
	} else {
		return;
	}
}

function closeCalendar() {
	form=window.document.forms[formName];
	calendarID=form.elements["calendar_id"].value;	
	xDate=form.elements["x_date"].value;	
	tmpArray=xDate.split("-");
	strYear=tmpArray[0].substr(2);
	strMonth=tmpArray[1];
	strDay=tmpArray[2];

	switch(calendarID){
		case "depart":
			form.elements["yeardepart"].value=strYear;
			form.elements["monthdepart"].value=strMonth;
			form.elements["daydepart"].value=strDay;
			break;
		case "return":
			form.elements["yearreturn"].value=strYear;
			form.elements["monthreturn"].value=strMonth;
			form.elements["dayreturn"].value=strDay;
			break;
		default:
			alert("Error!");
			window.location.href="airline_search.php";
			break;
	}
}