﻿/*-----WINDOW.ONLOAD MANAGER-----*/
window.onLoadListeners = new Array();
window.addOnLoadListener = function(listener) {
	window.onLoadListeners[window.onLoadListeners.length] = listener;
}
window.onload=function() {
	for(var i=0;i<window.onLoadListeners.length;i++) {
		var func = window.onLoadListeners[i];
		func.call();
	}
}


//END WINDOW.ONLOAD MANAGER

/*-----EVENT MANAGER-----*/// JScript File

function removeAllChildNodes(node) {
	if (node && node.hasChildNodes && node.removeChild) {
		while (node.hasChildNodes()) {
			node.removeChild(node.firstChild);
		}
	}
} // removeAllChildNodes()


 /*
This is a comment saying who wrote the code. Please do not remove it.

Script by RoBorg
RoBorg@geniusbug.com
http://javascript.geniusbug.com | http://www.roborg.co.uk
Please do not remove or edit this message
Please link to this website if you use this script!

 
The getElementValue function allows you to get the value of a form element.
It will return a string normally, although for certain elements it will return a boolean.
A multiple select is special, in that it will return an array of booleans.
*/
function getElementValue(formElement)
{
	if(formElement.length != null && formElement[0]) var type = formElement[0].type;
	if((typeof(type) == 'undefined') || (type == 0)) var type = formElement.type;
	
	var val = null;
	
	switch(type)
	{
		case 'undefined': return;
		case 'radio':
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].checked == true)
			val = formElement[x].value;break;

		case 'select-multiple':
			var myArray = new Array();
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].selected == true)
					myArray[myArray.length] = formElement[x].value;
			val = myArray;break;

		case 'checkbox': val = formElement.checked;break;
		default: val = formElement.value;break;
	}
	
	return val;
}



/*
net = namespace
net.ContentLoader = object {
	.req 			= Crossbrowser XML object
	.onload 		= onload functie
	.onerror 		= onerror functie (bij null = standaarderror)
	.loadXMLDoc 	= functie(ServiceUrl, 'POST|GET', 'x=1&y=2', ContentType)	-> ContentType is niet verplicht
	
	
	Gebruik:
	var loader1 = new net.ContentLoader('Service.php', ReadyHandlerFunctie, ErrorHandlerFunctie, "POST", 'parameter1=waarde1&parameter2=waarde2');
}

*/
var net=new Object();

net.READY_STATE_UNINITIALIZED=0;
net.READY_STATE_LOADING=1;
net.READY_STATE_LOADED=2;
net.READY_STATE_INTERACTIVE=3;
net.READY_STATE_COMPLETE=4;

net.ContentLoader=function(url,onload,onerror,method,params,contentType){
	this.req=null;
	this.onload=onload;
	this.onerror=(onerror) ? onerror : this.defaultError;
	this.loadXMLDoc(url,method,params,contentType);
}

net.ContentLoader.prototype.loadXMLDoc=function(url,method,params,contentType){
	if (!method){
		method="GET";
	}
	
	if (!contentType && method=="POST"){
		contentType='application/x-www-form-urlencoded';
	}
	
	if (window.XMLHttpRequest){
		this.req=new XMLHttpRequest();
	} else if (window.ActiveXObject){
		this.req=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (this.req){
    	try{
			var loader=this;
			this.req.onreadystatechange=function(){
				net.ContentLoader.onReadyState.call(loader);
			}
			
			this.req.open(method,url,true);
			
			if (contentType){
				this.req.setRequestHeader('Content-Type', contentType);
			}
			
			this.req.send(params);
		} catch (err){
			this.onerror.call(this);
		}
	}
}


net.ContentLoader.onReadyState=function(){
	var req = this.req;
	var ready = req.readyState;
	if (ready == net.READY_STATE_COMPLETE){
		var httpStatus = req.status;
		if (httpStatus == 200 || httpStatus == 0){
			this.onload.call(this);
		} else {
			this.onerror.call(this);
		}
	}
}

net.ContentLoader.prototype.defaultError=function(){
  alert("error fetching data!"
    +"\n\nreadyState:"+this.req.readyState
    +"\nstatus: "+this.req.status
    +"\nheaders: "+this.req.getAllResponseHeaders());
}





//END AJAX MANAGER
