/*---GENERIC ---*/
function doMaillink(usr,dom,txt) {
	//writes an E-mail address + maillink (anti-spam purposes)
	var at = "@";
	var mailaddress = usr + at + dom;
	if(txt=="") {
		txt = mailaddress; 
	}
	document.write("<a href=\"mailto:" + mailaddress + "\">" + txt + "</a>");
}	
function checkmail(str){
	if (str != '')
   	{	if (str.indexOf('.') == -1)
			 return false;
		if (str.indexOf('@') == -1)
			 return false;
		len = str.length;
		for (i = 0; i < len; i++)
		{	if (  ( str.charAt(i) < 'a' || str.charAt(i) > 'z' ) && isNaN(str.charAt(i)) )
				  if (str.charAt(i) < 'A' || str.charAt(i) > 'Z')
					   if (str.charAt(i) != '.' && str.charAt(i) != '-' && str.charAt(i) != '_' && str.charAt(i) != '@')
							return false;
		}
	}
	return true;
}	
function trim(value) {
  value = value.replace(/^\s+/,''); 
  value = value.replace(/\s+$/,'');
  return value;
}
function setfocus(a_field_id) {
	var thefield = document.getElementById(a_field_id);
	if(thefield)
	{	thefield.focus();
	}
}
//(key==46) || (key==45) || er uit gehaald .
function numeric(keyP){
	var key;	
	if (document.all) {key = window.event.keyCode;}
	else {key = keyP.which;}	
	if ((key>47 && key<58) || (key < 32 || key==127)) {return true;}
	else {return false;}
}
function floating(keyP){
	var key;	
	if (document.all) {key = window.event.keyCode;}
	else {key = keyP.which;}	
	if ((key>47 && key<58) || (key < 32 || key==127) || (key==46) || (key==44) ) {return true;}
	else {return false;}
}


