// JavaScript Document


/* STANDARD JS FUNCTIONS =============================================================================== */
function lengthWarn(obj,inf,msg){
	num = obj.value.length; 
	if(num>150){ 
		alert(msg); 
		obj.value = obj.value.substr(0,150); 
		num=150;
	} 
	inf.innerHTML = 150-num;
}

function properRound(n){
	n=String(n); n = n.replace(',','.').replace('%',''); n = Number(n);
	n = n*100; n = Math.round(n); n = n/100; 
	n=String(n); a = n.split('.');
	if(a.length == 2){if (a[1].length == 1){ n = n+'0';	}
	}else{n = n+'.00';}
	return n;
}

function startclock(){
	var thetime=new Date();
	var hours=thetime.getHours(); var mins=thetime.getMinutes();
	var month=thetime.getMonth(); var day=thetime.getDate(); var year=thetime.getYear();
	if (mins<10){ mins="0"+mins; } month+=1; if (month<10){ month="0"+month; }
	document.getElementById('uur_einddatum').value=day+"/"+month+"/"+year+" "+hours+":"+mins;
	setTimeout('startclock()',10000);
} 
			
			
// the money function ------------------------------------------		
function money(Mnum){
	Mnum = Math.round(Mnum*100)/100;
	Mnum = ''+Mnum+'';
	if(Mnum == '' || Mnum == '0') { Mnum = '0,00'; }else{
		Mafter = Mnum.split('.'); 
		MCount = Mafter.length
		if(MCount == 2){
			Mlength = Mafter[1].length;
			if (Mlength == 1){
				Mnum = Mnum+'0';	
			}
		}else{
			Mnum = Mnum+'.00';
		}
		Mnum = Mnum.replace('.',',');
	}
	return Mnum;
}
 // end money function ------------------------------------------


function getSelectedRadio(buttonGroup) {
   if (buttonGroup[0]) {
      for (var i=0; i<buttonGroup.length; i++) { //>
         if (buttonGroup[i].checked) {
            return i
         }
      }
   }else{
      if (buttonGroup.checked) { return 0; }
   }
   return -1;
}

function getSelectedRadioValue(buttonGroup) {
   var i = getSelectedRadio(buttonGroup);
   if (i==-1) { return ''; }else{
      if (buttonGroup[i]){
         return buttonGroup[i].value;
      } else {
         return buttonGroup.value;
      }
   }
}

 
function replaceAll(strText, strTarget, strSubString){
	var intIndexOfMatch = strText.indexOf( strTarget );
	while (intIndexOfMatch != -1){
		strText = strText.replace( strTarget, strSubString )
		intIndexOfMatch = strText.indexOf( strTarget );
	}
	return( strText );
}


function urlencode(str) {
	str = escape(str);
	str = replaceAll(str,'+', '%2B');
	str = replaceAll(str,'%20', '+');
	str = replaceAll(str,'*', '%2A');
	str = replaceAll(str,'/', '%2F');
	str = replaceAll(str,'@', '%40');
	return str;
}

function safeFilename(string){
	string = replaceAll(string,' ', '-');
	string = replaceAll(string,'&amp;', '-');
	string = replaceAll(string,'&', '');
	string = replaceAll(string,'\'', '');
	string = replaceAll(string,'"', '');
	string = replaceAll(string,':', '');
	string = replaceAll(string,'?', '');
	string = replaceAll(string,'/', '');
	string = replaceAll(string,'\\', '');
	string = replaceAll(string,';', '');
	string = replaceAll(string,'#', '');
	string = replaceAll(string,'$', '');
	string = replaceAll(string,'%', '');
	string = replaceAll(string,'@', '');
	string = replaceAll(string,',', '');
	return (string);
} 


function LoadScript(url){
   	var e = document.createElement("script"); 
  	e.type="text/javascript";
   	e.src = url;
   	document.getElementsByTagName("body")[0].appendChild(e); 
}


function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		var relvalue = anchor.getAttribute("rel");
		if (anchor.getAttribute("href")) {
			var external = /external/;
			var relvalue = anchor.getAttribute("rel");
			if (external.test(relvalue)) { anchor.target = "_blank"; }
		}
	}
}
window.onload = externalLinks;

/*
function silentErrorHandler() {return true;}
window.onerror=silentErrorHandler;
*/

