/**
 * Akce po načtení stránky.
 */
function load()
{
    // nastaví odkazům různé akce
    var links = document.getElementsByTagName('a');
    for (var i = 0; i < links.length; i++) {
        var link = links[i];

        // pokud se má odkaz otevřít do nového okna
        if (/new-window/.test(link.className)) {
            link.title += ' [Odkaz se otevře v novém okně]';
            link.onclick = function() {return !window.open(this.href);}
            link.onkeypressed = function() {return !window.open(this.href);}
			
			// pokusime se zjistit typ odkazovaneho dokumentu a podle toho nastavit CSS tridu odkazu (ikonka pred odkazem)
			var types = new Array (
				{'type' : 'jpg', 'class' : 'image'},
				{'type' : 'gif', 'class' : 'image'},
				{'type' : 'png', 'class' : 'image'},
				{'type' : 'pdf', 'class' : 'document'},
				{'type' : 'doc', 'class' : 'document'},
				{'type' : 'html', 'class' : 'document'},
				{'type' : 'zip', 'class' : 'archive'},
				{'type' : 'rar', 'class' : 'archive'}
			);
			
			for (j=0; j<types.length; j++) {
				reg = new RegExp('\\.' + types[j]['type'] + '$', 'i');
				//alert('Regular: ' + reg);
				className = link.className + ' link-type-' + types[j]['class'];
				if (reg.test(link.href)) {
					//alert('Nova trida: ' + className);
					links[i].className = className;
				}
			}
			
			/*
			if (/\.png$/.test(link.href)) {links[i].className = link.className + ' link-type-image';}
			if (/\.gif$/.test(link.href)) {links[i].className = link.className + ' link-type-image';}
			if (/\.pdf$/.test(link.href)) {links[i].className = link.className + ' link-type-document';}
			if (/\.doc$/.test(link.href)) {links[i].className = link.className + ' link-type-document';}
			if (/\.html$/.test(link.href)) {links[i].className = link.className + ' link-type-document';}
			if (/\.rar$/.test(link.href)) {links[i].className = link.className + ' link-type-archive';}
			if (/\.zip$/.test(link.href)) {links[i].className = link.className + ' link-type-archive';}
			*/
        }
    }
	
	// zvreni vsech marginalii
	closeAllMarginalie();
}

// provede se po načtení stránky
window.onload = load;

/**
 * Vytvoří cookie.
 */
function createCookie(name, value, days)
{
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = '; expires=' + date.toGMTString();
	} else {
		var expires = '';
	}
	document.cookie = name + '=' + value+expires + '; path=/';
}

/**
 * Přečte cookie.
 */
function readCookie(name)
{
	var nameEQ = name + '=';
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') {
			c = c.substring(1, c.length);
		}
		if (c.indexOf(nameEQ) == 0) {
			return c.substring(nameEQ.length, c.length);
  		}
	}

	return null;
}

/**
 * Umožňuje zadat druhé datum při některých možnostech.
 */
function enableDateTo()
{
	var dateType = document.getElementById('date');
	var dateTo = document.getElementById('date-to');
	var dateToTrigger = document.getElementById('date-to-trigger');

	dateTo.disabled = (dateType.selectedIndex == 2 || dateType.selectedIndex == 3);
	if (dateTo.disabled) {
		dateTo.value = '';
		dateToTrigger.style.display = 'none';
	} else {
		dateToTrigger.style.display = 'inline';
	}
}

/**
 * Zaškrtává/Odškrtává vše na stránce s výsledky.
 */
function toggleSelectButtons(element)
{
	var checkboxList = document.getElementsByName('doc[]');
	for (i = 0; i < checkboxList.length; i++) {
		checkboxList[i].checked = element.checked;
	}

	var checkboxAll = document.getElementsByName('all');
	for (i = 0; i < checkboxAll.length; i++) {
		checkboxAll[i].checked = element.checked;
	}
}

/**
 * Odškrtává chechboxy pro 'zaškrtnout vše', pokud nejsou zaškrtnuty všechny.
 */
function checkState()
{
	var checkboxList = document.getElementsByName('doc[]');
	var allChecked = true;
	for (var i = 0; i < checkboxList.length; i++){
		if (!checkboxList[i].checked) {
			allChecked = false;
			break;
		}
	}

	var checkboxAll = document.getElementsByName('all');
	for (i = 0; i < checkboxAll.length; i++) {
		checkboxAll[i].checked = allChecked;
	}
}