function fGetSDims () {
	var x, y;
	if (self.pageYOffset) { // all except Explorer
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6/7 Strict Mode
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) { // all other Explorers
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	return [x, y];
}
function scrollto(elementId, hideEl, space_on_top) {
	var coords = findPos(document.getElementById(elementId));
	if(space_on_top > 0)
	{	if((coords[1] - space_on_top) > 0 )
		{	coords[1] = coords[1] - space_on_top;
		}		
	}	
	var dist;
	var coef = 1;
	var y;
	var diff;	
	var slideStep = 30;
    var slideTime = 30;	
	var dimens = fGetSDims();
	y = dimens[1];	
	dist = coords[1] - y;
	if (dist < 0) {
		coef = -1;
	}	
	var timer = setInterval(function () {
		dimens = fGetSDims();
		y = dimens[1];
	
		if ((coords[1] - y)*coef < ((dist*coef)/slideStep)) {
			window.scrollTo(0, coords[1]);
			clearInterval(timer);
			if (hideEl) {
				hideEl.style.display = "none";
			}
		} else {
			window.scrollBy(0, (dist/slideStep));
			dimens = fGetSDims();		
			diff = dimens[1];			
			if (y === diff) { //scroll bottom reached
				clearInterval(timer);
				if (hideEl) {
					hideEl.style.display = "none";
				}
			}
		}
	}, slideTime);
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}
function inarray(arr, str)
{	var gevonden = false;
	for(i in arr)
	{	if (arr[i].toLowerCase() == str.toLowerCase())
		{	gevonden = true;
		}
	}
	return gevonden;
}
function isnumeric(sText)
{	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{	Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
        {	IsNumber = false;
		}
	}
	return IsNumber;
}
function validate_text(sText,ValidChars)
{	var IsOk=true;
	var Char;
	for (i = 0; i < sText.length && IsOk == true; i++) 
	{	Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
        {	IsOk = false;
		}
	}
	return IsOk;
}
function setValue(id, val){
	if (val) {
		var aa = document.getElementById(id);
		aa.value = foRev(val);
	}
}	
function getValue(id){
	var aa = document.getElementById(id);
	return aa.value;
}
function show_div(id)
{	var thediv = document.getElementById(id);
	thediv.style.display="";
}
function hide_div(id)
{	var thediv = document.getElementById(id);	
	thediv.style.display="none";
}

function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

/*--- LOGIN IN HEADER ---*/
function login_onblur_email(language)
{	var fld = document.getElementById("fld_login_email");
	if(fld)
	{	fld.style.background='#FFFFFF';	
		if (fld.value=='') 		
		{	fld.style.background='url(/images_template/login_email_' + language + '.gif) no-repeat #FFFFFF';
		}	
	}			
}		
function login_onblur_password(language)
{	var fld = document.getElementById("fld_login_pass");
	if(fld)
	{	fld.style.background='#FFFFFF';	
		if (fld.value=='') 		
		{	fld.style.background='url(/images_template/login_password_' + language + '.gif) no-repeat #FFFFFF';
		}		
	}		
}
function login_onfocus_email(lang)
{	var fld = document.getElementById("fld_login_email");
	fld.style.background='#FFFFFF';			
}	
function login_onfocus_password(lang)
{	var fld = document.getElementById("fld_login_pass");
	fld.style.background='#FFFFFF';			
}	
function LoginInit(language) {
	login_onblur_email(language);
	login_onblur_password(language);
}

/*--- NAVIGATION ---*/
function setNavClass(section) 
{	if ((section != '') && (section != 'none')) {
		var secid = document.getElementById(section);
		if(secid){
			secid.className = "mactive";
		}
	}
}

/*--- TABS ---*/
function hide_integration_tabs(tabblad_id, tabs_id)
{	var tabblad = document.getElementById(tabblad_id);
	if(tabblad)
	{	tabblad.style.display="none";
	}	
	tabs = document.getElementById(tabs_id);	
	if(tabs)
	{	for (var i=0; i < tabs.childNodes.length; i++ )
		{	tabs.childNodes[i].className= "s_tab_block_button";
		}	
	}
}
function hide_tabs(name, maxnr){
	var el_content;
	var el_button;
	for (i=0; i < maxnr; i++)
	{	el_content = document.getElementById("tab_" + name + "_content_" + (i +1))
		el_button = document.getElementById("tab_" + name + "_button_" + (i +1))
		if(el_content) el_content.style.display="none";
		if(el_button)
		{	if(el_button.className.indexOf("special") > 0)
			{	el_button.className = "s_tab_block_button_special";	
			}
			else
			{	if(el_button.className.indexOf("inactief") > 0)
				{	el_button.className = "s_tab_block_button_inactief";	
				}
				else
				{	el_button.className = "s_tab_block_button";	
				}
			}
		}
	}
}
function show_tab(name, tabnr, maxnr){
	if(!maxnr){
		maxnr = 20;
	}
	hide_tabs(name, maxnr);
	var el_content = document.getElementById("tab_" + name + "_content_" + tabnr);
	var el_button = document.getElementById("tab_" + name + "_button_" + tabnr);	
	if(el_content) el_content.style.display="";		
	if(el_button)
	{	
		if(el_button.className.indexOf("special") > 0)
		{	el_button.className = "s_tab_block_button_special_active";	
		}
		else
		{	if(el_button.className.indexOf("inactief") > 0)
			{	el_button.className = "s_tab_block_button_inactief_active";	
			}
			else
			{	el_button.className = "s_tab_block_button_active";	
			}
		}
	}	
}


/*--- LIGHTBOX ---*/
function ShowLightBox(name, focus_to){											
	//vergeet geen div aan te maken met id edit_block_background	
	var objOverlay = document.getElementById('lightbox_block_background');
	var objLightbox = document.getElementById(name);
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 ) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 ) / 2);
	objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
	if (document.body.scrollWidth > document.body.offsetWidth) // all but Explorer Mac											
	{	x = document.body.scrollWidth;
	}											
	else // Explorer Mac would also work in Explorer 6 Strict, Mozilla and Safari
	{	x = document.body.offsetWidth;
	}
	objOverlay.style.display="";
	objOverlay.style.width = x + "px";
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objLightbox.style.display = "";
	// probeer cursor in focus veld te plaatsen
	if(focus_to != "")
	{	setfocus(focus_to);
	}	
}
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function CloseLightBox(name){
	var thebox = document.getElementById(name);
	thebox.style.display = "none";
	document.getElementById("lightbox_block_background").style.display="none";	
}

