﻿var WarrantCall;
var WarrantPut;
var CBBCBull;
var CBBCBear;
var Color;
var ChartPath;
var ChartID;

function SetDivHeight()
{ 
   var maindivHeight = document.getElementById('maindiv').offsetHeight;
   
   document.getElementById("chartdiv").style.height = maindivHeight -3 + "px";
   document.getElementById("quotediv").style.height = maindivHeight + "px";
}

function WarrantList(issuer, name, name2)
{
    var href = '<a href="DetailQuote.aspx?symbol={0}" class="font12a">{1}</a>';
    var resultCall = ''; 
    var resultPut = '';  
    var symbolListCall, symbolListPut;
    
    try
    {
        symbolListCall = WarrantCall[issuer].split(',');
        for (i = 0; i < symbolListCall.length; i++)
        {
            resultCall += ', ' + href.replace('{0}', symbolListCall[i]).replace('{1}', symbolListCall[i]);
        }
        
        symbolListPut = WarrantPut[issuer].split(',');
        for (i = 0; i < symbolListPut.length; i++)
        {
            resultPut += ', ' + href.replace('{0}', symbolListPut[i]).replace('{1}', symbolListPut[i]);
        }
        
        if (resultCall != '')
        {
            resultCall = resultCall.substring(2);
        }
        if (resultPut != '')
        {
            resultPut = resultPut.substring(2);
        }
        
        var a = document.getElementById(name);
        if (a) {
            a.innerHTML = resultCall;
        }
        
        var b = document.getElementById(name2);
        if (b) {
            b.innerHTML = resultPut;
        }
    }
    catch (ex)
    {}  
}

function CBBCList(issuer, name, name2)
{
    var href = '<a href="DetailQuote.aspx?symbol={0}" class="font12a">{1}</a>';
    var resultCall = ''; 
    var resultPut = '';  
    var symbolListCall, symbolListPut;
    
    try
    { 
        symbolListCall = CBBCBull[issuer].split(',');
        for (i = 0; i < symbolListCall.length; i++)
        {
            resultCall += ', ' + href.replace('{0}', symbolListCall[i]).replace('{1}', symbolListCall[i]);
        }
        
        symbolListPut = CBBCBear[issuer].split(',');
        for (i = 0; i < symbolListPut.length; i++)
        {
            resultPut += ', ' + href.replace('{0}', symbolListPut[i]).replace('{1}', symbolListPut[i]);
        }
        
        if (resultCall != '')
        {
            resultCall = resultCall.substring(2);
        }
        if (resultPut != '')
        {
            resultPut = resultPut.substring(2);
        }
     
        var a = document.getElementById(name);
        if (a) {
            a.innerHTML = resultCall;
        }
        
        var b = document.getElementById(name2);
        if (b) {
            b.innerHTML = resultPut;
        }
             
    }
    catch (ex)
    {}  
}

function ChartChange()
{
    var chartdiv = document.getElementById("chartdiv");
    var maindivHeight = document.getElementById('maindiv').offsetHeight;
    var color = document.getElementById('hidColor').value;
    var period = document.getElementById('hidPeriod').value; 
    
    chartdiv.style.height = maindivHeight -3 + "px"; 
    
    document.getElementById(ChartID).src = ChartPath.replace("{1}", period).replace("{2}", color);
    
    if (color == "3")
    { 
        chartdiv.style.background = "#000000";
    }
    else
    { 
        chartdiv.style.background = "#FFFFFF";
    }
}

function SetHiddenValue(name, value)
{
    document.getElementById(name).value = value;
    if (name == "hidColor")
    { 
          setCookie("scheme",value,365);
    } 
    ChartChange(); 
}

function setCookie(name,value,expire){   
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expire);
	document.cookie = name + "=" + escape(value) + ";domain=.aastocks.com;path=/;" + ((expire==null) ? "" : ";expires="+exdate.toGMTString());
}

function QuoteMeter(msg)
{
    alert(msg);        
}

function overIC()
{  
    if (document.getElementById("divIC"))
    { 
        document.getElementById("divIC").style.visibility = "visible";
    }
}

function outIC()
{
    if (document.getElementById("divIC"))
    { 
        document.getElementById("divIC").style.visibility = "hidden";
    }    
}

function overDelayBtn()
{  
    if (document.getElementById("divDelay"))
    { 
        document.getElementById("divDelay").style.visibility = "visible";
    }
}

function outDelayBtn()
{
    if (document.getElementById("divDelay"))
    { 
        document.getElementById("divDelay").style.visibility = "hidden";
    }
}

var w3c=(document.getElementById)? true:false;
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));
var ie5=(w3c && ie)? true : false;
var ns6=(w3c && (navigator.appName=="Netscape"))? true: false;
var op8=(navigator.userAgent.toLowerCase().indexOf("opera")==-1)? false:true;
var offsettop = 5;
var offsetleft = 18;
var curr_w_pop_id = "";
var cLeft = 0;
var cTop = 0;

function ClipTransform(obj)
{
    this.objToTransfrom = obj;

    this.clipLeft = 0;
    this.clipRight= 350;
    this.clipBottom= 350;
    this.clipTop=0;
    this.increment= 1;
    this.step = 16;
    
    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 ietruebody()
{
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function showPW(id, btn)
{
    if(curr_w_pop_id != "")
    {
        hidePW(curr_w_pop_id);
    }

    getTopLeft(btn);
    
    curr_w_pop_id = id;
    var tipobj=document.getElementById(id);
    tipobj.style.visibility="visible";
    tipobj.style.top = cTop + btn.offsetHeight + offsettop + "px";

    var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20;
    tipobj.style.left = cLeft - tipobj.offsetWidth + offsetleft + "px";
    //new ClipTransform(tipobj).start();
    new ClipTransform(tipobj);
}

function hidePW(id)
{
    var tipobj=document.getElementById(id);
    tipobj.style.visibility="hidden";
}

function getTopLeft(obj)
{
    var nLt=0;
    var nTp=0;
    
    var offsetParent = obj;
    while (offsetParent!=null && offsetParent!=document.body) 
    {
        nLt+=offsetParent.offsetLeft;
        nTp+=offsetParent.offsetTop;
        if(!ns6)
        {
            parseInt(offsetParent.currentStyle.borderLeftWidth)>0?nLt+=parseInt(offsetParent.currentStyle.borderLeftWidth):"";
            parseInt(offsetParent.currentStyle.borderTopWidth)>0?nTp+=parseInt(offsetParent.currentStyle.borderTopWidth):"";
        }
        offsetParent=offsetParent.offsetParent;
    }
    
    cLeft = nLt;
    cTop = nTp;
}