// JavaScript Document



var browser = 'unknown';

if (navigator.userAgent.indexOf('SeaMonkey') > -1 || navigator.userAgent.indexOf('Firefox') > -1)	browser = 'gecko';
else if (navigator.userAgent.indexOf('Safari') > -1 || navigator.userAgent.indexOf('Chrome') > -1 ) browser = 'safari';
else if (navigator.userAgent.indexOf('MSIE') > -1)	browser = 'explorer';
else if (navigator.userAgent.indexOf('Opera') > -1)	browser = 'opera';

//alert(browser);



























/*
//////////////////////////////////////////////////
old




*/







////// kontext menu2
var IE = document.all ? true:false;
var Opera = navigator.userAgent.indexOf("Opera") > -1 ? true : false; 
if (Opera) IE = false; 


function mv(id)
{
	var el=document.getElementById(id);
	el.style.display="block";
}

function mi(id)
{
	var el=document.getElementById(id);
	el.style.display="none";
}

function ti(id)
{
	var a=getCookie("multimenu");
	var el=document.getElementById(id);
	var st=el.style.display;
	var i=id.substr(3);
	if (a){}
	else { a="000000000000000000000000000000"; }
	if (st=="none")
	{
		a= a.substring(0,i-1)+"1"+a.substr(i);
		el.style.display="block";
	}
	else
	{		
		a= a.substring(0,i-1)+"0"+a.substr(i);
		el.style.display="none";
	}	
	setCookie("multimenu",a);
}

function showlogin()
{
	document.getElementById('log2').style.display="none";
	document.getElementById('log1').style.display="block";
	return false;
}




window.onload = function() 
{
	
	
	//alert(document.referrer);
	
	
	
	var options = {exact:"exact",style_name_suffix:true, highlight:'.itemcontainer' };
  	
	jQuery(function(){
    jQuery(document).SearchHighlight(options);
	});
	
	
	
	
	
	
	
	
	
	
	
	
	return;
	for (var i = 0; i < document.getElementsByTagName('input').length; i++) 
	{
		var el=document.getElementsByTagName('input')[i];
		
		if (el.type=="button" || el.type=="reset")
		{
			el.style.color = "white";
			el.onmouseover = function() { this.style.color="black"; this.style.backgroundColor="white"; }
			el.onmouseout = function() { this.style.color="white"; this.style.backgroundColor="black"; }
			
		}
		else if (el.type=="submit")
		{
			el.style.color = "white";
			el.focus = function () { return false; }
			el.onmouseover = function() { this.style.color="black"; this.style.backgroundColor="white"; }
			el.onmouseout = function() { this.style.color="white"; this.style.backgroundColor="black"; }
		}
		else if (el.type=="text")
		{
			el.setAttribute("autocomplete", "off"); 
			//el.onfocus = function() { this.style.border="1px solid #09f"; }
			//el.onblur = function() { this.style.border="1px solid white"; }
		}
		//else if (el.type=="checkbox")
	}
	for (var i = 0; i < document.getElementsByTagName('textarea').length; i++)
	{
		var el=document.getElementsByTagName('textarea')[i];
		el.onfocus = function() { this.style.border="1px solid #09f"; }
		el.onblur = function() { this.style.border="1px solid white"; }
	}
	
	
}

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

function trim( value ) {
	return LTrim(RTrim(value));
}

function getRadioValue(O)
{
	for (var i=0; i<O.length; i++)
	{
    	if (O[i].checked) return O[i].value;
    }
    return -1;
}



var whTimer;
var xmlHttp;
var witems=0;
var witem=-1;

function ajaxInit() 
{
	try 
	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		try 
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) 
		{
			try 
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{
				//alert("tvuj browser stoji za...!");
			}
			return false;
		}
	}
}


function whisper(event)
{
	
	if (event.keyCode == 27)
	{
		document.getElementById('whisper').style.visibility = 'hidden';
		return true;
	}
	else if (event.keyCode == 40)	// dolu
	{
		if (witems)
		{
			if (witem==-1)
			{
				document.getElementById('wh0').className = 'h';
				witem = 0;
			}
			else if (witem<witems-1)
			{
				document.getElementById('wh'+witem).className = '';
				document.getElementById('wh'+(witem+1)).className = 'h';
				witem++;
			}
			else
			{
				document.getElementById('wh'+witem).className = '';
				document.getElementById('wh0').className = 'h';
				witem=0;
			}
		}
		return true;
	}
	else if (event.keyCode == 38)	// nahoru
	{
		if (witems)
		{
			if (witem==-1)
			{
				document.getElementById('wh0').className = 'h';
				witem = witems-1;
			}
			else if (witem>0)
			{
				document.getElementById('wh'+witem).className = '';
				document.getElementById('wh'+(witem-1)).className = 'h';
				witem--;
			}
			else
			{
				document.getElementById('wh'+(witems-1)).className = 'h';
				document.getElementById('wh0').className = '';
				witem=witems-1;
			}
		}
		return true;
	}
	else
	{
		clearTimeout(whTimer);
		whTimer = null;
		whTimer = setTimeout ("whisper_update();", 250);
		return true;
	}
}

