﻿function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function () {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function getTimeData() {
    // the url of the script where we send the asynchronous call
    var ajaxURL = 'http://forex-ufxbank.com/Toyga/httpHandlers/datetimehandler.ashx?op=getgmttime';
    // create a new script element
    var JSONPscript = document.createElement('script');
    // set the src attribute to that url
    JSONPscript.setAttribute('src', ajaxURL);
    JSONPscript.setAttribute('id', "jsonPScriptObject");
    // insert the script in out page
    document.getElementsByTagName('head')[0].appendChild(JSONPscript);
}
getTimeData();

function isBlocked() {
    var yearNow = myJSONObject.time.substr(6, 4);
    var monthNow = myJSONObject.time.substr(3, 2);
    var dayNow = myJSONObject.time.substr(0, 2);
    var hourNow = myJSONObject.time.substr(11, 2);
    var minuteNow = myJSONObject.time.substr(14, 2);
    var secondNow = myJSONObject.time.substr(17, 2);

    /*if (parseFloat(monthNow) > 9) {*/
        monthNow = parseFloat(monthNow) - 1;
    /*}*/

    var fridayHour = 20;
    var sundayHour = 21;

    /*    var fridayHour = 11;
    var sundayHour = 13; */

    var d = new Date(yearNow, monthNow, dayNow, hourNow, minuteNow, secondNow, 0);

    if ((d.getDay() == 5 && parseFloat(hourNow) >= fridayHour) || d.getDay() == 6 || (d.getDay() == 0 && parseFloat(hourNow) < sundayHour)) {
    /*if ((d.getDay() == 5 && parseFloat(hourNow) >= fridayHour) || d.getDay() == 6 || d.getDay() == 0 || (d.getDay() == 1 && parseFloat(hourNow) < sundayHour)) {*/
        // 5 = friday, 6 = saturday, 0 = sunday - Blocked
        if (typeof tradingIsClosed != 'undefined') {
            tradingIsClosed();
        }
        else {
            alert('Error 107!');
        }
    }
    else {
        if (typeof tradingIsOpen != 'undefined') {
            tradingIsOpen();
        }
        else {
            alert('Error 108!');
        }
    }
}
function HandleIsBlocked() {
    if (typeof myJSONObject != 'undefined') {
        isBlocked();
    }
    else {
        setTimeout('isBlocked()', 5000);
    }
}
addLoadEvent(HandleIsBlocked);

function tradingIsClosed() {
    if (typeof document.getElementById('tradingBlocked') != document.getElementById('tradingBlocked') != 'undefined' && typeof document.getElementById('tradingBlockeddiv') != 'undefined') {
        document.getElementById('tradingBlocked').style.display = "block";
        document.getElementById('tradingBlockeddiv').style.display = "block";
    }
}
function tradingIsOpen() {
    if (typeof document.getElementById('tradingBlocked') != document.getElementById('tradingBlocked') != 'undefined' && typeof document.getElementById('tradingBlockeddiv') != 'undefined') {
        document.getElementById('tradingBlocked').style.display = "none";
        document.getElementById('tradingBlockeddiv').style.display = "none";
    }
}

