function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

var scrollerSpeed=6;
var pauseScroller=1;

// Change nothing below!
scrollerSpeed=(document.all)? scrollerSpeed : Math.max(1, scrollerSpeed-1); //slow speed down by 1 for NS
var copySpeed = scrollerSpeed;
var scroller, prevbut,nextbut, scrollerWidth;
var pauseSpeed=(pauseScroller==0)? copySpeed: 0;

function dynamic_nav() {
	prevbut = document.getElementById("prevSubcats");
	nextbut = document.getElementById("moreSubcats");
	scroller = document.getElementById("dynnav");
	if (prevbut && nextbut && scroller) {
		prevbut.onclick = function () {
			return false;
		}
		prevbut.onmouseover = function () {
			leftTimeUp=setInterval('scrollLeft()',20);
		}
		prevbut.onmouseout = function () {
			clearTimeout(leftTimeUp);
		}
	
		nextbut.onclick = function () {
			return false;
		}
		nextbut.onmouseover = function () {
			leftTimeDown=setInterval('scrollRight()',20);
		}
		nextbut.onmouseout = function () {
			clearTimeout(leftTimeDown);
		}
		
		scrollerWidth = scroller.offsetWidth;
		scroller.style.left="0px";
	}	
}

function scrollLeft(){
	scrollerWidth=scroller.offsetWidth; // nodig voor Safari
	if (parseInt(scroller.style.left) < 0) {
		scroller.style.left=parseInt(scroller.style.left)+copySpeed+"px"
		nextbut.style.display = "block";
	}		
	else {
		prevbut.style.display = "none";	
	}
}

function scrollRight(){
	if (parseInt(scroller.style.left) > (scrollerWidth*(-1)+640)) {
		scroller.style.left=parseInt(scroller.style.left)-copySpeed+"px"
		prevbut.style.display = "block";
	}
	else {
		nextbut.style.display = "none";
	}
	
}

function forms() {
	var frm = document.quellebanqueform;
	if (frm) {
		var sel = frm.banque;
		if (sel) {
			sel.onchange = function() {
				searchPackage(1,this.value,document.quellebanqueform.this_language.value);
			}
		}
		var bg = frm.banquegroup;
		if (bg) {
			bg.onchange = function() {
				searchBanque(1,this.value,document.quellebanqueform.this_language.value,document.quellebanqueform.zip.value,document.quellebanqueform.origin.value);
			}
		}
		var zip = frm.zip;
		var city = frm.city;
		if (zip && city) {
			zip.onchange = function() {
				searchCities(this.value);
			}
			zip.onclick = function() {
				searchCities(this.value);	
			}
		}
		var hasjavascript = frm.hasJavascript;
		if (hasjavascript) {
			frm.hasJavascript.value = "Y";
		}
	}
	var waitdiv = document.getElementById("waitforresult");
	if (waitdiv) {
		setTimeout('showWaitDiv()', 4000);
	}
}

