function newXMLHttpRequest()
{
	if (window.XMLHttpRequest)
		return new XMLHttpRequest();
	else if (window.ActiveXObject)
	try {
		return new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	//error
}

function ajaxRequest(action, params, callback)
{
	var req = newXMLHttpRequest();
	var url = 'ajax?action='+action+'&'+params;

	req.onreadystatechange = function ()
	{
		if (req.readyState != 4) return;
		
		if (req.status != 200) {
			alert("AJAX Error "+req.status+".");
			return;
		}

		callback(eval(req.responseText));
	}

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

function getElement(id)
{
	return (document.getElementById ?
		document.getElementById(id) : document.all[id]);
}

function getSelectedOption(obj)
{
	if (obj.seletedIndex == -1) return null;
	opt = obj.options[obj.selectedIndex];
	return opt.value ? opt.value : opt.text;
}

function clearSelect(s)
{
	while (s.firstChild) s.removeChild(s.firstChild);
}

function appendOption(sel,txt,val)
{
	if (!val) val = txt;
	sel.options[sel.options.length] = 
		new Option(txt, val, false, false);
}

function selectOption(sel, opt)
{
	for (i = 0; i < sel.length; i++)
		if (sel.options[i].value == opt)
		{
			sel.selectedIndex = i;
			return;
		}
}

function setVisible(element,which,visible_value) {
	var v = visible_value ? visible_value : 'block';
	element.style.display = (which ? v : 'none');
}
