// JavaScript Document

function setOpacity(e, o) {
	e.style.opacity = (o / 100);
	e.style.filter = 'alpha(opacity=' + o + ')';
}

function getClientSize() {
	if (typeof window.innerHeight == 'number') {
		return [window.innerWidth, window.innerHeight];
	} else if (document.compatMode == 'CSS1Compat') {
		return [document.documentElement.clientWidth, document.documentElement.clientHeight];
	} else {
		return [document.body.clientWidth, document.body.clientHeight];
	}
}

function getLimitedClientSize(maxWidth, maxHeight) {
	cs = getClientSize();
	w = cs[0];
	h = cs[1];
	if (w > maxWidth) w = maxWidth;
	if (h > maxHeight) h = maxHeight;
	return [w, h];
}

function reduceSize(dim, maxWidth, maxHeight, keepAR) {
	keepAR = keepAR || true;
	if (!keepAR) {
		return [Math.min(dim[0], maxWidth), Math.min(dim[1], maxHeight)];
	}
	if (dim[0] < maxWidth && dim[1] < maxHeight) {
		return dim;
	}
	var rw = maxWidth / dim[0];
	var rh = maxHeight / dim[1];
	var r = Math.min(rw, rh);
	return [Math.floor(r * dim[0]), Math.floor(r * dim[1])];
}

function addHandlerByID(objID, evt, handler) {
	addHandler(document.getElementById(objID), evt, handler);
}

function addHandler(obj, evt, handler) {
	if (obj.addEventListener) {
		obj.addEventListener(evt, handler, false);
	} else if (obj.attachEvent) {
		obj.attachEvent('on' + evt, handler);
	} else {
		obj['on' + evt] = handler;
	}
}

function addOnLoadHandler(handler) {
	var onloadFunc = window.onload;
	window.onload = function() {
		if (onloadFunc) onloadFunc();
		handler();
	}
}

function logMsg(msg) {
	if (typeof console == 'object') {
		console.log(msg);
	}
}

function isAncestorOf(ancestor, descendant) {
	if (ancestor == null || descendant == null) return false;
	if (ancestor == descendant) return true;
	var p = descendant.parentNode;
	if (p == null) return false;
	if (p == ancestor) return true;
	return isAncestorOf(ancestor, p);
}

function isNumberEvent(evt) {
	var code = typeof evt.which == 'number' ? evt.which : ect.keyCode;
	return code == 8 || code == 0 || (code >= 48 && code <= 57);
}

function getSelectedOption(sel) {
	return sel.options[sel.selectedIndex].value;
}
