var SELECTED_RANGE = null;
function getSelectionHandler() {
var startDate = null;
var ignoreEvent = false;
return function(cal) {
var selectionObject = cal.selection;

if (ignoreEvent)
return;
var selectedDate = selectionObject.get();
if (startDate == null) {
startDate = selectedDate;
SELECTED_RANGE = null;
document.getElementById("info").innerHTML = "Click to select end date";
cal.args.min = Calendar.intToDate(selectedDate);
cal.refresh();
} else {
ignoreEvent = true;
selectionObject.selectRange(startDate, selectedDate);
ignoreEvent = false;
SELECTED_RANGE = selectionObject.sel[0];
startDate = null;
document.getElementById("info").innerHTML = selectionObject.print("%Y-%m-%d") +
"<br />Click again to select new start date";
cal.args.min = null;
cal.refresh();
}
};
};
Calendar.setup({
cont          : "cont",
fdow          : 1,
selectionType : Calendar.SEL_SINGLE,
onSelect      : getSelectionHandler()
});

