
var arrFunctions = new Array();
var arrMenuParts2Align = new Array();
var arrMenuParts2AlignDepth = new Array();


function set_cookie ( name, value, offset_exp_y, offset_exp_m, offset_exp_d, path, domain, secure ) {
  var cookie_string = name + "=" + escape ( value );
  if ( ! offset_exp_d ) {offset_exp_d = 0;}
  if ( ! offset_exp_m ) {offset_exp_m = 0;}
  if ( offset_exp_y ) {
    var offset = new Date();
    var expires = new Date ( offset.getFullYear() + offset_exp_y, offset.getMonth() + offset_exp_m, offset.getDate() + offset_exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }
  if ( path ) cookie_string += "; path=" + escape ( path );
  if ( domain ) cookie_string += "; domain=" + escape ( domain ); 
  if ( secure ) cookie_string += "; secure";
  document.cookie = cookie_string;
}



function switchImage(imageId, oldImage, newImage) {
	var imageElement = imageId;
	if(imageElement.src.lastIndexOf(oldImage) > -1) {
			imageElement.src = newImage;
	} 
	else {
			imageElement.src = oldImage;
	}
}

function MM_findObj(n, d) { //v3.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); return x;
}


function cm_bwcheck(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1) && window.opera
	this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1) && window.opera
	this.ie5 = (this.agent.indexOf("msie 5")>-1 && !this.op5 && !this.op6)
	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
	this.ie60 = (this.agent.indexOf("msie 6")>-1 && !this.op5 && !this.op6)
	this.ie4=(this.agent.indexOf("msie")>-1 && document.all &&!this.op5 &&!this.op6 &&!this.ie5&&!this.ie6)
	this.ie = (this.ie4 || this.ie5 || this.ie6)
	this.mac=(this.agent.indexOf("mac")>-1)
	this.ns6=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ns4=(!this.dom && document.layers)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6)
	this.usedom= this.ns6//Use dom creation
	this.reuse = this.ie||this.usedom //Reuse layers
	this.px=this.dom&&!this.op5?"px":""
	return this
}

/* =================== */
/* help popup          */
/* =================== */

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=534,left = 312,top = 234');");
}

function popupWindow(url, windowsettings) {
	var child = window.open(url, "popup", windowsettings); 
	if (child.opener == null) child.opener = self;
	child.focus();
}

//z-index fix for selects in IE
var arrHiddenSelects = new Array()
function hideSelects(obj) {
  if (cm_bwcheck().ie) {
    var arrSelectObjects = document.getElementsByTagName('SELECT')
    var arrObjPosition = getPosition(obj)
    for (var i=0; i<arrSelectObjects.length; i++) {
      var objElement = arrSelectObjects[i]
      var arrSelectPosition = getPosition(objElement)
      if ((arrSelectPosition.left >= arrObjPosition.right) || (arrSelectPosition.right <= arrObjPosition.left) || (arrSelectPosition.bottom <= arrObjPosition.top) || (arrSelectPosition.top >= arrObjPosition.bottom)) {
	    objElement.style.visibility = 'visible'
	  } else {
	    arrHiddenSelects[arrHiddenSelects.length] = objElement
	    objElement.style.visibility = 'hidden'
	  }
    }
  }
}

function showSelects() {
  if (cm_bwcheck().ie) {
    for (var i=0; i<arrHiddenSelects.length; i++) {
      arrHiddenSelects[i].style.visibility = 'visible'
    }
  }
}

function getPosition(objReference) {
	var arrPosition = new Array()
	if (objReference != null) {
  	arrPosition.left = 0
  	arrPosition.right = objReference.offsetWidth
  	arrPosition.top = 0
  	arrPosition.bottom = objReference.offsetHeight
  	while (objReference != null && objReference.tagName != 'BODY' && (objReference.style.position == '' || objReference.style.position == 'relative')) {
    	arrPosition.left += objReference.offsetLeft
    	arrPosition.top += objReference.offsetTop
	  	objReference = objReference.offsetParent
	  } 
	  arrPosition.right += arrPosition.left
	  arrPosition.bottom += arrPosition.top
  }
 	return arrPosition
}


