﻿// JScript File
//uses soapclient.js 

//SOAPClient.invoke() requires a URL for the web service. 
// Since pages in multiple directory levels use this .js file, 
// and the .js file acts like it's in the directory of the page using it
// we have to use an absolute link to "Rates.asmx".
// This project is built with different application paths depending on the server.
// If it's length is 1, it's just "/", but greater than that and it doesn't end with a "/"
function getRates()
{
    if (document.getElementById)
    {
        var pl = new SOAPClientParameters();
        
        if (__ApplicationPath.length > 1) __ApplicationPath += "/";
        SOAPClient.invoke(__ApplicationPath + "Rates.asmx", "GetRatesFromMarkOne", pl, true, getRates_callBack);
    }
}

//fill rate table with return values
function getRates_callBack(retval)
{
    var style = '';
    var data = '';
    var rows = Math.ceil(retval.length/2);
    var table = '<table border="0" cellpadding="0" cellspacing="0" class="index-rates">';
    
    for (var x=0; x < rows; x++)
    {
        table += '<tr>';
        
        if ( (x%2) == 0 ) style = 'alt';
        else style = '';
        
        data = retval[x].split('#');
        table += '<th class="' + style + '">' + data[0] + '</th>';
        table += '<td class="' + style + '">' + data[1] + '</td>';
        
        if (x + rows < retval.length) data = retval[x + rows].split('#'); 
        else data = ['',''];
        
        table += '<th class="' + style + '">' + data[0] + '</th>';
        table += '<td class="' + style + '">' + data[1] + '</td>';
        table += '</tr>';
    }
    
    table += '</table>';
    
    document.getElementById("rates").innerHTML = table;
    
    if (retval.length > 1)
        data = retval[0].split('#');
    if (data.length = 4)
        document.getElementById("lblRateUpdateDate").innerHTML = "as of " + data[2] + " ET " + data[3];
}

var OnLoad = 'getRates()';
window.onload = function() { eval(OnLoad); };

//update rates each minute
var rate_interval = 60000;

//call the web service every 'rate_interval' milliseconds
setInterval("getRates()", rate_interval);
