function UpdateQuote()
{
	var tickerExch = Ticker;
	if (Exchange.length > 0)
		tickerExch = Exchange + ":" + Ticker;
	var rand = Math.floor(Math.random() * 10000);

	ajax({
		url: "GetAQuote.aspx?ticker=" + tickerExch + "&rand=" + rand,
		onSuccess: function(text) {
			if (text.length <= 0)
				return;
			var qlist = text.split("|");
			if (qlist[0].toUpperCase() == "UNDEFINED")
				return;

			var obj = document.getElementById("QuoteLastDate");
			obj.innerHTML = qlist[1];

			obj = document.getElementById("QuoteLastPrice");
			obj.innerHTML = qlist[2];

			obj = document.getElementById("QuoteDayChange");
			obj.innerHTML = qlist[3];

			obj = document.getElementById("QuoteVolume");
			obj.innerHTML = qlist[4];

			obj = document.getElementById("QuoteOpenPrice");
			obj.innerHTML = qlist[5];

			obj = document.getElementById("QuoteDayRange");
			obj.innerHTML = qlist[6];

			obj = document.getElementById("QuoteMktCap");
			obj.innerHTML = qlist[7];

			if (domCountry != "USA")
			{
				obj = document.getElementById("QuoteYield");
				obj.innerHTML = qlist[8];
			}

			obj = document.getElementById("QuotePriceEarn");
			obj.innerHTML = qlist[9];

			obj = document.getElementById("QuotePriceSale");
			obj.innerHTML = qlist[10];

			obj = document.getElementById("QuotePriceCash");
			obj.innerHTML = qlist[11];
		}
	});
}

// Change chart
function ChgPrama(tag)
{
	GraphTag = tag;

	var tabgif, gifsuf = ".gif";
	if (Country != "USA")
		gifsuf = "_int.gif";
	if (tag == "Y*")
		tabgif = "http://im.morningstar.com/im/gqnavytd_299px.gif";
	else
		tabgif = "http://im.morningstar.com/im/gqnav" + tag + "_299px" + gifsuf;

	document.images["GraphNavBar"].src = tabgif;
	document.images["graph"].src = "http://tools.morningstar.com/images/waiting.jpg";
	var url = "Security=" + Ticker + "&CountryId=" + Country + "&ExchangeId=" + ExchangeId + "&TimeFrame=" + tag + "&Totals=&Types=&bSize=299&Legend=Yes";
	document.images["graph"].src = "http://tools.morningstar.com/charts/MStarCharts.aspx?" + url;
}

// Update Chart
function UpdateGraph()
{
	if (GraphTag != "D1")
		return;

	var rand = Math.floor(Math.random() * 10000);
	var url = "Security=" + Ticker + "&CountryId=" + Country + "&ExchangeId=" + ExchangeId + "&TimeFrame=" + GraphTag + "&Totals=&Types=&bSize=299&Legend=Yes&Rndnum=" + rand;
	document.images["graph"].src = GraphServer + "/charts/MStarCharts.aspx?" + url;	
}

function LoadAds()
{
	var top, left, obj, ad, adwidth;
	var adList, psList, wdList;
	adlist = new Array("AdLeft1", "AdRight");		// Array("AdLeft1", "AdMiddle1", "AdRight");
	pslist = new Array("posAdLeft1", "posAdRight");	// Array("posAdLeft1", "posAdMiddle1", "posAdRight");
	wdlist = new Array(175, 0);						// Array(175, 300, 0);

	for (var i = 0; i < adlist.length; i++)
	{
		top = 0; left = 0;
		obj = document.getElementById(pslist[i]);
		if (obj.offsetParent)
		{
			while (obj = obj.offsetParent)
			{
				top += obj.offsetTop;
				left += obj.offsetLeft;
			}
		}
		if (i >= 0 && i <= 2 && navigator.userAgent.toLowerCase().indexOf("safari") != -1)
			top -= 120;

		ad = document.getElementById(adlist[i]);
		adwidth = ad.offsetWidth;
		ad.style.top = top;
		if (wdlist[i] == 0)
			ad.style.left = left;
		else
			ad.style.left = left + (wdlist[i] - adwidth)/2;
		ad.style.visibility = "visible";
	}
}

function LoadVideo()
{
	if (secID == "" || sector == "")
		return;

	var rand = Math.floor(Math.random() * 10000);

	ajax({
		url: "GetVideo.aspx?secID=" + secID + "&sector=" + sector + "&rand=" + rand,
		onSuccess: function(text) {
			if (text.length <= 0)
				return;
			var video = text.split("|");
			var table, tbody, tr, td, i, j;

			table = document.createElement("table");
			table.setAttribute("width", 175);
			table.setAttribute("border", 0);
			table.setAttribute("cellPadding", 0);
			table.setAttribute("cellSpacing", 0);

			tbody = document.createElement("tbody");

			tr = document.createElement("tr");
				td = document.createElement("td");
				td.innerHTML = "<img src='http://im.morningstar.com/im/dot_clear.gif' height=20>";
			tr.appendChild(td);
			tbody.appendChild(tr);

			tr = document.createElement("tr");
				td = document.createElement("td");
				td.setAttribute("bgColor", "#000000");
				td.innerHTML = "<img src='http://im.morningstar.com/im/dot_clear.gif' height=1>";
			tr.appendChild(td);
			tbody.appendChild(tr);

			tr = document.createElement("tr");
				td = document.createElement("td");
				td.setAttribute("height", 15);
				td.className = "TextHeader";
				td.innerHTML = "Video Reports";
			tr.appendChild(td);
			tbody.appendChild(tr);

			tr = document.createElement("tr");
				td = document.createElement("td");
				td.innerHTML = "<img src='http://im.morningstar.com/im/dot_clear.gif' height=10>";
			tr.appendChild(td);
			tbody.appendChild(tr);

			tr = document.createElement("tr");
				td = document.createElement("td");
				var textVideo = "";
				textVideo += "<a title='" + video[3] + "' onClick=\"window.open('http://www.morningstar.com/cover/videocenter.html?lineup=stocks&bctid=" + video[1] + "','','width=860,height=705')\" href='javascript:void(0)'><img src='" + video[2] + "' alt='' border=0 height=133 width=175></a><br>";
				textVideo += "<img src='http://im.morningstar.com/im/thumbctrls.gif' border=0 height=15 width=175><br>";
				textVideo += "<a title='" + video[3] + "' onClick=\"window.open('http://www.morningstar.com/cover/videocenter.html?lineup=stocks&bctid=" + video[1] + "','','width=860,height=705')\" href='javascript:void(0)' class='TextVideo'>" + video[0] + "</a><br>";
				textVideo += "<img src='http://im.morningstar.com/im/dot_clear.gif' width=120 height=5><br>";
				textVideo += "<a class='LinkText' href='javascript:void(0)' onClick=\"window.open('http://www.morningstar.com/cover/videocenter.html?lineup=stocks','','width=860,height=705')\">More Videos...</a>";
				td.innerHTML = textVideo;
			tr.appendChild(td);
			tbody.appendChild(tr);

			tr = document.createElement("tr");
				td = document.createElement("td");
				td.innerHTML = "<img src='http://im.morningstar.com/im/dot_clear.gif' height=20>";
			tr.appendChild(td);
			tbody.appendChild(tr);

			table.appendChild(tbody);

			var obj = document.getElementById("idVideo");
			obj.appendChild(table);
		}
	});
}

