var agt = navigator.userAgent.toLowerCase();

window.onload = function(){
/*
Silas 160409:
code modified to allow dynamic selection of start tab
*/
	//var etalageTab = 1;
	//if(parseInt("") == 2
	//|| parseInt("") == 3){
	//	etalageTab = parseInt("");
	//}
	
	//etalage_init(etalageTab, true);		// use False for no animation
	////etalage_init(1, true);		// use False for no animation

	loadEtalage();	//silas - calls INLINE javascript so I can use scriptvars:
/*
End Silas 160409:
*/

	// Tools: lijkt niet meer nodig! initDocSpace();
	dynamicSelect("doelgroep", "categorie", null);
	if (getCookie('runOnlyOnce') != '1221558815487')
	{
		if (typeof popup_msg != 'undefined' && popup_msg != '')
		{
			setCookie('runOnlyOnce', '1221558815487');
			alert(popup_msg);
		}
	}
	if (typeof popup_focus != 'undefined' && popup_focus != '')
		popup_focus.focus();
		
	menu_init();

	// Tools: the line below makes sure that for IE6  the top element is shown?!: somehow an extra space is created and setting this in CSS does not suffy
	document.getElementById("top").style.overflow="hidden";
}

// 	Tools Changed: support of 2 combo's instead of 3
//
function dynamicSelect(id1, id2, id3) {
	// Browser and feature tests to see if there is enough W3C DOM support
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_mac = (agt.indexOf("mac") != -1);
	if (!(is_ie && is_mac) && document.getElementById && document.getElementsByTagName) {
		// Obtain references to both select boxes
		var sel1 = document.getElementById(id1);

		var sel2 = document.getElementById(id2);
		var div_sel2  = sel2.parentNode;
		div_sel2.style.display = 'none';
		var clone = sel2.cloneNode(true);

		var sel3 = null;
		if (id3) {
			sel3 = document.getElementById(id3);
			var div_sel3  = sel3.parentNode;
			div_sel3.style.display = 'none';
			var clone3 = sel3.cloneNode(true);
			var clonedOptions3 = clone3.getElementsByTagName("option");
		}
		var clonedOptions = clone.getElementsByTagName("option");
		// Onload init: call a generic function to display the related options in the dynamic select box
		refreshDynamicSelectOptions(sel1, sel2, sel3,clonedOptions, clonedOptions3 );
		// Onchange of the main select box: call a generic function to display the related options in the dynamic select box
		sel1.onchange = function() {
			refreshDynamicSelectOptions(sel1, sel2, sel3, clonedOptions);
			div_sel2.style.display = 'block';
		};
		if (id3) {
			sel2.onchange = function() {
				refreshDynamicSelectOptions2(sel1, sel2, sel3,  clonedOptions3 );
				div_sel3.style.display = 'block';
			};
		}
	}
}
// Delete all options of the dynamic select box
//
function refreshDynamicSelectOptions(sel1, sel2, sel3, clonedOptions ) {
	
	
	while (sel2.options.length) {
		sel2.remove(0);
	}
	if (sel3) {
		while (sel3.options.length) {
			sel3.remove(0);
		}
	}

	// Create regular expression objects for "select" and the value of the selected option of the main select box as class names
	var pattern1 = /( |^)(select)( |$)/;
	var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
	// Iterate through all cloned options
	for (var i = 0; i < clonedOptions.length; i++) {
		// If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box
		if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {
			// Clone the option from the hidden option pool and append it to the dynamic select box
			sel2.appendChild(clonedOptions[i].cloneNode(true));
		}
	}
}

// Tools: kan weg!
// afstemmen lijst3 op lijst2
function refreshDynamicSelectOptions2(sel1, sel2, sel3, clonedOptions3 ) {
	
	// Delete all options of the dynamic select box
	//alert(clonedOptions3.length);
	while (sel3.options.length) {
		sel3.remove(0);
	}
	
	// Create regular expression objects for "select" and the value of the selected option of the main select box as class names
	var pattern1 = /( |^)(select)( |$)/;
	var pattern2 = new RegExp("( |^)(" + sel2.options[sel2.selectedIndex].value + ")( |$)");
	// Iterate through all cloned options
	for (var i = 0; i < clonedOptions3.length; i++) 
	{
		// If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box
		if (clonedOptions3[i].className.match(pattern1) || clonedOptions3[i].className.match(pattern2)) 
		{
			// Clone the option from the hidden option pool and append it to the dynamic select box
			sel3.appendChild(clonedOptions3[i].cloneNode(true));
		}
	}
}