/*********************************************
ZipRockland.com Calendar (c)
**********************************************/

var xmlHttp

var g_months = new Array ('January', 'February', 'March', 'April', 'May', 'June',
						'July', 'August', 'September', 'October', 'November', 'December');

var g_curr_date = "";

function cal_parse_date(dt, day)
{
	var date_path = "";
	if (day)
		date_part = "-" + dt.getDate();

	return String(dt.getFullYear()) + "-" + String(dt.getMonth()) + date_part;
}

function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

function CalendarChangeDate(dt)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}		
	var url="newcalander_c.php?date="+dt;				
	xmlHttp.onreadystatechange=CalendarStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

	g_curr_date = dt;
}	

	
function CalendarStateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{	
		// The data resulted by the page:
		results = xmlHttp.responseText;
		// Write the data to page
		document.getElementById("calendarWidgetButtons").innerHTML = results;
		
		date_arr = g_curr_date.split("-");
		year = new Number(date_arr[0]);
		month = new Number(date_arr[1]);

		ind_m = month - 1;
		// Set month in bounds of 0-11;
		if (ind_m < 0) { ind_m = 11;} else if (ind_m > 11) {ind_m = 0;}
		// Change month span:
		document.getElementById("calendarWidgetMonth").innerHTML = g_months[ind_m];

		// Change link spans:
		the_date = new Date(year, month);
		// Whole month:
		document.getElementById("calendarWidgetLink").innerHTML = "<a href=\"events.php?month=current&dt=" + cal_parse_date(the_date, true) + "\">View all events for " + g_months[ind_m] + "</a>";
		// Prev month:
		the_date.setMonth (the_date.getMonth() - 1);
		document.getElementById("calendarWidgetPrev").innerHTML = "<a href='javascript:CalendarChangeDate(\"" + cal_parse_date(the_date, false) + "\");'>‹</a>";
		// Next month:
		the_date = new Date(year, month);
		the_date.setMonth (the_date.getMonth() + 1);
		document.getElementById("calendarWidgetNext").innerHTML = "<a href='javascript:CalendarChangeDate(\"" + cal_parse_date(the_date, false) + "\");'>›</a>";
	}
}
