/* ---------------------------------------------------------------------
Pure White Design
Calendar JavaScript Functions
--------------------------------------------------------------------- */




/* ---------------------------------------------------------------------
Function Set: AJAX
ajaxGetData(),ajaxProcessQueue()
------------------------------------------------------------------------
Function: ajaxGetData(filePath,elementId,additionalVars)
  Retrieves and returns information to HTML elements via AJAX.  Supports
  DIV, IMG, TEXTAREA, INPUT and P elements.

Input Variables
 *filePath        str  The path to the requested file
  elementId       str  Element ID to populate with AJAX return
  additionalVars  str  Additional variables for file being requested
  dataMode        str  "overwrite" will overwrite the contents of the
                         specified elementId, this is the default.
                       "append" will append the requested data to the
                         specified elementId's existing contents.
--------------------------------------------------------------------- */
var ajaxQueue = new Object();
ajaxQueue.ajaxReqs = new Array();
function ajaxGetData(filePath,elementId,additionalVars,dataMode) {
	var mLocation = "js:ajaxGetData(\""+filePath+"\",\""+elementId+"\",\""+additionalVars+"\")";
	var error = new Array();

	/* input checks */
	if ((typeof(filePath) == "undefined") || (filePath == null)) { error.push("Parameter 'filePath' is not defined."); }
	if ((typeof(elementId) != "undefined") && (elementId != null) && (document.getElementById(elementId) == null)) { error.push("The elementId specified as '"+elementId+"' does not exist."); }
	if ((typeof(dataMode) != "undefined") && (dataMode != null) && (!inArray(dataMode,['overwrite','append']))) { error.push("The value specified for 'dataMode' is invalid."); }
	if (error.length > 0) { 
//		for (var loop1 = 0; loop1 < error.length; loop1++) { alert("Error: "+error[loop1]); } 
		return false; 
	}

	ajaxQueue.ajaxReqs.push([filePath,additionalVars,elementId,"mLocation",(((typeof(dataMode) == "undefined") || (dataMode == null)) ? "overwrite":dataMode)]);
	ajaxProcessQueue();
}
/* ---------------------------------------------------------------------
Function: ajaxProcessQueue()
  Processes queue made by ajaxGetData()
--------------------------------------------------------------------- */
function ajaxProcessQueue() {
	if (ajaxQueue.ajaxReqs.length == 0) { return true; }

	var ajaxRequest = ajaxQueue.ajaxReqs.shift();
	try { var ajax = ((window.XMLHttpRequest) ? new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP")); } 
	catch (error) { return false; }
	try { ajax.open("POST",ajaxRequest[0]); } 
	catch (error) { return false; }
	try { ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded"); } 
	catch (error) { return false; }
	try { ajax.send("filePath="+ajaxRequest[0]+"&"+ajaxRequest[1]+"&elementId="+ajaxRequest[2]); } 
	catch (error) { return false; }
	ajax.onreadystatechange = function() {
		if ((ajax.readyState == 4) && (ajax.status == 200)) {
			if (document.getElementById(ajaxRequest[2]) != null) { var tagName = document.getElementById(ajaxRequest[2]).tagName.toLowerCase(); }
			if (ajaxRequest[2] == "latestNews") {
				if (document.getElementById('latestNews').innerHTML.length < 1) {
					setOpacity('latestNews',10);
					document.getElementById('latestNews').innerHTML = ajax.responseText;
					var timeOut = 0;
				}
				else {
					var timeOut = 0;
					for (loop1 = 4; loop1 >= 0; loop1--) { 
						setTimeout("setOpacity('latestNews',"+(loop1*2)+");",timeOut); 
						timeOut += 100;
					}
					setTimeout("document.getElementById('latestNews').innerHTML = '"+addslashes(ajax.responseText)+"';",timeOut);
					timeOut += 100;
					for (loop1 = 1; loop1 <= 5; loop1++) {
						setTimeout("setOpacity('latestNews',"+(loop1*2)+");",timeOut); 
						timeOut += 100;
					}
				}
				clearTimeout(latestNewsTimeout.timeOut);
				latestNewsTimeout.timeOut = setTimeout('latestNews()',timeOut+10000);
				return true;
			}
			if ((tagName == "div") || (tagName == "p")) { 
				if (ajaxRequest[4] == "append") { document.getElementById(ajaxRequest[2]).innerHTML = document.getElementById(ajaxRequest[2]).innerHTML+ajax.responseText; }
				else if (ajaxRequest[4] == "overwrite") { document.getElementById(ajaxRequest[2]).innerHTML = ajax.responseText; }
			}
			else if (tagName == "img") { document.getElementById(ajaxRequest[2]).src = ajax.responseText; }
			else if ((tagName == "textarea") || (tagName == "input")) { 
				if (ajaxRequest[4] == "append") { document.getElementById(ajaxRequest[2]).value = document.getElementById(ajaxRequest[2]).value+ajax.responseText; }
				else if (ajaxRequest[4] == "overwrite") { document.getElementById(ajaxRequest[2]).value = ajax.responseText; }
			}
			else if (document.getElementById(ajaxRequest[2]) != null) { }
			ajaxProcessQueue();
		}
		else if ((ajax.readyState == 4) && (ajax.status == 404)) { return false; }
		else if (ajax.readyState == 4) { return false; }
	}
}
setTimeout('ajaxProcessQueue()',1000);
/* ------------------------------------------------------------------ */


/* ---------------------------------------------------------------------
Function: showEvent(eventId)
  Loads the event information into a floating DIV.

Input Variables
 *eventId  num  Event ID of the event
--------------------------------------------------------------------- */ 
function showEvent(eventId) {
	if (document.getElementById('showEvent').style.display == 'none') { document.getElementById('showEvent').style.display = ''; }
	if (document.getElementById('fadePage').className == 'noDisplay') { document.getElementById('fadePage').className = 'display'; }
	ajaxGetData('calendar.showEvent.php','showEvent','eventId='+eventId);
}
function showEvent2(eventId) {
	if (document.getElementById('showEvent2').style.display == 'none') { document.getElementById('showEvent2').style.display = ''; }
	if (document.getElementById('fadePage').className == 'noDisplay') { document.getElementById('fadePage').className = 'display'; }
	ajaxGetData('calendar.showEvent.php','showEvent2','eventId='+eventId);
}
/* ------------------------------------------------------------------ */


function addslashes(str) {
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\0/g,'\\0');
return str;
}
function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}
