/* Benodigde functies voor redirect module */
function redirect() {
	popup ('/admin/redirect/index.php', 'mkb');
}
top.window.popupRedirect = function () {
	popup ('/admin/redirect/index.php');
}
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var popupscherm=0;
function popup (filename, fileid, width, height, scrollbars, resizable, menubar, toolbar, status, location) {
	if (popupscherm && ! popupscherm.closed) popupscherm.close();
	if (!filename || filename=="")    filename="http://www.mkbkeurmerk.nl";
	if (!fileid || fileid=="")     fileid="mkbkeurmerk";
	if (!width || width=="")     width="600";
	if (!height || height=="")     height="500";
	popupscherm=0;
	var args = "height="+height+",width="+width+",scrollbars=no,resizable=no,menubar=no,toolbar=no,status=no,location=no";
	popupscherm = open(filename, fileid, args);
	if (!InternetExplorer)       popupscherm.focus();
 }


/* Sets the maxlength of a textarea */
function isMaxlength(obj) {
	var mlength = obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength)
		obj.value=obj.value.substring(0,mlength)
}

/* Add a url input field (with a maximum of 5) to the company subscription form */
function addUrl() {
	var container = document.getElementById('extradomeinen');
	if (typeof container == "object") {
		var alleUrls = new Array();
		var alleUrls = nodes.childNodesBy(container,'tagName=INPUT');
		if (typeof alleUrls == "object") {
			var aantalUrls = alleUrls.length;
			if (aantalUrls > 3) {
				alert('U mag maximaal 5 website adressen toevoegen.');
				return false;
			}
		}
		container.innerHTML +="<input type=\"text\" name=\"extrawebsites[]\" errormsg=\"U bent vergeten om het extra website adres in te vullen.\" errormsgtype=\"alert\" validationrules=\"checkNotEmpty(oElement)___verplicht veld&#9;\"><br>";
		setHeights();
	}
}

function initLinks() {
	// plaats een klein icoontje achter een externe link en achter links die naar bestanden wijzen
	// standaard: http://, ftp://, mailto:, doc, xls, pdf
	
	// de icoontjes staan in de dir css/images/
	// en hebben de zelfde naam als de extensie
	// doc => /images/icons/doc.gif
	
	// voeg eventueel extra types (bestandsextenties toe)
	tagAhref.setType('docx');
	tagAhref.setType('xlsx');
	
	// plaats het icoontje links, ipv rechts
	tagAhref.left = true;
	
	// plaats het icoontje boven ipv onder
	tagAhref.top = 'top';
	
	// start met het toevoegen van icoontjes
	// geef eventueel een rootnode op, bijvoorbeeld tagAhref.init('maintable');
	tagAhref.init('maintable');
}


/**	Klap het menu op de vervolgpagina open of dicht **/
	function toggleMenu(handle,e) {
		e = e || window.event;
		if (e)
			var target= e.srcElement || e.target;
		if (target)
			var objectid = target.id;
		var handle = 'close';
		var parentid = 'main';
		
		if (target.parentNode.id)
			var parentid = target.parentNode.id;
		
		if (objectid.substr(0,4) == 'menu' || parentid.substr(0,4) == 'menu') {
			if (objectid.substr(0,6) !== 'menuIn' && target.style.display !== 'block')
				return false;
			else
				var handle = 'open';
		}
		toggleDiv.actie = handle;
		toggleDiv();
	}

/**	Stop alle events van dit object **/
	function stopevents(e) {
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
	}

