/*
#########################################################
#
# default javascript functions for the entire site
#
# Copyright:		2000-2008 S-Inside
# Project:			Any website
# Platform:			Javascript
#
#########################################################
*/

var $sPath = window.location.pathname;
var $sPage = $sPath.substring($sPath.lastIndexOf('/') + 1);

window.onload = function() {
	if (navigator.appName == "Microsoft Internet Explorer") {
		var $htmlStyle = document.getElementsByTagName('html')[0].style;
		var $bodyStyle = document.body.style;
		
		$bodyStyle.scrollbarFaceColor = $htmlStyle.scrollbarFaceColor = $nScrollFaceColor;
		$bodyStyle.scrollbarArrowColor = $htmlStyle.scrollbarArrowColor = $nScrollArrowColor;
		$bodyStyle.scrollbarTrackColor = $htmlStyle.scrollbarTrackColor = $nScrollTrackColor;
		$bodyStyle.scrollbarShadowColor = $htmlStyle.scrollbarShadowColor = $nScrollShadowColor;
		$bodyStyle.scrollbarHighlightColor = $htmlStyle.scrollbarHighlightColor = $nScrollHighlightColor;
		$bodyStyle.scrollbar3dlightColor = $htmlStyle.scrollbar3dlightColor = $nScroll3dlightColor;
		$bodyStyle.scrollbarDarkshadowColor = $htmlStyle.scrollbarDarkshadowColor = $nScrollDarkshadowColor;
	}
	
	externalLinks();	
	extraStartFunctions();
	
	if ($sPage == "fotogalerij.php") {
		$(function() {
			$('#galery_thumbnails a').lightBox();
		});
	} else {
		$(function() {
			$('a.lightbox').lightBox();
		});
	}
}

// common functions for all websites

function reloadCaptcha() {
	var img = document.getElementById("captchaimg");
	img.src = "img/refresh.gif";
	img.src = "captcha.php?code="+Math.random();
}

function gotoPage ($p_sURL) {
	this.location.href = $p_sURL;
}

if (top != self) self.location.href = $sHomepage;

function externalLinks() {
	if (!document.getElementsByTagName) {
		// browser is to old
		return;
	}
	
	var $aAnchors = document.getElementsByTagName("a");
	for (var i = 0; i < $aAnchors.length; i++) {
		var $sAnchor = $aAnchors[i];
		if (($sAnchor.getAttribute("href")) &&  ($sAnchor.getAttribute("rel") == "external") || ($sAnchor.getAttribute("rel") == "lightbox")) {
 			$sAnchor.target = "_blank";
		}
		if ($sAnchor.getAttribute("rel") == "lightbox") {
			$sAnchor.className = "lightbox";
		}
	}
	
	var $aForms = document.getElementsByTagName("form");
	for (var i = 0; i < $aForms.length; i++) {
		var $sForm = $aForms[i];
		if ($sForm.getAttribute("rel") == "external") {
 			$sForm.target = "_blank";
		}
	}
	
}

function MM_findObj(n, d) { //v4.0
	var p,i,x;  
	
	if(!d) {
		d=document; 
	}	
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}	
	if(!(x=d[n])&&d.all) {
		x=d.all[n]; 
	}	
	for (i=0;!x&&i<d.forms.length;i++) {
		x=d.forms[i][n];
	}
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) {
		x=MM_findObj(n,d.layers[i].document);
	}
	if(!x && document.getElementById) {
		x=document.getElementById(n); 
	}
	return x;
}

function MM_showHideLayers() { //v3.0
  	var i,p,v,obj,args=MM_showHideLayers.arguments;
  
	for (i=0; i<(args.length-2); i+=3) {
		if ((obj=MM_findObj(args[i]))!=null) {
			v=args[i+2];
			if (obj.style) { 
				 obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v;
			}
    		obj.visibility=v; 
		}
	}
	
	if (document.getElementById("image_big")) {
		hideBigImage();
	}
	if (document.getElementById("menu_zIndex")) {
		if (v == 'visible') {
			document.getElementById("menu_zIndex").style.zIndex = 111;			
		} else {
			document.getElementById("menu_zIndex").style.zIndex = 11;
		}
	}
}
  
