/******************************************************************************* 
Ajax XMLHTTPRequest functies 
*******************************************************************************/
if (typeof XMLHttpRequest == "undefined") {
	XMLHttpRequest = function() {
		try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
		try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
		try { return new ActiveXObject("Msxml2.XMLHTTP") }     catch(e) {}
		try { return new ActiveXObject("Microsoft.XMLHTTP") }  catch(e) {}
		throw new Error("Deze browser biedt geen ondersteuning voor XMLHttpRequest of XMLHTTP!" )
	};
}

function getURL(url) { 
    var xhr = new XMLHttpRequest();
	xhr.open("GET", url, true);
	xhr.onreadystatechange = function() { if ((xhr.readyState==4) && (xhr.status==200)) eval(xhr.responseText); };
	//url = url + "&ms=" + new Date().getTime();
	xhr.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xhr.setRequestHeader("Cache-Control", "no-cache");
	xhr.setRequestHeader("X_USERAGENT", "WebiaXHR");
	xhr.send(null);
}

function postURL(url, data) {
    var xhr = new XMLHttpRequest();
	xhr.open('POST', url, true);
	xhr.onreadystatechange = function() { if ((xhr.readyState==4) && (xhr.status==200)) eval(xhr.responseText); };
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.setRequestHeader("Content-length", data.length);
	xhr.setRequestHeader("Connection", "close");
	//xhr.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	//xhr.setRequestHeader("Cache-Control", "no-cache");
	xhr.setRequestHeader("X_USERAGENT", "WebiaXHR");
	xhr.send(data);
}

/******************************************************************************* 
Overig
*******************************************************************************/
var activepage = 0;

function showFlags(link, flags) {
	link.style.backgroundPosition = 'center';
	document.getElementById(flags).style.visibility = 'visible';
}
function hideFlags(link, flags) {
	if (link.id == ('item'+activepage)) link.style.backgroundPosition = 'bottom';
	else link.style.backgroundPosition = 'top';
	document.getElementById(flags).style.visibility = 'hidden';
}
function overFlag(img, language) { img.src = 'images/flg_'+language+'_over.png'; }
function outFlag(img, language) { img.src = 'images/flg_'+language+'.png'; }

function overMenu(link) { link.style.backgroundPosition = 'bottom'; }
function outMenu(link) { 
	if (link.id == 'item'+activepage) link.style.backgroundPosition = 'bottom';
	else link.style.backgroundPosition = 'top';
}

function loadPage(item, language) {
	if (item == 1) { // structure-id van home
		document.getElementById('contenttable').style.left = '-9999px';
		document.getElementById('homeheader').style.display = 'block';
	}
	else {
		document.getElementById('homeheader').style.display = 'none';
		document.getElementById('contenttable').style.left = '0px';
	}
	if (activepage != item) {
		var menuitem = document.getElementById('item'+activepage)
		if (menuitem) menuitem.style.backgroundPosition = '';
		menuitem = document.getElementById('item'+item)
		if (menuitem) {
			//alleen wanneer er geen vlaggen zijn
			if (menuitem.style.backgroundPosition.indexOf('center') == -1) menuitem.style.backgroundPosition = 'bottom';
		}
		activepage = item;
	}
	//laad content hoofdpagina
	getURL('xhr.php?act=loadpage&sid='+activepage+'&language='+language);
}

function loadSubPage(item, language) {
	getURL('xhr.php?act=loadsubpage&sid='+item+'&language='+language);
}

function loadAgenda(item, language) {
	getURL('xhr.php?act=loadagenda&aid='+item+'&language='+language);
}

function loadBG() {
	activepage = document.getElementById('sid').value; //init structure id
	document.body.style.backgroundImage = 'url(dynamicbg.php?w='+screen.width+'&h='+screen.height+')';
}

window.onload = function() { loadBG() };