function BlackFade(show) {
    var black = document.getElementById('blackFade');
    if (black == null) {
        black = document.createElement('div');
        black.id = 'blackFade';
        black.style.display = 'none';
        black.style.zIndex = '1950';
        document.getElementsByTagName('body')[0].appendChild(black);
    }
    if (show) {
        black.style.width = document.documentElement.scrollWidth + 'px';
        black.style.height = document.documentElement.scrollHeight + 'px';
        black.style.display = 'block';
    } else {
        black.style.display = 'none';
    }
}

function closePopUp(name) {
    var popupToClose = document.getElementById(name + '_moved');
    if (popupToClose != null) {
        popupToClose.style.display = "none";
    }
    BlackFade(false);
}

function showPopUp(name, width, height, widthauto, heightauto) {
    var left = 300;
    var top = 200;


    

    var originalElement = document.getElementById(name + '_moved');
    if (originalElement == null) {
        originalElement = document.createElement('div');
        originalElement.id = name + '_moved';
        document.getElementsByTagName('body')[0].appendChild(originalElement);
    }
    document.getElementById(name + '_moved').setAttribute("class", "popup");
    document.getElementById(name + '_moved').className = "popup";
    if (document.getElementById(name).innerHTML.length > 0) {
        document.getElementById(name + '_moved').innerHTML = document.getElementById(name).innerHTML;
    }
    document.getElementById(name).innerHTML = '';
    document.getElementById(name + '_moved').style.position = "absolute";
    document.getElementById(name + '_moved').style.display = "block";
    



    if (widthauto)
    { document.getElementById(name + '_moved').style.width = 'auto'; }
    else
    { document.getElementById(name + '_moved').style.width = width + 'px'; }

    if (heightauto) {
        document.getElementById(name + '_moved').style.height = 'auto';
        document.getElementById(name + "_Content").style.height = 'auto';
    }
    else {
        document.getElementById(name + '_moved').style.height = height + 'px';
        document.getElementById(name + "_Content").style.height = (height - 50) + 'px';
    }

    try {
        var winW = 600;
        var winH = 400;
        winW = document.documentElement.clientWidth;
        winH = document.documentElement.clientHeight;
        left = ((winW - 300) / 2);
        top = ((winH - document.getElementById(name + '_moved').clientHeight) / 2) + document.documentElement.scrollTop;
        //top = ((winH - 200) / 2) + document.documentElement.scrollTop;

        //alert(winH);
        //alert(document.documentElement.scrollTop);
        //alert(document.getElementById(name + '_moved').clientHeight);
        //alert(document.documentElement.scrollTop)

    } catch (e) { }

    document.getElementById(name + '_moved').style.left = left + 'px';
    document.getElementById(name + '_moved').style.top = top + 'px';
    //document.getElementById(name + "_Content").style.height = (height-50) + 'px';

    BlackFade(true);

    if (document.getElementById(name + "_popup_l") != null) {
        document.getElementById(name + "_popup_l").style.height = document.getElementById(name + "_popup_c").offsetHeight;
    }

    if (document.getElementById(name + "_popup_r")) {
        document.getElementById(name + "_popup_r").style.height = document.getElementById(name + "_popup_c").offsetHeight;
    }


}

function showPopUpNoFade(name, width, height, left, top) {
    try {
        var winW = 600;
        var winH = 400;
        winW = document.documentElement.clientWidth;
        winH = document.documentElement.clientHeight;

    } catch (e) { }

    var originalElement = document.getElementById(name + '_moved');
    if (originalElement == null) {
        originalElement = document.createElement('div');
        originalElement.id = name + '_moved';
        document.getElementsByTagName('body')[0].appendChild(originalElement);
    }
    var originalElement = document.getElementById(name);
    document.getElementById(name + '_moved').innerHTML = document.getElementById(name).innerHTML;
    document.getElementById(name).innerHTML = '';

    document.getElementById(name + '_moved').style.left = left + 'px';
    document.getElementById(name + '_moved').style.top = top + 'px';

    document.getElementById(name + '_moved').style.width = width + 'px';
    document.getElementById(name + '_moved').style.height = height + 'px';
    document.getElementById(name + '_moved').style.display = "block";
    document.getElementById(name + '_moved').style.position = "absolute";


    document.getElementById(name + "_Content").style.height = (height - 50) + 'px';

    BlackFade(false);
}

// Pre - Render the PopUp Images

function PreRenderPopUpImages() {
    if (document.images) {
        preload_image_object = new Image();
        // set all the image url used in popups
        image_url = new Array();
        image_url[0] = path + "/content/images/v2008/popup/popup_bg_tl.gif";
        image_url[1] = path + "/content/images/v2008/popup/popup_bg_t.gif";
        image_url[2] = path + "/content/images/v2008/popup/popup_bg_tr.gif";
        image_url[3] = path + "/content/images/v2008/popup/popup_bg_l.gif";
        image_url[4] = path + "/content/images/v2008/popup/popup_bg.gif";
        image_url[5] = path + "/content/images/v2008/popup/popup_bg_r.gif";
        image_url[6] = path + "/content/images/v2008/popup/popup_bg_bl.gif"
        image_url[7] = path + "/content/images/v2008/popup/popup_bg_b.gif";
        image_url[8] = path + "/content/images/v2008/popup/popup_bg_br.gif";
        image_url[9] = path + "/content/generator/v2008/0.gif";
        image_url[10] = path + "/content/generator/v2008/1.gif";
        image_url[11] = path + "/content/generator/v2008/2.gif";
        image_url[12] = path + "/content/generator/v2008/3.gif";
        image_url[13] = path + "/content/generator/v2008/4.gif";
        image_url[14] = path + "/content/generator/v2008/5.gif";

        var i = 0;
        for (i = 0; i <= 14; i++) {
            preload_image_object.src = image_url[i];
        }
    }
}

// INIT DOM READY FUNCTIONS

function init() {
    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

    // kill the timer
    if (_timer) {
        clearInterval(_timer);
        _timer = null;
    }

    // create the "page loaded" message

    //myfunction
    var funcName = 'Main';
    if (typeof funcName == 'string' && eval('typeof ' + funcName) == 'function') {
        eval(funcName + '()');
    }

    // Selectbox.js init (evt. naar Main function)	
    //(document.all && !window.print) ? null : setForm();
    PreRenderPopUpImages()
};

/* for Mozilla */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on@*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
    if (this.readyState == "complete") {
        init(); // call the onload handler
    }
};
/*@end@*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            init(); // call the onload handler
        }
    }, 10);
}

/* for other browsers */
window.onload = init;