function $ (obj) {
	return (typeof obj == 'string')? document.getElementById(obj): obj;
}
function hide (obj) {
	if (el = $(obj)) el.style.display = 'none';
}
function show (obj) {
	if (el = $(obj)) {
		if (CurrObj && el != CurrObj) CurrObj.style.display = 'none';
		if (CurrTimeout) CurrTimeout = window.clearTimeout(CurrTimeout);
		(CurrObj = el).style.display = '';
	}
}
function down () {
	CurrTimeout = window.setTimeout("hide(CurrObj); CurrObj = null;", 500);
}
var CurrObj = null;
var CurrTimeout = null;

function checkBrowser () {
	if (window.XMLHttpRequest) return true;
	if (window.ActiveXObject) return true;
	return false;
}
function getId (str) {
	if (typeof str == 'object') return str; // Already an object
	if (document.getElementById) return document.getElementById(str);
	if (document.all) return document.all[str];
	return null; // Not supporting older methods of getting ID
}
function getQuery () {
	var query = document.location.search.substring(1);
	var vars = query.split("&");
  for (var i=0; i<vars.length; i++) {
		var pair = vars[i].split("=");
		this[pair[0]] = pair[1];
  }
}
function getHTML (url, obj) {
	var el = getId (obj);
	if (el) getAsync (url, function (req) {el.innerHTML = req.responseText});
}
function getXML (url, obj) {
	var el = getId (obj);
	if (el) getAsync (url, function (req) {if (req.responseXML) el = req.responseXML.documentElement});
}
function getAsync (url, cb) {doAsync ('GET', url, null, cb)}
function postAsync (url, data, cb) {doAsync ('POST', url, data, cb)}
function doAsync (mode, url, data, cb) {
	var req = (window.XMLHttpRequest)? new XMLHttpRequest(): (window.ActiveXObject)?
		new ActiveXObject("Microsoft.XMLHTTP"): null;
	if (req) {
		req.onreadystatechange = function () {
			if (req.readyState == 4) {
				switch (req.status) {
				case 200:	if (cb) cb (req); break;
				case 205:	if (window.onload) window.onload; break;
				case 401: if (window.onload) window.onload; else window.location.reload(true); break;
				default:	window.status = "Error getting page: " + req.status;
				}
			} 
		}
		req.open (mode, url, true);
		if (mode == 'POST') req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.send (data);
	} 
}
function submitFormHTML (form, obj) {
	var el = getId (obj);
	if (el) submitForm (form, function (req) {el.innerHTML = req.responseText});
	return false;
}
function submitForm (form, cb) {
	if (form) {
		var method = form.method.toUpperCase(), action = form.action, data = "";
		for (var i=0; i<form.elements.length; i++)
			data += ((i>0)? '&': '') + form.elements[i].name + '=' + escape(form.elements[i].value);
		if (method == 'GET') {
			action += ((action.indexOf('?') > 0)? '&': '?') + data; data = null;
		}
		doAsync (method, action, data, cb)
	}
	return false;
}
function setProperty (obj, prop, value) {
	var el = getId (obj);
	if (el) el[prop] = value;
}

function popupImage (img) {
	window.open ('/app/popup_image.asp?img='+img, 'image', 'width=100,height=100,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no');
}