﻿//post parameters encoden voor gebruik in AJAX calls
function urlencode(str) {
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
}

// ajax request functies
function sendRequest(url, callback, postData) {
	var req=new XMLHttpRequest();
	if (!req) return;
	var method = (postData) ? 'POST' : 'GET';
	//plak een random nummer achter de  om te voorkomen dat de browser de pagina uit de cache haalt
	if (url.indexOf('?')==-1) {
		//? zit niet in de url
		url+='?rnd='+Math.random();
	}
	else {
		//? zit wel in url
		url+='&rnd='+Math.random();
	}
	
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData) {
		req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	}
	req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
			alert('Error in ajax call to '+url);
			return;
		}
		if (callback!==null) {
			callback(req);
		}
	}
	if (req.readyState == 4) return;
	req.send(postData);
}

function getXmlNodeValue(xmlDoc, node) {
	if (xmlDoc!=null) {
		var node=xmlDoc.selectSingleNode(node);
		//controleer of de node bestaat
		if (node!=null) {
			//controleer of de node niet leeg is
			if (node.firstChild!=null) {
				return node.firstChild.nodeValue;
			}
		}
		return '';
	}
	else {
		//GC van browser heeft xml document weggegooid
		alert('Please refresh the page you\'re requesting.')
	}
}