﻿function getRes() {
    var viewportwidth;
    var viewportheight;

    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerWidth;
        viewportheight = window.innerHeight
    }

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
    else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth;
        viewportheight = document.documentElement.clientHeight;
    }

    // older versions of IE
    else {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
        viewportheight = document.getElementsByTagName('body')[0].clientHeight;
    }

    return viewportwidth + 'x' + viewportheight + "|" + screen.width + 'x' + screen.height;
}

//create a new class for the jarHandle
//3 temporary methods to catch unhandled calls incase the flash isn't loaded
var jarHandle = new function () {
    try {
        this.jarPush = function () { return false; }
        this.jarPull = function () { return false; }
        this.jarClear = function () { return false; }
    }
    catch (e) { }
}

//function executed when the flash is loaded and ready
//params: none
//returns: none
function jarCallback(a) {
    try {
        jarHandle = document.getElementById("fs");
        setTimeout(jarInit, 500);
    }
    catch (e) { }
}

//function acts as a failsafe incase the jar swf hasnt fully loaded
//will repeat indefinitely until jar functions are found
//params: none
//returns: none
function jarInit() {
    //  WHD JS Error
    try {
        if (jarHandle.jarVer == undefined) {
            setTimeout(jarInit, 1000);
            return;
        }
        jarHandle = document.getElementById("fs");
    } catch (e) {

    }
}

function jarSetCookie(key, value) {
    /*
    if (jarHandle.jarVer == undefined) {
        setTimeout("jarSetCookie('" + key + "', '" + value + "');", 100);
        return;
    }
    */
    try {
        jarHandle.jarPush(key, value);
    } catch (err) {
        //alert(err);
    }
}

function jarGetCookie(key, returnfunc) {
try {
        if (jarHandle.jarPull(key) == null) {
            returnfunc += "('null');";
            eval(returnfunc);
            //return;
        }


        if (jarHandle.jarVer == undefined) {
            setTimeout("jarGetCookie('" + key + "', '" + returnfunc + "');", 500);
            return;
        }
        returnfunc += "('" + jarHandle.jarPull(key) + "');";
        eval(returnfunc);
    } catch (err) {
        //alert(err);
    }

}
//function to get a cookie
//params: none
//returns: none
//note: This is just an anonymous function for the button to call.
//the actual important bit is "jarHandle.jarPull" which actually does the magic.
//jarHandle.jarPull takes 1 input: ID (string)
//jarHandle.jarPull returns 1 value (variant/object)
//if the cookie with the ID doesn't exist, it returns NULL
function getCookie(id) {
    try {
        return jarHandle.jarPull(id);
    } catch (err) {
        //alert(err);
    }
    
}

//function to destroy a cookie
//params: none
//returns: none
//note: This is just an anonymous function for the button to call.
//the actual important bit is "jarHandle.jarPull" which actually does the magic.
//jarHandle.jarClear takes 1 input: ID (string)
//jarHandle.jarClear returns BOOL. True for successful deletion, FALSE for failure or error
function killCookie(id) {

    try {
        return jarHandle.jarClear(id);
    } catch (err) { }

}
