// Algemene Javascript functies

//browser controle
var UA = navigator.userAgent.toLowerCase();
var isNS = (UA.indexOf('mozilla') >= 0) ? true : false;
var isIE = (UA.indexOf('msie') >= 0) ? true : false;

var parkeerMotor = false;

function mailTo(name,address) {
	location.href = 'mailto:'+name+'@'+address;
}

function followMouse(evt){
	if(window.event){evt = window.event;}
	if(!parkeerMotor){
		if(evt){
			//var pos = evt.clientX + ", " + evt.clientY;
			var mouse = getObj("motorCursor");
				
			var verX = evt.clientX;
			var horY = evt.clientY;
	
			mouse.style.left = parseInt(verX) - 50;
			mouse.style.top = parseInt(horY) - 32;
		}
	}
}

function toPage(inhoud){
	getObj('mainTekst').innerHTML = eval(inhoud + "Inhoud");
}

function getObj(elementID){
	if(typeof elementID == "string"){
		return document.getElementById(elementID);
	}else{
		return elementID;
	}
}

function openpopup(scherm){
	breed = 640;
	hoog = 480+30;
	string = "width="+breed+",height="+hoog+",left=0, top=0";
	venster = window.open(scherm,"",string);
	venster.document.write('<html><head><title>Uitlaat Systeem</title></head>');
	venster.document.write('<body topmargin=0 leftmargin=0>');
	venster.document.write('<img src="' +scherm+ '" alt="afbeelding" border=0>');
	venster.document.write('<div align="center"><a href="javascript:window.close()">Sluit Venster</a></div>');
	venster.document.write('</body></html>');
}


//ajax functionaliteit
function getHttpRequestObject() {
	var xmlobj;
	// check for existing requests
	if(xmlobj != null && xmlobj.readyState != 0 && xmlobj.readyState != 4) {
		xmlobj.abort();
	}
	try {
		// instantiate object for Mozilla, Nestcape, etc.
		xmlobj = new XMLHttpRequest();
	}
	catch(e) {
		try {
			// instantiate object for Internet Explorer
			xmlobj = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch(e) {
			// Ajax is not supported by the browser
			xmlobj = null;
			return false;
		}
	}
	return xmlobj;
}

var receive = getHttpRequestObject();

//ophalen van data uit een extern php bestand bijvoorbeeld, waarvan het resultaat plain TXT bevat
function getPage(myUri){
	if (receive.readyState == 4 || receive.readyState == 0) {
		receive.open("GET", "../PHP/getdata.php?lang=NL&link=" + myUri, true);
		receive.setRequestHeader("Pragma", "no-cache");
		receive.setRequestHeader("Expires", 0);
		receive.onreadystatechange = function(){
			if (receive.readyState == 4) {
				//schrijf opgehaalde resultaat weg in het venster
				getObj('mainTekst').innerHTML = receive.responseText;
			}
		}
		receive.send(null);
	}
}