// @autor Mickey Johnnyson

var xmlHttp;
var obj;
//var mode;
	
function showResponse(url, itemId, mode) {
	obj = new Object();
	obj.url = url;
	obj.itemId = itemId;
	obj.mode = mode;
	xmlHttp = null;
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Your browser does not support AJAX!");
		return;
	}
	obj.url = obj.url + "&rand=" + Math.random();
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("POST", obj.url, true);
	xmlHttp.send(null);
}

function stateChanged() {
	if(xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			if (obj.mode == 0)
				document.getElementById(obj.itemId).innerHTML = xmlHttp.responseText;
			else if (obj.mode == 1)
				document.getElementsByName(obj.itemId)[0].value = xmlHttp.responseText;
		}
		else {
			alert('Status: '+xmlHttp.status+' URL: '+this.url+' Error communicating with the server!\nPlease check your input and try again.');
			return;
		}
	}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
	  // Internet Explorer
		try {
			xmlHttp=new ActiveXtObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
