if (navigator.appName=="Microsoft Internet Explorer")
{
	document.write("<link rel='stylesheet'  href='general/css/libralab_ie.css'>");
}

var helpArray = new Array;
function checkAll(frm, chkBox,pattern)
{		
	var check = true;
	if (! chkBox.checked)
	{
		check = false;
	}
	
	for (var c = 0; c < frm.elements.length; c++)
	{
		if (frm.elements[c].type == 'checkbox'&&(pattern!=null&&frm.elements[c].name.indexOf(pattern)>-1||pattern==null))
		{
			if(!frm.elements[c].disabled)
			{
				frm.elements[c].checked = check;
			}
		}
	}			
}

function numbersonly(e) {
    if (!e) {
        //if the browser did not pass the event information to the
        //function, we will have to obtain it from the event register
        if (window.event)//Internet Explorer
        {
            e = window.event;
        }
        else//total failure, we have no way of referencing the event
        {
            return;
        }
    }
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8 && unicode!=13)
	{ //if the key isn't the backspace key (which we should allow)
		if (unicode < 48|| unicode > 57) //if not a number
			return false //disable key press
	}
}

function trim(value) {
    value = value.replace(/^\s+/, '');
    value = value.replace(/\s+$/, '');
    return value;
}

function isInteger(s){
	var i;

    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    
    return true;
}

function checkKey(evt) {
	var keyCode = evt.keyCode;
	if(evt.shiftKey&&evt.ctrlKey&&evt.keyCode==68)
	{
		var strURL = window.location.toString();
		var strPrefix = strURL.indexOf('?')>0?'&':'?';
		strURL = strURL.replace('&debug=false','&debug=true');
		strURL = strURL.replace('?debug=false','?debug=true');
		if(strURL.indexOf('debug=true')<0)
		{
			strURL = window.location+strPrefix+"debug=true";
		}
		
		window.location = strURL;
	}
	else if(evt.ctrlKey&&evt.altKey&&evt.keyCode==68)
	{
		var strURL = window.location.toString();
		strURL = strURL.replace('&debug=true','&debug=false');
		strURL = strURL.replace('?debug=true','?debug=false');
		window.location = strURL;
	}
}


