﻿function fxboxv(ASymbolName){
	var symbolElm = document.getElementById("f" + ASymbolName + "n");
	var askElm = document.getElementById("f" + ASymbolName + "ac");
	var bidElm = document.getElementById("f" + ASymbolName + "bc");
	var percentChangeElm = document.getElementById("f" + ASymbolName + "pc");
	if (symbolElm && askElm && bidElm && percentChangeElm){
		symbolElm.style.backgroundColor="#F5F5DC";
		askElm.style.backgroundColor="#F5F5DC";
		bidElm.style.backgroundColor="#F5F5DC";
		percentChangeElm.style.backgroundColor="#F5F5DC";
		symbolElm.style.cursor="pointer";
		askElm.style.cursor="pointer";
		bidElm.style.cursor="pointer";
		percentChangeElm.style.cursor="pointer";
	}
}
function fxboxu(ASymbolName){
	var symbolElm = document.getElementById("f" + ASymbolName + "n");
	var askElm = document.getElementById("f" + ASymbolName + "ac");
	var bidElm = document.getElementById("f" + ASymbolName + "bc");
	var percentChangeElm = document.getElementById("f" + ASymbolName + "pc");
	if (symbolElm && askElm && bidElm && percentChangeElm){
		symbolElm.style.backgroundColor="";
		askElm.style.backgroundColor="";
		bidElm.style.backgroundColor="";
		percentChangeElm.style.backgroundColor="";
	}
}
function fxboxcl(AUrl){
	document.location.href = AUrl;
}

function fxboxFlashOff(AElm)
{
	elm = document.getElementById(AElm);
	elm.style.backgroundColor = "";
}	

function RefreshForexBox()
{
	var lastPercentChangePrice = 0;
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		 xmlhttp = false;
		}
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}	
	
	var url = "/fx/GetFxForexQuotes.aspx?forexbox=1&a=" + Math.round(Math.random() * 999999999999)
	xmlhttp.open("GET", url,true);
	xmlhttp.onreadystatechange = onReadyStateHandler;
	xmlhttp.send(null);
	
	function onReadyStateHandler()
	{
		if (xmlhttp.readyState == 4)
		{
			var xml = xmlhttp.responseXML;
			var path = "/data/i";
			if (window.ActiveXObject)
			{
				var nodes = xml.selectNodes(path);
				for (i = 0; i < nodes.length; i++){
					parseNode(nodes[i]);
				}
			}else{
				var nodes = xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);	
				var result = nodes.iterateNext();
				while (result)
				{
					parseNode(result);
					result = nodes.iterateNext();
				}
			}
		}
	}

	
	function parseNode(ANode)
	{
		var symbolName = ANode.getAttribute("n");	
		if (document.getElementById("f" + symbolName + "n"))
		{
			var lastAskPrice = document.getElementById("f" + symbolName + "la").innerHTML;
			if (lastAskPrice.length <= 0) {lastAskPrice = 0};
			var lastBidPrice = document.getElementById("f" + symbolName + "lb").innerHTML;
			if (lastBidPrice.length <= 0) {lastBidPrice = 0};
			
			var askPrice = ANode.getAttribute("a");
			var bidPrice = ANode.getAttribute("b");
			var percentChangePrice = ANode.getAttribute("p");
			document.getElementById("f" + symbolName + "la").innerHTML = askPrice;
			document.getElementById("f" + symbolName + "lb").innerHTML = bidPrice;
			if (symbolName.toUpperCase() == "USD/JPY")
			{
				document.getElementById("f" + symbolName + "a").innerHTML = formatFloat(askPrice, 2);
				document.getElementById("f" + symbolName + "b").innerHTML = formatFloat(bidPrice, 2);
				document.getElementById("f" + symbolName + "p").innerHTML = formatFloat(percentChangePrice, 2) + "%";
			}
			else
			{
				document.getElementById("f" + symbolName + "a").innerHTML = formatFloat(askPrice, 4);
				document.getElementById("f" + symbolName + "b").innerHTML = formatFloat(bidPrice, 4);
				document.getElementById("f" + symbolName + "p").innerHTML = formatFloat(percentChangePrice, 2) + "%";
			}
			flashOn(lastAskPrice, lastBidPrice, lastPercentChangePrice, askPrice, bidPrice, percentChangePrice, "f" + symbolName + "n", "f" + symbolName + "a", "f" + symbolName + "b", "f" + symbolName + "p");
			lastPercentChangePrice = percentChangePrice;
		}
	}
	
	function flashOn(ALastAskPrice, ALastBidPrice, ALastPercentChangePrice, AAskPrice, ABidPrice, APercentChangePrice, ASymbolElmName, AAskPriceElmName, ABidPriceElmName, APercentChangeElmName)
	{
		var flashOffInterval = 2000;
		var moveUpBgColor = "#b9e1a9";
		var moveDownBgColor = "#FDCBCB";
		var winnerColor = "#005D00";
		var looserColor = "#B40000";
		
		var askPriceElm = document.getElementById(AAskPriceElmName);
		var bidPriceElm = document.getElementById(ABidPriceElmName);
		var symbolElm = document.getElementById(ASymbolElmName);
		var percentChangeElm = document.getElementById(APercentChangeElmName);
		
		if (APercentChangePrice > 0)
		{
			symbolElm.style.color = winnerColor;
			askPriceElm.style.color = winnerColor;
			bidPriceElm.style.color = winnerColor;
			percentChangeElm.style.color = winnerColor;
		}
		else
		{
			if (APercentChangePrice < 0)
			{
				symbolElm.style.color = looserColor;
				askPriceElm.style.color = looserColor;
				bidPriceElm.style.color = looserColor;
				percentChangeElm.style.color = looserColor;
			}
		}
		
		if ((AAskPrice > 0)&&(ALastAskPrice > 0)){
			if (AAskPrice > ALastAskPrice)
			{
				askPriceElm.style.backgroundColor = moveUpBgColor;
			}
			else
			{
				if (AAskPrice < ALastAskPrice)
				{
					askPriceElm.style.backgroundColor = moveDownBgColor;
				}
			}
		}

		if ((ABidPrice > 0)&&(ALastBidPrice > 0)){
			if (ABidPrice > ALastBidPrice)
			{
				bidPriceElm.style.backgroundColor = moveUpBgColor;
			}
			else
			{
				if (ABidPrice < ALastBidPrice)
				{
					bidPriceElm.style.backgroundColor = moveDownBgColor;
				}
			}
		}
		
		if ((APercentChangePrice > 0)&&(ALastPercentChangePrice > 0)){
			if (APercentChangePrice > ALastPercentChangePrice)
			{
				percentChangeElm.style.backgroundColor = moveUpBgColor;
			}
			else
			{
				if (APercentChangePrice < ALastPercentChangePrice)
				{
					percentChangeElm.style.backgroundColor = moveDownBgColor;
				}
			}
		}
		
		
		setTimeout("fxboxFlashOff('" + AAskPriceElmName + "')", 2000);
		setTimeout("fxboxFlashOff('" + ABidPriceElmName + "')", 2000);
		setTimeout("fxboxFlashOff('" + APercentChangeElmName + "')", 2000);
	}
	
}