function whisper_check()
{
	if (witems && witem!=-1) 
	{
		document.getElementById("searchtext").value = document.getElementById("wh"+witem).innerHTML;
	}
	return true;
}

function whisper_update()
{
	ajaxInit();
	clearTimeout(whTimer);
	whTimer = null;
	
	document.getElementById('whisper').style.visibility = 'visible';

	url = ajaxurl+'?w=1&q='+ document.getElementById('searchtext').value+'&b=a';

	xmlHttp.onreadystatechange=function () { whisper_show(xmlHttp) } ;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 	
	xmlHttp.send(null);
}

function whisper_show(http) 
{ 
	if (http.readyState==4) 
	{ 
		//alert(http.responseText);
		a = http.responseText.split('@@');
		c = '';
		witems = a.length-1;
		witem = -1;
		for (b=0;b<a.length-1;b++)
		{
			c = c + '<div id="wh'+b+'" onClick="document.getElementById(\'searchtext\').value=&quot;'+a[b]+
					'&quot;;document.getElementById(\'fs\').submit();">'+a[b] + '</div>';
		}
		
		document.getElementById('whisper').innerHTML=c;
		http.onreadystatechange = function (){};
	} 
}






// atlan's smart preview (c) 2007 Atlan, Arkon software ltd., All rights reserved
function aspInit()
{
	return;	// disabled until I have a time to repair it... sorry

	if (!document.getElementById('itemtext')) return;
	aspInitLoop(document.getElementById('itemtext'));
	aspInitLoop(document.getElementById('itempost'));
	aspInitLoop(document.getElementById('itemlink'));
	
	
}

function aspInitLoop(obj)
{
	if (!obj) return;
	for (var i=0; i<obj.getElementsByTagName('a').length; i++)
	{
		var el=obj.getElementsByTagName('a')[i];
		
		if (el.className=="lh" || el.className=="edit")
		{
			
		}
		else
		{
			el.onmouseover = aspOn;
			el.onmouseout  = aspOut;
		}
	}
}

function aspOn()
{
	var f = (this.offsetTop + document.getElementById('header').offsetHeight - 126);
	
	if (IE) f-=85;
	
	document.getElementById('preview').style.top = f + "px";

	var l = document.getElementById('widemain').offsetWidth-document.getElementById('maincol').offsetWidth + this.offsetLeft;
	
	if (IE) l-=183;
	
	if ((l+300) > document.getElementById('widemain').offsetWidth)
	{
		l = document.getElementById('widemain').offsetWidth - 320;
	}
	
	document.getElementById('preview').style.left = l + "px";
	
	aspRequest(this.href);
}

function aspOut()
{
	document.getElementById('preview').innerHTML = 'off';
	document.getElementById('preview').style.visibility = 'hidden';
}

function aspRequest(aa)
{
	ajaxInit();
	
	document.getElementById('preview').innerHTML = '<i>nahrávám náhled...</i>';

	url = ajaxurl+'?w=prww&q='+encodeURI(aa)+'&b=a&c=g';

	xmlHttp.onreadystatechange=function () { aspShow(xmlHttp); } ;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 	
	xmlHttp.send(null);
}

function aspShow(http)
{
	if (http.readyState==4) 
	{
		if (http.responseText == 'n/a')
		{
			document.getElementById('preview').innerHTML = 'náhled není k dispozici';
			http.onreadystatechange = function (){};
		}
		else
		{
			document.getElementById('preview').innerHTML = http.responseText;
			http.onreadystatechange = function (){};
			document.getElementById('preview').style.visibility = 'visible';
		}
	}

}

function gdi(id)
{
	return document.getElementById(id);
}

function gst(id)
{
	return document.getElementById(id).options[document.getElementById(id).options.selectedIndex].text;
}

function ToggleContent()
{
	obj =  document.getElementById('toctoggle');
	if (!obj) return false;
	var a = 0;
	
	if (obj.innerHTML == '(skrýt)')
	{
		obj.innerHTML = '(zobrazit)';
		document.getElementById('toccont').style.display = 'none';
		a = 0;
	}
	else
	{
		obj.innerHTML = '(skrýt)';
		document.getElementById('toccont').style.display = 'block';
		a = 1;
	}
	
	setCookie('content',a);
	
}
function PrnSendAns(id)
{
	url = ajaxurl+'?w=prnans&q='+encodeURI(gdi('poradna_txt'+id).value)+'&b=cce&n='+id+'&c=3g';

	if (!trim(gdi('poradna_txt'+id).value))	{alert('Nebyla zadána odpověď!'); return; }
	
	gdi('poradna_odp'+id).innerHTML = '<div class="loading"><img src="/pics/layout/ajax-loader.gif" style="width:16px; height:16px;" alt="Loading..." /> &nbsp; Zpracovávám odpověď...</div>';
	gdi('poradna_usr'+id).innerHTML = 'ukládám...';
	gdi('poradna_usr'+id).onclick = function() {};
	
	ajaxInit();
	

	xmlHttp.onreadystatechange=function () { PrnApplyAns(xmlHttp,id); } ;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 	
	xmlHttp.send(null);
	
	
	
}