function OpenPopup(url,width,height, left, top,debug) 
{
	var curWinLeft = 0;
	var curWinTop = 0;
	var resizable = 'no';
	if(width==null||height==null)
	{
		width = 600;
		height = 400;
		resizable = 'yes';
	}
	curWinLeft = screen.availWidth/2-(width/2);
	curWinTop = screen.availHeight/2-(height/2);
	if (left >= 0 && top >=0 )
	{
	
		if (navigator.appName=="Microsoft Internet Explorer")
		{
			curWinLeft =  window.screenLeft;
			curWinTop =  window.screenTop;
		} else {
			curWinLeft =    window.screenX;
			curWinTop = window.screenY;
		}		
		curWinLeft += left;
		curWinTop += top;
	}
	
	if(debug)
	{
		var popup = window.open(url,null,'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height + ', left=' + curWinLeft+',top=' + curWinTop);
	}
	else
	{
		var popup = window.open(url,null,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable='+resizable+',copyhistory=no,width='+width+',height='+height + ', left=' + curWinLeft+',top=' + curWinTop);
	} 
}

function mouse_over(context)
{
	var msg = helpArray[context];
	var el  = document.getElementById('contexthelp');
	
	el.innerHTML = msg;
}
function mouse_out()
{
	var el  = document.getElementById('contexthelp');
	el.innerHTML = '';
}

function mouse_str_over(msg)
{
	var el  = document.getElementById('contexthelp');
	
	el.innerHTML = msg;
}
function ch2(e) {
        mark=e.childNodes.item(0).childNodes.item(0);                 
        contents=e.childNodes.item(1);
        if (mark.innerHTML=="+") {
            mark.innerHTML="-";                   
            contents.style.display="block";  
        }
        else {
            mark.innerHTML="+";
            contents.style.display="none";
        }
 }       
 
 //functie kan worden overloaded in eigen xslt (als event...)
 function SelectDeselectChange(strSelectedID)
 {
    var objSelected = document.getElementById(strSelectedID);
    var objSelectedKeys = document.getElementById(strSelectedID + '_keys');
    var strSelectedKeys = "";
    var i;
    for (i = 0 ; i<=objSelected.length-1; i++)
    {
        var objOptSelected = objSelected.options[i]
        strSelectedKeys+=objOptSelected.value+",";
    }
    objSelectedKeys.value = strSelectedKeys.substring(0,strSelectedKeys.length-1);
 }
	
function SelectDeselect_Move(strFromID,strToID)
{

	var objFrom = document.getElementById(strFromID);
	var objTo = document.getElementById(strToID);
	var i;
	for (i = objFrom.length - 1; i >=0 ; i--) 
	{

		var objOptSelected = objFrom.options[i]

		if (objOptSelected.selected) 
		{
			var objOptNew = document.createElement('option');
			objOptNew.text = objOptSelected.text;
			objOptNew.value = objOptSelected.value;
			
			try 
			{
				objTo.add(objOptNew, null); // standards compliant; doesn't work in IE
			}
			catch (ex) 
			{
				objTo.add(objOptNew); // IE only
			}
			objFrom.remove(i);
		}
	}
}

//function to sort items in a listbox
function SortListbox(sortedListboxId) 
{

var sel = document.getElementById(sortedListboxId);
// convert OPTIONs NodeList to an Array 
// - keep in mind that we're using the original OPTION objects 
var optionArray = 
(function (nl) 
    {
        var a = [];
        for (var i = 0, len = nl.length; i < len; i++)
            a.push(nl.item(i));
        return a;
    }
)(sel.options);
// sort OPTIONs Array 
optionArray.sort(function (a, b) 
{    
    // sort by text
    return a.text.toLowerCase() < b.text.toLowerCase() ? -1 : a.text.toLowerCase() > b.text.toLowerCase() ? 1 : 0; 
});
// remove all OPTIONs from SELECT (don't worry, the original 
// OPTION objects are still referenced in "optionArray")
for (var i = 0, len = optionArray.length; i < len; i++)
    sel.remove(optionArray[i].index);
// (re)add re-ordered OPTIONs to SELECT
for (var i = 0, len = optionArray.length; i < len; i++)
{
    
    try 
    {
        sel.add(optionArray[i], null); // standards compliant; doesn't work in IE
    }
    catch (ex) 
    {
        sel.add(optionArray[i]); // IE only
    }
}
}
	
function getRadioValue(theObj) 
{
	for (var i=0; i < theObj.length; i++) 
	{
		if (theObj[i].checked) { return theObj[i].value;}
	}
	return "";
}
		
function mkArrayFromElements(strNameToContain, objForm)
{
	var intSize				= objForm.elements.length; 
	var strName				= '';
	var arrNewNames			= new Array(intSize);
	var intArrLength		= 0;

	for( i = 0; i < intSize; ++i ) 
	{
		strName	= objForm.elements[i].name;
		
		if(strName != null)
		{
			if(strName.indexOf(strNameToContain) != -1)
			{
				arrNewNames[intArrLength] =  objForm.elements[i].value;
				if(objForm.elements[i].value == '')
				{
					blnHasEmptyValues = true;
				}
				intArrLength += 1;
			}
		}
	} 
	
	arrNewNames		= arrNewNames.slice(0,intArrLength);
	return (arrNewNames);
}

function CheckUniqueValuesInArray(arrToCheck)
{
	var strName				= '';
	var strNameToCompare	= '';
	var blnUnique			= true;			

	for( i = 0; i < arrToCheck.length; ++i ) 
	{
		strName	= arrToCheck[i];
	
		for( j = 0; j < arrToCheck.length; ++j ) 
		{
			if(i != j)//Dezelfde vergelijken heeft dus geen zin
			{
				strNameToCompare	= arrToCheck[j];
				if(strNameToCompare != '' && strName != '' && strName == strNameToCompare)//Lege waarden ook niet vergelijken
				{
					blnUnique = false;
				}
			}
		} 
	}
	return (blnUnique);
}

function ChangeTab(newtab)
{
	//alert('Hey collega!\nDeze functie moet je overloaden op je form zodat je van tab kan wisselen');
	
	/*
	Voorbeeld code:
	this.CurrentTab.value = newtab;
	submitform(this,'changetab')
	*/
}

function mkArrayFromSelectedElements()
{
	var intSize				= ThisForm.elements.length; 
	var strName				= '';
	var arrSelectedNrs			= new Array(intSize);
	var intArrLength		= 0;

	for( i = 0; i < intSize; ++i ) 
	{
		strName	= ThisForm.elements[i].name;
		
		if(strName != null)
		{
			if(strName.indexOf('blnSelected') != -1)
			{
				if(ThisForm.elements[i].checked == true)
				{
					stringNr	= new String(strName);
					stringNr	= stringNr.replace('blnSelected','');
				
					arrSelectedNrs[intArrLength] =  stringNr;
					intArrLength += 1;
				}
			}
		}
	} 
	
	arrSelectedNrs		= arrSelectedNrs.slice(0,intArrLength);
	return (arrSelectedNrs);
}


/*############################################
# Berekend iemands leeftijd in jaren 
##############################################*/
function GetAge(dtmJS)
{
	dd = dtmJS.getDate();
	mm = dtmJS.getMonth() + 1;
	yy = dtmJS.getFullYear();

	days = new Date();
	gdate = days.getDate();
	gmonth = days.getMonth()+1;
	gyear = days.getFullYear();
	age = gyear - yy;
	if ((mm > gmonth) || (mm == gmonth && gdate < dd))age --;
	
	return age;
}


/*############################################
# Functions om de x en y posities van een element op te halen 
##############################################*/
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function AllowTabCharacter() 
{   
	if (event != null) 
	{      
		if (event.srcElement) 
		{         
			if (event.srcElement.value) 
			{            
				if (event.keyCode == 9) 
				{  // tab character               
					if (document.selection != null) 
					{                  
						document.selection.createRange().text = '\t';                  
						event.returnValue = false;               
					}               
					else 
					{                  
						event.srcElement.value += '\t';                  
						return false;               
					}
	            }
			}
		}
	}
}


function loadTextFile(url)
{

url += "?" + Math.random();
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.onreadystatechange=state_Change
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
    xmlhttp.onreadystatechange=state_Change
    xmlhttp.open("GET",url,true)
    xmlhttp.send()
    }
  }
}

