/* include this after "dateselector.js" to extend the
   DateSelector class with AJAX functionality.
   
   remember to include "miniajax.js" too!
   
   and add an 'ajax' key to the configuration array in
   the constructor, containing the ajax url.
*/

DateSelector.prototype.init = function() {
	this.active_days = new Array();
	this.load_month();
}

DateSelector.prototype.parent_render_day = DateSelector.prototype.render_day;

DateSelector.prototype.render_day = function(id, op, d, m ,y) {
	var a = this.active_days[y+'-'+m];
	if (a && a[d] == '1') {
		return this.parent_render_day(id, op, d, m, y);
	} else {
		return '<span class="' + this.config['class'] + '_disabled">' + d + '</span>';
	}
}

DateSelector.prototype.render = function() {
	if (this.ajaxing) {
		this.mainDiv.innerHTML = this.config['ajax_wait'];
	} else {
		this.load_month();
		this._render();
	}
}

DateSelector.prototype.load_month = function() {
	if (this.active_days[this.date.getFullYear()+'-'+this.date.getMonth()]) return;
	if (this.config['pages_id']) {
		p = "&p=" + this.config['pages_id'];
	} else {
		p = "";
	}
	this.ajaxing = true;
	this.render();
	var ajax = new AJAX();
	var _datesel = this;
	ajax.onLoad = function(text) {
		_datesel.ajaxing = false;
		_datesel.active_days[_datesel.date.getFullYear()+'-'+_datesel.date.getMonth()] = text.split(',');
		_datesel.render();
	}
//	ajax.onError = function() {
//		window.alert("ouch! I'm dead.");
//	}
	ajax.load(this.config['ajax'] + '?m=' + (this.date.getMonth()+1) + '&y=' + this.date.getFullYear() + '&d=' + this.config['domain'] + p, 'days');
}
