﻿//=============================================================================
// Script Name: InvestorRelations.js
// Description: Consumes the investorRelation data from local service (XML format)
//              and injects the data in the InvestorRelations usercontrol
//=============================================================================


function GetSharePriceData() {
    var url = "/SharePriceService.axd";
    var jqxhr = $.ajax({
        type: "GET",
        url: url,
        dataType: "xml",
        success: function (xml) {
            $(xml).find('shareprice').each(function () {
                var up = "<img src='/style library/images/bhpb/share_trend_up.gif' width='19' height='8' alt='Up' />";
                var down = "<img src='/style library/images/bhpb/share_trend_down.gif' width='19' height='8' alt='Down' />";
                var exchange = $(this).find('exchange');
                var pctmove = $(this).find('pctmove');
                var price = $(this).find('price');
                var currency = $(price).attr('currency');

                if (exchange.text() == "ASX") {
                    $("#ASXPrice").text(price.text());
                    $("#ASXMove").text(pctmove.text());
                    if (pctmove.text().charAt(0) == '-') {
                        $("#ASXMove").prepend(down);
                    } else {
                        $("#ASXMove").prepend(up);
                    }
                }
                else if (exchange.text() == "LSE") {
                    $("#LSEPrice").text(price.text());
                    $("#LSEMove").text(pctmove.text());
                    if (pctmove.text().charAt(0) == '-') {
                        $("#LSEMove").prepend(down);
                    } else {
                        $("#LSEMove").prepend(up);
                    }
                }
                else if (exchange.text() == "JSE") {
                    $("#JSEPrice").text(price.text());
                    $("#JSEMove").text(pctmove.text());
                    if (pctmove.text().charAt(0) == '-') {
                        $("#JSEMove").prepend(down);
                    } else {
                        $("#JSEMove").prepend(up);
                    }
                }
                else if (exchange.text() == "NYSE (Ltd ADR)") {
                    $("#NYSELtdPrice").text(price.text());
                    $("#NYSELtdMove").text(pctmove.text());
                    if (pctmove.text().charAt(0) == '-') {
                        $("#NYSELtdMove").prepend(down);
                    } else {
                        $("#NYSELtdMove").prepend(up);
                    }
                }
                else if (exchange.text() == "NYSE (Plc ADR)") {
                    $("#NYSEPlcPrice").text(price.text());
                    $("#NYSEPlcMove").text(pctmove.text());
                    if (pctmove.text().charAt(0) == '-') {
                        $("#NYSEPlcMove").prepend(down);
                    } else {
                        $("#NYSEPlcMove").prepend(up);
                    }
                }
            }); //close each
            var timeOut = $(xml).find('timeout');
            if (timeOut.text() != "") {
                //hide table
                $("#XML_data").hide();
                //set message for time out
                $("#XML_timeout").text(timeOut.text());
            }
        }
    });
}