function showWaitDiv() {
	var waitdiv = document.getElementById("waitforresult");
	if (waitdiv) {
		waitdiv.style.display = "none";
	}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
	  // Internet Explorer
	  try {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	  catch (e) {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	}
	return xmlHttp;
}

function addCity(id, naam) {
	var theForm = document.quellebanqueform;
	var newIndex = theForm.city.options.length;
	theForm.city.options[newIndex]= new Option(naam, id,false,false);
}

function CitiesSearched() {
	var theForm = document.quellebanqueform;
	while (theForm.city.options.length > 1) {
		theForm.city.options[(theForm.city.options.length - 1)] = null;
	}
 	var splitter;
	if (xmlHttp5.readyState == 4) {
		var lines = xmlHttp5.responseText.split("\n");
		for(i=0; i < lines.length - 1; i++) {
			splitter = lines[i].split("|");
			addCity(splitter[0], splitter[1]);
		}
   }
}

function searchCities(str) {
	xmlHttp5=GetXmlHttpObject();
	if (xmlHttp5==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	if (xmlHttp5.readyState == 4 || xmlHttp5.readyState == 0) {
		if(str.length >= 5) {
			xmlHttp5.onreadystatechange = CitiesSearched; 
			xmlHttp5.open("GET", "/inc/searchCities.dhtml?str=" + str , true);
			xmlHttp5.send(null);
		}
		else {
			var theForm = document.quellebanqueform;
			while (theForm.city.options.length > 1) {
				theForm.city.options[(theForm.city.options.length - 1)] = null;
			}		
		}
	}		
}

function addPackage(id, naam) {
	var theForm = document.quellebanqueform;
	var newIndex = theForm.pack.options.length;
	theForm.pack.options[newIndex]= new Option(naam, id,false,false);
}

function PackageSearched() {
	var theForm = document.quellebanqueform;
	while (theForm.pack.options.length > 0) {
		theForm.pack.options[(theForm.pack.options.length - 1)] = null;
	}
	theForm.pack.options[0]= new Option("", "", true, true);
 	var splitter;
	if (xmlHttp4.readyState == 4) {
		var lines = xmlHttp4.responseText.split("\n");
		for(i=0; i < lines.length - 1; i++) {
			splitter = lines[i].split("|");
			addPackage(splitter[0], splitter[1]);
		}
   }
}

var xmlHttp4;
function searchPackage(startingAt,str,lang) {
	xmlHttp4=GetXmlHttpObject();
	if (xmlHttp4==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	if (xmlHttp4.readyState == 4 || xmlHttp4.readyState == 0) {
		if(str.length >= startingAt) {
			xmlHttp4.onreadystatechange = PackageSearched; 
			xmlHttp4.open("GET", "/inc/searchPackage.dhtml?str=" + str  + ",content_language=" + lang , true);
			xmlHttp4.send(null);
		}
		else {
			var theForm = document.quellebanqueform;
			while (theForm.pack.options.length > 0) {
				theForm.pack.options[(theForm.pack.options.length - 1)] = null;
			}
		}
	}		
}

function addBanque(id, naam,check) {
	var theForm = document.quellebanqueform;
	var newIndex = theForm.banque.options.length;
	if (check == "false") {
		theForm.banque.options[newIndex]= new Option(naam, id,false,false);
	}
	else {
		theForm.banque.options[newIndex]= new Option(naam, id,true,true);
	}
}

function BanqueSearched() {
	var theForm = document.quellebanqueform;
	while (theForm.pack.options.length > 0) {
		theForm.pack.options[(theForm.pack.options.length - 1)] = null;
	}
	while (theForm.banque.options.length > 0) {
		theForm.banque.options[(theForm.banque.options.length - 1)] = null;
	}
 	var splitter;
	if (xmlHttp5.readyState == 4) {
		var lines = xmlHttp5.responseText.split("\n");
		if (lines.length > 2) {
			theForm.banque.options[0]= new Option("", "", true, true);
		}
		for(i=0; i < lines.length - 1; i++) {
			splitter = lines[i].split("|");
			addBanque(splitter[0], splitter[1],splitter[2]);
		}
		if (lines.length == 2) {
			document.getElementById("banquediv").style.display = "none";
		}
		else {
			document.getElementById("banquediv").style.display = "block";
		}
		searchPackage(1,theForm.banque.value,theForm.this_language.value);
   }
}

var xmlHttp5;
function searchBanque(startingAt,str,lang,zip,origin) {
	xmlHttp5=GetXmlHttpObject();
	if (xmlHttp5==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	if (xmlHttp5.readyState == 5 || xmlHttp5.readyState == 0) {
		if(str.length >= startingAt) {
			xmlHttp5.onreadystatechange = BanqueSearched; 
			xmlHttp5.open("GET", "/inc/searchBanque.dhtml?str=" + str  + ",content_language=" + lang + ",zip=" + zip + ",origin=" + origin, true);
			xmlHttp5.send(null);
		}
		else {
			var theForm = document.quellebanqueform;
			while (theForm.pack.options.length > 0) {
				theForm.pack.options[(theForm.pack.options.length - 1)] = null;
			}
			while (theForm.banque.options.length > 0) {
				theForm.banque.options[(theForm.banque.options.length - 1)] = null;
			}
		}
	}		
}

addLoadEvent(forms);
addLoadEvent(dynamic_nav);

var simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

function simpleEncode(valueArray,maxValue) {

var chartData = ['s:'];
  for (var i = 0; i < valueArray.length; i++) {
    var currentValue = valueArray[i];
    if (!isNaN(currentValue) && currentValue >= 0) {
    chartData.push(simpleEncoding.charAt(Math.round((simpleEncoding.length-1) * currentValue / maxValue)));
    }
      else {
      chartData.push('_');
      }
  }
return chartData.join('');
}

/*********** banners ***************/

function rotate() {
	var banner = document.getElementById("partenaires");
	if(banner) {
		banner.innerHTML = banners_array[curr_banner];
	}
}

function ticker() {
	if(curr_banner >= banners_array.length) {
		curr_banner = 0;
	}
	rotate();
	curr_banner++;

	setTimeout("ticker()", 5600);
}

var curr_banner = 1;

function banners() {
	var banner = document.getElementById("partenaires");
	if (banner && banners_array.length > 0) {
		setTimeout("ticker()",5600);
	}
}
