//---AJAX RequestText Script for use with PHP functions and CSS---Created by Nicholas Aiello, blinkrz.com---
var xhr = false;
function sendRequest(url, params , id_name) {
	document.getElementById(id_name).innerHTML = "<div style=\"font:bold 12px 'Arial'; vertical-align:center; color:#E4E4E4;\">loading...</div>";
	xhr = false;
	if(window.XMLHttpRequest) { //if FF
		xhr = new XMLHttpRequest();
	}else if(window.ActiveXObject) { //if IE
		try {
			var XmlHttpVersions = new Array("Microsoft.XMLHTTP",
										"MSXML2.XMLHTTP",
										"MSXML2.XMLHTTP.6.0",
										"MSXML2.XMLHTTP.5.0",
										"MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0");
			for(var i=0; i<XmlHttpVersions.length && !xhr; ++i) {
				try {
					xhr = new ActiveXObject(XmlHttpVersions[i]);
				}
				catch(e){}
			}
		}catch(e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {}
		}
	}
	
		
	if(!xhr) {
		alert("ERROR: Could not create XMLHttpRequest Object");
		return false;
	}
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4) {
			if(xhr.status == 200) {
				textResponse = xhr.responseText;
				document.getElementById(id_name).innerHTML = textResponse;
			}else {
				alert('ERROR: Unable to retreive data from server');
		}
	}
	}
	xhr.open('GET', url + params, true);
	xhr.send(null);
}

function postRequest(url, id_name) {
	xhr = false;
	if(window.XMLHttpRequest) { //if FF
		xhr = new XMLHttpRequest();
	}else if(window.ActiveXObject) { //if IE
		try {
			var XmlHttpVersions = new Array("Microsoft.XMLHTTP",
										"MSXML2.XMLHTTP",
										"MSXML2.XMLHTTP.6.0",
										"MSXML2.XMLHTTP.5.0",
										"MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0");
			for(var i=0; i<XmlHttpVersions.length && !xhr; ++i) {
				try {
					xhr = new ActiveXObject(XmlHttpVersions[i]);
				}
				catch(e){}
			}
		}catch(e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {}
		}
	}
	
		
	if(!xhr) {
		alert("ERROR: Could not create XMLHttpRequest Object");
		return false;
	}
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4) {
			if(xhr.status == 200) {
				textResponse = xhr.responseText;
				document.getElementById(id_name).innerHTML = textResponse;
			}else {
				alert('ERROR: Unable to retreive data from server');
		}
	}
	}
	xhr.open('POST', url, true);
	xhr.send(null);
}

function changeContents(id_name) { //not used
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			textResponse = xmlHttp.responseText;
			document.getElementById(id_name).innerHTML = textResponse;
		}else {
			alert('ERROR');
		}
	}
}

function setAjaxHistory() {
	var body = document.getElementsByTagName('body');
	body[0].setAttribute("onunload", "AjaxBack()");
}

function AjaxBack() {
		var historyFrame = document.getElementById('history_frame');
		sendRequest(historyFrame.src, '', 'middle');
}