/**
 * Custom calendar popup
 */
var calFrom = new CalendarPopup("fromdiv");
calFrom.showNavigationDropdowns();
calFrom.setYearSelectStartOffset(10);
var calTo = new CalendarPopup("todiv");
calTo.showNavigationDropdowns();
calTo.setYearSelectStartOffset(10);

/**
 * Prepare the from calendar
 */
function onClickDateFrom(){
	calFrom.disabledDatesExpression = "";
	document.form1.dateto.value = "";
	today = new Date();
	calFrom.addDisabledDates(null, formatDate(today,"dd-NNN-yyyy") );
	calFrom.select(document.form1.datefrom,"datefrom","dd-NNN-yyyy");
}

/**
 * Prepare the to calendar
 */
function onClickDateTo(){
	if( document.form1.datefrom.value !="" ){ 
	nextDay=new Date(getDateFromFormat(document.form1.datefrom.value, "dd-NNN-yyyy")); 
	nextDay.setDate(nextDay.getDate()-1); 
	calTo.disabledDatesExpression = "";
	calTo.addDisabledDates(null, formatDate(nextDay,"dd-NNN-yyyy"));
	// Set To date to valid date
	nextDay.setDate(nextDay.getDate()+1); 
	document.form1.dateto.value = formatDate(nextDay,"dd-NNN-yyyy");
	}
	calTo.select(document.form1.dateto,"datefrom","dd-NNN-yyyy");
}
/**
 *  Reset the from and to calendars
 */
function reset_CalendarPopup(){
calFrom.disabledDatesExpression = "";
calTo.disabledDatesExpression = "";
}
/**
 * Clears a date field
 * @param string id				- element id of the date field
 */
function clear_date(id) {
	var el = document.getElementById(id);
	if (!el) return;
	el.value = '';
}
/**
 * Clear both date fields
 */
function clear_dates() {
	clear_date('datefrom');
	clear_date('dateto');
	reset_CalendarPopup();
}