/*
	toon grote foto en vervaag de rest van de pagina 
	voorbeeld: onclick="showBigImage('consument_1.jpg',350,249, "some text");return false;"
*/ 
function showBigImage ($p_sImage, $p_nWidth, $p_nHeight, $p_sText) {
	//alert($p_nImage);
	var $sText = "";
	var $nWindowWidth = 0, $nWindowHeight = 0;
	var $nPosLeft = 0;
	var $nPosTop = 0;
	
	document.getElementById("image_big").innerHTML = "";
	
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		$nPosTop = window.pageYOffset;
		//$nScrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		$nPosTop = document.body.scrollTop;
		//$nScrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		$nPosTop = document.documentElement.scrollTop;
		//$nScrOfX = document.documentElement.scrollLeft;
	}
	//alert($nPosTop);
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		$nWindowWidth = window.innerWidth;
		$nWindowHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		$nWindowWidth = document.documentElement.clientWidth;
		$nWindowHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		$nWindowWidth = document.body.clientWidth;
		$nWindowHeight = document.body.clientHeight;
	}
	$nPosLeft = ($nWindowWidth - $p_nWidth + 100) / 2;
	
	$sText = "<img src='"+$p_sImage+"' width='"+$p_nWidth+"' height='"+$p_nHeight+"' border='0' ";
	$sText += "alt='Klik om te sluiten' title='Klik om te sluiten' />";
	
	// add extra text at the bottom of the image
	if (($p_sText) && ($p_sText.length > 0)) {
		$sText += "<p><b>"+$p_sText+"</b></p>";
	}
	
	fadeContent(2);
    if ($nPosLeft > 0) {
    	document.getElementById("image_big").style.left = parseInt($nPosLeft)+'px';
	}
	if ($nPosTop > 0) {
		if ($nPosTop < 150) {
			$nPosTop += 120;
		} else if ($nPosTop > ($nWindowHeight - $p_nHeight)) {
			$nPosTop = $nWindowHeight - $p_nHeight - 100;
		}
		document.getElementById("image_big").style.top = parseInt($nPosTop)+'px';
	}
	
    document.getElementById("image_big").innerHTML = $sText;
    document.getElementById("image_big").style.display = "inline";
    
}

// hide the big image again
function hideBigImage () {
	fadeContent(10);
	if (document.getElementById("image_big")) {
		document.getElementById("image_big").style.display = "none";
		document.getElementById("image_big").innerHTML = "";
	}	
}

// fade site depending on p_nOpacity, 10 sets to complete visible again
function fadeContent($p_nOpacity) {
	var $sDisplay = "none";
	if ($p_nOpacity == 10) {
		$sDisplay = "inline";
	}
	
	if (document.getElementById("page")) {
		document.getElementById('page').style.opacity = $p_nOpacity/10;
		
		// deze veroorzaakt in IE7 lichtere letters, vooral bij titels zichtbaar
		// ligt aan opacity en cleartype 
		if ((document.getElementById('page').style.filter) || ($p_nOpacity < 10)) {
			// werkt in IE8 niet, heeft wel geen last meer van lichtere letters!
			document.getElementById('page').style.filter = 'alpha(opacity=' + $p_nOpacity*10 + ')';
		}
	}
	
	if (document.forms.length > 0) {
		// hide select boxes because they get in front of error div
		for (n = 0; n < document.forms.length; n++) {
			var $field = document.forms[n];
				
		    // loop through the fields of the form
			for (i = 0; i < $field.length; i++) {
				if (($field.elements[i].type == "select-one") && ($field.elements[i].name != "mce_editor_0_formatSelect")) {
					//alert($field.elements[i].name);
					if ($field.elements[i]) {
						$field.elements[i].style.display = $sDisplay;
					}
		     	}
		  	}
	  	}
  	}
}

// function to show news item
function showTextField ($p_sID) {
	if (document.getElementById($p_sID)) {
		if (document.getElementById($p_sID).style.display != "block") {
			document.getElementById($p_sID).style.display = "block";
		} else {
			document.getElementById($p_sID).style.display = "none";
		}
	}
}

// hide error field
function hideError () {	
	fadeContent(10);
	if (document.getElementById("foutmelding")) {
		document.getElementById("foutmelding").innerHTML = "";
		document.getElementById("foutmelding").style.display = "none";
	}	
}