function showNoClickDiv()
{
	var objDiv	= document.getElementById("noClickDiv");
	var objProgressDiv	= document.getElementById("progressBar");
	
	objDiv.className			= 'noClickDivVisible';
	objProgressDiv.className	= 'progressBarVisible';
	
	resizeNoClickDiv();// Zet de initieele grootte
	
	hideAllCombos(); //Omdat deze anders door de div heen komen.
}

function resizeNoClickDiv()
{
	var strBrowserType	= navigator.appName;
	
	setStyle("noClickDiv", "top", (document.body.scrollTop) + "px");
	setStyle("noClickDiv", "width", (document.body.offsetWidth) + "px");
	
	
	if(strBrowserType.indexOf("Microsoft") > -1)//IE
	{
		setStyle("noClickDiv", "height", (document.body.offsetHeight) + "px");
	}
	else//Mozilla
	{
		setStyle("noClickDiv", "height", (document.documentElement.offsetHeight) + "px");
	}
	
	var intImageWidth	= 174;//getStyle(document.getElementById("progressImage"), "width");
	var intImageHeigth	= 25;//getStyle(document.getElementById("progressImage"), "height");
	
	
	setStyle("progressBar", "left", (document.body.offsetWidth/2) - (intImageWidth/2) + "px");
	setStyle("progressBar", "top", (document.body.offsetHeight/2) - (intImageHeigth/2) + document.body.scrollTop + "px");
}

function setStyle(objId, style, value)
{
    document.getElementById(objId).style[style] = value;
}

