/* =================== */
/* 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();
}

//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";
	}
	
	if (printUrl.indexOf("printpreview") == -1)
	{	    
	    printUrl = printUrl + ((printUrl.indexOf("?") != -1) ? "&" : "?") + "printpreview=true";
	}		

	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); 
    }
}

// -------------------- 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";
	        }
	    }
	}
}

function changeHeightForBackground() {
    $(".cz_default_content_center").height("auto");
    var windowHeight = $(window).height();
    var contentHeight = $(".cz_default_content_center").height();
    if (contentHeight < (windowHeight - 195) ) {
        $(".cz_default_content_center").height(windowHeight - 198);
    }
}

function zoeken_submit(el) {
    var form = document.getElementById("advsearch");
    form.submit();
}

function clearInput(el) {
    el.value = "";
}
function setColor(el) {
    el.style.color = "black";
}

function zoeken_submit_google(el) {
    var form = document.getElementById("searchform");
    form.submit();
}

var currentQuestionDiv = null;
var currentAnswerDiv = null;

function ShowDiv(strDivId) {
    var divQuestionElement = document.getElementById('Question' + strDivId);
    var divAnswerElement = document.getElementById('Answer' + strDivId);

    if (divQuestionElement) {
        divQuestionElement.style.display = "none";
        divAnswerElement.style.display = "block";

        if (currentQuestionDiv) {
            currentQuestionDiv.style.display = "block";
            currentAnswerDiv.style.display = "none";
        }

        currentQuestionDiv = divQuestionElement;
        currentAnswerDiv = divAnswerElement;
    }
    changeHeightForBackground();
}

/* */
$(document).ready(function() {
    $('#ppmenuWrapper').css('width', '30px');
    $('#ppmenuWrapper').css('left', '966px');
    $('#ppmenu').css('right', '-912px');
    $('#ppmenubutton').addClass('button_open');
    $('#ppmenubutton').attr('title', $('#openbuttonalttext').text());

    $('#ppmenubutton').toggle(
        function() {
            $('#ppmenuWrapper').css('width', '940px');
            $('#ppmenuWrapper').css('left', '56px');
            $('#ppmenu').animate({
                right: "0px"
            }, 1000);
            $('#ppmenubutton').removeClass();
            $('#ppmenubutton').addClass('button_sluiten');
            $('#ppmenubutton').attr('title', $('#closebuttonalttext').text());
        }, function() {

            $('#ppmenu').animate({
                right: "-912px"
                }, 1000, function() {
                    $('#ppmenuWrapper').css('width', '30px');
                    $('#ppmenuWrapper').css('left', '966px');
                });

            $('#ppmenubutton').removeClass();
            $('#ppmenubutton').addClass('button_open');
            $('#ppmenubutton').attr('title', $('#openbuttonalttext').text());
        }
    );

    $('#ppmenubutton').click(function() {
        var clickName = $('#ppmenubutton').is('.button_open') ? $('#managementinfcloseclickname').text() : $('#managementinfopenclickname').text();
        managementinfo.registerElementClick(clickName, $(this));
    });

    changeHeightForBackground();
    IFrameManager.registerAfterResizeEvents(changeHeightForBackground);
});

/* function for matrixlab popup, see also metrixlab.xsl */
function metrixlab_onready(el, func) {
    this.args = new Array(el, func);
    this.doTry = function() {
        try {
            var el = eval(this.args[0]);
            el.onloading = this.args[1];
            el.onloading();
            clearInterval(this.args[2]);
        }
        catch (e) { }
    }
    this.doTry.bind = function(object) {
        var method = this;
        return function() {
            method.apply(object);
        }
    }
    this.args[2] = setInterval(this.doTry.bind(this), 250);
    return this;
}

/* Used on error pages (error.xml) */
function swapHtml(divId1, divId2) {
    var elem1 = document.getElementById(divId1);
    var elem2 = document.getElementById(divId2);

    if (elem1 && elem2) {
        elem1.innerHTML = elem2.innerHTML;
        if (changeHeightForBackground != undefined) {
            changeHeightForBackground();
        }
    }
}

window.isIframeOnline = new Array();

$(document).ready(function() {
    $(".iframeErrorImage").each(function() {
        window.isIframeOnline[$(this).attr("id")] = true;
    });

    $(".iframeErrorImage").error(function() {
        window.isIframeOnline[$(this).attr("id")] = false;
        $(".autooffline_" + $(this).attr("id")).hide();
    });
});
