/**
 * W3C and MS compatible way to attach multiple events
 */
function listen(ev, el, fn) {
	if (el.addEventListener) {
		el.addEventListener(ev, fn, false);
		return true;
	} else if (el.attachEvent) {
		return el.attachEvent("on" + ev, fn);
	}
	return false;
}

/**
 * Return a random integer inclusively within the bounds
 */
Math.randRange = function(min, max) {
	return Math.floor(Math.random() * (max-min+1))+min;
}

/**
 * Sleep for the given number of seconds
 */
function sleep(s) {
	var now = new Date();
	var exitTime = now.getTime() + (1000*s);
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime) return;
	}
}