// general function, show given div
function showDiv ($p_nID) {
	if (document.getElementById($p_nID)) {
		$sDiv = document.getElementById($p_nID);
		$sDiv.className = 'visible';
		$sDiv.style.display='block';
	}
}
// general function, hide given div
function hideDiv ($p_nID) {
	if (document.getElementById($p_nID)) {
		$sDiv = document.getElementById($p_nID);
		$sDiv.className = 'hidden';
		$sDiv.style.display='none';
	}
}

// check CMS form input
function checkForm() {
	var $sText = "", $sValue;
	var $nCounter = 0, $nPosLeft = 0, $nPosTop = 0, $nWindowWidth = 0;
	var $aMissing = new Array();
	var $aRequired = document.forms['contact'].elements['verplicht'].value.split(",");
	var $aMultipleFields, $bMultiFieldChecked;
	
	for($i = 0; $i < $aRequired.length; $i++) {
		if (document.forms['contact'].elements[$aRequired[$i]]) {
			if (!document.forms['contact'].elements[$aRequired[$i]].length) {
				// textbox or simular, one field with that name
				$sValue = document.forms['contact'].elements[$aRequired[$i]].value;
				if ((!$sValue) || ($sValue.length < 1)) {
					$aMissing[$nCounter] = $aRequired[$i];
					$nCounter++;
				}
			} else {
				// radioboxes or select, more then one with same name
				$bMultiFieldChecked = false;
				$aMultipleFields = document.forms['contact'].elements[$aRequired[$i]];
				for (var $nCount = 0; $nCount < $aMultipleFields.length; $nCount++) {
					if ($aMultipleFields[$nCount].checked == true) {
						// radiobox
						$bMultiFieldChecked = true;
					} else if (($aMultipleFields[$nCount].selected == true) && ($aMultipleFields[$nCount].value != "")) {
						// selected item, not value == ""
						$bMultiFieldChecked = true;
					}
				}
				if (!$bMultiFieldChecked) {
					$aMissing[$nCounter] = $aRequired[$i];
					$nCounter++;
				}
			}
		} else {
			// checkboxes
			$bMultiFieldChecked = false;
			$aMultipleFields = document.forms['contact'].elements[ $aRequired[$i]+"[]" ];
			if ($aMultipleFields) {
				if ($aMultipleFields.length) {
					// more then one checkbox
					for (var $nCount = 0; $nCount < $aMultipleFields.length; $nCount++) {
						if ($aMultipleFields[$nCount].checked == true) {
							$bMultiFieldChecked = true;
						}
					}
				} else if ($aMultipleFields.checked == true) {
					// only one checkbox, check value
					$bMultiFieldChecked = true;
				}
				if (!$bMultiFieldChecked) {
					$aMissing[$nCounter] = $aRequired[$i];
					$nCounter++;
				}
			}
		}
	}
	
	// check captcha
	var $sCaptcha = get_cookie("sCaptchaCMS");
	var $sUserCaptcha = null;
	if (document.forms['contact'].elements['Tekens']) {
		$sUserCaptcha = document.forms['contact'].elements['Tekens'].value;
	}
	if (($sCaptcha) && ($sCaptcha.length > 0) && ($sUserCaptcha)) {
		if ($sCaptcha != MD5($sUserCaptcha.toLowerCase())) {
			$aMissing[$nCounter] = "Tekens";
			$nCounter++;
		}
	}
	
	
	if ($nCounter > 0) {
		// we have empty required fields, show error
		if (parseInt(navigator.appVersion)>3) {
			// get screenport width
			if (navigator.appName=="Netscape") {
				$nWindowWidth = window.innerWidth;
			}
			if (navigator.appName.indexOf("Microsoft")!=-1) {
				$nWindowWidth = document.body.offsetWidth;
			}
		}
		$nPosLeft = ($nWindowWidth - 400 + $nImagePlaceWidth) / 2;
		
		// get screenport height
		/*if (window.pageYOffset) {
			$nPosTop = window.pageYOffset;
		} else if (document.documentElement.scrollTop) {
			$nPosTop = document.documentElement.scrollTop;
		}*/
		//$nPosTop = ($(document).height()-$(window).scrollTop());
		//alert($("#form").height());
		// fade rest of the page
		fadeContent(2);
		// set position of error div
	    if ($nPosLeft > 0) {
	    	document.getElementById("foutmelding").style.left = parseInt($nPosLeft)+'px';
		}
		//document.getElementById("foutmelding").style.top = parseInt($nPosTop/2)+'px';
		
		
		// create text with missing fields in bold		
		$sText += "<h4 class='normaltext'>Foutmelding</h4><p>De volgende verplichte velden zijn niet of niet correct ingevuld:</p>";
		for($i = 0; $i < $aMissing.length; $i++) {
			$sText += "&nbsp;&nbsp;&nbsp;<b>"+$aMissing[$i]+"</b><br />";
		}
		$sText += "<p>Sluit dit venster door er op te klikken en vul de aangegeven velden correct in.</p>";
		$sText += "<img src='img/closelabel.gif' width='66' height='22' border='0' alt='' align='right' hspace='5' /><br /><br />";
		
		// show text in error div and show text
		document.getElementById("foutmelding").innerHTML = $sText;
	    document.getElementById("foutmelding").style.display = "inline";
		
		return false; 
		
	} else {
		// all required fields filled out, go on
		return true;
	}
}