/**
 * Zabalování/rozbalování bloků na stránce hledání.
 */
function searchExpandCollapse(element)
{
	var div = document.getElementById(element);
	var strong = div.parentNode.getElementsByTagName('strong')[0];

	if (div.className == 'hidden') {
		createCookie('is' + element + 'opened', 1, 365);
		div.className = null;
		strong.className = 'open';
	} else {
		createCookie('is' + element + 'opened', 0, 365);
		div.className = 'hidden';
		strong.className = 'closed';
	}
}

/**
 * Funkce pro schování/zobrazení podrobností v menu výsledků vyhledávání.
 */
function expandCollapse(element)
{
	var div = document.getElementById(element).getElementsByTagName('div')[1];
	var ul = document.getElementById(element + 'ul');

	if (ul.className == 'hidden'){
		ul.className = null;
		div.className = 'onclick open';
	} else {
		ul.className = 'hidden';
		div.className = 'onclick';
	}
}

/**
 * Zabalování/rozbalování položek u stromů na stránce výsledků hledání.
 * Zabalování/rozbalování položek u obsahu právních předpisů.
 */
function resultTreeMainExpandCollapse(element)
{
	var elms = element.parentNode.getElementsByTagName('ul');
	
	if (elms.length > 0){
		if (elms[0].className == 'hidden'){
			elms[0].className = 'visible';
			element.className = element.className.replace(/plus/, 'minus');
		} else {
			elms[0].className = 'hidden';
			element.className = element.className.replace(/minus/, 'plus');
		}
	}
}

/**
 * Zabalování pravých bloků na stránce výsledků hledání.
 */
function resultTreeCAll(element)
{
	var elms = document.getElementById(element).getElementsByTagName('ul');
	for(var i = 0; i < elms.length; i++){
		elms[i].className = 'hidden';
	}
	var pm = document.getElementById(element).getElementsByTagName('span');
	for (var i = 0; i < pm.length; i++){
		if (pm[i].className.indexOf('minus') != -1) {
			pm[i].className = pm[i].className.replace(/minus/, 'plus');
		}
	}
}

/**
 * Otevře obsah u dokumentů, pokud je zadán nějaký nadpis.
 */
function openContents()
{
	var hash = document.location.hash;
	if ((hash != '') && (hash.indexOf('#heading') == 0)) {
		var headingId = hash.substr(1);

		var li = document.getElementById('contents-' + headingId);
		while (li.parentNode.id != 'contentsBoxul') {
			var ul = li.parentNode;
			var li = ul.parentNode;
			var span = li.getElementsByTagName('span')[0];

			if (ul.className == 'hidden'){
				ul.className = 'visible';
				span.className = span.className.replace(/plus/, 'minus');
			} else {
				ul.className = 'hidden';
				span.className = span.className.replace(/minus/, 'plus');
			}
		}
	}
}

/**
 * Zobrazí skryje info o produktech uživatele.
 */
function showHideInfo(userId, url, event)
{
	var infoName = 'info' + userId;
	var info = document.getElementById(infoName);

	if (info == null) {
		var info = document.createElement('div');
		info.className = 'licenceinfo block';
		info.id = infoName;
		info.style.top = (event.clientY + 30) + 'px';
		info.style.left = event.clientX + 'px';

		info.innerHTML = '<img src="/img/loading.gif" alt="Nahrávám..." />';
		info.innerHTML += '<p><a href="#" onclick="showHideInfo(' + userId + '); return false;">Skrýt</a></p>';

		var ajax = new Ajax();
		if (ajax == null) {
			return false;
		}

		ajax.open('GET', url + '?id=' + userId, true);
		ajax.onreadystatechange = function()
		{
			if ((ajax.readyState == 4) && (ajax.status == 200)) {
				info.innerHTML = ajax.responseText;
			}
		}
		ajax.send(null);

		document.getElementsByTagName('body')[0].appendChild(info);
	} else {
		if (info.className.indexOf('hidden') != -1) {
			info.className = info.className.replace(/hidden/, 'block');
		} else {
			info.className = info.className.replace(/block/, 'hidden');
		}
	}
}

