/**
 * @param String container
 * @param Model model
 * @param Controller controller
 */
function CalendarView(container, model, controller){
	this.container = container;
	this.model = model;
	this.controller = controller;
	
	this.model.addEventListener("appStateChange", BoundMethod.create(this, this.appStateChangeHandler));
}

CalendarView.prototype.createChildren = function(){
	$("#"+this.container).datepicker({
		dateFormat: "yy-mm-dd",
		dayNamesMin: this.model.getDictionary().dayNamesMin,
		dayNames: this.model.getDictionary().dayNames,
		monthNames: this.model.getDictionary().monthNames,
		defaultDate: this.model.getDate(),
		onSelect: BoundMethod.create(this, this.datepickerSelectHandler)
	});
}

CalendarView.prototype.datepickerSelectHandler = function(dateText, inst){
	this.controller.changeDate(new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay));
}

CalendarView.prototype.appStateChangeHandler = function(event){
	if(this.model.getAppState()==AppStateTypes.DOCUMENT_READY){
		this.createChildren();
	}
}

