var TotalWindowWidth = 0;

function GetWindowWidth()
{
	var windowWidth = 100;
	if (typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		windowWidth = window.innerWidth;
	}

	if (document.body && document.body.clientWidth)
	{
		//IE 4 compatible
		windowWidth = document.body.clientWidth;
 	}
 
  	if (document.documentElement && document.documentElement.clientWidth)
	{
		//IE 6+ in 'standards compliant mode'
		windowWidth = document.documentElement.clientWidth;
	}
	return windowWidth;
}

function AjaxPageRequest(url, callback) {
	var http_request = false;

	if (window.XMLHttpRequest)
		http_request = new XMLHttpRequest();

	else if (window.ActiveXObject)
	{
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (errA)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (errB)
			{
			}
		}
	}

	if (!http_request)
	{
		alert('Cannot create XMLHTTP instance');
		return false;
	}

	http_request.onreadystatechange = function()
	{
		if (http_request.readyState == 4)
			callback(http_request.responseText);
	}

	http_request.open('GET', url, true);
	http_request.send(null);
}

function news_load()
{
	AjaxPageRequest('./phpscripts/ajax_messagealerts.php', returnv);
}

function returnv(retText) 
{
	var news_json = eval(' (' + retText + ') ');
	
	document.getElementById('news_scroll').innerHTML = "";
	document.getElementById('top_most').style.width = "" + document.getElementById('top_most').offsetParent.clientWidth + "px";
	for(var x = 0; x < news_json.length; x++)
	{
		if (x != 0)
			document.getElementById('news_scroll').innerHTML += " | ";

		document.getElementById('news_scroll').innerHTML += news_json[x].title + ": " + news_json[x].text;
	}

	document.getElementById('news_cont').innerHTML = document.getElementById('news_scroll').innerHTML;
	TickerWidth = document.getElementById('news_scroll').clientWidth;
	//document.getElementById('news_scroll').style.display = "none";
	//document.getElementById('top_most').style.width = "100%";
	scroll_news();
}

function scroll_news()
{
	var el = document.getElementById('news_cont').style;
	var new_margin = document.getElementById('top_most').clientWidth;
	
	if (TotalWindowWidth != GetWindowWidth())
	{
		TotalWindowWidth = GetWindowWidth();
		document.getElementById('top_most').style.width = "100px";
		document.getElementById('top_most').style.width = "" + document.getElementById('top_most').offsetParent.clientWidth + "px";
	}
	if (el.marginLeft > "!")
		new_margin = el.marginLeft.substr(0, (el.marginLeft.length-2)) - 2;

	if ((document.getElementById('news_scroll').clientWidth) < (0-new_margin))
		new_margin = document.getElementById('top_most').clientWidth;

	el.marginLeft = new_margin + 'px';
	setTimeout('scroll_news()', 25);
}

