function getById(id) {
	return document.getElementById(id);
}
function getElement(id) {
	return document.getElementById(id);
}
function setHtml(id, html) {
	if (getElement(id))
		getElement(id).innerHTML = html;
}
function smartResponseHandler(text) {
	parts = text.split('[boundary]');
	for (i in parts) {
		if (i > 0) {
			subParts = parts[i].split('[/boundary]');
			if (subParts[0] == 'script')
				setTimeout(subParts[1], 0);
			else {
				metaParts = subParts[0].split(':');
				if (metaParts[0] == 'inner')
					setHtml(metaParts[1], subParts[1]);
			}
		}
	}
}
function htmlRequest(url, params, returnHandler) {
	var req;
	if (window.XMLHttpRequest)
		req = new XMLHttpRequest();
	else if (window.ActiveXObject)
		req = new ActiveXObject('Microsoft.XMLHTTP');
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			if (req.status == 200) {
				if (returnHandler)
					returnHandler(req, params);
				else
					smartResponseHandler(req.responseText);
			}
			// else
			// document.location = document.location;
		}
	}
	req.open('POST', url, true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.setRequestHeader('Cache-Control', 'no-cache');
	args = '';
	for (key in params) {
		args += key;
		args += '=';
		args += encodeURIComponent(params[key]);
		args += '&';
	}
	if (args.length > 0)
		args = args.substring(0, args.length - 1);
	// document.title = args;
	req.send(args);
}
function form2params(form) {
	params = new Object()
	for (i = 0; i < form.elements.length; i++) {
		element = form.elements[i];
		switch (element.type) {
		case 'text':
		case 'textarea':
		case 'hidden':
		case 'password': {
			params[element.name] = element.value;
			break;
		}
		case 'select-one': {
			if (element.selectedIndex != -1)
				params[element.name] = element.options[element.selectedIndex].value;
			else
				params[element.name] = '';
			break;
		}
		case 'radio':
		case 'checkbox': {
			if (!params[element.name])
				params[element.name] = '';
			if (element.checked) {
				if (params[element.name] != '')
					params[element.name] += ',';
				params[element.name] += element.value;
			} else if (element.attributes.uncheckedvalue) {
				if (params[element.name] != '')
					params[element.name] += ',';
				params[element.name] += element.attributes.uncheckedvalue.value;
			}
			break;
		}
		}
	}
	return params;
}
function getGeometry(o) {
	if (o) {
		x = 0;
		y = 0;
		po = o;
		while (po) {
			x += po.offsetLeft;
			y += po.offsetTop;
			po = po.offsetParent;
		}
		if (o.style.position != 'absolute') {
			po = o.parentNode
			while (po && po != document.body) {
				if (!isNaN(po.scrollTop)) {
					x -= po.scrollLeft
					y -= po.scrollTop
				}
				po = po.parentNode
			}
		}
		return {
			x : x,
			y : y,
			w : o.offsetWidth,
			h : o.offsetHeight
		}
	}
}

