/* Utility functions */
function addEvent(obj, evType, fn, useCapture) { // By Scott Andrew
 if (obj.addEventListener) { obj.addEventListener(evType, fn, useCapture); return true; }
 else if (obj.attachEvent) { var r = obj.attachEvent('on' + evType, fn); return r; }
 else { obj['on' + evType] = fn; }
 return void(0);
}
// call it like this
//addEvent(window, 'load', scrollInit, false);
function element(id) {
	var e = false;
	if (document.getElementById) { e = document.getElementById(id); }
	else if (document.all) { e = document.all(id); }
	return e;
}
function displayValue() {
  var returnvalue = 'table';
  var offset = navigator.userAgent.indexOf('MSIE');
  if (offset != -1) { returnvalue = 'block';}
  return returnvalue;
}
function checkAfleveradres() {
	var radioparent = element('afleveradres');
	var subform = element('afleverform');
	if(radioparent){
		var radios = radioparent.getElementsByTagName('input');
		if(radios){
			for(var i=0; i<radios.length; i++){
				var radio = radios[i];
				radio.onclick = function(){
					if(this.checked != false && this.value == 'anders'){
						subform.style.display = 'block';
					} else {
						subform.style.display = 'none';
					}
				}
			}
		}
	}
	return void(0);
}
function checkCondition(formid) {
	var form = element(formid);
	var check = element('akkoord');
	if(check){
		if(check.checked == false) {
			alert('U bent niet akkoord met de algemene leveringsvoorwaarden');
			//check.className = 'error';
			check.parentNode.style.backgroundColor = '#ff3333';
			return false;
		} else {
			//check.className = '';
			check.parentNode.style.backgroundColor = 'transparent';
			if(form) form.submit();
		}
	}
	return false;
}
// login
function toPassword(objOldInput) {
	var objNewElement = document.createElement('input');
	objNewElement.setAttribute('type', 'password');
	objNewElement.setAttribute('name', objOldInput.name);
	objOldInput.parentNode.replaceChild(objNewElement, objOldInput);
	toPassword.el = objNewElement;
	setTimeout('toPassword.el.focus()',100);
	return true;
}
// menu.js
function hasULchildren(linode) {
	var uls = linode.getElementsByTagName('ul')[0];
	if(uls) return true;
	return false;
}
function efMenu(menuid, menutype) {
	var menudiv = element(menuid);
	var listitems = menudiv.getElementsByTagName('li');
	if(listitems){
		for(var i=0; i<listitems.length; i++){
			var listitem = listitems[i];
			if(hasULchildren(listitem)) {
				listitem.onmouseover = function (e) {
					if (this.firstChild.nodeName.toUpperCase() == 'A') {
						if(this.firstChild.className.indexOf('active') != -1) { this.firstChild.className = 'active mouse'; }
						else { this.firstChild.className = 'mouse'; }
					}
					for (var i=0; i < this.childNodes.length; i++) {
						var child = this.childNodes[i];
						if (child.nodeName.toUpperCase() == 'UL') {child.style.visibility = 'visible'; }
					}
					return false;
				};
				// onmouseout function
				listitem.onmouseout = function (e) {
					for (var i=0; i < this.childNodes.length; i++) {
						var child = this.childNodes[i];
						if (child.nodeName.toUpperCase() == 'UL') {	child.style.visibility = 'hidden';}
					}
					if (this.firstChild.nodeName.toUpperCase() == 'A') {
						if(this.firstChild.className.indexOf('active') != -1) { this.firstChild.className = 'active'; }
						else { this.firstChild.className = ''; }
					}
					return false;
				};
			}
		}
	}
	return void(0);
}

function changePage(id){
	var val='';
	var selectbox = element(id);
	if (selectbox) { val = selectbox.options[selectbox.selectedIndex].value; }
	if (val != '') { document.location = val; }
}

function foldCatList(){
	var catList = element('categories');
	if(catList) {
		var catBoxen = catList.getElementsByTagName('H2');
		if(catBoxen){
			for(var i=0; i<catBoxen.length; i++){
				var catBox = catBoxen[i];
				catBox.onclick = function(){
					if(this.firstChild.className == 'active') this.firstChild.className = 'inactive';
					else this.firstChild.className = 'active';
					if(this.nextSibling){
						if(this.nextSibling.style.display == 'none') this.nextSibling.style.display = 'block';
						else this.nextSibling.style.display = 'none';
					}
					return false;
				}
			}
		}
	}
	return false;
}

function accordion(){
	$("#accordionHintsmenu dd:not(:last)").hide();
	$("#accordionHintsmenu dt:last").css('background', 'url(/skins/default/pics/bgHints-a.gif) no-repeat 0 100%');
	$("#accordionHintsmenu dt a").each(function(){
		$(this).css('cursor', 'pointer');
	});
	$("#accordionHintsmenu dt a").click(function(){
		if($(this).parent().hasClass("lastNode")) {
			$(this).parent().css('background', 'url(/skins/default/pics/bgHintsEnd-a.gif) no-repeat 0 100%');
		} else {
			$(this).parent().css('background', 'url(/skins/default/pics/bgHints-a.gif) no-repeat 0 100%');
		}
		if($(this).parent().prev().is(":hidden")) {
			var parentprev = $(this).parent().prev();
			$("#accordionHintsmenu dd:visible").slideUp(300);
			if($("#accordionHintsmenu dd:visible").next().hasClass("lastNode")) {
				$("#accordionHintsmenu dd:visible").next().css('background', 'url(/skins/default/pics/bgHintsEnd2.gif) no-repeat 0 100%');
			} else {
				$("#accordionHintsmenu dd:visible").next().css('background', 'url(/skins/default/pics/bgHints2.gif) no-repeat 0 100%');
			}
			parentprev.slideDown(300); 
		} 
		return false;
	});
}
function targetMenu(state){
	$("#DoelgroepenmenuBox ul ul").hide();
	if(state=='on'){
		$("#DoelgroepenmenuBox ul ul:first").show();
		$("#DoelgroepenmenuBox ul a:first").attr('class','ef_ta active');
	}
	$("#DoelgroepenmenuBox ul a.ef_ta").css('cursor','pointer');
	$("#DoelgroepenmenuBox ul a.ef_ta").click(function(){
		$("#DoelgroepenmenuBox ul ul").hide();
		//$("#DoelgroepenmenuBox ul a").removeAttr('class');
		$("#DoelgroepenmenuBox ul a.ef_ta").attr('class','ef_ta');
		$(this).next().show('normal');
		$(this).attr('class','ef_ta active');
		$(this).next().mouseover(function(){ 
			$(this).prev().attr('class','ef_ta active');
			$(this).show(); 
		});
		return false;
	});
	if(state!='on'){
		$("#content").click(function(){
			$("#DoelgroepenmenuBox ul ul").hide();
			$("#DoelgroepenmenuBox ul a.ef_ta").attr('class','ef_ta');
		});
	}	
}

addEvent(window, 'load', foldCatList, false);
