Object.prototype.attachEvent = function (sEvent, fnHandler, bUseCapture) {
	this.addEventListener(sEvent.indexOf('on') == 0 ? sEvent.replace('on', '') : sEvent, fnHandler, bUseCapture);
}
Object.prototype.detachEvent = function (sEvent, fnHandler, bUseCapture) {
	this.removeEventListener(sEvent.indexOf('on') == 0 ? sEvent.replace('on', '') : sEvent, fnHandler, bUseCapture);
}


Array.prototype.bsearch = function(searchItem, compare, right) {

	if (searchItem === undefined) return null
	if (!compare) {
		compare = function(a, b) {return (String(a) == String(b)) ? 0 : (String(a) < String(b)) ? -1 : +1}
	}
	var found = false, l = 0, u = this.length - 1
	while (l <= u) {
		var m = parseInt((l + u) / 2)
		switch (compare(this[m], searchItem)) {
		case -1:
			var ml = m
			l = m + 1
			break
		case +1:
			var mu = m
			u = m - 1
			break
		default:
			found = true
			if (right) {l = m + 1} else {u = m - 1}
		}
	}
	if (!found) {
		this.insertIndex = (ml + 1) || mu || 0
		return -1
	}
	return (right) ? u : l
}


function getElementComputedStyle(elem, prop) { 

	if (typeof(elem) != "object") elem = document.getElementById(elem)

	if (document.defaultView && document.defaultView.getComputedStyle) {
		if (prop.match(/[A-Z]/)) prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase()
		return document.defaultView.getComputedStyle(elem, "").getPropertyValue(prop)
	}

	if (elem.currentStyle) {
		var i
		while ((i=prop.indexOf("-"))!=-1) prop = prop.substr(0, i) + prop.substr(i+1,1).toUpperCase() + prop.substr(i+2);
		return elem.currentStyle[prop]
	}
	  
	return ""
}

