// JavaScript Document
function addEventToObject(obj,evt,func) {
	var oldhandler = obj[evt];
	obj[evt] = (typeof obj[evt] != 'function') ? func : function(ev){oldhandler(ev);func(ev);};
}
var xmlhttp;
function loadXMLDoc(url)
{
	xmlhttp=null;
	if (window.XMLHttpRequest)
  		{// code for IE7, Firefox, Mozilla, etc.
  		xmlhttp=new XMLHttpRequest();
  		}
	else if (window.ActiveXObject)
  		{// code for IE5, IE6
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
	if (xmlhttp!=null)
  		{
  		xmlhttp.onreadystatechange=onResponse;
  		xmlhttp.open("GET", '/public/stock_info.xml',true);
  		xmlhttp.send(null);
  		}
	else
  		{
  		alert("Your browser does not support XMLHTTP.");
  		}
}



	function onResponse()
	{  
	if (xmlhttp.readyState == 4) // Complete state
{
 if (xmlhttp.status == 200) // Success status code
 {
		x=xmlhttp.responseXML.documentElement.getElementsByTagName("stock");
			for (var i=0;i<x.length;i++)
				{
				/*xx=x[i].getElementsByTagName("name");*/
				stockTxt=x[i].getElementsByTagName('name')[0].firstChild.nodeValue + ": " + x[i].getElementsByTagName('current')[0].firstChild.nodeValue + "&nbsp;&nbsp;";
				if (x[i].getElementsByTagName('change')[0].firstChild.nodeValue < 0)
					{
					stockTxt=stockTxt + "<span style='color:#999'>" + x[i].getElementsByTagName('change')[0].firstChild.nodeValue + "</span>";
					}
				else
					{
					stockTxt=stockTxt + "<span style='color:#3399ff'>" + x[i].getElementsByTagName('change')[0].firstChild.nodeValue + "</span>";
					}
				stockTxt=stockTxt + " | " + x[i].getElementsByTagName('date')[0].firstChild.nodeValue + " " + x[i].getElementsByTagName('time')[0].firstChild.nodeValue;	
				}
			document.getElementById('stocks').innerHTML=stockTxt;
	 
	}
 }
}
addEventToObject(window,'onload',loadXMLDoc)
