function cacheImages(imgList, path) {
    if (path == null) path = '';
    var images = new Array();
    for (var i = 0; i < imgList.length; i++) {
        images[i] = new Image();
        images[i].src = path + imgList[i];
    }
}

function toggle_visibility(id) {
    var e = element(id);
    if (e.style.display == 'block')
        e.style.display = 'none';
    else
        e.style.display = 'block';
}

function element(id) {
    e = document.getElementById(id);
    return e;
}

function pass(func) {
    eval(func);
}

function changeClass(objectId, className) {

    if ((element(objectId) != null) && (element(objectId) != undefined)) {
        element(objectId).className = className;
    }
}

//==== [ (Popup) windows open ] ============================================================

// plain (normal, like _Blank option
function ShowNew(pageUrl) {
    var newWindow = null;
    var options = { url: pageUrl, name: 'new', scrollbars: 'yes', resizable: 'yes', directories: 'yes', status: 'yes', locatation: 'yes', toolbar: 'yes' };
    newWindow = popup(options);
}

// modual window
function ShowModal(pageUrl, windowName, dialogWidth, dialogHeight) {
    var modalWindow = null;
    if (window.showModalDialog) {
        modalWindow = window.showModalDialog(pageUrl, windowName, 'dialogWidth:' + dialogWidth + 'px;dialogHeight:' + dialogHeight + 'px;edge:raised;help:no;scroll=no;status:no;resizable:no;center:yes;');
    }
    else {

        var options = { url: pageUrl, name: windowName, width: dialogWidth, height: dialogHeight, modal: 'yes' };
        modalWindow = popup(options);
    }
}

// popup window
function ShowPopup(pageUrl, windowName, dialogWidth, dialogHeight) {
    var popupWindow = null;
    var options = { url: pageUrl, name: windowName, width: dialogWidth, height: dialogHeight };
    popupWindow = popup(options);
}

// help window
function ShowHelp(pageUrl) {
    var helpWindow = null;
    var options = { url: pageUrl, name: 'Help', width: 500, height: 600, xpos: 'right', ypos: 'bottom', scrollbars: 'yes' };
    helpWindow = popup(options);
    helpWindow.focus();
    return false;
}

var popup = function(o) {
    //Constants
    var correctionsLeftPosition = -20;
    var correctionsTopPosition = -76;

    //Default(s):
    var defaultUrl = 'http://www.endon.nl/';
    var defaultName = 'Popup window';
    var defaultDirectories = 'no';
    var defaultScrollbars = 'no';
    var defaultResizable = 'no';
    var defaultStatus = 'no';
    var defaultLocation = 'no';
    var defaultToolbar = 'no';
    var defaultModal = 'no';
    //var defaultChannelmode = 'no';

    //parameterts:
    o.url = (typeof o.url == 'undefined') ? defaultUrl : o.url;
    o.width = (typeof o.width == 'undefined') ? screen.width / 2 : o.width;
    o.height = (typeof o.height == 'undefined') ? screen.height / 2 : o.height;
    if ((o.width <= 1) && (o.width > 0)) { o.width *= screen.width }
    if ((o.height <= 1) && (o.height > 0)) { o.height *= screen.height }
    o.xpos = (typeof o.xpos == 'undefined') ? (screen.width / 2) - (o.width / 2) : o.xpos;
    o.ypos = (typeof o.ypos == 'undefined') ? (screen.height / 2) - (o.height / 2) : o.ypos;
    o.xoffset = (typeof o.xoffset == 'undefined') ? 0 : o.xoffset;
    o.yoffset = (typeof o.yoffset == 'undefined') ? 0 : o.yoffset;
    o.name = (typeof o.name == 'undefined') ? defaultName : o.name;
    o.directories = (typeof o.name == 'undefined') ? defaultDirectories : o.directories;
    o.scrollbars = (typeof o.scrollbars == 'undefined') ? defaultScrollbars : o.scrollbars;
    o.resizable = (typeof o.resizable == 'undefined') ? defaultResizable : o.resizable;
    o.status = (typeof o.status == 'undefined') ? defaultStatus : o.status;
    o.location = (typeof o.location == 'undefined') ? defaultLocation : o.location;
    o.toolbar = (typeof o.toolbar == 'undefined') ? defaultToolbar : o.toolbar;
    //o.channelmode = (typeof o.channelmode == 'undefined') ? defaultChannelmode : o.channelmode;
    o.modal = (typeof o.modal == 'undefined') ? defaultModal : o.modal;

    //determine positions
    if (o.xpos == "left") { o.xpos = 0; }
    if (o.xpos == "right") { o.xpos = (screen.availWidth - o.width) + correctionsLeftPosition; }

    if (o.ypos == "top") { o.ypos = 0; }
    if (o.ypos == "bottom") { o.ypos = (screen.availHeight - o.height) + correctionsTopPosition; }

    o.xpos += o.xoffset;
    o.ypos += o.yoffset;

    //Build features
    var scrollbarstext = 'scrollbars = ' + o.scrollbars + ",";
    var resizabletext = 'resizable = ' + o.resizable + ",";
    var statustext = 'status = ' + o.status + ",";
    var directories = 'directories = ' + o.status + ",";
    var locationtext = 'location = ' + o.locat + ",";
    var toolbartext = 'toolbar = ' + o.toolbar + ",";
    var modaltext = 'modal = ' + o.modal + ",";

    features = scrollbarstext + resizabletext + statustext;
    features = features + locationtext + toolbartext;
    features = features + directories + modaltext;
    features = features + 'width = ' + o.width + ',height = ' + o.height;
    features = features + ',top = ' + o.ypos;
    features = features + ',left = ' + o.xpos;

    return window.open(o.url, o.name, features);
}

function getScreenHeightWidth(getWidth) {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    if (getWidth) {
        return myWidth;
    }
    else {
        return myHeight;
    }
}
