var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
var WEEK = 7 * DAY;
function selected(cal, date) {
	cal.sel.value = date; // just update the date in the input field.
	//if(cal.sel.name=='DATE_DEB') copieDateFin();
	if(cal.sel2!=null)
	{
		cal.sel2.value = date;		
	}
	if (cal.dateClicked )
	// if we add this call we close the calendar on single-click.
	// just to exemplify both cases, we are using this only for the 1st
	// and the 3rd field, while 2nd and 4th will still require double-click.
	cal.callCloseHandler();		
	if(cal.sel2!=null && cal.dateClicked) showCalendar(cal.sel2.id,cal.dateFormat);
}
function closeHandler(cal) {
	cal.hide();                        // hide the calendar
	cal.destroy();
	calendar = null;
}
function showCalendar(id, format, showsTime,id2) {
	var el = document.getElementById(id);
	var el2 = document.getElementById(id2);
	if (calendar != null) {
	// we already have some calendar created
	calendar.hide();                 // so we hide it first.
	} else {
	// first-time call, create the calendar.S
	var cal = new Calendar(true, null, selected, closeHandler);
	// uncomment the following line to hide the week numbers
	// cal.weekNumbers = false;
	/*if (typeof showsTime == "string") {
	cal.showsTime = true;
	cal.time24 = (showsTime == "24");
	}*/
	calendar = cal;                  // remember it in the global var
	cal.setRange(1900, 2070);        // min/max year allowed.
	cal.create();
	}

	calendar.setDateFormat(format);    // set the specified date format
	calendar.parseDate(el.value);      // try to parse the text in field
	calendar.sel = el;                 // inform it what input field we use
	if(el2!=null) calendar.sel2 = el2;
	// the reference element that we pass to showAtElement is the button that
	// to the button.
	calendar.showAtElement(el.nextSibling, "Br");        // show the calendar
	return false;
}