var ted = new Date();
var timestamp = ted.getTime();
var jsRemove = false;

// prihlaseni na akci
function _prihlas_nominace (nominaceID, hotovo) {
	if (_load_JS('http://' + domena + '/ajax/nominace-' + (hotovo ? 'hotovo-' : '') + nominaceID + '.html')) {
		return false;
	} else {
		return true;
	}
}

// nabor, kontakt
function _formular (textID, hotovo) {
	if (_load_JS('http://' + domena + '/ajax/' + textID + (hotovo ? '-hotovo' : '') + '.html')) {
		return false;
	} else {
		return true;
	}
}

function _komentar (clanekID, hotovo) {
	if (_load_JS('http://' + domena + '/ajax/komentar-' + (hotovo ? 'hotovo-' : '') + clanekID + '.html')) {
		return false;
	} else {
		return true;
	}
}

function _obchod (clanekID, hotovo) {
	if (_load_JS('http://' + domena + '/ajax/obchod-' + (hotovo ? 'hotovo-' : '') + clanekID + '.html')) {
		return false;
	} else {
		return true;
	}
}

// AJAX
function _load_JS (url, e) {
	var script = document.createElement('script');
	var thisHead = document.getElementsByTagName('head')[0];

	if (jsRemove) {
		thisHead.removeChild(thisHead.lastChild);
	}
	
	jsRemove = true;
	script.id = 'scriptLoader';
	script.src = url;

	if (typeof(thisHead.appendChild(script)) != "undefined") {
		return true;
	} else {
		return false;
	}
}

// posun DHTML prvku
function _posun (thisItem, smer) {
	var number = 0;
	var thisItemWidth = parseInt(thisItem.offsetWidth);
	var thisItemHeight = parseInt(thisItem.offsetHeight);
	var w_width, w_height;
	
	//thisItem.style.height = thisItemHeight + 'px';
	
	if (smer == "y") {
		// je velikost prvku větší než okno prohlížeče?
		if (thisItemHeight > pageHeight()) {
			thisItemHeight = pageHeight() - 10;
			thisItem.style.height = (thisItemHeight - 24)+ 'px';	// kvůli padding: 10px; a border: 2px;
		}
		number = posTop() + parseInt(pageHeight() / 2 - thisItemHeight / 2);
		number = number < 0 ? 0 : number;
	} else if (smer == "x") {
		number = posLeft() + parseInt(pageWidth() / 2 - thisItemWidth / 2);
		number = number < 0 ? 0 : number;
	} else if (smer == "max") {
		number = parseInt(document.body.clientHeight);
	}

	return number;
}

function _overlay (id, visible) {
	var thisOverlay = myGet(id);
	var height = document.body.clientHeight;
	
	if (thisOverlay) {
		thisOverlay.style.height = (pageHeight() > height ? pageHeight() : height) + 10 + 'px';
		thisOverlay.className = visible ? 'visible' : 'hidden';
	}
}

function _hide (id) {
	thisItem = myGet(id);
	
	_overlay(id + '_overlay', false);
	if (thisItem) {
		thisItem.innerHTML = '';
		thisItem.title = '';
		thisItem.className = 'hidden';
		thisItem.style.cursor = 'pointer';
	}
}

// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() {
	x = window.innerWidth != null ? 
		window.innerWidth : document.documentElement && document.documentElement.clientWidth ?
			document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : 0;

	return parseInt(x);
}

function pageHeight() {
	x = window.innerHeight != null ? 
		window.innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body != null? document.body.clientHeight : 0;
	
	return parseInt(x);
}

function posLeft() {
	x = typeof window.pageXOffset != 'undefined' ? 
		window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? 
			document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;

	return parseInt(x);
}

function posTop() {
	x = typeof window.pageYOffset != 'undefined' ? 
		window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
			document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;

	return parseInt(x);
}

function posRight() {
	x = posLeft() + pageWidth();

	return parseInt(x);
} 

function posBottom() {
	x = posTop() + pageHeight();

	return parseInt(x);
}