/* function for editing CSS tags on the fly */
function addCSStag(tag,content,myCSS){
	if(myCSS.cssRules){ var IECSS=false; }else{ var IECSS=true; }
	if(IECSS){
		myCSS.addRule(tag, content);
	}else{
		var newRule = tag + '{' + content + ';}';
		var newIndex = myCSS.cssRules.length;
		myCSS.insertRule(newRule,newIndex); 
	}
}

/* helper tools for screen sizes */
function getBrowserWidth(){
	if (window.innerWidth){ return window.innerWidth-20;}else
	if (document.documentElement && document.documentElement.clientWidth != 0){return document.documentElement.clientWidth;}else
	if (document.body){return document.body.clientWidth;}
	return 0;
}
function getBrowserHeight(){
	if (window.innerHeight){ return window.innerHeight;}else
	if (document.documentElement && document.documentElement.clientHeight != 0){return document.documentElement.clientHeight;}else
	if (document.body){return document.body.clientHeight;}
	return 0;
}
function getScrollPosition() {
	return filter (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function filter(vwin, vdocel, vbody) {
	var vresult = vwin ? vwin : 0;
	if (vdocel && (!vresult || (vresult > vdocel)))
		vresult = vdocel;
	return vbody && (!vresult || (vresult > vbody)) ? vbody : vresult;
}

function overlay(contentW,contentH,contentHTML){
	var shader = document.getElementById('overlayFade');
	var content = document.getElementById('overlayContent');
	
	if(content.style.display=='none' && contentW && contentH && contentHTML){
		addCSStag('html','overflow:hidden',document.styleSheets[2]);
		
		var offsetY = getScrollPosition(); var docY = getBrowserHeight();
		if(docY>contentH){ var contentOffset = offsetY + Math.round((docY-contentH)/2); }else{ var contentOffset = offsetY+10; }
		content.style.top=contentOffset+'px';
		
		content.innerHTML = contentHTML;
		content.style.width=contentW+'px';
		content.style.height=contentH+'px';
		content.style.marginLeft='-'+(Number(contentW)/2)+'px';
		
		content.style.display='block';
		shader.style.display ='block';
	}else{
		$("#overlayFade").fadeOut(1000,function(){
			content.innerHTML='';	
			addCSStag('html','overflow:auto',document.styleSheets[2]);
		});
		$("#overlayContent").fadeOut(1000);
	}
}

// escape key handeler
function keyPressHandler(e) {
      var kC  = (window.event) ?    // MSIE or Firefox?
                 event.keyCode : e.keyCode;
      var Esc = (window.event) ?   
                27 : e.DOM_VK_ESCAPE // MSIE : Firefox
      if(kC==Esc){
         
		 if(document.getElementById('overlayFade')){
			 if(document.getElementById('overlayFade').style.display=='block'){
			 	overlay();
			 }
		 }
	  }
   }
 
if(window.addEventListener){ window.addEventListener('onkeypress', keyPressHandler, false);}
window.onkeypress = document.onkeypress = keyPressHandler;

/* STANDARD JS FUNCTIONS =============================================================================== */


/* CMS JS FUNCTIONS =============================================================================== */
function showHideCMSMenuHolder(){
	if(Number(document.getElementById('cmsMenusHolder').style.top.replace('px',''))<0){
		$('#cmsMenusHolder').animate({'top': '37px'}, 1000,
			function(){ 
				if(document.getElementById('cmsInnerMenuHolder')){document.getElementById('cmsInnerMenuHolder').style.overflow='auto';}
				if(document.getElementById('cmsInnerSubHolder')){document.getElementById('cmsInnerSubHolder').style.overflow='auto';}
				if(document.getElementById('cmsInnerSubsubHolder')){document.getElementById('cmsInnerSubsubHolder').style.overflow='auto';}
			} );
	}else{
		if(document.getElementById('cmsInnerMenuHolder')){ document.getElementById('cmsInnerMenuHolder').style.overflow='hidden';}
		if(document.getElementById('cmsInnerSubHolder')){ document.getElementById('cmsInnerSubHolder').style.overflow='hidden'; }
		if(document.getElementById('cmsInnerSubsubHolder')){document.getElementById('cmsInnerSubsubHolder').style.overflow='hidden';}
		$('#cmsMenusHolder').animate({'top': '-369px'}, 1000);
	}
}

function deleteMenu(id,msg,x){
	if(confirm(msg)){
		window.location = '?dm='+id+x;
	}
}
/* CMS JS FUNCTIONS =============================================================================== */







