/* global http request object */
var xmlhttp;


/* deserializer class and methods */
function objDeSerializerElement(strContent) {
	// properties
	this.strFieldDelimiter="!!field!!";
	this.strFieldValueSeperator="!!equals!!";
	this.arrFieldValue=new Array();
	this.serialized_content=strContent;

	// methods
	this.parse=_dseParse;
	this.getValue=_dseGetValue;
}

function _dseParse() {	
	arrFields=this.serialized_content.split(this.strFieldDelimiter);
	for(i=0;i<arrFields.length;i++) {
		strFieldValue=arrFields[i];
		arrSep=strFieldValue.split(this.strFieldValueSeperator);
		strField=arrSep[0];		
		strValue=arrSep[1];
		this.arrFieldValue[strField]=strValue;
	}
}

function _dseGetValue(strField) {
	return this.arrFieldValue[strField];
}

function objDeSerializer(strContent) {
	// properties
	this.strRowDelimiter="!!row!!";
	this.objs=new Array();
	this.serialized_content=strContent;
		
	// methods
	this.parse=_dsParse;
	this.getObj=_dsGetObj;
	this.numberOfObjs=_dsNumberOfObjs;
}

function _dsParse() {
	//alert(this.serialized_content);
	arrLines=this.serialized_content.split(this.strRowDelimiter);	
	//alert(arrLines.length);
	for(j=0;j<arrLines.length;j++) {		
		objElement = new objDeSerializerElement(arrLines[j]);
		objElement.parse();
		this.objs[this.objs.length]=objElement;
	}
}

function _dsGetObj(i) {
	return this.objs[i];
}

function _dsNumberOfObjs() {
	return this.objs.length;
}


/* request and div manipulation functions */
function isOff(strDivId) {
	if (document.getElementById(strDivId).innerHTML=='') {
		return true;
	} else {
		return false;
	}
}

function setOn(strDivId) {
	document.getElementById(strDivId).style.display='block';
	document.getElementById(strDivId).style.visibility='visible';
}

function setOff(strDivId) {
	document.getElementById(strDivId).innerHTML='';		
	document.getElementById(strDivId).style.display='none';
	document.getElementById(strDivId).style.visibility='hidden';
}

function simpleRequest(myUrl, callBackFunc, strParams)  {	
	var strResult="";
	var xmlhttp;

	
	if(window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera
	} else if(window.ActiveXObject) {
		xmlhttp = new ActiveXObject("MSXML2.XMLHTTP"); // Internet Explorer
	} else {
		return false;
	}
	xmlhttp.open("GET", myUrl, true); // Open a connection. Replace GET with HEAD in order to do a HEAD request.

	xmlhttp.onreadystatechange=function () {
		 if (xmlhttp.readyState==4) {
			if (xmlhttp.status==200) {
				callBackFunc(xmlhttp,strParams)
			}
		}
	}
	
	xmlhttp.send(null); // send() is used to initiate the transfer. No actual data have to be sent in this case.
}

function clearSelectBox(objBox) {
	for(i=0; objBox.options.length>0;i++) {
		objBox.options[0]=null;
	}
}

function addOptionToSelectBox(objBox, strOption, strValue) {
	var objOption = new Option(strValue, strOption);
	objBox.options[objBox.options.length] = objOption
}

function zetEenMomentAub(booModus) {	
	try {
		if (booModus) {
			document.getElementById('een_moment_aub').style.visibility='visible';
			document.getElementById('een_moment_aub').style.display='block';			
		} else {
			document.getElementById('een_moment_aub').style.visibility='hidden';
			document.getElementById('een_moment_aub').style.display='none';
		}
	} catch(e) {
		// Niet altijd is er een "een moment aub" div aanwezig. Bijvoorbeeld bij pane ajax requests.
	}
}

function writeInId(xmlhttp, strDivId) {
	//alert(xmlhttp.responseText);			
	document.getElementById(strDivId).innerHTML = xmlhttp.responseText;
	zetEenMomentAub(false);
}