function getStyle(el, style)
{
	if(!document.getElementById) return;
   
	var value = el.style[toCamelCase(style)];
   
    if(!value)
    {
        if(document.defaultView)
        {
            value = document.defaultView.getComputedStyle(el, "").getPropertyValue(style);
		}
        else
        {
			if(el.currentStyle)
			{
				value = el.currentStyle[toCamelCase(style)];
			}
		}
	}
	return value;
}

function toCamelCase( sInput )
{
    var oStringList = sInput.split('-');

    if(oStringList.length == 1)
    {
        return oStringList[0];
	}
    
    var ret = sInput.indexOf("-") == 0 ? oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    
    for(var i = 1, len = oStringList.length; i < len; i++)
    {
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1);
    }
    return ret;
}

function hideAllCombos()
{
	if(document.all)
	{
		var arrSelects = document.getElementsByTagName('select');
		
		for (var intI = 0; intI < arrSelects.length; intI++)
		{
			arrSelects[intI].style.visibility	= 'hidden';
			arrSelects[intI].style.display		= 'none';
		}
	}
}

function DisableCache()
{
	var url	= location.href;
	
	if(url.indexOf('?') < 0)//Geen parameters aanwezig
	{
		window.location = url + '?cache=false';
	}
	else
	{
		url = url.replace('&cache=true', '');
		url = url.replace('&cache=false', '');
		
		window.location = url + '&cache=false';
	}	
}

function EnableCache()
{
	var url = location.href;
	
	if(url.indexOf('?') < 0)//Geen parameters aanwezig
	{
		window.location = url + '?cache=true';
	}
	else
	{
		url = url.replace('&cache=true', '');
		url = url.replace('&cache=false', '');
		
		window.location = url + '&cache=true';
	}	

}

//Functie voor uitbellen vanuit Herbie met Frontline.
function formatPhoneNumber(string)
{
	var tstring = "";
	string = '' + string;
	valid = "1234567890+";
	 
	for(i = 0; i < string.length; i++)
	{
		if (valid.indexOf(string.charAt(i)) != -1)
		{
			tstring += string.charAt(i);
		}
	}
	window.location = "callto://" + tstring;			
}
	
function setSelectedIndex(id,val)
{
  var x=document.getElementById(id);
  for (i=0;i<x.length;i++)
  {
    if(x.options[i].value == val)
    {
        x.options[i].selected = true;
    }
  }

}

function showpagexmlInfo(id) {
    var objDebugHref = document.getElementById('href' + id);
    var objDebug = document.getElementById(id);

    if (objDebug && objDebugHref) {
        if (objDebugHref.innerHTML == 'show') {
            objDebug.style.display = 'block';
            objDebug.style.visibility = 'visible';
            objDebugHref.innerHTML = 'hide';
        } else {
            objDebug.style.display = 'none';
            objDebug.style.visibility = 'hidden';
            objDebugHref.innerHTML = 'show';
        }
    }
}

/*
Standaard object om AJAX calls te verwerken.
*/
function AJAXInteraction(url, callback, id, blnXML) {

    var req = init();    
    req.onreadystatechange = processRequest;

    function init() {
        if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    function processRequest() {
        if (req.readyState == 4) {
            //		alert(req.status);
            if (req.status == 200) {

                if (callback) {                   
                    if (blnXML)
                        callback(req.responseXML, id);
                    else
                        callback(req.responseText, id);
                }
            }
        }
    }

    this.doGet = function() {
        req.open("GET", url, true);
        req.send(null);
    }



    this.doPost = function(body) {
        req.open("POST", url, true);
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        req.setRequestHeader("Content-length", body.length);
        req.setRequestHeader("Connection", "close");
        req.send(body);
    }
}
/*Standaard functie om een ajax call te doen.
roept returnFuncAjax aan om resultaat in id te zetten.*/
function CallAjax(url, id) {
    var obj = new AJAXInteraction(url, returnFuncAjax, id);
    obj.doGet();
}

function returnFuncAjax(response, id) {

    if (document.getElementById(id)) {
        document.getElementById(id).innerHTML = response;
    }
}



var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