/**
 * Vytvoří instanci ajaxu.
 */
function Ajax()
{
	var ajax = null;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
		try {
			ajax = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				ajax = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (E) {
				ajax = null;
			}
		}
	@end @*/
	if ((ajax == null) && (typeof XMLHttpRequest != 'undefined')) {
		ajax = new XMLHttpRequest();
	}

	return ajax;
}


///////////////////////////////// MERITUM /////////////////////////////////////
document.getElementsByClassName = function(cl) {
	var retnode = [];
	var regexp = '^[^\\-]*' + cl + '[^\\-]*$';
	
	var myclass = new RegExp(regexp);
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
}; 
var marginalie = new Array();
function switchMarginalie(id) {
	
	el = document.getElementById(id);
	if (!el) return false;
	
	// otevreni nebo zavreni
	if (!marginalie[id]) {
		// otevreni
		el.className = 'marginalie open';
		marginalie[id] = true;
	} else {
		// zavreni
		el.className = 'marginalie closed';
		marginalie[id] = false;
	}
	
	return true;
}
function closeAllMarginalie() {
	marginalie = document.getElementsByClassName('marginalie');
	
	for (var i=0; i<marginalie.length; i++) {
		//alert('M class: ' + marginalie[i].className + '')
		marginalie[i].className = 'marginalie closed';
	}
}


function addOperator(operator, element) {
	
	var new_value = '';
	
	el = document.getElementById(element);
	if (!el) return false;
	
	if (operator == 'phrase') term = window.prompt('Zadejte text fráze: ', '');
	else term = window.prompt('Zadejte termín: ', '');

	if (term && term != '') {
		switch (operator)
		{
		case 'and':
		  term = term.replace(/ /g, ' +')
		  new_value = '+'+term;
		  break;
		case 'not':
		  term = term.replace(/ /g, ' -')
		  new_value = '-'+term;
		  break;
		case 'recommend':
		  term = term.replace(/ /g, ' #')
		  new_value = ' #'+term;
		  break;
		case 'or':
		  term = term.replace(/ /g, ' |')
		  new_value = '|'+term;
		  break;
		case 'phrase':
		  new_value = '"'+term+'"';
		  break;
		default:
		  // fall through
		}
		
		if (el.value == '') el.value = new_value;
		else el.value += ' '+new_value;
	}
	el.focus(); 
}




// script slouzici ke skryvani a odkryvani casti textu

function show(text, kotvaA, kotvaB) {
	document.getElementById(text).style.display = "block";
	document.getElementById(kotvaA).style.display = "none";	
	document.getElementById(kotvaB).style.display = "inline";
}

function hid(text, kotvaA, kotvaB) {
	document.getElementById(text).style.display = "none";
	document.getElementById(kotvaA).style.display = "inline";	
	document.getElementById(kotvaB).style.display = "none";
}

// vrati rozliseni okna
function ScreenSize() {
	if (parseInt(navigator.appVersion)>3) {
		screenW = screen.width;
		screenH = screen.height;
	} else if (navigator.appName == "Netscape" 	&& parseInt(navigator.appVersion)==3 && navigator.javaEnabled()) {
		// stare browsery
		var jToolkit = java.awt.Toolkit.getDefaultToolkit();
		var jScreenSize = jToolkit.getScreenSize();
		screenW = jScreenSize.width;
		screenH = jScreenSize.height;
	}
	
	return Array(screenW, screenH);
}


function hideElement(element) {
	document.getElementById(element).style.display = "none";
}

function showElement(element) {
	document.getElementById(element).style.display = "block";
}

function disableElement(element) {
	document.getElementById(element).className = "disabled";
}

// pozavira popup okna (pred odeslanim formulare)
function closePopupWindows() {
	
	if(popupWindow && false == popupWindow.closed) {
		popupWindow.close();
	}
	if(popupIssueWindow && false == popupIssueWindow.closed) {
		popupIssueWindow.close();
	}
	if(popupPersonAuthorWindow && false == popupPersonAuthorWindow.closed) {
		popupPersonAuthorWindow.close();
	}
	if(popupCompanyAuthorWindow && false == popupCompanyAuthorWindow.closed) {
		popupCompanyAuthorWindow.close();
	}
	if(popupTextTypeWindow && false == popupTextTypeWindow.closed) {
		popupTextTypeWindow.close();
	}
}

