//20080414 BvD Added sluitdoeblok() for module keuzetarief
//20080707 BvD Added cookie handling functions 
//20080814 BvD Added global Essent root element
//20081112 BvD Added Essent.include function, removed unneeded stuff
//20090130 BvD Added essent-hbx-jslinks for ESSDEV-349

var Essent = {
	include : function(filename) {
		Rico.include('../../system/js/' + filename);
	}
};

//******************************************************************************************//
// Dynamic javascript includes															    //
//******************************************************************************************//
Essent.include('essent-search.js');
Essent.include('essent-menu.js');
Essent.include('essent-hbx-jslinks.js');


//******************************************************************************************//
// File for cookie related fnctions in JavaScript											//
// Author : 	   Manish Hatwalne (http://www.technofundo.com/)							//
// Feedback :  	   feedback@technofundo.com		(for feedback/bugs)							//
// Created : 	   19 August 2001  															//
// Functions :	   	  		 																//
// 			 (1) setCookie(szName, szValue [,szExpires] [,szPath] [,szDomain] [,szSecure])	//
//			 (2) getCookie(szName) 		   						  			  				//
//			 (3) deleteCookie(szName)														//
// 			 	 																			//
// Feel free to use/modify the code in this file, but always keep the header intact.		//
// And DO NOT re-distribute this file, instead provide a link to the site 	   				//
// http://www.technofundo.com/. Thank You.	  		 										//
// 									  														//
//******************************************************************************************//
//******************************************************************************************
//
// A CGI program uses the following syntax to add cookie information to the HTTP header:
// 
// Set-Cookie:   name=value   
// [;EXPIRES=dateValue]   
// [;DOMAIN=domainName]   
// [;PATH=pathName]   
// [;SECURE]
//
// This function sets a client-side cookie as above.  Only first 2 parameters are required
// Rest of the parameters are optional. If no szExpires value is set, cookie is a session cookie.
//
// Prototype : setCookie(szName, szValue [,szExpires] [,szPath] [,szDomain] [,bSecure])
//******************************************************************************************
function setCookie(szName, szValue, szExpires, szPath, szDomain, bSecure)
{
 	var szCookieText = 	   escape(szName) + '=' + escape(szValue);
	szCookieText +=	 	   (szExpires ? '; EXPIRES=' + szExpires.toGMTString() : '');
	szCookieText += 	   (szPath ? '; PATH=' + szPath : '');
	szCookieText += 	   (szDomain ? '; DOMAIN=' + szDomain : '');
	szCookieText += 	   (bSecure ? '; SECURE' : '');
	
	document.cookie = szCookieText;
}

//******************************************************************************************
// This functions reads & returns the cookie value of the specified cookie (by cookie name) 
//
// Prototype : getCookie(szName)
//******************************************************************************************
function getCookie(szName)
{
 	var szValue =	  null;
	if(document.cookie)	   //only if exists
	{
       	var arr = 		  document.cookie.split((escape(szName) + '=')); 
       	if(2 <= arr.length)
       	{
           	var arr2 = 	   arr[1].split(';');
       		szValue  = 	   unescape(arr2[0]);
       	}
	}
	return szValue;
}

//******************************************************************************************
// To delete a cookie, pass name of the cookie to be deleted
//
// Prototype : deleteCookie(szName)
//******************************************************************************************
function deleteCookie(szName)
{
 	var tmp = 	  			 	 getCookie(szName);
	if(tmp) 
	{ setCookie(szName,tmp,(new Date(1))); }
}

function addHandler(strEvent, fnc) {
	var oldhandler = window[strEvent]; 
	window[strEvent] = function() {
		try {
			oldhandler();
		}
		catch(e) {
		} 
		fnc(); 
	}; 									
}

/****************************************************************************
** Original functions.js by Indivirtual dd 18/01/2008
/****************************************************************************
/*******
** vp **	
*******/

window.onload = function() {
	setPopupHandler();
	sitemap();
}



var SCREEN_WIDTH = 910;

	/*	 Dynamic Doe-Blok
	---------------------------------------------- */

	function setPopupHandler() {
		if (document.getElementById('dynamicFRM')) {
			var dynamicBlock = document.getElementById('dynamicFRM');
			var entries = document.getElementsByTagName('div');
			for (var i=0; i<entries.length; i++) {
				if (entries[i].className.indexOf('doeblok') != -1) {
					entries[i].getElementsByTagName('div')[0].id = 'doeblok1234567890U1';
					var links = entries[i].getElementsByTagName('a');
					for (var o=0; o<links.length; o++) {
						links[o].href = 'javascript:;';
						links[o].onclick = function() {
							document.getElementById('doeblok1234567890U1').style.display = 'none';
							dynamicBlock.style.display = 'block';
						}
					}
				}
			}	
		}
	}
		
	function closePopup() {
		var entries = document.getElementsByTagName('iframe');
		for (var x=0; x<entries.length; x++) {
			if (entries[x].className == 'contentFRM') {
				if (typeof entries[x].src != "undefined") {
					var f = entries[x].src;
					entries[x].src = ''
					entries[x].src = f;
					if (typeof entries[x].contentWindow != "undefined") {
						entries[x].contentWindow.location = entries[x].src;
					}
				}
			}
		}

		if (document.getElementById('dynamicFRM') != null) {
			document.getElementById('dynamicFRM').style.display = 'none';
		}
		
		if (document.getElementById('doeblok1234567890U1') != null) {
			document.getElementById('doeblok1234567890U1').style.display = 'block';
		}
	}

	//For module "Keuzetarief". This module calls sluitdoeblok() iso closePopup()
	function sluitdoeblok() { closePopup(); }


function sitemap() {
	var entries = document.getElementsByTagName('a');
	for (var i=0; i<entries.length; i++) {
		if (entries[i].id) {
			if (entries[i].id.indexOf('SS') != -1) {
				var ID = entries[i].id.substr(1,4);
				document.getElementById(ID).style.display = 'none';
				entries[i].href = 'javascript:;';
				entries[i].onclick = function () {
					var ID = this.id.substr(1,4);
					if (document.getElementById(ID).style.display == 'none' || document.getElementById(ID).style.display == '') {
						document.getElementById(ID).style.display = 'block';
						this.className = 'selected';
					}
					else if (document.getElementById(ID).style.display == 'block') {
						document.getElementById(ID).style.display = 'none';
						this.className = '';
					}
				}
			}
		}
	}
}