// JavaScript Document

var SERVER = { 
	loaded : false,
	requestobj : false,
	fun : false,
	load : function() {
		if( SERVER.loaded == false ) {
			this.loaded = SERVER.loadrequestobj(); //probeer te laden
		}
		return this.loaded;
	},
	loadrequestobj : function () {
		if (window.XMLHttpRequest){ // if Mozilla, Safari etc or IE7
			this.requestobj = new XMLHttpRequest();
			if (this.requestobj.overrideMimeType) this.requestobj.overrideMimeType('text/xml');
				return true;
		}
		else if (window.ActiveXObject){ // if IE, not IE7
			try {
				this.requestobj = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					this.requestobj = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					return false;
				}
			}
			return true;
		}
		return false;
	},
	GETrequest : function (url, data, func) {
		if( !this.load() ) return false;
		this.requestobj.open('GET', url+'?'+data, true);
		if(func) this.requestobj.onreadystatechange = func;
		this.requestobj.send(null);	
		return true;
	},
	POSTrequest : function(url, data, func, fun) {
		if( !this.load() ) return false;
		
		this.requestobj.open('POST', url, true);
		this.requestobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.requestobj.setRequestHeader("Content-length", data.length);
		this.requestobj.setRequestHeader("Connection", "close");
		this.requestobj.send(data);
		
		if(fun != false) this.fun = fun;
		
		if(func) this.requestobj.onreadystatechange = func;
		
		return true;
	},
	Ontvangst : function() {
		if( this.requestobj.readyState != 4 ) return false;
		else if( this.requestobj.status != 200 ) return 'Fout: '+this.requestobj.statusText;
		else return this.requestobj.responseText;
	},
	GetFun : function() {
		return this.fun;
	}
}