// Global rate object.
var xhrRate;
var xhrSingleRate;
var xhrSingleRateTimerID;

function createXMLHttpRequest() {
    if (window.XMLHttpRequest) {
        // code for all new browsers
        return new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        // Microsoft IE 5.X+
        try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch (e) { }
        try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch (e) { }
        try { return new ActiveXObject("Msxml2.XMLHTTP") } catch (e) { }
        try { return new ActiveXObject("Microsoft.XMLHTTP") } catch (e) { }
        //throw new Error( "This browser does not support XMLHttpRequest." );
    }
}

function GetRate() {
    if (xhrRate == null) {
        xhrRate = createXMLHttpRequest();
    }

    if (xhrRate != null) {
        xhrRate.open("POST", "/FXLiveRateStream2.asp", true);
        xhrRate.onreadystatechange = function() {
            if (xhrRate.readyState == 4) {
                if (xhrRate.status == 200) {
                    document.getElementById("rateElement").innerHTML = xhrRate.responseText;
                } else {
                    //alert("GetRate:  message returned, but with error status.");
                }
            }
        }
        xhrRate.send('');
        window.setTimeout("GetRate()", 1000);
    }
}

function GetSingleRate(strQuery) {
    if (xhrSingleRateTimerID != null)
    {
        window.clearTimeout(xhrSingleRateTimerID);
    }
    if (xhrSingleRate == null) {
        xhrSingleRate = createXMLHttpRequest();
    }

    if (xhrSingleRate != null) {
        xhrSingleRate.open("GET", "/FXLiveRateStreamSingle2.asp?"+strQuery, true);
        xhrSingleRate.onreadystatechange = function () {
            if (xhrSingleRate.readyState == 4) {
                if (xhrSingleRate.status == 200) {
                    g_rate = xhrSingleRate.responseText;
                } else {
                    alert("GetRate:  message returned, but with error status.");
                }
            }
        }
        xhrSingleRate.send(strQuery);
        xhrSingleRateTimerID = window.setTimeout("GetSingleRate('" + strQuery + "')", 1000);
    }
}

function toggleDrop()
{
	if( !window.XMLHttpRequest )
	{
	    try {
	        var elemDrop = document.getElementById("currdrop");
	        if (elemDrop.style.display == "block") {
	            elemDrop.style.display = "none";
	        }
	        else {
	            elemDrop.style.display = "block";
	        }
	    } catch (e) { }
	}
}