//Get cookie routine by Shelley Powers 
function get_cookie(Name) {
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		// if cookie exists
		if (offset != -1) { 
			offset += search.length
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

/* Modified to support Opera */
function bookmarksite(title,url){
	if (window.sidebar) {
		// firefox
		//window.sidebar.addPanel(title, url, "");
		alert("Druk nu op Ctrl-D om onze pagina bij uw bladwijzers te zetten.");
	} else if (window.opera && window.print) { 
		// opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if(document.all) {
		// ie
		window.external.AddFavorite(url, title);
	}
}

function switchYearCalendar ($p_nYear, $p_nSite) {
	self.location.href = $p_nSite + $p_nYear;
}

function expandDiv ($p_sWhat) {
	if (document.getElementById($p_sWhat)) {
		var $sWhat = document.getElementById($p_sWhat);
		
		if ($sWhat.style.display == "inline") {
			$sWhat.style.display = "none";
		} else {
			$sWhat.style.display = "inline";
		}
	}
}

function switchProductSort ($p_sSort) {
	self.location.href = "products.php?sort="+$p_sSort;
}

function setDirectoryImage ($p_sID) {
	var $aImages = document.getElementsByTagName('img');
	var $sImageID = "folder_"+$p_sID;
	
	for ($nCount = 0; $nCount < $aImages.length; $nCount++) {
		var $sField = $aImages[$nCount].id;
		if (($sField.substr(0, 7) == "folder_") && (document[$sField])) {
			document[$sField].src='img/cms/folder.gif';
		}
  	}
  	//if (document[$sImageID]) {
  		document.getElementById($sImageID).src='img/cms/folder1.gif';
  	//}
}

function changeRelativeURLs ($p_sNewSite) {
	var $aIMG = document.getElementsByTagName('img');
	for (var $nCount = 0; $nCount < $aIMG.length; $nCount++){
	   //Do Work on doc[i], this sets the border of the Div black
	   $aIMG[$nCount].src = $p_sNewSite + "/" + $aIMG[$nCount].src;
	}
}

/*
// show big page and fade rest of site 
function showBigPage () {
 	var $sText = "";
 	var $sPrevious = "";
 	var $sNext = "";
 	
 	if (parseInt(navigator.appVersion)>3) {
 		if (navigator.appName=="Netscape") {
 			$nWindowWidth = window.innerWidth;
 		}
 		if (navigator.appName.indexOf("Microsoft")!=-1) {
 			$nWindowWidth = document.body.offsetWidth;
 		}
 	}
 	$nPosLeft = ($nWindowWidth - 798) / 2;
 	
 	fadeContent(2);
     if ($nPosLeft > 0) {
     	document.getElementById("page_big").style.left = parseInt($nPosLeft)+'px';
 	}
 	
     document.getElementById("page_big").style.display = "inline";
     
 }

function hideBigPage () {
 	fadeContent(10);
 	if (document.getElementById("page_big")) {
 		document.getElementById("page_big").style.display = "none";
 	}
 	
 	if (document.getElementById("foutmelding")) {
 		document.getElementById("foutmelding").innerHTML = "";
 		document.getElementById("foutmelding").style.display = "none";
 	}
 	
 	//enablelinks();	
}*/
