JoeDex = {
    Base : {
        getViewport : function()
        {
            var oRtrn = new Object();

            oRtrn.width = null;
            oRtrn.height = null;

            if (parseInt(navigator.appVersion) > 3)
            {
                if (navigator.appName == "Netscape")
                {
                    oRtrn.width = window.innerWidth;
                    oRtrn.height = window.innerHeight;
                }
                if (navigator.appName.indexOf("Microsoft") != -1)
                {
                    oRtrn.width = document.documentElement.clientWidth;
                    oRtrn.height = document.documentElement.clientHeight;
                }
            }

            return oRtrn;
        },
        getEventPosition : function(evt)
        {
            var pos = new Object();
            pos.x = 0;
            pos.y = 0;

            if( ! evt )
            {
                var evt = window.event;
            }

            if( typeof( evt.pageX ) == "number" )
            {
                pos.x = evt.pageX;
                pos.y = evt.pageY;
            }
            else
            {
                pos.x = evt.clientX;
                pos.y = evt.clientY;
                if( ! top.opera )
                {
                    if( ( ! window.document.compatMode) || (window.document.compatMode == 'BackCompat') )
                    {
                        pos.x += window.document.body.scrollLeft;
                        pos.y += window.document.body.scrollTop;
                    }
                    else
                    {
                        pos.x += window.document.documentElement.scrollLeft;
                        pos.y += window.document.documentElement.scrollTop;
                    }
                }
            }

            return pos;
        },
        getBodyDimensions : function()
        {
            iHeight = 0;
            iWidth = 0;

            if (window.innerHeight && window.scrollMaxY) // Firefox
            {
                iHeight = window.innerHeight + window.scrollMaxY;
                iWidth = window.innerWidth + window.scrollMaxX;
            }
            else if(document.body.scrollHeight > document.body.offsetHeight) // All but Explorer Mac
            {
                iHeight = document.body.scrollHeight;
                iWidth = document.body.scrollWidth;
            }
            else // Works in Explorer 6 Strict, Mozilla (not FF) and Safari
            {
                iHeight = document.body.offsetHeight;
                iWidth = document.body.offsetWidth;
            }

            return { width: iWidth, height: iHeight }
        }
    },
    EventHandler : {

        eventContainer : [],
        addEvent : function(strEventRef, fNewEvent)
        {
            // Check if the eventContainer allready has a array for this event type. If not, create it.
            if(this.eventContainer[strEventRef] == null)
            {
                this.eventContainer[strEventRef] = [];
            }

            // Append the event to the event container
            this.eventContainer[strEventRef][this.eventContainer[strEventRef].length] = fNewEvent;

            // Reset the event on the reference, and make it fire the fireEvents method
            eval(strEventRef + "= function(e) { JoeDex.EventHandler.fireEvents('"+strEventRef+"', e); }");

            return;
        },
        fireEvents : function(strEventRef, e)
        {
            // Loop through all the events parsed to the event container, under this event reference
            for(var x = 0; x < this.eventContainer[strEventRef].length; x++)
            {
                this.eventContainer[strEventRef][x](e);
            }

            return;
        }

    }
}

//
// OnLoad handler class (DEPRECTED, use JoeDex.EventHandler.addEvent)
//
window.onload = function() { OnLoadHandler.loadEvents(); }
OnLoadHandler = {

    eventContainer : [],
    eventOrder : 0,
    cancelAllEvents : false,

    addEvent : function( f )
    {
        this.eventContainer[this.eventOrder++] = f;
        return;
    },
    loadEvents : function()
    {
        if( ! this.cancelAllEvents )
        {
            for( var x = 0; x < this.eventContainer.length; x++ )
            {
                if(this.eventContainer[x] != null)
                {
                    this.eventContainer[x]();
                }
            }
        }

        return;
    },
    clearEvents : function()
    {
        this.eventContainer = [];

        return;
    }
}
//
// window.open wrapper
//
function openWindow(strUrl, iWidth, iHeight, strWindowId)
{
    var winl = (screen.width - iWidth) / 2;
    var wint = (screen.height - iHeight) / 2;
    var winProps = 'height='+iHeight+',width='+iWidth+',top='+wint+',left='+winl+',resizable=0,scrollbars=1';
    var oWinPop = window.open(strUrl, strWindowId, winProps);

    oWinPop.focus();

    return oWinPop;
}
//
// Cookie functionality
//
function setCookie(name, value, expires, path, domain, secure)
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    // If the expires variable is set, make the correct expires time, the current script below will set it for x number of days, to make it for hours, delete * 24, for minutes, delete * 60 * 24
    if ( expires )
    {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + expires );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );

    return;
}
function getCookie(check_name)
{
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for (i = 0; i < a_all_cookies.length; i++)
    {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split('=');

        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if ( cookie_name == check_name )
        {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if ( a_temp_cookie.length > 1 )
            {
                cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
            }

            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;

            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if ( !b_cookie_found )
    {
        return null;
    }
}
//
// Date object extension (gets a week number)
//
Date.prototype.getWeek = function()
{
    // Get the date of january first, choosen year (use the selected date, minus one month, to satisfy the danish calendar)
    var oFirstJanTmp = new Date(this.getFullYear(), this.getMonth() - 1, this.getDate());
    var iFirstJan = new Date(oFirstJanTmp.getFullYear(), 0, 1);

    // Make a new date matching choosen date (use the selected date, minus one month, to satisfy the danish calendar)
    var oDanish = new Date(this.getFullYear(), this.getMonth() - 1, this.getDate());

    // Calculate the WeekNo :-)
    return Math.ceil( (((oDanish - iFirstJan) / 86400000) + iFirstJan.getDay()) / 7);
}
//
// parseInt wrapper
//
function ParseInt(strNumber)
{
    return parseInt(strNumber, 10);
}