/* ------------------------------------ AJAX --------------------------------- */
var ajaxDirectory = "/ajax/";
var errorText = "error";
var generalErrorMessage = "Er heeft zich een fout voorgedaan. Probeer het opnieuw aub."
var noBrowserSupport = "Sorry, uw browser ondersteunt geen AJAX technologie."
var xmlHttp;
var responseText;
var responseXml;
var ajaxasync = true;

// geef de pagina (met parameters die uitgevoerd moet worden) en de js functie die na de call moet uitgevoerd worden
function fdoAjaxPostText(page, funcname)
{	fdoAjax(page, funcname,"text", "post")
}
function fdoAjaxText(page, funcname)
{	fdoAjax(page, funcname,"text", "get")
}
function fdoAjaxXml(page, funcname)
{	fdoAjax(page, funcname,"xml", "get");	
}
function fdoAjax(pagina, funcname,method, post_or_get) 
{	responseText = '';
	responseXml = '';
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert (noBrowserSupport);
		return;
	}	
	if(post_or_get=="get")
	{	var url=ajaxDirectory + pagina+"&sid="+Math.random();		
		xmlHttp.onreadystatechange=Function("fEndAjax(" + funcname + ",'"+ method+"')");
		xmlHttp.open("GET",url,ajaxasync);
		xmlHttp.send(null);
	}
	else
	{	var url= ajaxDirectory + pagina.split("?")[0];
		var query= pagina.split("?")[1];
		xmlHttp.open("POST", url, true);		
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", query.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange = Function("fEndAjax(" + funcname + ",'"+ method+"')");
		xmlHttp.send(query);
	}
}
function fEndAjax(funcname,method)
{	document.body.style.cursor = 'wait';
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 
	{ 	if(xmlHttp.status != '200')
		{	alert(xmlHttp.status + "-" + xmlHttp.responseText);
		}
		if (xmlHttp.status == '200')
		{	if (method=="text")
			{	if (xmlHttp.responseText != errorText) 
				{	responseText= xmlHttp.responseText;
					funcname();
				}
				else 
				{	alert(generalErrorMessage + " (code 1)")					
				}
			} 
			else 
			{	if (xmlHttp.responseText != errorText) 
				{	// processed OK
					if (window.ActiveXObject)
					{	responseXml=new ActiveXObject("Microsoft.XMLDOM");
					}
					// code for Mozilla, Firefox, Opera, etc.
					else if (document.implementation && document.implementation.createDocument)
					{	responseXml=document.implementation.createDocument("","",null);
					}					
					responseXml = xmlHttp.responseXML;
					funcname();
				} else { //an error occurred
					alert(generalErrorMessage + " (code 2)")
				}			
			}
		} 
		else 
		{	alert(generalErrorMessage + " (code 3)")
		}
	}	
	document.body.style.cursor = 'default';
}
function GetXmlHttpObject() { 
	var objXMLHttp=null
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
function fillbox(box, list){
	var rec	= list.split("-|-");
	var ret = "";
	box.options.length = 0;
	for (i in rec){
		if (rec[i]!=''){
			var dd = rec[i].split('-,-')[0].indexOf('*');
			var ee = dd != -1 ? true:false;
			box[i] = new Option(rec[i].split('-,-')[1], rec[i].split('-,-')[0].replace('*', ''),false,ee);
			if (ee) {ret = rec[i].split('-,-')[0].replace('*', '');}
		}
	}
	return ret;	
}
function URLencode(sStr) {
    return escape(sStr).
             replace(/\+/g, '%2B').
                replace(/\"/g,'%22').
                   replace(/\'/g, '%27').
                     replace(/\//g,'%2F');
}
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	var str = ""
	
	str = objImage.src;
	if(str.indexOf('?x=') > 0)
	{	str = str.split('?x=')[0];
	}
	if(str.indexOf('&x=') > 0)
	{	str = str.split('&x=')[0];
	}	
	if(objImage.src.indexOf('?') > 0)
	{	str += '&x=' + now.toUTCString();	
	}
	else
	{	str += '?x=' + now.toUTCString();	
	}
	objImage.src = str;
}

/* --- Macromedia --- */
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}


function next_div(name_prefix, divs, curnrfieldid)
{	curnrfield = document.getElementById(curnrfieldid);	
	if(curnrfield)
	{	curnr = curnrfield.innerHTML ;
		curnr++;
		if(curnr > divs)
		{	curnr = 1;
		}	
		for (i=1; i<=divs; i++)
		{	hide_div(name_prefix + "_" + i);
		}
		show_div(name_prefix + "_" + curnr);		
		curnrfield.innerHTML=curnr;
	}
}

function prev_div(name_prefix, divs, curnrfieldid)
{	curnrfield = document.getElementById(curnrfieldid);	
	if(curnrfield)
	{	curnr = curnrfield.innerHTML;
		curnr--;
		if(curnr < 1)
		{	curnr = divs;
		}
		for (i=1; i<=divs; i++)
		{	hide_div(name_prefix + "_" + i);
		}
		show_div(name_prefix + "_" + curnr);	
		curnrfield.innerHTML=curnr;
	}
}
function isEmpty() {
	//test if ANY ONE of a series of values (in the args) is empty and return true if so.
	for (var i=0; i<isEmpty.arguments.length; i++) {
		if (isEmpty.arguments[i] == '')
			return true;
	}
	return false;
}
function isEmail(str) {
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  if (!reg1.test(str) && reg2.test(str)) { // syntax is valid
    return true;
  }
  return false;
}
function noSelection(fld) {
	//tests if the value of a SELECT selection = empty string and returns true if it is
	if(fld[fld.selectedIndex].value == '')
		return true;
	else
		return false;
}
function no0Selection(fld) {
	//tests if the value of a SELECT selection = empty string and returns true if it is
	if(fld[fld.selectedIndex].value == '0')
		return true;
	else
		return false;
}
function noRadioChecked(fldlist) {
	//test if, for a list of radio button groups, none of the radio buttons in ANY ONE or the list have been checked and if so, return true, otherwise, return false
	var noCheck;
	for (var i=0; i<noRadioChecked.arguments.length; i++) {
		fld = noRadioChecked.arguments[i]
		noCheck = true;
		for (var j = 0; j < fld.length ; j++) {
			if(fld[j].checked) {
				noCheck = false }
		}
		if (noCheck)
			return true; // no radio btn was checked in the current group
	}
	return false; // if no unchecked group has been found
}
function radio_checked(fld)
{	var selectedval = "";
	for (var i=0; i < fld.length; i++)
	{	if (fld[i].checked)
		{	 return fld[i].value;			
		}
	}	
	return "";
}
function radio_set_checked(radioObj, newValue) 
{	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
function to_integer(fld) {
	var strnum = fld.value;
	len = strnum.length;
	var newstrnum = '';
	for (i = 0; i < len; i++)
	{	if (strnum.charAt(i) != '.' && strnum.charAt(i) != ',' && strnum.charAt(i) != ' ')
		{ newstrnum = newstrnum + strnum.charAt(i); }
	}
	len = newstrnum.length;
    for (i = 0; i < len; i++)
	{ 	if (newstrnum.charAt(i) < '0' || newstrnum.charAt(i) > '9')
		{	fld.value = '';				  
			alert('Vul een geldige getalwaarde in aub');
			return false;
			break;
		}
	}
	fld.value = newstrnum;
	return true;
}