/**
 * @author buenger
 */
function MonthSelect (a_id, a_monthSelectId, a_yearSelectId) {
	
	this.id;
	this.name = "MonthSelect";
	this.type = "Element";
	this.isFutureSelect = false;
	
	var monthSelect;
	var yearSelect;
	
	var monthSelectId;
	var yearSelectId;
	
	
	var _self = this;
	
	this.value = function () {
		if (yearSelect.value() >= 12) return 1;
		else if (monthSelect.value() == 0 || yearSelect.formValue() == "") return -1;
		else {
			var date = new Date();
			date.setFullYear(Number(yearSelect.formValue()), Number(monthSelect.value()) -1);
			return date;
		}
	}
		
	function init (a_id, a_monthSelectId, a_yearSelectId) {
		_self.id = a_id;
		monthSelectId = a_monthSelectId;
		yearSelectId = a_yearSelectId;
		window.addEvent("load", handleWindowLoad);
	}
	
	function handleWindowLoad () {
		window.removeEvent("load", handleWindowLoad);
		monthSelect = Form.getElement(monthSelectId);
		yearSelect = Form.getElement(yearSelectId);
		monthSelect.addEvent("propChange", handleValueChange)
		yearSelect.addEvent("propChange", handleValueChange)		
	}
	
	function handleValueChange () {
		checkValues();
		_self.fireEvent("propChange");
	}
	
	function checkValues () {
		if (_self.value() == 1) {
			monthSelect.setValue(0);
			monthSelect.setCheckable(false);
		}
		else monthSelect.setCheckable(true);
		
		if (_self.value() ==  -1 || _self.value() ==  1 || _self.value() ==  2) return;
		else {
			if (_self.isFutureSelect) {
				if (_self.value() < new Date()) {
					monthSelect.setValue(0);
					yearSelect.setValue(0);
				}
			} else {
				if (_self.value() > new Date()) {
					monthSelect.setValue(0);
					yearSelect.setValue(0);
				}
			}
		}
	}
	
	//MOOTOOLS EVENTS
	$extend(this, new Events());
	
	init (a_id, a_monthSelectId, a_yearSelectId);
}
