function SetStatus($msg) { 
	window.status = $msg;
}

function SetSource($nam, $img) {
	$s = "document." + $nam + ".src = '" + $img + "'";
	eval($s);
}

function SetValues($nam, $img, $msg) {
	$s = "document." + $nam + ".src = '" + $img + "'";
	eval($s);
	window.status = $msg;
	return true;
}

function LoadEvents($y, $m) {
	getajaxwithmessage("calendar","ajax_calendar.php?y=" + $y + "&m=" +
					   $m, "<b><i>Loading events...</i></b>" +
					   "<br><br><br><br><br><br><br><br><br><br><br><br><br>" +
					   "<br><br><br>");
}

/*******************************************************************************
 * ajax.js
 * rev. 2008-Jan-22
 * Mark Kintigh
 * _____________________________________________________________________________
 *
 * This is a VERY simple AJAX library.  This is designed to handle only ONE
 * request at a time.  It requires two global variables (defined below) called
 * "ajax_http" (used to hold the HTTP XML object) and "ajax_element" (used to
 * hold the name of the DIV used).
 * _____________________________________________________________________________
 *
 * FUNCTIONS
 *
 * setajax(elementname, message)
 *     * Used to set the HTML within the given DIV ("elementname") to the given
 *       value ("message").  This can be used to set a "processing" message of
 *       some sort while the AJAX is processing, etc.
 *
 * clearajax(elementname)
 *     * Used to clear the HTML within the given DIV ("elementname").
 *
 * getajax(elementname, url)
 *     * Sends a GET request using the given URL ("url") and storing the results
 *       within the given DIV ("elementname").
 *
 * getajaxwithmessage(elementname, url, message)
 *     * Sends a GET request using the given URL ("url") and storing the results
 *       within the given DIV ("elementname"). While the GET is being processed
 *       a given message ("message") is displayed within the DIV.
 *
 * post_getvalues(formname)
 *     * This is one of the two INTERNAL SUPPORT functions.  This function is
 *       designed to build the POST string containing the values that are set
 *       for the given form ("formname", by name please) and return this value.
 *
 * postajax(elementname, url, formname)
 *      * Sends a POST request to the given URL ("url"), sending the values that
 *        were set in the given form ("formname", by name please), and stores
 *        the results within the given DIV ("elementname").
 *
 * postajaxwithmessage(elementname, url, formname, message)
 *      * Sends a POST request to the given URL ("url"), sending the values that
 *        were set in the given form ("formname", by name please), and stores
 *        the results within the given DIV ("elementname").  While the POST is
 *        being processed a given message ("message") is displayed within the
 *        DIV.
 *
 * handleResponse()
 *      * This is one of the two INTERNAL SUPPORT functions.  This function
 *        handles setting the returned values once the readyState of the HTTP
 *        XML shows completed.  It will handle both the "OK" (200) and "Page not
 *        found" (404) status.
 *
 ******************************************************************************/
var ajax_http;
var ajax_element = "";

function setajax(elementname, message) {
	//
	// By its name, set the innerHTML value of the given DIV
	//
	document.getElementById(elementname).innerHTML = message;
}

function clearajax(elementname) {
	//
	// By its name, set the innerHTML value to nothing for the given DIV
	//
	document.getElementById(elementname).innerHTML = "";
}

