GALILEO.util.Event.clearCalendar = new YAHOO.util.CustomEvent("clearCalendar");

/**
  * Definicion de un calendario personalizado para cylog que se utilizara en el
  * treeview
  **/
GALILEO.cylog.widget.CyLoGCalendar = function() {
	var navConfig = {
			strings : { month: "Seleccione Mes", year: "Introduzca A&ntilde;o", submit: "Aceptar", cancel: "Cancelar", invalidYear: "Por favor, introduzca un a&ntilde;o v&aacute;lido"},
			monthFormat: YAHOO.widget.Calendar.LONG,
			initialFocus: "year"
		};
	var calendarConfig = {
		id: YAHOO.util.Dom.generateId(null, 'treeview-calendar-'),
		containerId: YAHOO.util.Dom.generateId(null, 'container-treeview-calendar-'),
		navigator: navConfig
	};
	
	this._isCargaInput = false;
	GALILEO.cylog.widget.CyLoGCalendar.superclass.constructor.call(this, calendarConfig);
};

YAHOO.extend(GALILEO.cylog.widget.CyLoGCalendar, GALILEO.widget.GCalendar);

GALILEO.cylog.widget.CyLoGCalendar.prototype._activeNode = null;
GALILEO.cylog.widget.CyLoGCalendar.prototype._isCargaInput = false;

GALILEO.cylog.widget.CyLoGCalendar.prototype.setElements = function (node, inputEl, hrefEl) {
	this._activeNode = node;
	this.setHRefEl(hrefEl);
	this.setInputEl(inputEl);
};

GALILEO.cylog.widget.CyLoGCalendar.prototype.setHRefEl = function(el) {
	if (typeof el == "string") {
		el = YAHOO.util.Dom.get(el);
	}
	
	this._href = el;
};

GALILEO.cylog.widget.CyLoGCalendar.prototype.setInputEl = function(el) {
	if (typeof el == "string") {
		el = YAHOO.util.Dom.get(el);
	}
	this._inputEl = el;
};

GALILEO.cylog.widget.CyLoGCalendar.prototype.show = function() {
	if (this._inputEl && this._inputEl.value.length > 0) {
		this.setDateFromInput();
		this.customConfig();
		this.render();
		this.configClear();
		this.configNav();
	} else {
		GALILEO.cylog.widget.CyLoGCalendar.superclass.clear.call(this);
	}
	GALILEO.cylog.widget.CyLoGCalendar.superclass.show.call(this);
};

GALILEO.cylog.widget.CyLoGCalendar.prototype._onSelectEvent = function(e, args, obj) {

	obj.updateDate();
	obj.hide();	

	if (!this._isCargaInput) {
		if (obj._activeNode) {
			obj._activeNode._selectedDate(obj._inputEl);
		}
		obj._activeNode = null;
	} else {
		this._isCargaInput = false;
	}
	 
};

GALILEO.cylog.widget.CyLoGCalendar.prototype.clear = function() {
	GALILEO.cylog.widget.CyLoGCalendar.superclass.clear.call(this);
	if (this._activeNode) {
		this._activeNode._clearCalendar(this._inputEl);
	}
	this._activeNode = null;
};