// document.all simulator for NN6
if (cm_bwcheck().ns6) {
  Node.prototype.__defineGetter__("all", function() {
    if (document.getElementsByTagName("*").length) {
      switch (this.nodeType) {
        case 9:
		  return document.getElementsByTagName("*")
          break
        case 1:
		  return this.getElementsByTagName("*")
		  break
		}
      }
      return ""
	}
  )
  Node.prototype.__defineSetter__("all", function() {})
}

function GetSelectedCategories(frm)
{

	var selection = document.forms[frm].selectie; // get checkbox selection
	var separator = ""; // declare separator for separator-separated string

	document.forms[frm].categories.value = ""; // empty nodes hidden form field

	for(var i=0; i < selection.length; i++) // loop through checkbox selection
	{
		if(selection[i].checked) //  if checkbox is selected, continue
		{
			document.forms[frm].categories.value += separator+selection[i].value; //  add checkbox selection to nodes hidden form field
			separator = ",";
			
			if (selection[i].value == "medicinfo")
			{
				document.forms[frm].categories.value = ""; // empty nodes hidden form field
			};
		}
	}
}

//for print function
var gl_printwindow = null;

function openWindowAndPrint () {
  var browserWidth = screen.availWidth-20;
	var positionRight = location.href.length;
	if (location.href.indexOf("#") != -1) {
		positionRight = location.href.indexOf("#");
	}
	var printUrl = location.href.substr(0,positionRight);
	if (printUrl.indexOf("popup=true") == -1)
	{
		printUrl = printUrl + ((printUrl.indexOf("?") != -1) ? "&" : "?") + "popup=true";
    }
    printUrl = printUrl + ((printUrl.indexOf("?") != -1) ? "&" : "?") + "PrintPreview=1";	

	if (browserWidth<780)
	{
		var left = (screen.availWidth - 550) / 2;
		var top = (screen.availHeight - 350) / 2;
		var printwindow = window.open(printUrl, "newwindow", "left="+left+", top="+top+", width=550, height=350, location=no, menubar=yes, status=no, toolbar=no, scrollbars=yes, resizable=yes");
	}
	else 
	{
		var left = (screen.availWidth - 550) / 2;
		var top = (screen.availHeight - 600) / 2;
		var printwindow = window.open(printUrl, "newwindow","left="+left+", top="+top+", width=550, height=600, location=no, menubar=yes, status=no, toolbar=no, scrollbars=yes, resizable=yes");
	}

    gl_printwindow = printwindow;
    printThisWindow();
}

//delay the print call because the dyframe script has to set the domain first...
function printThisWindow(){
    try {
        if (gl_printwindow.print) {
            gl_printwindow.focus();
            if (navigator.appName == 'Netscape' && navigator.userAgent.indexOf('Firefox') != -1) {
                gl_printwindow.onload = gl_printwindow.print;
            } else {
                gl_printwindow.print();
            }
        } else {
            var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
            document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
            WebBrowser1.ExecWB(6, 2); //Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
        }
        return;
    }
    catch(e)
    {
        window.setTimeout(printThisWindow,200); 
    }
}

function chooseStyle(newstyle) {
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + (1000*3600*24*365));
	document.cookie = 'style=' + newstyle + '; expires=' + expdate.toGMTString() + '; path=/';
	window.location.reload(true);
}

function addMenuPart2Alignment(obj_id,depth) {
	var newItemIndex = arrMenuParts2Align.length;
	arrMenuParts2Align[newItemIndex] = obj_id;
	arrMenuParts2AlignDepth[newItemIndex] = depth;
}