/**	Zet de display-style van de div-elementen in onderstaande array  **/
	function toggleDiv() {
		if (/\/admin\//.test(document.location))
			return false;
		
		var actie = toggleDiv.actie;
		var linktohome					= document.getElementById('linktoHome');
		var menuArr = [];
		menuArr['menublokAll'] 			= document.getElementById('menublokAll');
		menuArr['menublokConsument']	= document.getElementById('menublokConsument');
		menuArr['menublokBedrijf'] 		= document.getElementById('menublokBedrijf');
		menuArr['menublok_transp'] 		= document.getElementById('menublok_transp');
		menuArr['menublok_transpBig']	= document.getElementById('menublok_transpBig');
		
		
		if (typeof menuArr == "object") {
			for (key in menuArr) {
				if (actie == 'open') {
					menuArr[key].style.display = 'block';
					if (linktohome)
						linktohome.style.display = 'none';
				} else {
					menuArr[key].style.display = 'none';
					if (linktohome)
						linktohome.style.display = 'block';
				}
			}
		}
	}

/** popup voor modules binnen admin **/
	top.window.popupModule = function () {
		popupModules('bedrijven');
	}
	function popupModules(modulenaam) {
		var filename	= "/admin/modules/"+modulenaam+"/index.php";
		var fileid		= modulenaam;
		var width		= "650";
		var height		= "580";
		var popupscherm	= 0;
		var args 		= "height=" + height + ", width=" + width + ", scrollbars=no, resizable=no, menubar=no, toolbar=no, status=no,location=no";
		popupscherm = top.window.open(filename, fileid, args);
	}

/** this function will get the current/computed style in IE and Moz/FF **/
	function getStyle(obj,Attribute) {
		if (obj) {
			if (obj.currentStyle)
				var value = eval('obj.currentStyle.'+Attribute)
			else
				var value = eval('document.defaultView.getComputedStyle(obj, null).'+Attribute)
			return parseInt(value);
		}
	}

/**rotating images for partner logos **/
	function showRotatingImage () {
		var linktag  =  document.getElementById('partnerlogoLink');
		var sfeerbeeld  =  document.getElementById('partnerlogoImg');
		
		if (!sfeerbeeld)
			return false;
	
		sfeerbeeld.src = imgArr[showRotatingImage.nr];
		linktag.href = altArr[showRotatingImage.nr];
		linktag.setAttribute('icon','false');
		showRotatingImage.nr++;
	
		if (showRotatingImage.nr >= imgArr.length)
			showRotatingImage.nr = 0;
	
		window.setTimeout(showRotatingImage,4000)
	}

/**	Zet hoogte van de maintable goed **/
	var isNav4, isNav6
	var isBrand = navigator.appName
	var navVer = parseInt(navigator.appVersion)
	
	//browser check
	var isNav4 = (isBrand == "Netscape" && navVer < 5) ? true : false
	var isNav6 = (isBrand == "Netscape" && navVer >= 5) ? true : false
	
	//give back the computed style
	function getStyle(obj,Attribute) {
		if (obj) {
			if (obj.currentStyle)
				var value = eval('obj.currentStyle.'+Attribute)
			else
				var value = eval('document.defaultView.getComputedStyle(obj, null).'+Attribute)
			return parseInt(value);
		}
	}
	
	//haal hoogte window binnen
	function getInsideWindowHeight() {
		if (isNav4 || isNav6)
			return window.innerHeight
	 	else 
		    return document.body.clientHeight
	}
	
	function setHeights() {
		var mainsite			= document.getElementById("mainsite");
		if (mainsite) {
			var maintable			= document.getElementById("maintable");
			var divmaintable		= document.getElementById("divMaintable");
			var template			= mainsite.className;
			var schermhoogte 		= getInsideWindowHeight();
			var maintabletop		= getStyle(divmaintable,'top') - 5;
			if (setHeights.afterwizard == true)
				var metanavheight	= 65;
			else
				var metanavheight	= 40;
			var maintableheight	= maintable.offsetHeight + maintabletop + metanavheight;
			
			if (maintableheight < schermhoogte) {
				divmaintable.style.height = schermhoogte - maintabletop;
				if (template !== 'pp') {
					maintable.style.height = schermhoogte - maintabletop - metanavheight;
					mainsite.style.height = schermhoogte - 5;
				}
			} else {
				mainsite.style.height = maintableheight;
			}
		}
	}

/**	Verzamelfunctie die alle andere functies initialiseerd **/
function initAll() {
	initLinks();
	setHeights();
}