var Calendar = new Object();
Calendar.day = null;
Calendar.listEvents = false;
Calendar.maxEventListings = 3;
Calendar.month = null;
Calendar.year = null;
Calendar.divTag = null;
Calendar.divTag_eventList = null; //div tag for even description
Calendar.url = '/ajax/calendar.php';
Calendar.selectDay_hook = null;
Calendar.linkAll = 0;
Calendar.montStr = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

Calendar.call = function() {
	var urlParameters = this.getUrlParameters();
	var ajax  = new Ajax.Request(
		this.url,
		{
			method:     "post",
			parameters: urlParameters,
			onSuccess:  Calendar.render
		} 
	);
}

Calendar.changeDate = function(m,y) {
	this.month = m;
	this.year = y;
	this.setDate(y,m,1);
	this.call();
}

Calendar.getUrlParameters = function() {
	if (this.day == null || this.month == null || this.year == null) {
		this.setDate(); //set the current date.
	}
	return "&m="+this.month+"&y="+this.year+"&d="+this.day+"&linkAll="+this.linkAll;
}

Calendar.initialize = function(divTag) {
	var date = new Date();
	this.divTag = divTag;
	this.setDate();
	this.call();
}

Calendar.render = function(response) {
	divTag = document.getElementById(Calendar.divTag);
	divTag.innerHTML = response.responseText;
}

Calendar.selectDay = function(day) {
	if (typeof(this.selectDay_hook) == "function") {
		this.selectDay_hook(day);
	}
}

Calendar.setDate = function(year, month, day) {
	date = new Date();
	if (day != null) {
		this.day = day;
	} else {
		this.day = date.getDate();
	}
	if (year != null) {
		this.year = year;
	} else {
		this.year = date.getYear();
		if (this.year > 100 && this.year < 1000) {
			this.year = this.year - 100;
		}
	}
	if (month != null) {
		this.month = month;
	} else {
		this.month = date.getMonth();
	}
}
