// JavaScript Document
var remotingDiv;
var xmlHttp; 
var bw= "";

//bepaal de browserversie
bw = new cm_bwcheck()

function execAjax(strUrl) {
	// This is non-blocking (asynchronous)
	xmlHttp = GetXmlHttpObject(stateChangeHandler);
	if (xmlHttp) {
		//Send the xmlHttp get to the specified url 
		xmlHttp_Get(xmlHttp, strUrl);
	}
	else {
		//execute iframe workaround
		sendRequest(strUrl);
	}
}

function createRemotingDiv(id,url) {
	//create div
	var rDiv = document.createElement('div');
	rDiv.id = 'remotingDiv';
	var style = 'border:0;width:0;height:0;';
	//create iframe within div-tags
	rDiv.innerHTML = "<iframe name='"+id+"' id='"+id+"' style='"+style+"'><html></html></iframe>";
	
	//append div to documentbody
	document.body.appendChild(rDiv);
	rDiv.iframe = document.getElementById(id);
	
	//fill property form of div with form and form-properties
	rDiv.form = document.createElement('form');
	rDiv.form.setAttribute('id', id+'RemotingForm');
	rDiv.form.setAttribute('action', url);
	rDiv.form.setAttribute('target', id);
	rDiv.form.setAttribute('method', 'post');

	//append form to div
	rDiv.appendChild(rDiv.form);

	return rDiv;
}
function sendRequest(url) {
	if (!remotingDiv) {
		remotingDiv = createRemotingDiv('remotingFrame','blank.html');
	}
	remotingDiv.form.action = url;
	remotingDiv.form.submit();
	
	iframeDoc = document.getElementById("remotingDiv").iframe;

	if (stateChangeHandler) {
		remotingDiv.iframe.onload = stateChangeHandler; 
		remotingDiv.iframe.onerror = stateChangeHandler; 
		remotingDiv.iframe.onreadystatechange = stateChangeHandler;
	}
}	

//stateChangeHandler will fire when the state has changed, i.e. data is received back 
// This is non-blocking (asynchronous) 
//Must return valid Javascript
function stateChangeHandler() 
{ 
	if (xmlHttp){
		//readyState of 4 or 'complete' represents that data has been returned 
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
			//Gather the results from the callback 
			var jsScript = xmlHttp.responseText;
			xmlHttp = null;
			evalJsScript(jsScript);
		}
	}
    else if (iframeDoc) {
	    if (iframeDoc.readyState == 4 || iframeDoc.readyState == 'complete') {
		    var jsScript = frames['remotingFrame'].window.document.body.innerHTML;
		    evalJsScript(jsScript);
        }
	}
} 
//Must return valid Javascript
function evalJsScript(jsScript)
{
	try{ 
		eval(jsScript);
	}
	catch(e){ 
		alert("An error has occured while processing this data.")
		//alert(jsScript);
	}
	try{ 
		showThem();
	}
	catch(e){ 
		//bovenstaande functie is momenteel pagina specifiek
	}	
}

function xmlHttp_Get(xmlhttp, url) { 
    // Functie voor een ASYNCHRONOUS HTTP GET
    // XMLHttp send GET request
    //aanroep --> 
	//xmlHttp = GetXmlHttpObject(stateChangeHandler);     --voor teruggeven van pure JS
	//xmlHttp_Get(xmlHttp, url); 
    if (xmlhttp) {
        xmlhttp.open('GET', url, true); 
        xmlhttp.send(null); 
    }
} 
function syncHTTPGetResponse(URL)
{
    // Functie voor een SYNCHRONOUS HTTP GET
    //aanroep --> var activiteitType = syncHTTPGetResponse(strCompleteUrl);	

    var http = GetXmlHttpObject();
    http.open('get', URL, false);
    http.send(null);
    return http.responseText;
}
function GetXmlHttpObject(handler) { 
    var objXmlHttp = null;    //Holds the local xmlHTTP object instance 

    //Depending on the browser, try to create the xmlHttp object 
    // code for Mozilla, IE7 etc. (blijkbaar kent IE6 ook window.XMLHttpRequest, dus mag niet)
    if ((window.XMLHttpRequest) && !(bw.ie5) && !(bw.ie6)) {
        objXmlHttp = new XMLHttpRequest(); 
        if (handler) {
            objXmlHttp.onload = handler; 
            objXmlHttp.onerror = handler; 
            objXmlHttp.onreadystatechange = handler;
        }
    }
    // code for IE5 en 6
    else if (window.ActiveXObject) {
        //The object to create depends on version of IE 
        //If it isn't ie5, then default to the Msxml2.XMLHTTP object 
        var strObjName = (bw.ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; 
        //Attempt to create the object 
        try{ 
            objXmlHttp = new ActiveXObject(strObjName); 
            if (handler) objXmlHttp.onreadystatechange = handler; 
        } 
        catch(e){ 
            //Object creation errored 
            //alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled'); 
            return; 
        } 
    }
    else if (bw.op6){ 
        //Opera has some issues with xmlHttp object functionality 
        alert('Opera detected. The page may not behave as expected.'); 
        return; 
    } 

    //Return the instantiated object 
    return objXmlHttp; 
} 

function vul_options(box, opt, selvalue, bDelete){ 
	var obj = document.getElementById(box);
	var selectedOption = 0;
	var i;
	/* verwijderen bestaande options als bDelete = true */
	if (bDelete) { 
		obj.options.length = 0;
		intStart = 0;
		intEind = opt.length;
	}
	else {
		intStart = obj.options.length;
		intEind = obj.options.length + opt.length;
	}
	for(i=intStart;i<intEind;i++) {
		if (opt[i-intStart][2]==selvalue) { selectedOption = i; } 
		obj.options[i] =  new Option(unescapeHTML(opt[i-intStart][1]),unescapeHTML(opt[i-intStart][2]),false,false);	
	}
	//selected value pas zetten als alle options geladen zijn, anders gaat dit fout
	//als selvalue is leeg of undefined dan niks doen
	if(selvalue != "" && selvalue != undefined) obj.options[selectedOption].selected = true;
}	

function SelectAll(selectlist) {
	var obj = document.getElementById(selectlist)
 	// Loop over de lijst met opties uit de selectlist.
 	for (var i=0;i<obj.options.length;i++) {
	 	// Selecteer deze optie.
 		obj.options[i].selected = true;
	}
}

/* bepaal browser versie */
function cm_bwcheck(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1) && window.opera 
	this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1) && window.opera   
	this.ie5 = (this.agent.indexOf("msie 5")>-1 && !this.op5 && !this.op6)
	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
	this.ie6 = (this.agent.indexOf("msie 6")>-1 && !this.op5 && !this.op6)
	this.ie4=(this.agent.indexOf("msie")>-1 && document.all &&!this.op5 &&!this.op6 &&!this.ie5&&!this.ie6)
	this.ie = (this.ie4 || this.ie5 || this.ie6)
	this.mac=(this.agent.indexOf("mac")>-1)
	this.ns6=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ns4=(!this.dom && document.layers)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6)
	this.usedom= this.ns6//Use dom creation
	this.reuse = this.ie||this.usedom //Reuse layers
	this.px=this.dom&&!this.op5?"px":""

	return this
}