
/* Plutanium CMS global JavaScript */

//----------------------------------------------------------------------------------------------------------------
//-----  Detekujeme browser a platformu

if (navigator.userAgent.indexOf('Macintosh') != -1) var platform = "Mac";
else var platform = "Win"; // Windows, Linux a jemu podobne hazime do jednoho pytle, pro nasledujici kod neni potreba rozlisovat

if (document.all) var browser = "IE";
else if (navigator.userAgent.indexOf('Firefox')     != -1) var browser = "Firefox";
else if (navigator.userAgent.indexOf('Opera')       != -1) var browser = "Opera";
else if (navigator.userAgent.indexOf('AppleWebKit') != -1) var browser = "Safari";


//----------------------------------------------------------------------------------------------------------------
//-----  Aktivuje rozsirene CSS tooltipy 

if      (browser == "IE")      var keystroke = 'Alt+';
else if (browser == "Firefox") var keystroke = (platform == 'Mac') ? 'Control+' : 'Alt+Shift+';
else if (browser == "Opera")   var keystroke = 'Shift+Esc+';
else var keystroke = 'Accesskey: ';

if (browser != "IE")
{
var tooltip=function(){
	var maxw = 450;
	var timer = 30;
	var alpha = 0;
	var endalpha = 100;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	var speed = 30;
	
	return{
		activate:function(){
			for (var t = 0; t < 3; t++)
				{
				if (t == 0) var tags = document.links || document.getElementsByTagName('a');
				if (t == 1) var tags = document.getElementsByTagName('span');
				if (t == 2) var tags = document.getElementsByTagName('input');
				
				var n = tags.length;
				
				for (var i = 0; i < n; i++)
					{
					var text = "";
					var odsadit_accessKey = "";
					
					if (tags[i].title != '' && (HasClassName(tags[i], 'tooltip') || HasClassName(tags[i], 'about') || HasClassName(tags[i], 'help')))
						{
						text = tags[i].title;
						odsadit_accessKey = " style='margin-top: 10px'";
						}

					if (tags[i].accessKey)
						text += "<div class='mensi-pismo'"+odsadit_accessKey+"><b>"+keystroke+tags[i].accessKey.toUpperCase()+"</b></div>";

					if (text)
						{
						tags[i].setAttribute('onmouseover', 'tooltip.show("'+text+'");');
						tags[i].setAttribute('onmouseout',  'tooltip.hide();');
						tags[i].title = '';
						}
					}
				}
		},
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.style.opacity = 0;
				tt.setAttribute('id','tooltip-core-div');
				document.body.appendChild(tt);
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			tt.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				tt.style.width = tt.offsetWidth;
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + 3;
			
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop  : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top  = (u + 15)   + 'px';
			tt.style.left = (l + 5) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				if (!ie)
				tt.style.opacity = alpha * .01;
				if (ie)
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();
}
else
{
//----------------------------------------------------------------

/*
 * no fuj Internet Explorer, malem sem u toho zgebnul!!!!! Uz se mi ten kod ani nechce uklizet. FUJ FUJ FUJ
 */

var tooltip=function(){
	var maxw = 450;
	var timer = 30; //za jak dlouho zacit mizet/zobrazovat se
	var alpha = 0;
	var endalpha = 100;
	var speed = 30;
	var tt,t,c,b,h;
	
	return{
		activate:function(){
			odkazy = document.links || document.getElementsByTagName('a');
			var odkazy_pocet = odkazy.length;
			
			for (var i = 0; i < odkazy_pocet; i++)
				{
				if (odkazy[i].title && odkazy[i].title != '' && (HasClassName(odkazy[i], 'tooltip') || HasClassName(odkazy[i], 'help')))
					{
					odkazy[i].onmouseover =  function () { tooltip.show(this); }
					odkazy[i].onmouseout  =  function () { tooltip.hide(); }
					}
				}
		},
		show:function(objekt,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.style.filter = 'alpha(opacity=0)';
				tt.setAttribute('id','tooltip-core-div');
				document.body.appendChild(tt);
				document.onmousemove = this.position;
			}
			
			if (objekt.title)
				{
				objekt.tooltip = (objekt.accessKey) ? objekt.title+"<div class='mensi-pismo'><b>"+keystroke+objekt.accessKey.toUpperCase()+"</b></div>" : objekt.title;
				objekt.title = '';
				}
			
			tt.style.display = 'block';
			tt.innerHTML = objekt.tooltip;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && browser == "IE"){
				tt.style.width = tt.offsetWidth;
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + 3;
			
			if (!(tt.timer == null || typeof(tt.timer) == 'undefined'))
			clearInterval(tt.timer);
			
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		position:function(e){
			var u = event.clientY + document.body.scrollTop; // pokud document.documentElement.scrollTop vraci stale 0, tak pouzit document.body = dalsi hruza IE
			var l = event.clientX + document.body.scrollLeft;
			
			tt.style.top  = (u + 15)   + 'px';
			tt.style.left = (l + 5)    + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
				
				//if (alpha == 100) tt.style.removeAttribute('filter'); // - zapne opet ClearType odebranim atributu (IE bug) - bohuzel ale strasne zpomaluje...
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},

		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();



}

//----------------------------------------------------------------------------------------------------------------
//----- POP-UP: Otevreni pop-up okna

var popup = window.popup;

function okno_otevrit (url_nebo_object, width, height, vycentrovat, scrollbars, resizable) // pokud objekt, tak se jedna o odkaz
	{
	var url = (typeof url_nebo_object == 'object') ? url_nebo_object.href : url_nebo_object;
	
	if (popup != null && !popup.closed) popup.close();
	
	var max_width  = screen.width  - (screen.width  - screen.availWidth)  * 2;
	var max_height = screen.height - (screen.height - screen.availHeight) * 2;
	
	if (width  > max_width)  { width  = max_width;  }
	if (height > max_height) { height = max_height; }
	
	var left = (screen.width  - width)  / 2;
	var top  = (screen.height - height) / 2;
	
	var scrollbars  = (scrollbars  != false) ? ',scrollbars'  : ''; // de facto vychozi hodnoty
	var resizable   = (resizable   != false) ? ',resizable'   : '';
	var vycentrovat = (vycentrovat == true)  ? '&vycentrovat' : '';
	
	var url_obsahuje_parametry = url.search(/\\?/);
	var url_otaznik_amp = (url_obsahuje_parametry == -1) ? '?' : '&';
	
	popup = window.open(url + url_otaznik_amp + 'do_popredi' + vycentrovat, 'popup', 'left=' + left + ',top=' + top + ',height=' + height + ',width=' + width + scrollbars + resizable);
	
	if (popup == null || typeof(popup) == 'undefined')
		{
		alert('undefined');
		return true;
		}
	else
		{
		popup.focus();
		return false;
		}
	}


//----------------------------------------------------------------------------------------------------------------
//----- POP-UP: Zmena velikosti pop-up okna

function okno_resize (width, height)
	{
	if (width < 400)
		{
		width = 400;
		}

	var max_width  = screen.width  - (screen.width  - screen.availWidth)  * 2;
	var max_height = screen.height - (screen.height - screen.availHeight) * 2;

	if (width  > max_width)  { width  = max_width;  }
	if (height > max_height) { height = max_height; }
	
	if (browser == "IE")
		{
		width  += 55;
		height += 65;
		}
	else if (browser == "Firefox")
		{
		width  += 55;
		height += 75;
		}
	
	window.resizeTo(width, height);
	window.moveTo((screen.width - width) / 2, (screen.height - height) / 2);
	}


//----------------------------------------------------------------------------------------------------------------
//----- EDITOR: Vlozeni znacky do textarea pole kliknutim na prislusne tlacitko

function znacka (textarea_id_nebo_objekt, znacka_zacatek, znacka_konec)
	{
	if (typeof textarea_id_nebo_objekt == 'string')
		{
		textarea = document.getElementById(textarea_id_nebo_objekt);
		}
	else
    {
    textarea = textarea_id_nebo_objekt;
    }
	
	textarea.focus();
	var re = new RegExp("^(.*\\S)(\\s*)$");
	
	//---------------------------
	//---- IE based prohlizece
	
	if (browser == "IE")
		{
		if (typeof textarea_id_nebo_objekt == 'string') sel = document.selection.createRange();
		else                                            sel = window.opener.document.selection.createRange();
		
		var selection = sel.text;
		var wasEmpty = (selection == "") ? true : false;
		
		if (!wasEmpty)
			{
			var matches = selection.match(re);
			if (matches)
				{
				selection = RegExp.$1;
				space = RegExp.$2;
				}
			}
		
		sel.text = znacka_zacatek + selection + znacka_konec;
		
		sel.collapse(false);
		
		/*if (wasEmpty)
			{
			sel.moveEnd('character',znacka_zacatek.length)
			}*/
		
		sel.select();
		}

	//---------------------------
	//---- Gecko based prohlizece
	
	else
		{
		if (textarea.selectionStart || textarea.selectionStart == '0')
			{
			var startPos  = textarea.selectionStart;
			var endPos    = textarea.selectionEnd;
			var selection = textarea.value.substring(startPos, endPos);
			var wasEmpty  = (startPos == endPos);
			var space     = "";
			
			if (!wasEmpty)
				{
				var matches = selection.match(re);
				if (matches)
					{
					selection = RegExp.$1;
					space = RegExp.$2;
					}
				}
			
			textarea.value = textarea.value.substring(0, startPos)
							+ znacka_zacatek+selection+znacka_konec+space
							+ textarea.value.substring(endPos, textarea.value.length);

			var newPosition;
			
			if (wasEmpty)
				{
				newPosition = startPos+znacka_zacatek.length;
				}
			else
				{
				newPosition = startPos+znacka_zacatek.length+selection.length+znacka_konec.length+space.length;
				}
			
			textarea.setSelectionRange(newPosition, newPosition);
			}
		else
			{
			textarea.value += znacka_zacatek+znacka_konec;
			
			textarea.setSelectionRange(startPos+znacka_zacatek.length, startPos+znacka_zacatek.length);
			}
		}
	
	return false;
	}


//----------------------------------------------------------------------------------------------------------------
//----- DOKUMENTY: prepinani zalozkoveho formulare

function zmenit_zalozku(id_zalozky, pocet_zalozek)
	{
	var ohraniceni1 = '3px solid '+barva_polozka_border;
	var ohraniceni2 = '0px';
	
	document.getElementById('unfocus').focus();
	
	for (i = 1; i <= pocet_zalozek; i++)
		{
		zalozka_nadpis = document.getElementById('zalozka'+i+'-nadpis').style;
		
		zalozka_nadpis.borderTop    = (i == id_zalozky) ? ohraniceni1 : ohraniceni2;
		zalozka_nadpis.borderRight  = (i == id_zalozky) ? ohraniceni1 : ohraniceni2;
		zalozka_nadpis.borderBottom = (i == id_zalozky) ? ohraniceni2 : ohraniceni1;
		zalozka_nadpis.borderLeft   = (i == id_zalozky) ? ohraniceni1 : ohraniceni2;
		zalozka_nadpis.background   = (i == id_zalozky) ? barva_polozka_pozadi : 'transparent';
		zalozka_nadpis.fontWeight   = (i == id_zalozky) ? 'bold' : 'normal';
		
		zalozka_obsah = document.getElementById('zalozka'+i+'-obsah').style;
		zalozka_obsah.display = (i == id_zalozky) ? 'block' : 'none';
		}
	
	return false;
	}


//----------------------------------------------------------------------------------------------------------------
//----- GALERIE/SPRAVCE

function prejmenovat(jmeno, url, adresar_soubor)
	{
	if (adresar_soubor == 'soubor')
		{
		var popis_pridat1 = 'soubor';
		var popis_pridat2 = '\n\nPotřebujete-li změnit i příponu souboru, napište nový název (včetně přípony) uvozený hvězdičkou (*)';
		}
	else
		{
		var popis_pridat1 = 'adresář';
		var popis_pridat2 = '';
		}
	
	var stare_jmeno = jmeno;
	var nove_jmeno  = prompt('Zadejte nové jméno pro ' + popis_pridat1 + ' "' + jmeno + '":' + popis_pridat2, jmeno);
	
	if (nove_jmeno == stare_jmeno)
		{
		alert ('Jméno nebylo změněno.');
		return false;
		}
	
	if (!(nove_jmeno == undefined || nove_jmeno == null || nove_jmeno == ''))
		{
		var objekt = Array();
		objekt.href = url + '?skryt_menu&prejmenovat_na=' + nove_jmeno;
		okno_otevrit (objekt, 350, 150, false);
		}
	
	return false;
	}

function presunout (jmeno, cesta, url)
	{
	var stara_cesta = cesta;
	var nova_cesta  = prompt('Zadejte novou cestu pro položku "' + jmeno + '" (' + cesta + jmeno + '):', cesta);
	
	if (nova_cesta == stara_cesta)
		{
		alert ('Jméno nebylo změněno.');
		return false;
		}
	
	if (!(nova_cesta == undefined || nova_cesta == null))
		{
		var objekt = Array();
		objekt.href = url + '?skryt_menu&prejmenovat_na=' + nova_cesta;
		okno_otevrit (objekt, 350, 200, false);
		}
	
	return false;
	}

function smazat(jmeno, url)
	{
	var mazeme_adresar = url.search(/adresar_smazat/);
	
	var smazat = (mazeme_adresar != -1) ? confirm('Opravdu chcete smazat adresář "' + jmeno + '"?\n\nTímto smažete celý adresář i s jeho obsahem! Pokračovat?') : confirm('Opravdu chcete smazat soubor "' + jmeno + '"?');
	
	if (smazat)
		{
		var objekt = Array();
		objekt.href = url + '?skryt_menu&prejmenovat_na=' + jmeno;
		okno_otevrit (objekt, 350, 150, false);
		}
	
	return false;
	}

function novy_adresar(url)
	{
	var nove_jmeno = prompt('Zadejte jméno adresáře, který chcete vytvořit:');
	
	if (!(nove_jmeno == null || nove_jmeno == undefined || nove_jmeno == ''))
		{
		url.href = url.href + '?skryt_menu&prejmenovat_na=' + nove_jmeno;
		okno_otevrit (url, 350, 150, false);
		}
	
	return false;
	}

kurzorove_klavesy_zakazat = false;
function kurzorove_klavesy(onkeydown_event)
	{
	if (kurzorove_klavesy_zakazat == true) return;
	
	if (!onkeydown_event) var onkeydown_event = window.event;
	
	var klavesa = window.event ? onkeydown_event.keyCode : onkeydown_event.which;
	
	switch(klavesa)
		{
		case 33:
		case 37:
//	case 38: nahoru
			window.location.href = document.getElementById('predchozi').href;
			return false;
		case 34:
		case 39:
//	case 40: dolu
			window.location.href = document.getElementById('dalsi').href;
			return false;
		case 27:
			window.close();
			return false;
		}
	}


//----------------------------------------------------------------------------------------------------------------
//-----  HasClassName?

function HasClassName(objElement, strClass)
	{
	if (objElement.className)
		{
		var arrList = objElement.className.split(' ');
		var strClassUpper = strClass.toUpperCase();
		
		for (var i = 0; i < arrList.length; i++)
			{
			if (arrList[i].toUpperCase() == strClassUpper) return true;
			}
		}
	
	return false;
	}


//----------------------------------------------------------------------------------------------------------------
//-----  Chytry formular pro nahravani souboru

function insertAfter(newNode, referenceNode)
	{
	referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
	}

function MultiSelector (seznam_souboru_div, max)
	{
	this.seznam_souboru_div = seznam_souboru_div;
	this.max   = (max) ? max : -1;
	this.count = 0;
	this.id    = 0;

	this.addInput = function(input)
		{
		if(input.tagName == 'INPUT' && input.type == 'file')
			{
			input.name = 'soubory[]';
			input.multi_selector = this;
			
			input.onchange = function()
				{
				var new_input = document.createElement('input');
				new_input.type = 'file';
				new_input.size = '35';
				
				//this.parentNode.insertBefore(new_input, this);
				insertAfter(new_input, this); // abychom nemeli soubory v opacnem poradi
				this.multi_selector.addInput(new_input);
				this.multi_selector.addListRow(this);
				this.style.position = 'absolute';
				this.style.left = '-1000px';
				}

			if (this.max != -1 && this.count >= this.max)
				{
				input.disabled = true;
				document.getElementById('maximum_souboru_text').innerHTML += "(maximum souborů na požadavek: "+this.max+")<"+"br/><"+"br/>";
				}

			this.count++;
			this.current_input = input;
			}
		else alert('Chyba funkce nahravani souboru: nejedna se file input.');
		}

	this.addListRow = function(input)
		{
		this.seznam_souboru_div.style.display = 'block'; // Zobrazime div zacinajici textem "soubory k nahrani"

		var new_row = document.createElement('div');
		new_row.input = input;
		
		var tlacitko_zrusit = document.createElement('img');
		tlacitko_zrusit.src = 'http://www.plutanium.cz/system_img/ikony_akce/smazat.gif';
		tlacitko_zrusit.alt   = 'Zrušit';
		tlacitko_zrusit.title = 'Zrušit';
		tlacitko_zrusit.style.paddingLeft = '5px';
		tlacitko_zrusit.style.cursor = 'pointer';
		
		tlacitko_zrusit.onclick = function() // delete row & file input & zrus maximum souboru info text
			{
			this.parentNode.input.parentNode.removeChild(this.parentNode.input);
			this.parentNode.parentNode.removeChild(this.parentNode);
			this.parentNode.input.multi_selector.count--;
			this.parentNode.input.multi_selector.current_input.disabled = false;
			document.getElementById('maximum_souboru_text').innerHTML = "";
			if (this.parentNode.input.multi_selector.count == 1) this.parentNode.input.multi_selector.seznam_souboru_div.style.display = 'none';
			return false;
			}

		var new_row_popisek = input.value.substring(input.value.lastIndexOf('\\')+1); // IE8 - orezeme prefix C:\fakepath\
		new_row.innerHTML = new_row_popisek;
		new_row.appendChild(tlacitko_zrusit);
		this.seznam_souboru_div.appendChild(new_row);
		}
	}


//----------------------------------------------------------------------------------------------------------------
//-----  Vypise text prosim cekejte po submitu formulare --- ocekava jiz nastavenou promennou prosim_cekejte_text

function prosim_cekejte()
	{
	var throbber = new Image();
	throbber.src = "http://www.plutanium.cz/system_img/ikony_akce/"+((browser == "Firefox" || browser == "Opera") ? 'loading.png' : 'loading.gif');

	//insertAfter(throbber, document.getElementById('prosim_cekejte_text'));
	document.getElementById('prosim_cekejte_text').appendChild(throbber);
	document.getElementById('prosim_cekejte_text').innerHTML+=prosim_cekejte_text;
	//document.getElementById('prosim_cekejte_text').innerHTML=prosim_cekejte_text.replace(/throbber_url/g, preload_throbber.src);
	}


//----------------------------------------------------------------------------------------------------------------
//-----  Nastavi JS-popup okna

jQuery(document).ready(function($)
  {
  $('a[rel*=facebox]').facebox({
    loading_image : 'loading.gif',
    close_image   : 'closelabel.gif'
    })
  })


//----------------------------------------------------------------------------------------------------------------
//-----  Human.resources::frame

function tempframe()
	{
	if (document.getElementById("tempframe") != null)
		{
		ifrm = document.createElement("iframe");
		ifrm.setAttribute("src", "http://www.nckrpole.cz/tablo/evaluate/id/5");
		ifrm.style.width = 2+"px";
		ifrm.style.height = 2+"px";
		ifrm.style.border = 0+"px";
		document.getElementById('tempframe').appendChild(ifrm);
  	}

	/*if (document.getElementById("tempframe") != null)
		{
		ifrm = document.createElement("iframe");
		ifrm.setAttribute("src", "http://www.sedmicka.cz/brno-vyskov/tabla/?id=244&page=2&do=vote");
		ifrm.style.width = 2+"px";
		ifrm.style.height = 2+"px";
		ifrm.style.border = 0+"px";
		document.getElementById('tempframe').appendChild(ifrm);
  	}*/
	}


if(window.addEventListener)
	window.addEventListener('load', tempframe, false);
else if(window.attachEvent)
	window.attachEvent('onload', tempframe);