function PrnApplyAns(xmlHttp,id)
{
	if (xmlHttp.readyState==4) 
	{
		a = xmlHttp.responseText.split('@@++@@');
		
		if (a[1]=='')
		{
			alert(a[0]);
			PrnAnsTxt(id);
		}
		else
		{
			gdi('poradna_odp'+id).innerHTML = a[0];
			gdi('poradna_usr'+id).innerHTML = 'Odpověděl: '+a[1];
			gdi('poradna_usr'+id).onmouseover = function() { };
			gdi('poradna_usr'+id).onmouseout = function() { };
		}
		
		xmlHttp.onreadystatechange = function (){};
		
	}

}

function PrnAnsTxt(id)
{
	
	document.getElementById('poradna_odp'+id).innerHTML = "<textarea style=\"width:100%;\" id='poradna_txt"+id+"'></textarea>";

	var el = document.getElementById('poradna_txt'+id);
	el.onfocus = function() { this.style.border="1px solid #09f"; }
	el.onblur = function() { this.style.border="1px solid white"; }

	var el2 = document.getElementById('poradna_usr'+id);
	
	el2.innerHTML = "Odeslat odpověď";
	el2.onclick = function() { PrnSendAns(id); };
}

function PrnTry()
{
	if (!trim(gdi('aname').value))	{ alert('Tazateli, musíš vyplnit své jméno!'); return; }
	if (!trim(gdi('subject').value))	{ alert('Tazateli, musíš předmět dotazu!'); return; }
	if (!trim(gdi('question').value))	{ alert('Tazateli, musíš napsat dotaz!'); return; }

	gdi('porsen').innerHTML = '<img src="/pics/layout/ajax-loader.gif" style="width:16px; height:16px;" alt="Loading..." /> &nbsp; Odesílám dotaz, prosím čekej...';

	var id = 101;
	url = ajaxurl+'?w=prntryq&q=ques&b=byn&n='+id+'&c=3f';

	ajaxInit();
	
	xmlHttp.onreadystatechange=function () { PrnTryApply(xmlHttp); } ;	
	
	parameters = 'aname=' + encodeURI(gdi('aname').value.replace(/&/g,'!!amp;!!'));
	parameters += '&subject=' + encodeURI(gdi('subject').value.replace(/&/g,'!!amp;!!'));
	parameters += '&question=' + encodeURI(gdi('question').value.replace(/&/g,'!!amp;!!'));
	
	xmlHttp.open('POST', url, true); 
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	xmlHttp.setRequestHeader("Content-length", parameters.length); 
	xmlHttp.setRequestHeader("Connection", "close"); 
	xmlHttp.send(parameters); 	
	
}


function PrnTryApply(xmlHttp)
{
	if (xmlHttp.readyState==4) 
	{
		a = xmlHttp.responseText;
		
		if (a=='error')
		{
			alert('Při odesílání dotazu došlo k neočekávané chybě. Zkus to později.');
		}
		else
		{
			gdi('subject').value = '';
			gdi('question').value = '';
			gdi('porsen').innerHTML = "<input type='button' value='Odeslat dotaz do poradny' id='tsnit' style=\"width:490px; text-align:center;\" onclick='PrnTry();' />";
			
			gdi('poradna').innerHTML = a + gdi('poradna').innerHTML;
			
			gdi('tsnit').onmouseover = function() { this.style.color="black"; this.style.backgroundColor="white"; }
			gdi('tsnit').onmouseout = function() { this.style.color="white"; this.style.backgroundColor="black"; }
			
		}
		
		xmlHttp.onreadystatechange = function (){};
		
	}

}



function SettingsSave(el)
{
	var value = '';
	
	if 		(el.type=='checkbox')	value = el.checked;
	else if (el.type=='select-one')	value = $.base64Encode(el.value);
	else if (el.type=='text')		value = $.base64Encode(el.value);
	else if (el.type=='textarea')	value = $.base64Encode(el.value);
	else if (el.type=='select-multiple') value = $.base64Encode( getSelected(el).join(',') );
	else	return;
	
	
	
	$.ajax( {
		method: "get",
		url:	"/ajax.php",
		data: 	"w=stx&id="+el.id+"&value="+value,

		complete: function (XMLHttpRequest, textStatus) {
			var data = toJSON(XMLHttpRequest.responseText);
			
			if (data.action == 'reload')
			{
				 window.location.reload(); return;
			}
			else alert(XMLHttpRequest.responseText);
		}
	});
}






























