// showQuote.js - gets xml quotes from yahoo.com through anders.com

var req;

function loadXMLDoc( url ) {
    if ( window.XMLHttpRequest ) { // branch for native XMLHttpRequest object
        req = new XMLHttpRequest( );
        req.onreadystatechange = processReqChange;
        req.open( "GET", url, true );
        req.send( null );

    }
    else if ( window.ActiveXObject ) { // branch for IE/Windows ActiveX version
        req = new ActiveXObject( "Microsoft.XMLHTTP" );
        if ( req ) {
            req.onreadystatechange = processReqChange;
            req.open( "GET", url, true );
            req.send( );

        }

    }

}

function processReqChange( ) {
    if ( req.readyState == 4 ) {
        if ( req.status == 200 ) {
	    response = req.responseXML.documentElement;
            symbol = response.getElementsByTagName( 'symbol' )[0].firstChild.data;
	    companyName = response.getElementsByTagName( 'companyName' )[0].firstChild.data;
            lastTrade = response.getElementsByTagName( 'lastTrade' )[0].firstChild.data;
            lastTradeTime = response.getElementsByTagName( 'lastTradeTime' )[0].firstChild.data;
	    change = response.getElementsByTagName( 'change' )[0].firstChild.data;
            eval( "document.getElementById( '" + symbol + "' ).title = companyName + ' (' + symbol + ') ' + lastTrade + ' ' + change + ' as of ' + lastTradeTime" );

        }
	else {
            alert( "There was a problem retrieving the XML data:\n" + req.statusText );

        }

    }

}

function showQuote( symbol ) {
  url = 'getQuote.jsp?symbol=' + symbol;
  loadXMLDoc( url );

}