function AlignMenuParts() {
	var i;
  var MenuWidth = 206;
  //debugger;
  if (0 < arrMenuParts2Align.length) {
		for(i=0; i < arrMenuParts2Align.length; i++) {
			var htmlObject = document.getElementById(arrMenuParts2Align[i]);
			var objPos = getPosition(htmlObject.parentNode);
			//if menuparts parent is not out of the screen then it is the actual menu button
			// thus we can measure its left position and calculate everything from there
			var actualMenuPos;
			if (arrMenuParts2AlignDepth[i] == 0) {actualMenuPos = objPos.left;}
			if (actualMenuPos) { //without an actual menuposition we do nothing
				if (arrMenuParts2AlignDepth[i] > 0) { // if it is an actual submenu
					if (actualMenuPos + ((arrMenuParts2AlignDepth[i]+1) * MenuWidth) > windowWidth()) {	htmlObject.style.marginLeft = "-216px"; }
					else //default situation
					{	htmlObject.style.marginLeft = MenuWidth + "px";}
				}
			}
		} //for
	} //if
} //function

function addFunction(fReference)
{
	/* Deze functie voegt een functie-pointer toe aan de array van functies die uitgevoerd wordt in de body onload. */
	arrFunctions[arrFunctions.length] = fReference;
}

function callAllFunctions()
{
	var i;

	if (0 < arrFunctions.length)
	{
		for(i=0; i < arrFunctions.length; i++)
		{
			arrFunctions[i]();
		}
	}
}
function windowWidth() {
   if (document.getElementById){

       if (window.innerWidth)
         return window.innerWidth;
       if (document.documentElement&&document.documentElement.clientWidth)
         return document.documentElement.clientWidth;
       if (document.body.clientWidth)
         return document.body.clientWidth;
   }
}

// -------------------- podcast functions

function podcastHover(id, evt)
{
	var hover = document.getElementById(id);
	if (hover)
	{
		if (hover.style.display == 'none')
		{
      hover.style.zIndex = 600;
			hover.style.left = mouseX(evt) + 5 + 'px';
			hover.style.top = mouseY(evt) + 5 + 'px';
      hover.style.display = 'block';			
		}
		else
		{
			hover.style.display = 'none';
		}
	}
}

function podcastPlay(id)
{
	var feat = 'status=0,toolbar=0,menubar=0,directories=0,resizable=0,scrollbars=0,height=535,width=640';
	var sUrl = '/podcast?popup=true&id=' + id;
	w = window.open(sUrl, 'podcast', feat);
	w.moveTo(0,0);
}

function mouseX(evt) {
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
	   return evt.clientX + (document.documentElement.scrollLeft ?
	   document.documentElement.scrollLeft :
	   document.body.scrollLeft);
	else return null;
}
function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
	   return evt.clientY + (document.documentElement.scrollTop ?
	   document.documentElement.scrollTop :
	   document.body.scrollTop);
	else return null;
}


if(document.attachEvent)
{
	document.attachEvent('onkeyup', AlertKeyCode);
}
else if(document.addEventListener)
{
	document.addEventListener('keyup', AlertKeyCode, true);
}


var originalColor = "";
var originalBackgroundColor = "";
var focusedElement = null;

function AlertKeyCode(e)
{
	if(document.attachEvent)
	{
		e=event;
	}
	
	if(e.keyCode == 9)
	{  
	    if(focusedElement != null)
	    {
	        focusedElement.style.color = originalColor;
	        focusedElement.style.backgroundColor = originalBackgroundColor;
	    }
	    
	    var elem = null;
	    if ("activeElement" in document)
	    {
	        elem = document.activeElement;
	    }else{
	        elem = e ? e.explicitOriginalTarget : null; 
	    }
	    
	    if(elem)
	    {
	        if(elem.tagName == "A")
	        {
	            focusedElement = elem;
	            originalColor = elem.style.color;
	            originalBackgroundColor = elem.style.backgroundColor;
	            elem.style.color = "#cccccc";   
	            elem.style.backgroundColor = "#000000";
	        }
	    }
	}
}

$(document).ready(function() {
    changeHeightForBackground();
    $(window).resize(function() {
        changeHeightForBackground();
    });
    IFrameManager.registerAfterResizeEvents(changeHeightForBackground);
});

function changeHeightForBackground() {
    $(".cz_default_content_center").height('auto');
    var windowHeight = $(window).height();
    var defaultHeight = $("#cz_default_content").height();
    if (windowHeight - 198 > defaultHeight) {
        $(".cz_default_content_center").height(windowHeight - 198);
    }
}
