// JavaScript Document
var ajaxObjID;

function ajaxRequest(mode,params) {
	//alert("Mode: " + mode + "\r\nParams:" + params);
	if (params.length == 0) {
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert("Browser does not support ajax requests");
		return;
	}
	xmlHttp.onreadystatechange = stateChanged;
	var sendData = "?mode=" + mode + "&params=" + params;
	xmlHttp.open("GET", "ajaxCaller.php" + sendData, true);
	xmlHttp.send(null);
}
function stateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		//alert("Response Text:\r\n" + xmlHttp.responseText);
		return xmlHttp.responseText;
	}
}


// Seperate function to fill subscribers
function ajaxSubscriberRequest(mode,params) {
	//alert("Mode: " + mode + "\r\nParams: " + params);
	if (params.length == 0) {
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert("Browser does not support ajax requests");
		return;
	}
	xmlHttp.onreadystatechange = stateChangedSubscriberRequest;
	var sendData = "?mode=" + mode + "&params=" + params;
	xmlHttp.open("GET", "ajaxCaller.php" + sendData, true);
	xmlHttp.send(null);
}
function stateChangedSubscriberRequest() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		var sResp = eval('(' + xmlHttp.responseText + ')');
		//alert("Response Text:\r\n" + sResp);
		var oSpan = document.getElementById('subscribersSpan');
		oSpan.innerHTML = "";
		var i;
		for (i in sResp) {
			oSpan.innerHTML += sResp[i]['UserLink'] + '&nbsp;';
		}
	}
}


// Seperate function for quoting a post.
function ajaxQuoteRequest(mode,params) {
	//alert("Mode: " + mode + "\r\nParams:" + params);
	if (params.length == 0) {
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert("Browser does not support ajax requests");
		return;
	}
	xmlHttp.onreadystatechange = stateChangedQuotePost;
	var sendData = "?mode=" + mode + "&params=" + params;
	xmlHttp.open("GET", "ajaxCaller.php" + sendData, true);
	xmlHttp.send(null);
}
function stateChangedQuotePost() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		//alert("Response Text:\r\n" + xmlHttp.responseText);
		var temp = new Array();
		var sResp = xmlHttp.responseText;
		temp = sResp.split("|||");
		document.getElementById('subject').value = temp[0];
		var oPostBox = document.getElementById('postreply_body');
		oPostBox.value = temp[1];
		oPostBox.focus();
		tinyMCE.idCounter=0;
		tinyMCE.execCommand('mceAddControl', false, 'postreply_body');
	}
}


function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		// Firefox, Operan, & Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		//IE
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
