﻿//common functions////////////////////////////////////

function ToggleControl(id, display)
{
	var control=document.getElementById(id);
	if (display==null)
	    if (control.style.display=="block") 
	        control.style.display="none";
	    else 
	        control.style.display="block";
	else
	    control.style.display=display;
}

//feature functions////////////////////////////////////////
function RefreshPage()
{   
    ToggleControl("SignInFrame");
    document.location.reload(true);
}

function GetCookie(name)
{
  // cookies are separated by semicolons
  var cookieList = document.cookie.split("; ");
  for (var i=0; i < cookieList.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var cookieValue = cookieList[i].split("=");
    if (name == cookieValue[0]) 
      return unescape(cookieValue[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

function ShowQuote()
{
    var theXml = document.all.quoteXml;
    var theXsl = document.all.showQuoteXsl;
    
    if (theXsl.xml=='')
    {
        theXsl.async=false;
        theXsl.load("/xml/showstockquote.xsl");
    }
  
    document.all.MainDiv.innerHTML=theXml.transformNode(theXsl);
}

function ShowNews()
{
    var theXml = document.all.newsXml;
    var theXsl = document.all.showNewsXsl;
    
    if (theXsl.xml=='')
    {
        theXsl.async=false;
        theXsl.load("/xml/shownews.xsl");
    }
    document.all.MainDiv.innerHTML=theXml.transformNode(theXsl);
}

function ShowInsider()
{
    var theXml = document.all.insiderXml;
    var theXsl = document.all.showInsiderXsl;
    
    if (theXsl.xml=='')
    {
        theXsl.async=false;
        theXsl.load("/xml/showInsider.xsl");
    }
    document.all.MainDiv.innerHTML=theXml.transformNode(theXsl);
}

function ShowStockList()
{
    var theXml = document.all.stockListXml;
    var theXsl = document.all.showStockListXsl;

    var watchList=GetCookie("WatchList");
  
    if (watchList=="undefined"||watchList=="null"||watchList==null)
    {
        watchList="";
    }    

    if(theXsl.xml=="")
    {
        theXsl.async=false;
        theXsl.load("/xml/ShowStockList.xsl");
    }

    var xslAttribute=theXsl.selectSingleNode("//xsl:variable[@name='WatchList']/@select");
    xslAttribute.value="'"+watchList+"'";  
    
    document.all.MainDiv.innerHTML=theXml.transformNode(theXsl);
}

function RefreshStockList()
{
    var theXml = document.all.stockListXml;
    var theXsl = document.all.showStockListXsl;

    var watchList=GetCookie("WatchList");
  
    if (watchList=="undefined"||watchList=="null"||watchList==null)
    {
        watchList="";
    }    

    if(theXml.xml=="")
    {
        theXsl.async=false;
    
        theXsl.load("/xml/ShowStockList.xsl");
    }

    var xslAttribute=theXsl.selectSingleNode("//xsl:variable[@name='WatchList']/@select");
    xslAttribute.value="'"+watchList+"'";  
   
    document.all.MainDiv.innerHTML=theXml.transformNode(theXsl);
}

function sort(col,dataType,theXml,theXsl)
{
    var sortAttribute=theXsl.selectSingleNode("//xsl:sort/@select");
    var orderAttribute=theXsl.selectSingleNode("//xsl:sort/@order");
    var dataTypeAttribute=theXsl.selectSingleNode("//xsl:sort/@data-type");
    
    if (sortAttribute.value==col)
    {
        if (orderAttribute.value=="ascending")
        {
            orderAttribute.value="descending";
        }
        else
        {
           orderAttribute.value="ascending";
        }
    }
    sortAttribute.value=col
    dataTypeAttribute.value=dataType;
    
    document.all.MainDiv.innerHTML=theXml.transformNode(theXsl);
}

function sortEx(col,dataType,theXml,theXsl)
{
    var sortAttribute=theXsl.selectSingleNode("//xsl:sort/@select");
    var orderAttribute=theXsl.selectSingleNode("//xsl:sort/@order");
    var dataTypeAttribute=theXsl.selectSingleNode("//xsl:sort/@data-type");
 
    if (sortAttribute.value==col)
    {
        if (orderAttribute.value=="ascending")
        {
            orderAttribute.value="descending";
        }
        else
        {
           orderAttribute.value="ascending";
        }
    }
    sortAttribute.value=col
    dataTypeAttribute.value=dataType;
    
    sortAttribute=theXsl.selectSingleNode("//xsl:sort[@case-order]/@select");
    orderAttribute=theXsl.selectSingleNode("//xsl:sort[@case-order]/@order");
    dataTypeAttribute=theXsl.selectSingleNode("//xsl:sort[@case-order]/@data-type");
    
    if (sortAttribute.value==col)
    {
        if (orderAttribute.value=="ascending")
        {
            orderAttribute.value="descending";
        }
        else
        {
           orderAttribute.value="ascending";
        }
    }
    sortAttribute.value=col
    dataTypeAttribute.value=dataType;

    document.all.MainDiv.innerHTML=theXml.transformNode(theXsl);
}

function AddToWatchList(symbol,selected)
{
    var watchList;
    watchList=GetCookie("WatchList");

    if (watchList==null|watchList==null)
    {
        watchList="";
    }
    
    if (selected)
    {
        watchList+="|"+symbol+"|";
    }
    else
    {
        watchList=watchList.replace("|"+symbol+"|","");
    }
    var d=new Date(2020,1,1);
    document.cookie="WatchList="+watchList+";expires="+d.toGMTString();
    RefreshStockList();
}

function ShowShortInterest()
{
    var theXml = document.all.shortInterestXml;
    var theXsl = document.all.showShortInterestXsl;
    
    if (theXsl.xml=='')
    {
        theXsl.async=false;
        theXsl.load("/xml/showShortInterest.xsl");
    }
  
    document.all.MainDiv.innerHTML=theXml.transformNode(theXsl);
}

function ToggleOTC(hideOTC)
{
    var d=new Date(2020,1,1);
    document.cookie="HideOTC="+hideOTC+";expires="+d.toGMTString();
    document.location.reload(true);   
}

function ToggleOptional(optionalOnly)
{
    var d=new Date(2020,1,1);
    document.cookie="OptionalOnly="+optionalOnly+";expires="+d.toGMTString();
    document.location.reload(true);   
}

if(document.implementation.createDocument){alert("Many features of this site is not available using Firefox at this moment, sorry about that.")};