﻿function oBrowser() { this.win = (navigator.platform == "Win32"); this.mac = (navigator.platform == "MacPPC" || navigator.platform == "MacIntel"); this.ver = navigator.appVersion; this.ua = navigator.userAgent; this.dom = document.getElementById; this.safari = (window.addEventListener && navigator.vendor == "Apple Computer, Inc."); this.ie7 = (this.ver.indexOf("MSIE 7") != -1 && this.dom); this.ie6 = (this.ver.indexOf("MSIE 6") != -1 && this.dom); this.ie5 = (this.ver.indexOf("MSIE 5") != -1 && this.dom); this.ie4 = (document.all && !this.dom); this.ie = (this.ie5 || this.ie4 || this.ie6 || this.ie7); this.ns7 = (this.ua.indexOf('Netscape/7') != -1); this.ns6 = (this.dom && parseInt(this.ver) >= 5); this.ns4 = (document.layers && !this.dom); this.ns = (this.ns4 || this.ns6 || this.ns7); this.op = window.opera || false; this.bw = (this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.ns7); this.bx = (this.ie5 || this.ns6 || this.ie6 || this.ns7); this.iWidth = 0; this.iHeight = 0; this.pLoaded = false; return this; }
var browser = new oBrowser(); var d = document; function gE(e) { return d.getElementById(e); }
var setOnce = true; function setDomain() {
    if (setOnce) { setOnce = false; } else { return; }
    if (browser.ie) {
        try {
            var a = document.domain.split(".").reverse(); if (isNaN(parseInt(a[0]))) {
                var b = []; for (var i = 0; a[i]; i++) { b.push(a[i]); if (a[i].length > 3) { break; } }
                document.domain = b.reverse().join(".");
            } 
        } catch (e) { } 
    } 
}
function getQS(p) { setDomain(); return new RegExp("[?&]+" + p + "=([^&$]*)", "gi").test(document.location.href) ? RegExp.$1 : ""; }
try { document.execCommand('BackgroundImageCache', false, true); } catch (e) { }
if (typeof Array.prototype.push != "function") { Array.prototype.push = function(o) { this[this.length] = o; }; }
String.prototype.encode = function() { return this.replace(/([^\x01-\x7E])/g, function(s) { return "&#" + s.charCodeAt(0) + ";"; }); }; String.prototype.decode = function() {
    Number.prototype.toHex = function(pad) {
        var s = this.toString(16).toUpperCase(); var v = ""; if (typeof pad == "number") { while (v.length + s.length < pad) { v += "0"; } }
        return v + s;
    }; return this.replace(/(&#([^;]*);)/g, function(s) { return unescape("%u" + Number(RegExp.$2).toHex(4)); });
}; function evt_load(fn) { var oldOnload = window.onload; if (typeof (window.onload) != "function") { window.onload = function() { if (typeof fn == "function") { fn(); } }; } else { window.onload = function() { oldOnload(); if (typeof fn == "function") { fn(); } }; } }
function sC(n, v, dy) {
    var s = ""; if (dy) { var dt = new Date(); dt.setTime(dt.getTime() + (dy * 24 * 60 * 60 * 1000)); s = "; expires=" + dt.toGMTString(); }
    d.cookie = n + "=" + v + s + "; path=/";
}
function gC(n) {
    var nEQ = n + "="; var aC = d.cookie.split(';'); for (var i = 0; i < aC.length; i++) {
        var c = aC[i]; while (c.charAt(0) == ' ') { c = c.substring(1, c.length); }
        if (c.indexOf(nEQ) === 0) { return c.substring(nEQ.length, c.length); } 
    }
    return null;
}
function eC(n) { sC(n, "", -1); }
var bLogin = true; function checkSubmit(e) {
    if (e.keyCode == 13) {
        var target = e.target || e.srcElement; var form = target.parentNode; while (form.tagName.toLowerCase() != "form" && form != document) { form = form.parentNode; }
        form.getElementsByTagName("a")[0].onclick();
    } 
}
function fieldHasValue(o) { return (o.getAttribute("type") == "hidden" || (o.value !== "" && o.value != o.defaultValue)); }
function clearField(o) { if (o.value == o.defaultValue) { o.value = ""; } }
function submitLogin(f) {
    var s1 = arguments[1] || "Please enter your Account Number."; 
    var s2 = arguments[2] || "Please enter your Password."; 
    if (bLogin) {
        var id = f.account_id;
        var pass = f.password;
        if (!fieldHasValue(id)) {
            alert(s1); id.focus(); id.select(); 
            return false;
        }
        else if (!fieldHasValue(pass)) 
        {
            alert(s2); pass.focus(); pass.select(); 
            return false;
        }
        else 
        {
            id.value = id.value.toUpperCase(); pass.value = pass.value.toUpperCase();
            var domain = "www.marketdatasystems.com";

            if (/^DEMO-/.test(id.value)) {
                window.location = "http://www.hlmarkets.co.uk/cfd-files/error/hls/en_gb/re_no_demo.html"; 
               
            }
            else {
                if (/^https/.test(f.action)) {
                    if (/^DEMO-/.test(id.value)) {
                        f.action = f.action.replace("www.", "demo.");
                    }
                    else if (!(/www./.test(domain))) {
                        f.action = f.action.replace("www", domain.substring(0, domain.indexOf(".")));
                    }
                }
                else {
                    f.action = "https://www.marketdatasystems.com/login/dealing/pd/spreadbet/security?action=authenticate";
                    bLogin = false;
                    f.submit();
                }
            }
        }
        return false;
    } 
}
function oFormVal(sName, spanID) { this.active = true; this.checkboxes = []; this.checkboxesm = []; this.radios = []; this.radiosm = []; this.mails = []; this.mailsm = []; this.longer = []; this.longerm = []; this.nr = []; this.either = []; this.dateText = []; this.sName = sName; this.spanID = (arguments.length = 2) ? spanID : null; }
oFormVal.prototype.addRequiredCheckBox = function(sName, sMessage) { this.checkboxes.push(sName); this.checkboxesm.push(sMessage); }; oFormVal.prototype.addRequiredRadio = function(sName, sMessage) { this.radios.push(sName); this.radiosm.push(sMessage); }; oFormVal.prototype.addMail = function(sName, sMessage) { this.mails.push(sName); this.mailsm.push(sMessage); }; oFormVal.prototype.addEither = function(sName1, sName2, sMessage) { this.either.push([sName1, sName2, sMessage]); this.nr[sName1] = true; this.nr[sName2] = true; }; oFormVal.prototype.addDate = function(sName, sMessage) { this.dateText.push([sName, sMessage]); }; oFormVal.prototype.addLonger = function(sName, sMessage) { this.longer.push(sName); this.longerm.push(sMessage); }; oFormVal.prototype.notRequired = function(sName) { this.nr[sName] = true; }; oFormVal.prototype.isCheckBox = function(o) { return (typeof o.nodeName == "string" && o.type == "checkbox"); }; oFormVal.prototype.isRadio = function(o) { return (o.type == "radio"); }; oFormVal.prototype.outputMessage = function(s) { if (this.spanID == null) { alert(s); } else { document.getElementById(this.spanID).innerHTML = s; } }
oFormVal.prototype.validate = function(s) {
    var f = d.forms[this.sName].elements; s = s || 'Sorry, please complete all details.'; if (this.spanID != null) { document.getElementById(this.spanID).innerHTML = ''; }
    for (var i = 0; f[i]; i++) { if (!this.nr[f[i].name] && f[i].name.length > 0 && !fieldHasValue(f[i]) && !this.isCheckBox(f[i]) && !this.isRadio(f[i])) { this.outputMessage(s); f[i].focus(); return false; } }
    for (i = 0; this.either[i]; i++) {
        if ((f[this.either[i][0]].value.length + f[this.either[i][1]].value.length) == 0)
        { this.outputMessage(this.either[i][2]); f[this.either[i][0]].focus(); return false; } 
    }
    for (i = 0; this.dateText[i]; i++) { if (!/^(0[1-9]|[12]\d|3[01])\/(0[1-9]|1[0-2])\/19[4-9]\d/.test(f[this.dateText[i][0]].value)) { this.outputMessage(this.dateText[i][1]); f[this.dateText[i][0]].focus(); return false; } }
    for (i = 0; this.checkboxes[i]; i++) { if (!f[this.checkboxes[i]].checked) { this.outputMessage(this.checkboxesm[i]); return false; } }
    for (i = 0; this.radios[i]; i++) {
        var radioChecked = false; for (var p = 0; f[this.radios[i]][p]; p++) { if (f[this.radios[i]][p].checked) { radioChecked = true; } }
        if (!radioChecked) { this.outputMessage(this.radiosm[i]); return false; } 
    }
    for (i = 0; this.mails[i]; i++) { if (!/^.+\@[A-Za-z0-9][A-Za-z0-9\-]+\..+[A-Za-z]$/.test(f[this.mails[i]].value)) { this.outputMessage(this.mailsm[i]); f[this.mails[i]].focus(); return false; } }
    for (i = 0; this.longer[i]; i++) { if (f[this.longer[i]].value.length < 2) { this.outputMessage(this.longerm[i]); f[this.longer[i]].focus(); return false; } }
    return true;
}; function AJAX(url, fn) {
    var rand = "ajax_" + Math.round(Math.random() * 5000); while (typeof window[rand] != "undefined") { rand = "ajax_" + Math.round(Math.random() * 5000); }
    if (browser.ie) { try { window[rand] = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { window[rand] = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { window[rand] = false; } } } else if (typeof XMLHttpRequest != "undefined") { window[rand] = new XMLHttpRequest(); }
    if (window[rand]) { window[rand].open("GET", url, true); window[rand].onreadystatechange = function() { if (window[rand].readyState == 4 && window[rand].status == 200) { fn(window[rand].responseText); } else if (window[rand].readyState == 4 && window[rand].status == 404) { fn("AJAX Error " + window[rand].status + ": Page not found"); } else if (window[rand].readyState == 4 && parseInt(window[rand].status) == 5) { fn("AJAX error " + window[rand].status + ": Internal server error"); } }; window[rand].send(null); return window[rand]; } else { return null; } 
}
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false; function ControlVersion() {
    var version; var axo; var e; try { axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"); version = axo.GetVariable("$version"); } catch (e) { }
    if (!version)
    { try { axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"); version = "WIN 6,0,21,0"; axo.AllowScriptAccess = "always"; version = axo.GetVariable("$version"); } catch (e) { } }
    if (!version)
    { try { axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); version = axo.GetVariable("$version"); } catch (e) { } }
    if (!version)
    { try { axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); version = "WIN 3,0,18,0"; } catch (e) { } }
    if (!version)
    { try { axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); version = "WIN 2,0,0,11"; } catch (e) { version = -1; } }
    return version;
}
function GetSwfVer() {
    var flashVer = -1; if (navigator.plugins != null && navigator.plugins.length > 0) {
        if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
            var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : ""; var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description; var descArray = flashDescription.split(" "); var tempArrayMajor = descArray[2].split("."); var versionMajor = tempArrayMajor[0]; var versionMinor = tempArrayMajor[1]; var versionRevision = descArray[3]; if (versionRevision == "") { versionRevision = descArray[4]; }
            if (versionRevision[0] == "d") { versionRevision = versionRevision.substring(1); } else if (versionRevision[0] == "r") { versionRevision = versionRevision.substring(1); if (versionRevision.indexOf("d") > 0) { versionRevision = versionRevision.substring(0, versionRevision.indexOf("d")); } }
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
        } 
    } else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) { flashVer = 4; } else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) { flashVer = 3; } else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) { flashVer = 2; } else if (isIE && isWin && !isOpera) { flashVer = ControlVersion(); }
    return flashVer;
}
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) {
    var versionStr = GetSwfVer(); if (versionStr == -1) { return false; } else if (versionStr != 0) {
        if (isIE && isWin && !isOpera) { var tempArray = versionStr.split(" "); var tempString = tempArray[1]; var versionArray = tempString.split(","); } else { var versionArray = versionStr.split("."); }
        var versionMajor = versionArray[0]; var versionMinor = versionArray[1]; var versionRevision = versionArray[2]; if (versionMajor > parseFloat(reqMajorVer)) { return true; } else if (versionMajor == parseFloat(reqMajorVer)) { if (versionMinor > parseFloat(reqMinorVer)) { return true; } else if (versionMinor == parseFloat(reqMinorVer)) { if (versionRevision >= parseFloat(reqRevision)) { return true; } } }
        return false;
    } 
}
var bFlash = (DetectFlashVer(8, 0, 0)); function detectFlash() { return bFlash; }
function insertFlash(movie, w, h, mode, bg, vars, target, replacementIMG, replacementURL) {
    var str = ""; if (bFlash) {
        var a = [["movie", movie], ["wmode", mode], ["bgcolor", bg], ["flashvars", vars]]; str = '<object type="application/x-shockwave-flash" data="' + movie + '" width="' + w + '" height="' + h + '">'; for (var i = 0; a[i]; i++) { if (a[i][1]) { str += '<param name="' + a[i][0] + '" value="' + a[i][1] + '" />'; } }
        str += '</object>';
    } else { if (replacementIMG && replacementURL) { str = "<a href=" + replacementURL + "><img src=\"" + replacementIMG + "\" width=" + w + " height=" + h + " border='0'></a>"; } }
    if (!target || target == "undefined") { d.write(str); } else if (target == "return string") { return str; } else if (typeof target == "string") { if (gE(target)) { gE(target).innerHTML = str; } } else if (typeof target == "object") { target.innerHTML = str; } 
}
function goTo(s) { if (document.selectLanguage) { var of = document.selectLanguage; of.action = s; of.submit(); } else { window.location.href = s; } }
function openWindow(url, n, w, h, bResize, bScroll, bStatus, nSame) {
    var l = parseInt((screen.availWidth / 2) - (w / 2)); var t = parseInt((screen.availHeight / 2) - (h / 2)); if (!nSame) { n == n + Math.floor(Math.random() * 99); }
    var win = window.open(url, n, 'toolbar=0,location=0,menubar=0,directories=0,scrollbars=' + bScroll + ',status=' + bStatus + ',resizable=' + bResize + ',Width=' + w + ',Height=' + h + ',left=' + l + ',top=' + t + ',screenX=' + l + ',screenY=' + t + ''); if (win && !win.closed) { win.focus(); }
    if (top.wins) { top.wins[top.wins.length] = win; }
    return win;
}
function whatsNew() { var sCol = arguments[0] || "#336699"; var sOver = arguments[1] || "#003366"; var ul = gE("ulWhatsNew"); var div = gE("divScroller"); if (ul && div && bFlash) { var v = "w=150&h=75&headerFont=trebuchet%20ms&bodyFont=Verdana&fontCol=" + sCol + "&RollOverCol=" + sOver + "&hold=4000&data=" + escape(ul.innerHTML.encode()); insertFlash("/flash/WNScroller.swf", 150, 75, "transparent", "", v, div); } else if (ul && div) { div.style.display = 'none'; ul.style.display = 'block'; } }
function openHelp(s) { openWindow("/content/" + s + ".html", "Help", 660, 500, 0, 0, 0); }
function openDealer() { var sIG3G = gC("iconStateSetting"); if (sIG3G) { if ((screen.width - 17) < 1050) { window.open(sIG3G, "dealingApplication", "fullscreen=0,titlebar,resizable,status=1,height=" + (screen.height - 67) + ",width=" + (screen.width - 17) + ",left=2,top=2"); } else { window.open(sIG3G, "dealingApplication", "fullscreen=0,titlebar,resizable,status=1,height=768,width=1024,left=2,top=2"); } } }
function confirmContext() { if (!gC("iconStateSetting")) { top.location.replace("/"); } }
function importScript(src) { var scriptElem = document.createElement('script'); scriptElem.setAttribute('src', src); scriptElem.setAttribute('type', 'text/javascript'); document.getElementsByTagName('head')[0].appendChild(scriptElem); }
var handleSuccess = function(o) { var DOM = YAHOO.util.Dom; DOM.addClass(DOM.get(oSource), "hidden"); if (o.responseText.indexOf("responseObject") >= 0) { DOM.removeClass(DOM.get(oSuccess), "hidden"); } else { DOM.removeClass(DOM.get(oFailed), "hidden"); } }; var handleFailure = function(o) { var DOM = YAHOO.util.Dom; DOM.addClass(DOM.get(oSource), "hidden"); DOM.removeClass(DOM.get(oFailed), "hidden"); }; var callback = { success: handleSuccess, failure: handleFailure }; var submitXForm = function(f, o) {
    if (o) {
        var fields = f.getElementsByTagName("input"); var postData; var arRadios = {}; for (var i = 0; i < fields.length; i++) { if (fields[i].type != "radio") { if (fields[i].type == "checkbox") { if (fields[i].checked) { postData += "&" + fields[i].name + "=" + fields[i].value; } } else { postData += "&" + fields[i].name + "=" + fields[i].value; } } else { arRadios[fields[i].name] = true; } }
        for (var rName in arRadios) { var radioName = f[rName]; for (var p = 0; radioName[p]; p++) { if (radioName[p].checked) { postData += "&" + radioName[p].name + "=" + radioName[p].value; } } }
        var request = YAHOO.util.Connect.asyncRequest('POST', f.action, callback, postData);
    }
    return false;
}; var getFirstParentByTagName = function(el, tagName) {
    var parent = el; while (parent && parent.tagName && parent.tagName.toLowerCase() != tagName.toLowerCase()) {
        if (parent.tagName.toLowerCase() == "html") { return null; }
        parent = parent.parentNode;
    }
    return parent;
}
