function crossXHR() {
	var crossxhr = false;
	if(window.XMLHttpRequest) {
		crossxhr = new XMLHttpRequest();
		if(crossxhr.overrideMimeType) {
			crossxhr.overrideMimeType('text/xml');
		}
	} else if(window.ActiveXObject) {
		try {
			crossxhr = new ActiveXObject('Msxml2.XMLHTTP');
		} catch(e) {
			try {
				crossxhr = new ActiveXObject('Microsoft.XMLHTTP');
			} catch(e) {
				crossxhr = false;
			}
		}
	}
	return crossxhr;
}

function getNodeValue(obj,tag) {
	return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;
}

// Declare timetag for cache-prevention
function tag() {
	var time = new Date();
	var time = "&time=" + time.getTime();
	return time;
}

function setText(id, data) {
	if (document.getElementById(id))
	document.getElementById(id).value = data;
}

function setInnerText(id, data) {
	if (document.getElementById(id))
	document.getElementById(id).innerHTML = data;
}

function setLink(id, data) {
	if (document.getElementById(id))
	document.getElementById(id).href = data;
}

function setSource(id, data) {
	if (document.getElementById(id))
	document.getElementById(id).src = data;
}

// Submit ajax command. Optional data (parameters), optional id(div id) and optional animation (boolean).
function getPage(page, data, id, animation) {
	var xmlhttp = crossXHR();
	xmlhttp.open("POST", "ajax.php?xc=" + page + tag(),true);//method, target, async (set always true!)
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	if (data) xmlhttp.setRequestHeader("Content-length", data.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==1) {
			if (animation == true) setInnerText(id, '<img src="content/images/ajax-loader.gif"/>');
		} else if (xmlhttp.readyState==4) {
			if (id) setInnerText(id, xmlhttp.responseText);
			getJavascript(page, data);
		}
	}
	xmlhttp.send(data);
}

function getJavascript(page, data) {
	var xmlhttp = crossXHR();
	xmlhttp.open("POST", "javascript.php?jc=" + page + tag(),true);//method, target, async (set always true!)
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	if (data) xmlhttp.setRequestHeader("Content-length", data.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			eval(xmlhttp.responseText);
		}
	}
	xmlhttp.send(data);	
}