function getajax(elementname, url) {
	//
	// Store the name of the DIV we are going to use to store the data
	//
	ajax_element = elementname;
	//
	// Check to see if this browser uses XMLHttpRequest (non-IE browser)
	//
	if(window.XMLHttpRequest) {
		//
		// Create a new XMLHttpRequest object, set the readyState function,
		// open the request, and send it
		//
		ajax_http = new XMLHttpRequest();
		ajax_http.onreadystatechange = handleResponse;
		ajax_http.open("GET", url, true);
		ajax_http.send(null);
	} else if(window.ActiveXObject) {
		//
		// Create a new ActiveX XML object
		//
		ajax_http = new ActiveXObject("Microsoft.XMLHTTP");
		//
		// Was it created?
		//
		if(ajax_http) {
			//
			// Yes, so set the readyState function, open
			// the request, and send it (no "null" for IE)
			//
			ajax_http.onreadystatechange = handleResponse;
			ajax_http.open("GET", url, true);
			ajax_http.send();
		} else {
			//
			// Failed, so display a failure message
			//
			//alert("Failed to create the necessary objects.  Perhaps " +
			//	  "your Internet Explorer is blocking ActiveX objects.");
			setajax("Failed to create the necessary objects.  Perhaps " +
				  "your Internet Explorer is blocking ActiveX objects.");
		}
	} else {
		//
		// Incompatible browser
		//
		//alert("Your browser is NOT Internet Explorer 5 or higher, " +
		//	  "Firefox, Safari, or Opera; therefore, you will have " +
		//	  "problems viewing this page properly.");
		setajax("Your browser is NOT Internet Explorer 5 or higher, " +
			  "Firefox, Safari, or Opera; therefore, you will have " +
			  "problems viewing this page properly.");
	}
}

function getajaxwithmessage(elementname, url, message) {
	//
	// Set the given message within the DIV and then send the GET command
	//
	setajax(elementname, message);
	getajax(elementname, url);
}

function post_getvalues(formname) {
	//
	// More than just variable definitions:
	// * Set return value to ""
	// * Set a reference to the form using the eval() function
	//
	var x, ret="", theform = eval("document." + formname);
	//
	// For each element within the form....
	//
	for(x=0; x<theform.elements.length; x++) {
		//
		// If the return value has a value (not "")
		//
		if(ret.length>0) {
			//
			// Append an ampersand ("&") for the next field name
			//
			ret = ret + "&";
		}
		//
		// Append the field name and then equal its values
		//
		ret = ret + theform.elements[x].name + "=" + theform.elements[x].value;
	}
	return ret;
}

function postajax(elementname, url, formname) {
	var postdata="";
	
	ajax_element = elementname;
	postdata = post_getvalues(formname);
	if(window.XMLHttpRequest) {
		ajax_http = new XMLHttpRequest();
		ajax_http.onreadystatechange = handleResponse;
		ajax_http.open("POST", url, true);
		ajax_http.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
		ajax_http.setRequestHeader("Content-length",
			postdata.length);
		ajax_http.setRequestHeader("Connection", "close");
		ajax_http.send(postdata);
	} else if(window.ActiveXObject) {
		ajax_http = new ActiveXObject("Microsoft.XMLHTTP");
		if(ajax_http) {
			ajax_http.onreadystatechange = handleResponse;
			ajax_http.open("POST", url, true);
			ajax_http.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded");
			ajax_http.setRequestHeader("Content-length",
				postdata.length);
			ajax_http.setRequestHeader("Connection", "close");
			ajax_http.send(postdata);
		}
	} else {
		//alert("Your browser is NOT Internet Explorer 5 or higher, " +
		//	  "Firefox, Safari, or Opera; therefore, you will have " +
		//	  "problems viewing this page properly.");
		setajax("Your browser is NOT Internet Explorer 5 or higher, " +
			  "Firefox, Safari, or Opera; therefore, you will have " +
			  "problems viewing this page properly.");
	}
}

function postajaxwithmessage(elementname, url, formname, message) {
	setajax(elementname, message);
	postajax(elementname, url, formname);
}

function handleResponse() {
	if(ajax_http.readyState==4 && ajax_http.status==200) {
		var response = ajax_http.responseText;
		if(response) {
			document.getElementById(ajax_element).innerHTML = response;
		}
	} else if(ajax_http.readyState==4 && ajax_http.status==404) {
		document.getElementById(ajax_element).innerHTML = 
			"Internal error - could not find support document.";
	}
}
