/* standalone functions */
function SelectFlatCalendarDate(calendar) {
	if (calendar.dateClicked) {
		var y = calendar.date.getFullYear().toString();
		var m = (calendar.date.getMonth()+1).toString();     // integer, 0..11
		if (m.length == 1) m = '0'+m;
		var d = calendar.date.getDate().toString();      // integer, 1..31
		if (d.length == 1) d = '0'+d;
		this.flatCalendarForm.service_date.value = d+'-'+m+'-'+y;
	}
}

function CheckFlatCalDisabledDate(date, y, m, d) {
	var currentDate = new Date();
	var currD = currentDate.getDate();
	var currM = currentDate.getMonth();
	var currY = currentDate.getFullYear();
	
	if (m == 11 && (d == 25 || d == 26)) {
		return true;
	} else if (y < currY) {
		return true;
	} else if (m < currM && y == currY) {
		return true;
	} else if (d < currD && m == currM && y == currY) {
		return true;
	}
	return false;
}

/* this is where the class starts */
function FlatCalendar() {
	this.calendarForm = null;
	
	this.SetFlatCalendarForm = SetFlatCalendarForm;
	this.InitFlatCalendar = InitFlatCalendar;
}

function SetFlatCalendarForm(formObject) {
	this.calendarForm = formObject;
}

function InitFlatCalendar(divIdValue) {
	if (typeof(divIdValue) !== 'undefined') {
		var divId = divIdValue;
	} else {
		var divId = 'gridCalendar'+this.gadgetId;
	}
	thisPointer = this;
	Calendar.setup(
	    {
	      flat         : divId, // ID of the parent element
	      flatCallback : SelectFlatCalendarDate,           // our callback function
	      dateStatusFunc : CheckFlatCalDisabledDate,
	      weekNumbers : false,
	      flatCalendarForm : thisPointer.calendarForm,
	      calendarDivId : divId
	    }
	  );
}