// upravi vysku okna
function setWindowHeigh(new_height) {
	var width = 400;
	var screenSize = ScreenSize();
	
	var max_height = screenSize[1]-100;

	
	if (new_height <= max_height)	
		var height = new_height;
	else							
		var height = max_height;
	
	window.resizeTo(width,height);
}


/* --------------------------------------------------------------------------
	Vyber pojmu z rejstriku
 -------------------------------------------------------------------------- */


// otevreni okna se stromem rejstriku
function openIndexTreeWindow(url) {
	
	var width = 400;
	var height = 600;
	//var popupWindow = false;

	// vycentrovani
	var screenSize = ScreenSize();
	var left = (screenSize[0] - width) / 2;
	var top = (screenSize[1] - height) / 2;
	
	popupWindow = window.open(url, 'popupWindow', 'location=no, status=no, toolbar=no, menubar=no, resizable=yes, scrollbars=yes, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + '');
	
	popupWindow.focus();
	return false;
}

// prida vybrany pojem z vecneho rejstriku do formu pro vyhledavani
function addIndexItem(name, id) {

	var targetId = 'keywords-container';

	// pridani do podminek vyhledavani
	predefinedElement = window.opener.document.getElementById('keyword-item-'+id)
	if ( !predefinedElement ) {
		targetElement = window.opener.document.getElementById(targetId);
		targetElement.innerHTML += '<div class="keyword-item" id="keyword-item-'+id+'"><input type="hidden" name="index[]" id="index_keyword_'+id+'" value="'+id+'" />'+name+' <span>[<a class="removeIndex" onclick="removeIndexItem(\''+name+'\', '+id+')" title="odstranit tento výraz z podmínky pro vyhledávání">X</a>]</span></div>';
	}
	// schovani pridaneho vyrazu
	sourceElement = document.getElementById('item'+id);
	//sourceElement.style.display = 'none';
	sourceElement.className = 'disabled';
	
	// zobrazeni informace o pridani
	//alert('Výraz "'+name+'" byl přidán.');
}


// odstrani vybrany pojem z vecneho rejstriku z formu pro vyhledavani
function removeIndexItem(name, id) {
	
	var formElement = '';
	var dateObj = new Date();
	newId = dateObj.getTime();
	
	formElement = document.getElementById('index_keyword_'+id);
	if (formElement) {
		// "vynulovani" hodnoty prislusneho prvku ve formulari
		formElement.value = '-1';
		
		// "prepsani" ID formularoveho prvku
		formElement.id = 'index_keyword_'+newId;
	}
	
	// "prepsani" ID formularoveho prvku a jeho nasledne skryti
	divElement = document.getElementById('keyword-item-'+id);
	if (divElement) {
		divElement.id = 'keyword-item-'+newId;
		newDivElement = document.getElementById('keyword-item-'+newId);
		newDivElement.style.display = 'none';
	}
	
	// zobrazeni prvku ve stromu (nyni byl skryty)
	if (popupWindow != null && popupWindow.self != null && popupWindow.self.document != null) {
		if ( (popupElement = popupWindow.self.document.getElementById('item'+id)) != null) {
			//popupElement.style.display = 'list-item';
			popupElement.className = 'enabled';
		}
	}
	//else alert('popupWindow neni definovano');
	
	// zobrazeni informace o odstraneni
	//alert('Výraz "'+name+'" byl odstraněn.');
}








/* --------------------------------------------------------------------------
	Vyber vydani
 -------------------------------------------------------------------------- */


// otevreni okna se stromem zdroju a vydani
function openIssueTreeWindow(url) {
	
	var width = 400;
	var height = 600;
	//var popupWindow = false;

	// vycentrovani
	var screenSize = ScreenSize();
	var left = (screenSize[0] - width) / 2;
	var top = (screenSize[1] - height) / 2;
	
	popupIssueWindow = window.open(url, 'popupWindow', 'location=no, status=no, toolbar=no, menubar=no, resizable=yes, scrollbars=yes, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + '');
	
	popupIssueWindow.focus();
	return false;
}

// prida vybrany klic zdroj-vydani do formu vyhledavani
function addIssueItem(name, id, value) {

	var targetId = 'issues-container';

	// pridani do podminek vyhledavani
	predefinedElement = window.opener.document.getElementById('issue-item-'+id)
	if ( !predefinedElement ) {
		targetElement = window.opener.document.getElementById(targetId);
		targetElement.innerHTML += '<div class="issue-item" id="issue-item-'+id+'"><input type="hidden" name="sources_issues[]" id="source_issue_'+id+'" value="'+value+'" />'+name+' <span>[<a class="removeIssue" onclick="removeIssueItem(\''+name+'\', \''+id+'\')" title="odstranit toto vydání z podmínky pro vyhledávání">X</a>]</span></div>';
	}
	
	// schovani pridaneho vyrazu
	sourceElement = document.getElementById('item'+id);
	//sourceElement.style.display = 'none';
	sourceElement.className = 'disabled';
	
	// zobrazeni informace o pridani
	//alert('Vydání "'+name+'" bylo přidáno.');
}


// odstrani vybrane vydani z vecneho rejstriku z formu pro vyhledavani
function removeIssueItem(name, id) {
	
	var formElement = '';
	var dateObj = new Date();
	newId = dateObj.getTime();
	
	formElement = document.getElementById('source_issue_'+id);
	if (formElement) {
		// "vynulovani" hodnoty prislusneho prvku ve formulari
		formElement.value = '-1';
		
		// "prepsani" ID formularoveho prvku
		formElement.id = 'source_issue_'+newId;
	}
	
	// "prepsani" ID formularoveho prvku a jeho nasledne skryti
	divElement = document.getElementById('issue-item-'+id);
	if (divElement) {
		divElement.id = 'issue-item-'+newId;
		newDivElement = document.getElementById('issue-item-'+newId);
		newDivElement.style.display = 'none';
	}

	// zobrazeni prvku ve stromu (nyni byl skryty)
	if (popupIssueWindow != null && popupIssueWindow.self != null && popupIssueWindow.self.document != null) {
		if ( (popupElement = popupIssueWindow.self.document.getElementById('item'+id)) != null ) {
			//popupElement.style.display = 'list-item';
			popupElement.className = 'enabled';
		}
	}
	//else alert('popupWindow neni definovano');
	
	// zobrazeni informace o odstraneni
	//alert('Vydání "'+name+'" bylo odstraněno.');
}








/* --------------------------------------------------------------------------
	Vyber zdroju
 -------------------------------------------------------------------------- */


// pouziva stejne okno jako vydani


// prida vybrany klic zdroj do formu vyhledavani
function addSourceItem(name, id, value) {

	var targetId = 'issues-container';

	// pridani do podminek vyhledavani
	predefinedElement = window.opener.document.getElementById('source-item-'+id)
	if ( !predefinedElement ) {
		targetElement = window.opener.document.getElementById(targetId);
		targetElement.innerHTML += '<div class="issue-item" id="source-item-'+id+'"><input type="hidden" name="source[]" id="source_'+id+'" value="'+value+'" />'+name+' <span>[<a class="removeIssue" onclick="removeSourceItem(\''+name+'\', \''+id+'\')" title="odstranit tento zdroj z podmínky pro vyhledávání">X</a>]</span></div>';
	}
	
	// schovani pridaneho vyrazu
	sourceElement = document.getElementById('item-source'+id);
	//sourceElement.style.display = 'none';
	sourceElement.className = 'disabled';
	
	// zobrazeni informace o pridani
	//alert('Vydání "'+name+'" bylo přidáno.');
}


// odstrani vybrany zdroj z formu pro vyhledavani
function removeSourceItem(name, id) {

	var formElement = '';
	var dateObj = new Date();
	newId = dateObj.getTime();
	
	formElement = document.getElementById('source_'+id);
	if (formElement) {
		// "vynulovani" hodnoty prislusneho prvku ve formulari
		formElement.value = '-1';
		
		// "prepsani" ID formularoveho prvku
		formElement.id = 'source_'+newId;
	}
	
	// "prepsani" ID formularoveho prvku a jeho nasledne skryti
	divElement = document.getElementById('source-item-'+id);
	if (divElement) {
		divElement.id = 'source-item-'+newId;
		newDivElement = document.getElementById('source-item-'+newId);
		newDivElement.style.display = 'none';
	}

	// zobrazeni prvku ve stromu (nyni byl skryty)
	if (popupIssueWindow != null && popupIssueWindow.self != null && popupIssueWindow.self.document != null) {
		if ( (popupElement = popupIssueWindow.self.document.getElementById('item-source'+id)) != null ) {
			//popupElement.style.display = 'list-item';
			popupElement.className = 'enabled';
		}
	}
	//else alert('popupWindow neni definovano');
	
	// zobrazeni informace o odstraneni
	//alert('Zdroj "'+name+'" byl odstraněn.');
}






/* --------------------------------------------------------------------------
	Vyber autoru (fyzicke osoby a instituce zvlast)
 -------------------------------------------------------------------------- */

// otevreni okna se seznamem autoru
function openAuthorWindow(url, mode) {
	
	var width = 400;
	var height = 600;

	
	// vycentrovani
	var screenSize = ScreenSize();
	var left = (screenSize[0] - width) / 2;
	var top = (screenSize[1] - height) / 2;
	
	if (mode == 'person') {
		popupPersonAuthorWindow = window.open(url, 'popupWindow', 'location=no, status=no, toolbar=no, menubar=no, resizable=yes, scrollbars=yes, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + '');
		popupPersonAuthorWindow.focus();
	}
	if (mode == 'company') {
		popupCompanyAuthorWindow = window.open(url, 'popupWindow', 'location=no, status=no, toolbar=no, menubar=no, resizable=yes, scrollbars=yes, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + '');
		popupCompanyAuthorWindow.focus();
	}
	
	
	return false;
}

// prida vybraneho autora do podminky vyhledavani
function addAuthorItem(name, id, mode) {

	if (mode == 'person') {
		var targetId = 'author-person-container';
		//var inputName = 'author_person';
	}
	if (mode == 'company') {
		var targetId = 'author-company-container';
		//var inputName = 'author_company';
	}
	
	// pridani do podminek vyhledavani
	predefinedElement = window.opener.document.getElementById('author-item-'+id);
	if ( !predefinedElement ) {
		targetElement = window.opener.document.getElementById(targetId);
		targetElement.innerHTML += '<div class="author-item" id="author-item-'+id+'"><input type="hidden" name="author[]" id="author_'+id+'" value="'+id+'" />'+name+' <span>[<a class="removeAuthor" onclick="removeAuthorItem(\''+name+'\', \''+id+'\', \''+mode+'\')" title="odstranit tohoto autora z podmínky pro vyhledávání">X</a>]</span></div>';
	}
	
	// schovani pridaneho vyrazu
	sourceElement = document.getElementById('item'+id);
	//sourceElement.style.display = 'none';
	sourceElement.className = 'disabled';
	
	// zobrazeni informace o pridani
	//alert('Autor "'+name+'" byl přidán.');
}


// odstrani vybraneho autora z formu pro vyhledavani
function removeAuthorItem(name, id, mode) {
	
	var formElement = '';
	var dateObj = new Date();
	newId = dateObj.getTime();
	
	formElement = document.getElementById('author_'+id);
	if (formElement) {
		// "vynulovani" hodnoty prislusneho prvku ve formulari
		formElement.value = '-1';
		
		// "prepsani" ID formularoveho prvku
		formElement.id = 'author_'+newId;
	}
	
	// "prepsani" ID formularoveho prvku a jeho nasledne skryti
	divElement = document.getElementById('author-item-'+id);
	if (divElement) {
		divElement.id = 'author-item-'+newId;
		newDivElement = document.getElementById('author-item-'+newId);
		newDivElement.style.display = 'none';
	}
	
	// zobrazeni prvku ve stromu (nyni byl skryty)
	if (mode == 'person') {
		if (popupPersonAuthorWindow != null && popupPersonAuthorWindow.self != null && popupPersonAuthorWindow.self.document != null) {
			if ( (popupElement = popupPersonAuthorWindow.self.document.getElementById('item'+id)) != null ) {
				//popupElement.style.display = 'list-item';
				popupElement.className = 'enabled';
			}
		}
		//else alert('popupWindow neni definovano');
	}
	if (mode == 'company') {
		if (popupCompanyAuthorWindow != null && popupCompanyAuthorWindow.self != null && popupCompanyAuthorWindow.self.document != null) {
			if ( (popupElement = popupCompanyAuthorWindow.self.document.getElementById('item'+id)) != null ) {
				//popupElement.style.display = 'list-item';
				popupElement.className = 'enabled';
			}
		}
		//else alert('popupWindow neni definovano');
	}

	
	// zobrazeni informace o odstraneni
	//alert('Autor "'+name+'" byl odstraněn.');
}





/* --------------------------------------------------------------------------
	Vyber typu textu
 -------------------------------------------------------------------------- */


// otevreni okna se stromem typu textu
function openTextTypeTreeWindow(url) {

	var width = 400;
	var height = 600;
	//var popupWindow = false;

	// vycentrovani
	var screenSize = ScreenSize();
	var left = (screenSize[0] - width) / 2;
	var top = (screenSize[1] - height) / 2;
	
	popupTextTypeWindow = window.open(url, 'popupWindow', 'location=no, status=no, toolbar=no, menubar=no, resizable=yes, scrollbars=yes, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + '');
	
	popupTextTypeWindow.focus();
	return false;
}

// prida vybrany typ textu do formu vyhledavani
function addTextTypeItem(name, id) {

	var targetId = 'text-types-container';

	// pridani do podminek vyhledavani
	predefinedElement = window.opener.document.getElementById('type-item-'+id);
	if ( !predefinedElement ) {
		targetElement = window.opener.document.getElementById(targetId);
		targetElement.innerHTML += '<div class="type-item" id="type-item-'+id+'"><input type="hidden" name="type[]" id="type_'+id+'" value="'+id+'" />'+name+' <span>[<a class="removeType" onclick="removeTextTypeItem(\''+name+'\', \''+id+'\')" title="odstranit tento typ textu z podmínky pro vyhledávání">X</a>]</span></div>';
	}
	// schovani pridaneho vyrazu
	sourceElement = document.getElementById('item'+id);
	//sourceElement.style.display = 'none';
	sourceElement.className = 'disabled';
	
	// zobrazeni informace o pridani
	//alert('Typ textu "'+name+'" byl přidán.');
}


// odstrani vybrany typ textu z formu pro vyhledavani
function removeTextTypeItem(name, id) {
	
	var formElement = '';
	var dateObj = new Date();
	newId = dateObj.getTime();
	
	formElement = document.getElementById('type_'+id);
	if (formElement) {
		// "vynulovani" hodnoty prislusneho prvku ve formulari
		formElement.value = '-1';
		
		// "prepsani" ID formularoveho prvku
		formElement.id = 'type_'+newId;
	}
	
	// "prepsani" ID formularoveho prvku a jeho nasledne skryti
	divElement = document.getElementById('type-item-'+id);
	if (divElement) {
		divElement.id = 'type-item-'+newId;
		newDivElement = document.getElementById('type-item-'+newId);
		newDivElement.style.display = 'none';
	}
	
	// zobrazeni prvku ve stromu (nyni byl skryty)
	if (popupTextTypeWindow != null && popupTextTypeWindow.self != null && popupTextTypeWindow.self.document != null) {
		if ( (popupElement = popupTextTypeWindow.self.document.getElementById('item'+id)) != null ) {
			//popupElement.style.display = 'list-item';
			popupElement.className = 'enabled';
		}
	}
	//else alert('popupWindow neni definovano');
	
	// zobrazeni informace o odstraneni
	//alert('Typ textu "'+name+'" byl odstraněn.');
}

// Slider pomocne funkce
function zeroPad(num,count) {
	var numZeropad = num + '';
	while(numZeropad.length < count) {
		numZeropad = "0" + numZeropad;
	}
	return numZeropad;
}

function toDay(dayStamp) {
	var myDate = new Date( dayStamp * 3600 * 1000);
	var day = zeroPad(myDate.getDate(), 2);
	var month = zeroPad(myDate.getMonth() + 1, 2);
	var year = myDate.getFullYear().toString();
	
	return  day + '.' + month + '.' + year;	
}

function toDayStamp(timestamp) {
	myDate = Math.round(timestamp / 3600);
	return myDate;
}
