/*
function toggleDiv(sDivId) {
	var oDiv = document.getElementById(sDivId);
	oDiv.style.display = (oDiv.style.display == "none") ? "block" :	"none";
}
*/

AjaxCaller2 = function() {

	this.oDoc = null;

	this.toCall = null;
	this.aArgs = null;
	this.sType = null;

	this.onerror = this.defaultError;
}

AjaxCaller2.prototype.makeCall = function(toCall, aArgs, sUrl, sQueryString, sMethod, sType) {

	_self = this;

	this.toCall = toCall;
	this.aArgs = aArgs;
	this.sType = sType;

	if (window.ActiveXObject) {
		this._oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		this._oXmlHttp = new XMLHttpRequest();
	}

	if (sMethod == 'get') {
		if (sQueryString != '') {
			var arr = new Array();
			arr[0] = sUrl;
			arr[1] = '?';
			arr[2] = sQueryString;
			sUrl = arr.join('');
		}
		this._oXmlHttp.onreadystatechange = function() { AjaxCaller2.prototype.callback.call(_self); }
		this._oXmlHttp.open('GET', sUrl, true);
		this._oXmlHttp.send(null);
	}
	else if (sMethod == 'post') {
		this._oXmlHttp.onreadystatechange = function() { AjaxCaller2.prototype.callback.call(_self); }
		this._oXmlHttp.open('POST', sUrl, true);
		this._oXmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this._oXmlHttp.send(sQueryString);
	}
}

AjaxCaller2.prototype.callback = function() {

	if (this._oXmlHttp.readyState == 4) {
		if (this._oXmlHttp.status == 200) {

			if (this.sType == 'xml') {
				this.oDoc = _self._oXmlHttp.responseXML;
			} else if (this.sType == 'txt') {
				this.oDoc = this._oXmlHttp.responseText;
			} else {
				alert("Huston, we've got a problem!");
			}
			delete this._oXmlHttp;

			this.toCall.apply(this, this.aArgs);
		}
	}
}

AjaxCaller2.prototype.defaultError = function() {
	alert("error fetching data!"
		+"\n\nreadyState:"+this._oXmlHttp.readyState
		+"\nstatus: "+this._oXmlHttp.status
		+"\nheaders: "+this._oXmlHttp.getAllResponseHeaders());
}

var oCaller2 = new AjaxCaller2();



//------------------------------------------------------------------------------

function handleContent(sDivId) {
	var oDiv = document.getElementById(sDivId);

	if (oDiv.innerHTML == "") {
		oDiv.innerHTML = "<br><strong>Loading content, please wait...</strong>";

		oParam = {};
		oParam.fnCallback = handleContentCallback;
		oParam.aArgs = new Array(sDivId);
		oParam.sUrl = 'mxs_files/'+sDivId+'.html';
		oParam.sQueryString = '';
		oParam.sMethod = 'post';
		oParam.sType = 'txt';
	
		oCaller2.makeCall(oParam.fnCallback, oParam.aArgs, oParam.sUrl, oParam.sQueryString, oParam.sMethod, oParam.sType);
	}
	else {
		oDiv.style.display = (oDiv.style.display == "none") ? "block" :	"none";
	}
}

function handleContentCallback(sDivId) {
	var oDiv = document.getElementById(sDivId);
	oDiv.innerHTML = oCaller2.oDoc;
}


function parseContent(sDivId) {
	var oDiv = document.getElementById(sDivId);

	if (oDiv.innerHTML == "") {
		oDiv.innerHTML = "<br><strong>Loading content, please wait...</strong>";

		oParam = {};
		oParam.fnCallback = parseContentCallback;
		oParam.aArgs = new Array(sDivId);
		oParam.sUrl = 'mxs_files/mxsParser.php';
		oParam.sQueryString = '&filename='+sDivId+'.html';
		oParam.sMethod = 'post';
		oParam.sType = 'txt';
	
		oCaller2.makeCall(oParam.fnCallback, oParam.aArgs, oParam.sUrl, oParam.sQueryString, oParam.sMethod, oParam.sType);
	}
	else {
		oDiv.style.display = (oDiv.style.display == "none") ? "block" :	"none";
	}
}

function parseContentCallback(sDivId) {
	var oDiv = document.getElementById(sDivId);
	oDiv.innerHTML = oCaller2.oDoc;
}

