// IE - fix blikajicich backgroundu
eval("try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}");
var timer = null;

function obj(id) {
	return document.getElementById(id);
}

function clearInput(o,defaultValue) {
	if (o.value == defaultValue ) o.value = "";
	focusObj = o;
}
function defaultInput(o,defaultValue) {
	if (o.value == "" ) o.value = defaultValue;
}

function initRandom(element,items,parenttagname) {
	var j = 0;
	var itemClass;
	var randomNumbers = new Array();
	var showAll = false;

 	var subItems = $(element+" "+parenttagname);

	if (subItems.length <= items) {
		showAll = true;
	}
	else {
		while (j < items) {
			var randNumber = Math.floor((subItems.length)*Math.random());
			if (! isInArray(randNumber,randomNumbers)) {
				randomNumbers[j] = randNumber;
				j++;
			}
		}
	}

	for (var i = 0; i < subItems.length; i++) {
		if ((isInArray(i,randomNumbers)) || (showAll)) {
			subItems[i].className = 'i';
		}
		else {
			subItems[i].className = 'i hidden';
		}
	}

}

function isInArray(needle, arrayHaystack) {
	for (x = 0; x < arrayHaystack.length; x++)
		if (arrayHaystack[x] == needle)
			return true;
		return false;
}

function goToParentWeb(url,opener) {
	if (opener == null)  {
		return true;
	}
	else {
		opener.location.href = url;
		opener.focus();
		return false;
	}
}

function scrollToLeft() {
	timer = setInterval("scrollIt(-10)", 15);
}
function scrollToRight() {
	timer = setInterval("scrollIt(10)", 15);
}
function scrollIt(px) {
	var box = obj("table-content");
	box.scrollLeft += px;
}
function updateButtons() {
	var box = obj("table-content");

	if ((obj("button-left") != null) && (obj("button-right") != null)) {
		obj("button-left").className = 'enabled';
		obj("button-right").className = 'enabled';
	
		if (box.scrollLeft == 0) {
			obj("button-left").className = 'disabled';
			if (timer != undefined) {
				clearInterval(timer);
			}
		}
		if (box.scrollLeft >= (box.scrollWidth - box.clientWidth)) {
			obj("button-right").className = 'disabled';
			if (timer != undefined) {
				clearInterval(timer);
			}
		}
	}
}
function stopScroll() {
	clearInterval(timer);
}
function showTitles() {
	var cellTitle = "Kliknutím odeberete sloupec";
	var thCells = obj("wideTable").getElementsByTagName("TH");
	var thCell;
	for (var i=0; i<thCells.length; i++ ) {
		thCell = thCells[i];
		if ((thCell.id != "caption") && (thCell.id != "")) {
			thCell.title = cellTitle;
		}
	}
}
