﻿function Quote(sSymbol)
{
	this.Symbol= sSymbol;
	this.Ask= "";
	this.Bid= "";
	this.Dir= "";
	this.AssetName = "";
	this.AssetShortName = "";
};
		
function QuotesBox(sQBID,arrSymbols)
{
	this.QBID = sQBID;
	this.Symbols = arrSymbols;
	this.Alerted = 0;
	this.init = function()
	{
		for(i=0;i<arrSymbols.length;i++)
		{
			if( (i % 2) ==0)
				$(arrSymbols[i]).className = "QROWE";
				
		    $(arrSymbols[i]+"_Symbol").innerHTML = arrSymbols[i];
		}
	};
	this.QuotesArived = function()
	{
	    //AddToNotice("oQs.QuotesData.length  = " + oQs.QuotesData.length + "~~~")
	   var quoteBoxTable = $('QuotesBox');
	   try{
	    for(i=0;i<quoteBoxTable.rows.length;i++){
	        if (oQs.QuotesData[i] == undefined)
	        {
	            quoteBoxTable.rows[i].style.visibility = "hidden";
	        }
	        else
	        {
	            quoteBoxTable.rows[i].style.visibility = "visible";
			    colorDir = "black";
	            if(oQs.QuotesData[i].Dir=="Up"){
				    colorDir = "Green";
			    }else if(oQs.QuotesData[i].Dir=="Down"){
				    colorDir = "Red";
			    };
    			
			    //AddToNotice("oQs.QuotesData[i].Symbol = " + oQs.QuotesData[i].Symbol + "~~~")
			    if (quoteBoxTable.rows[i].cells[0].symbol != oQs.QuotesData[i].Symbol || 
			    quoteBoxTable.rows[i].cells[0].innerHTML.indexOf(oQs.QuotesData[i].AssetName) == -1 ||
			        quoteBoxTable.rows[i].cells[0].innerHTML.indexOf(oQs.QuotesData[i].AssetShortName) == -1 )
			    {
			        var sClickURL = oQs.QuotesData[i].Symbol.substr(0,3)+"/"+oQs.QuotesData[i].Symbol.substr(3,6);
			        this.Alerted++;
			        
			        if(sQuoteBoxChartPage != "")
			        {
			            sClickURL = "<a title='"+ sQuoteBoxChartLinkInstructions.replace("{0}" , oQs.QuotesData[i].AssetName).replace("{1}" , oQs.QuotesData[i].AssetShortName) +"' class='QBSymbolLink' href='javascript:OpenChatWin(\""+sQuoteBoxChartPage+"?symbol="+oQs.QuotesData[i].Symbol+"\","+sQuoteBoxChartPageWidth+","+sQuoteBoxChartPageHeight+")'>"+oQs.QuotesData[i].Symbol.substr(0,3)+"/"+oQs.QuotesData[i].Symbol.substr(3,6)+"</a>";
        			}
			        quoteBoxTable.rows[i].cells[0].innerHTML = sClickURL;
			        quoteBoxTable.rows[i].cells[0].symbol = oQs.QuotesData[i].Symbol;
			        quoteBoxTable.rows[i].cells[0].AssetName = oQs.QuotesData[i].AssetName;
			        quoteBoxTable.rows[i].cells[0].AssetShortName = oQs.QuotesData[i].AssetShortName;
    			}
    			
    			
    			
			    // $(oQs.QuotesData[i].Symbol+"_Ask").innerHTML = (oQs.QuotesData[i].Ask=='')? '&nbsp;' : oQs.QuotesData[i].Ask;
			    // $(oQs.QuotesData[i].Symbol+"_Bid").innerHTML = (oQs.QuotesData[i].Bid=='')? '&nbsp;' : oQs.QuotesData[i].Bid;
			    //AddToNotice("oQs.QuotesData[i].Bid = " + oQs.QuotesData[i].Bid + "")
			    quoteBoxTable.rows[i].cells[1].innerHTML = (oQs.QuotesData[i].Bid=='' || oQs.QuotesData[i].Bid==undefined)? '&nbsp;' : "<a href='"+sQuoteBoxRedirectTradingPage+"?'>" + oQs.QuotesData[i].Bid + "</a>";
			    quoteBoxTable.rows[i].cells[3].innerHTML = (oQs.QuotesData[i].Ask=='' || oQs.QuotesData[i].Ask==undefined)? '&nbsp;' : "<a href='"+sQuoteBoxRedirectTradingPage+"?'>" + oQs.QuotesData[i].Ask + "</a>";
    			
    			
    			
			     //$(oQs.QuotesData[i].Symbol).style.color=colorDir;
			    //$(oQs.QuotesData[i].Symbol+"_Ask").className = ""
    			
			    quoteBoxTable.rows[i].cells[0].className = "QTDSYM " + oQs.QuotesData[i].Dir;
			    quoteBoxTable.rows[i].cells[1].className = "QTDBV " + oQs.QuotesData[i].Dir;
			    quoteBoxTable.rows[i].cells[3].className = "QTDAV " + oQs.QuotesData[i].Dir;
    			
    			
			    quoteBoxTable.rows[i].cells[2].firstChild.src=ApplicationPath+"img/"+colorDir+".gif";
		    }
		};
		}
		catch(ex)
		{
		 this.Alerted = 0;
		}
		if (this.Alerted == 0)
		{
		this.Alerted ++;
		try{
            oQs.getNames = true;
            oQs.GetQuotes();
            
		}
		catch(ex)
		{debugger;}
		}
		
	};
};

function OpenChatWin(url,w,h){ 
    var w = window.open(url,'w','height='+h+',width='+w+',status=no,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no');
    w.focus();
}