﻿
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];
    }
}

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;
    }
}

//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 ShowPopup(title, frameSource, width, height) {

    var lbl = document.getElementById("PopupTitleDiv");
    lbl.innerHTML = title;
    var frame = document.getElementById("PopupIFrame");
    frame.src = frameSource;
    frame.width = width + "px";
    frame.height = height + "px";

    var frameContainer = document.getElementById("FrameContainer");
    frameContainer.style.width = width + "px";
    frameContainer.style.height = height + 37 + "px";
    frameContainer.style.marginLeft = "-" + ((width / 2) + 5) + "px"; // don't know why i need to fix for those 5px... but it works now
    //container.style.marginTop = "-" + (height / 2) + "px";
    //alert(frame);

    var popupContainer = document.getElementById("PopupContainer");
    popupContainer.style.visibility = "visible";
    popupContainer.style.display = "block";
}

function HidePopup() {
    var popupContainer = document.getElementById("PopupContainer");
    var frame = document.getElementById("PopupIFrame");
    frame.src = "";
    popupContainer.style.visibility = "hidden";
    popupContainer.style.display = "none";
}
//--------------------------------------------------------------


function SetPositions() {
    try {
        InitMenus();
    } catch (ex) {
    }
    try {
        //PositionLanguageMenu();

    } catch (ex) {
    }
    try {
        var popupCont = document.getElementById("PopupBackground");
        var loginCont = document.getElementById("LoginPopupBackground");
        popupCont.style.height = document.body.scrollHeight + "px";
        loginCont.style.height = document.body.scrollHeight + "px";
    } catch (ex) { }


}

function WindowOnLoad() {
    SetPositions();
    MM_preloadImages('http://www.hfx.com/Content/Images/Global/mainBtnsTop.png',
                               'http://www.hfx.com/Content/Images/Global/mainBtnsTopOn.png',
                               'http://www.hfx.com/Content/Images/Global/mainBtnsBottm.png',
                               'http://www.hfx.com/Content/Images/Global/mainBtnsBottmOn.png',
                               'http://www.hfx.com/Content/Images/Global/cntntBtnLeft.png',
                               'http://www.hfx.com/Content/Images/Global/cntntBtnLeftOn.png',
                               'http://www.hfx.com/Content/Images/Global/cntntBtnRight.png',
                               'http://www.hfx.com/Content/Images/Global/cntntBtnRightOn.png',
                               'http://www.hfx.com/Content/Images/Global/goldBtn.png',
                               'http://www.hfx.com/Content/Images/Global/goldBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/headerBtnsLogin.png',
                               'http://www.hfx.com/Content/Images/Global/headerBtnsLoginOn.png',
                               'http://www.hfx.com/Content/Images/Global/orangeBtn.png',
                               'http://www.hfx.com/Content/Images/Global/orangeBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/platinumBtn.png',
                               'http://www.hfx.com/Content/Images/Global/platinumBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/silverBt.png',
                               'http://www.hfx.com/Content/Images/Global/silverBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/asseRightBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/asseRightBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/assetLeftBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/assetLeftBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/Btn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/BtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/innerBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/innerBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/iTraderBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/iTraderBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/sideMenuTop.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/startBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/startBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/topBarLeftBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/topBarLeftBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/topBarRightBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/topBarRightBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/ContactUs/chatBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/ContactUs/chatBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/ContactUs/submitBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/ContactUs/submitBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/DepositMethods/greyBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/DepositMethods/greyBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/DepositMethods/orangeBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/DepositMethods/orangeBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/PasswordRecovery/recoverBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/PasswordRecovery/recoverBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/Refer/SendBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Inner/Refer/SendBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Login/loginBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Login/loginBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Login/loginRegisterBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Login/loginRegisterBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/NotFound/cntntBtnLeftOn.png',
                               'http://www.hfx.com/Content/Images/Global/NotFound/cntntBtnRight.png',
                               'http://www.hfx.com/Content/Images/Global/TradeNow/webTraderLogin_leftBtn.png',
                               'http://www.hfx.com/Content/Images/Global/TradeNow/webTraderLogin_leftBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/TradeNow/webTraderLogin_rightBtn.png',
                               'http://www.hfx.com/Content/Images/Global/TradeNow/webTraderLogin_rightBtnOn.png',
                               'http://www.hfx.com/Content/Images/Global/Deposit/depositBtn.png',
                               'http://www.hfx.com/Content/Images/Global/Deposit/depositBtnOn.png');
    try {
        //marquee on homepage
        var calScroll = new MarqueeObject(document.getElementById("calendarContainerDiv"), document.getElementById("calendarScrolledDiv"));
        var analScroll = new MarqueeObject(document.getElementById("analysisContainerDiv"), document.getElementById("analysesScrolledDiv"));
    } catch (ex) { }
    try {
        //videos
        LaunchVideoTutorial();
    } catch (ex) { }
    try {
        SetLeftBarHeight();
    } catch (ex) { }
}

function WindowOnResize() {
    SetPositions();

}
window.onload = WindowOnLoad;
 
window.onresize = WindowOnResize;


function MM_preloadImages() {
    //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

