﻿var lastUpdateMin = new Date();
function ClipTransform(obj)
{
    this.objToTransfrom = obj;

    this.clipLeft = 0;
    this.clipRight= 350;
    this.clipBottom= 350;
    this.clipTop=0;
    this.increment= 1;
    this.step = 30;
    
    this.cl=350;
    this.cr=350;
    this.cb=0;
    this.ct=0;
    this.changeNeed =false;
    this.timeoutID = 0;
    this.transform =function()
    {   
        var d = "rect(" + this.ct + "px " + this.cr + "px " + this.cb + "px " + this.cl + "px )";
        this.objToTransfrom.style.clip = d;
        if (this.change())
           this.timeoutID = setTimeout(this.transform.bind(this) ,this.increment);
    };
    
    this.objToTransfrom.style.display="";
    this.change =  function()
    {
        this.changeNeed =false;
        if (this.cl > 0 )
        {
            this.cl -=this.step;
            this.changeNeed =true;
        }
        if (this.cb < this.clipBottom)
        {
            this.cb += this.step;
            this.changeNeed =true;
        }
        if (this.ct < this.clipTop)
        {
            this.ct += this.step;
            this.changeNeed =true;
        }
        return this.changeNeed;
    };
  
    this.stop = function ()
    {
        clearTimeout(this.timeoutID);
        this.changeNeed =false;
    };
     
    this.start= function() {
        this.objToTransfrom.style.clip="rect(0px 0px 0px 0px)";
        this.timeoutID = setTimeout(this.transform.bind(this) ,this.increment);
    };
}

function showPW_LTP(a, b) {
    if (curr_w_pop_id != "") {
        hidePW(curr_w_pop_id)
    }
    getTopLeft(b);
    curr_w_pop_id = a;
    var c = document.getElementById(a);
    c.style.visibility = "visible";
    c.style.top = cTop + b.offsetHeight + offsettop + "px";
    var d = ie && !window.opera ? ietruebody().clientWidth : window.innerWidth - 20;
    c.style.left = cLeft + "px";
    new ClipTransform(c)
}
function goToCBBCMore(a, b, c) {
    if (c == 1) {
        location.href = a
    } else if (c == 2) {
        location.href = a + "RedeemType=" + b
    }
}
function goToWarrantMore(a, b, c) {
    if (c == 1) {
        location.href = a
    }
}
function goToCF(a, b, c) {
    location.href = a + "CFType=" + b + "&symbol=" + c
}
function openRTQNews(a) {
    winopen(a, 800, 600)
}
function ChartChange(f) {
    if (new Date() - lastUpdateMin >= 2 * 1000 * 60) {
        xmlhttpPost(f)
    } else {
        var a = document.getElementById("chartdiv");
        var b = document.getElementById('innerchartDiv').offsetHeight;
        var c = document.getElementById('hidColor').value;
        var d = document.getElementById('hidPeriod').value;
        document.getElementById(ChartID).src = ChartPath.replace("{1}", d).replace("{2}", c);
        if (c == "3") {
            a.style.background = "#000000"
        } else {
            a.style.background = "#FFFFFF"
        }
    }
}
function SetHiddenValue(a, b, c) {
    document.getElementById(a).value = b;
    if (a == "hidColor") {
        setCookie("scheme", b, 365)
    }
    ChartChange(c)
}
function showPW(a, b) {
    if (curr_w_pop_id != "") {
        hidePW(curr_w_pop_id)
    }
    getTopLeft(b);
    curr_w_pop_id = a;
    var c = document.getElementById(a);
    c.style.visibility = "visible";
    c.style.top = cTop + b.offsetHeight + offsettop + "px";
    var d = ie && !window.opera ? ietruebody().clientWidth : window.innerWidth - 20;
    c.style.left = cLeft - c.offsetWidth + offsetleft + "px";
    new ClipTransform(c)
}
function hidePW(a) {
    var b = document.getElementById(a);
    b.style.visibility = "hidden"
}
function setCookie(a, b, c) {
    var d = new Date();
    d.setDate(d.getDate() + c);
    document.cookie = a + "=" + escape(b) + ";domain=.aastocks.com;path=/;" + ((c == null) ? "" : ";expires=" + d.toGMTString())
}
function overIC() {
    if (document.getElementById("divIC")) {
        document.getElementById("divIC").style.visibility = "visible";
        document.getElementById("divOverID").style.visibility = "hidden"
    }
}
function outIC() {
    if (document.getElementById("divIC")) {
        document.getElementById("divIC").style.visibility = "hidden";
        document.getElementById("divOverID").style.visibility = "visible"
    }
}
function overID() {
    if (document.getElementById("divID")) {
        document.getElementById("divID").style.visibility = "visible"
    }
}
function outID() {
    if (document.getElementById("divID")) {
        document.getElementById("divID").style.visibility = "hidden"
    }
}
function updateChart(t) {
    var a = document.getElementById("chartdiv");
    var c = document.getElementById('hidColor').value;
    var d = document.getElementById('hidPeriod').value;
    if (c == "3") {
        a.style.background = "#000000"
    } else {
        a.style.background = "#FFFFFF"
    }
    ChartPath = ChartPath.substring(0, ChartPath.lastIndexOf("=") + 1) + t;
    var b = ChartPath.replace("{1}", d).replace("{2}", c);
    document.getElementById(ChartID).src = b
}
function xmlhttpPost(f) {
    var a = false;
    var b = this;
    if (window.XMLHttpRequest) {
        b.xmlHttpReq = new XMLHttpRequest()
    } else if (window.ActiveXObject) {
        b.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP")
    }
    b.xmlHttpReq.open('POST', 'LTPTChartProxy.aspx', true);
    b.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    b.xmlHttpReq.onreadystatechange = function () {
        if (b.xmlHttpReq.readyState == 4) {
            lastUpdateMin = new Date();
            updateChart(b.xmlHttpReq.responseText)
        }
    };
    b.xmlHttpReq.send("symbol=" + f + ".HK")
}
