﻿
function Hashtable() {
    this.length = 0;
    this.items = new Array();

    this.getItems = function () {
        return this.items;
    }

    for (var i = 0; i < arguments.length; i += 2) {
        if (typeof (arguments[i + 1]) != 'undefined') {
            this.items[arguments[i]] = arguments[i + 1];
            this.length++;
        }
    }

    this.removeItem = function (in_key) {
        var tmp_previous;
        if (typeof (this.items[in_key]) != 'undefined') {
            this.length--;
            var tmp_previous = this.items[in_key];
            delete this.items[in_key];
        }

        return tmp_previous;
    }

    this.getItem = function (in_key) {
        return this.items[in_key];
    }

    this.setItem = function (in_key, in_value) {
        var tmp_previous;
        if (typeof (in_value) != 'undefined') {
            if (typeof (this.items[in_key]) == 'undefined') {
                this.length++;
            }
            else {
                tmp_previous = this.items[in_key];
            }

            this.items[in_key] = in_value;
        }

        return tmp_previous;
    }

    this.hasItem = function (in_key) {
        return typeof (this.items[in_key]) != 'undefined';
    }

    this.clear = function () {
        for (var i in this.items) {
            delete this.items[i];
        }

        this.length = 0;
    }
}

function GetPosition(oElement) {
    if (typeof (oElement.offsetParent) != 'undefined') {
        for (var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) {
            posX += oElement.offsetLeft;
            posY += oElement.offsetTop;
        }
        return [posX, posY];
    } else {
        return [oElement.x, oElement.y];
    }
}


//Refresh login iframe
function RefreshTopLogin() {
    var loginFrame = document.getElementById("TopLoginFrame");
    var doc = loginFrame.contentWindow || loginFrame.contentDocument;
    doc.location.href = doc.location.href;
}

//OUR GENERIC POPUP IFRAME
//-------------------------------------------------------------
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_scrollTop() {
    return f_filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
//--------------------------------------------------------------
function ShowPopup(obj) {
    obj.style.visibility = "visible";
}

function SetPopupOverlaySize(obj) {
    obj.style.height = document.body.scrollHeight + "px";
}

function SetPopupFramePosition(obj) {

    var oHeight = f_scrollTop() + document.documentElement.clientHeight / 2;
    oHeight = oHeight - obj.offsetHeight / 2;
    obj.style.marginLeft = ((obj.offsetWidth / 2) * -1) + "px";
    obj.style.top = (oHeight) + "px";
}

//init window events to avoid null
window.onload = function () { };
window.onresize = function () { };
window.onscroll = function () { };

//handle additional methods for onload/onresize
function addOnLoad(fn, params) {
    var old = window.onload;
    window.onload = function () {
        old();
        try {
            if (fn) {
                fn(params);
            }
        } catch (ex) { }
    };
}

function addOnResize(fn, params) {
    var old = window.onresize;
    window.onresize = function () {
        old();
        try {
            if (fn) {
                fn(params);
            }
        } catch (ex) { }
    };
}

function addOnScroll(fn, params) {
    var old = window.onscroll;
    window.onscroll = function () {
        old();
        try {
            if (fn) {
                fn(params);
            }
        } catch (ex) { }
    };
}







