function getElem(name)
{
	name = name.toString();
	if (document.getElementById)
	{
		return document.getElementById(name);
	}
	else if (document.all)
	{
		return document.all[name];
	}
	else if (document.layers)
	{
		return document.layers[name];
	}
	else
	{
		return null;
	}
}

var g_ajax_debug = false;
var RequestFactory = {
	'requests':new Object(),
	'createRequest':function(url,id,func,argObj,abortable,abortOthers,query,type)
	{
		if(abortOthers)
		{
			RequestFactory.abortAll();
		}

		if(!RequestFactory.requests[id])
		{
			RequestFactory.requests[id] = new CustomRequest(url,id,func,argObj,abortable,query,type);
		}

		RequestFactory.requests[id].init(id);
		return RequestFactory.requests[id];
	},
	'abortAll':function()
	{
		for(var i in RequestFactory.requests)
		{
			RequestFactory.requests[i].abort();
		}
	},
	'getRequest':function(id)
	{
		return RequestFactory.requests[id];
	}
};

function CustomRequest(url,id,func,argObj,abortable,query,type)
{
	this.id = id;
	this.req = null;
	this.type = type;
	this.url = url;
	this.query = query;
	this.argObj = argObj;
	this.func = func;
	this.abortable = null;

	if(typeof abortable == 'undefined' || abortable == null)
	{
		this.abortable = true;
	}
	else
	{
		this.abortable = abortable;
	}

	this.abort = function()
	{
		if(this.req && this.abortable)
		{
			this.req.abort();
		}
	}

	this.init = function(id)
	{
		if(!this.type)
		{
			this.type = 'GET';
		}

		if(!this.argObj)
		{
			this.argObj = new Object();
		}

		if(!this.query)
		{
			this.query = '';
		}

		if(this.req == null)
		{
			if(window.XMLHttpRequest)
			{
				try
				{
					this.req = new XMLHttpRequest();
				}
				catch(e)
				{
					this.req = null;
				}
			}
			else if(window.ActiveXObject)
			{
				try
				{
					this.req = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e)
				{
					try
					{
						this.req = new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch(e)
					{
						this.req = null;
					}
				}
			}
		}

		if(this.req)
		{
			this.req.onreadystatechange = function()
			{
				var localReq = RequestFactory.getRequest(id);
				if (localReq.req.readyState == 4)
				{
					if (localReq.req.status == 200 || g_ajax_debug)
					{
						localReq.argObj['responseXML'] = localReq.req.responseXML;
						localReq.func(localReq.argObj);
					}
				}
			}

			this.req.open(this.type,this.url, true);
			if(this.type == 'POST')
			{
				this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
			}
			this.req.send(this.query);
		}
	}
}

function getNews() {
	var args = new Object();
	var url = new String('/xml/news.asp');
	var id = new String('frontnews');
	args['divId'] = new String('newsbox');
	RequestFactory.createRequest(url,id,displayNews,args);
}

function displayNews(args) {
	try {
		divId = new String(args['divId']);
		element = getElem(divId);
		var items = args['responseXML'].getElementsByTagName('item');
		if (items && items.length > 0) {
			lastPubDate = '';
			output = ''
			for (var i=0;i<items.length;i++) {
				try {
					var title = items[i].getElementsByTagName('title')[0].firstChild.nodeValue;
					var link = items[i].getElementsByTagName('link')[0].firstChild.nodeValue;
					var pubDate = items[i].getElementsByTagName('pubDate')[0].firstChild.nodeValue;
					var source = items[i].getElementsByTagName('source')[0].firstChild.nodeValue;
	
					if (title && link && pubDate && source) {
						if (pubDate != lastPubDate) {
							output += '<strong>' + pubDate + '</strong><br />';
						}
	
						output += '<a href="' + link + '">' + title + '</a><br />';
						output += '<em>' + source + '</em><br /><br />';
						lastPubDate = pubDate;
					}
				}catch(e){}
			}

			element.innerHTML = output;
			
		}
	} catch(e) {
		//alert(e.message + ' : ' + e.name);
	}
}
/*
window.onerror = handleError; // safety net to trap all errors
function handleError(message, URI, line) {
	// alert the user that this page may not respond properly
	return true; // this will stop the default message
}
*/