
// JAVASCRIPT JE CASE-SENSITIVE!

 var month = new Array;
 
 var tz = -60;  // Central European Standard (Winter) Time = GMT + 1 hour
 var msie = navigator.userAgent.indexOf("MSIE");
 var frmSize = 21;
 var now = new Date();
 var nowL = new Date();
 var TZL = nowL.getTimezoneOffset(); // = what browser thinks is TZ; but
        // MS IE version 3 gives wrong sign of TZ
    // MSIE 4.0b2 shifts TZ by -1 hour

 // This piece of js code should give the Central European time anywhere on Earth
 // To adapt to another time zone adjust the value of variable tz,
 //   and modify the daylight/standard time switching if necessary

 if(msie > -1) {
    if(navigator.userAgent.substring(msie+5,msie+6) <= 3) TZL *= -1;
    else if(navigator.userAgent.indexOf("4.0b2") > -1) TZL += 60;
 }
 now.setTime(nowL.getTime() + (TZL - tz) * 60000);
        // Summer/Winter Time switching: last Sunday of March at 2am WT
        //                  last Sunday of October at 3 am ST (2 am WT)
 var H = now.getHours() + now.getMinutes()/60 + now.getSeconds()/3600;
 var M = now.getMonth();
 var d = now.getDate();
 var D = now.getDay();
 if((M>2 ||
     (M==2 && (D==0 && d>24 && H>2 || D==1 && d>25 || D==2 && d>26 ||
               D==3 && d>27 || D==4 && d>28 || D==5 && d>29 || D==6 && d==31)
     )) &&
    (M<9 ||
     (M==9 && (d<25 || D==0 && d>24 && H<2 || D==1 && d<26 || D==2 && d<27 ||
               D==3 && d<28 || D==4 && d<29 || D==5 && d<30 || D==6 && d<31)
     ))) tz = tz - 60;  // Daytime Saving Time - Letní čas
 var offset = (TZL - tz) * 60000;   

var ti, tiOld, delay = 950;

var lpjsBgMidi;
var lpjsLoaded = false;
var lpjsWriteEnabled = true;
var lpjsHostDir='a';

var himd = "";
var hims = new Array();

function himdir (dir)
{
		if (document.images) himd = dir+'/';
}

function him (name, ext)
{
	if (document.images)
	{
		hims[name] = new Image ();
		hims[name].src = himd+name+'.'+ext;
		hims[name+'_hover'] = new Image ();
		hims[name+'_hover'].src = himd+name+'_hover.'+ext;
	}
}

function himf (imagename,objectsrc)
{
	if (document.images) document.images[imagename].src = hims[objectsrc].src;
}

function lpjsForm (f, e)
{
	var form = document.getElementById (f);
	
	if (!form) return form;
	
//	if (form[0].elements) window.alert ("Invalid form "+f);
	
	if (e) return form[e];	
	else return form;
}

function lpjsDoubleClickup ()
{
	window.scrollTo (0,0);
}

function lpjsAddBookmark (url, title, errorstr)
{
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else // if(window.opera && window.print) 
		{ // Opera Hotlist
		window.alert (errorstr); }
 }

function lpjsOpenEmailWindow (address)
{
	var mywin = window.open (address, 'email','width=600,height=400,scrollbars=yes,resizable=yes,menubar=0');
	if (mywin) mywin.focus (); 
}

function lpjsMMMSingle (url)
{
	var iMyWidth;
	var iMyHeight;
	var width=600;
	var height=400;
	
	if (url.href) url = url.href;
	//gets top and left positions based on user's resolution so hint window is centered.
	iMyWidth = (window.screen.width/2) - (width/2 + 10); //half the screen width minus half the new window width (plus 5 pixel borders).
	iMyHeight = (window.screen.height/2) - (height/2 + 50); //half the screen height minus half the new window height (plus title and status bars).
	iMyWidth = window.screen.width - width - 50;
	iMyHeight = window.screen.height - height - 77;
	var winPopup = window.open(url,'poselstvi',"width="+width+",height="+height+",scrollbars=yes,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight); // menubar=yes,toolbar=no,
	if (winPopup) winPopup.focus();		
}

// http://www.jakpsatweb.cz/javascript/window.open.html

function lpjsPopup (myurl, width, height)
{
	if (width == 0)
	{
		width = window.screen.width - 50;
		if (width > 790)
			width = 790; 
	}
	if (height == 0)
	{
		height = window.screen.height - 200;
	}
	var left = (window.screen.width/2) - (width/2 + 10); //half the screen width minus half the new window width (plus 5 pixel borders).
	var top = (window.screen.height/2) - (height/2 + 100);

	var popupWin = window.open (myurl,'popupwin',"width="+width+",height="+height+",scrollbars=yes,resizable=yes,location=yes,directories=no,status=yes,copyhistory=no,menubar=1,toolbar=1,top="+top+",left="+left);
	if (popupWin) popupWin.focus();
}


function lpjsSetFindDate ()
{
	var f = lpjsForm ('f-find');
	if (f)
	{
		var state = !f.checkDate.checked;
	
		f.fromDay.disabled = state;
		f.fromMonth.disabled = state;
		f.fromYear.disabled = state;
		f.toDay.disabled = state;
		f.toMonth.disabled = state;
		f.toYear.disabled = state;
	}
}

function _lpjsInitFindDate ()
{
	if (lpjsForm ('f-find', 'fromDay')) lpjsSetFindDate ();
}


function lpjsSetHomePage (page, url, errstr)
{
	if (document.all && !window.opera)
	{
		page.style.behavior='url(#default#homepage)';
		page.setHomePage(url);
	}
	else window.alert (errstr);
}

function lpjsClickReturn ()
{
	var bAgent = window.navigator.userAgent; 
	var bAppName = window.navigator.appName;
	if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0) && (bAgent.indexOf("Mac") >= 0))
		return true; // dont follow link
	else return false; // dont follow link
}


function lpjsInitText ()
{

}


function _lpjsMPrint ()
{
	window.print ();
}


function lpjsInitPrintOnDemand ()
{

}

function lpjsInitPrintStart ()
{
	_lpjsMPrint ();	
}

function lpjsInitIm ()
{
//	document.ondblclick=window.print;
}

function lpjsInitIndex ()
{
	
}

function lpjsInitEmail ()
{
	
}

function lpjsInitPda ()
{
	lpjsInitPrint ();	
}


function lpjsItemFocus (id)
{
	var e = document.getElementById (id);
	if (e) e.focus ();
	return e;
}

function lpjsItemSelect (id)
{
	var e = document.getElementById (id);
	if (e)
	{
		e.focus ();
		e.select ();
	}
	return e;
}



function lpjsItemClear (id)
{
	var e = document.getElementById (id);
	if (e)
	{
		e.focus (); 
		e.select ();
		e.value = '';
	}
	return e;
}


function lpjsItemClean (id)
{
	var e = document.getElementById (id); 
	if (e)
	{
		e.value = '';
	}
	return e;	
}


function lpjsItemSet (id, val)
{
	var e = document.getElementById (id);
	if (e)
	{
		e.value = val;
	}
	return e;	
}


function lpjsItemIns (id, s)
{
	var e = document.getElementById (id); 
	if (e)
	{
		e.focus ();
		e.value += s;
	}
	return e;
}

function lpjsHideLayer (number, number2)
{
    e = lpjsItemSet ("code", number + number2);
	e.parentNode.style.position = "absolute";
	e.parentNode.style.left = "-9999px";
	e.tabIndex = "-1";
}


var _lpjsArselEnabledDisabled = false;
var _lpjsNumChecked = 0;
var _lpjsNumTotal = 0;


function _lpjsArSelEnableDisableButton (f,e,c)
{
	var element = lpjsForm (f, e);
	if (element) element.disabled = c;
}


function _lpjsEnableDisableArSel (f, c)
{
	if (_lpjsArselEnabledDisabled != c)
	{
		_lpjsArSelEnableDisableButton (f, 'arSelPrint', c);
		_lpjsArSelEnableDisableButton (f, 'arSelDisplay', c);
		_lpjsArselEnabledDisabled = c;
	}
}


function _lpjsArSelSetup (f, total, count)
{
	_lpjsNumChecked = count; 
	// window.status = _lpjsNumChecked;
	_lpjsEnableDisableArSel (f, !count);
}

function lpjsArSelSetup (f, e, total)
{
	var form = lpjsForm (f);
		_lpjsNumChecked = 0;
	_lpjsNumTotal = total;	
	for (i = 0; i < total; i++)
	{
		if (form[e+'['+i+']'].checked)
			_lpjsNumChecked++;
	}
	// window.status = _lpjsNumChecked;
	_lpjsEnableDisableArSel (f, !_lpjsNumChecked);
}

 
function lpjsArSelSetAll (f, e, total)
{
	var form = lpjsForm (f);
	for (i = 0; i < total; i++)
	{
		form[e+'['+i+']'].checked = true;
	}
	_lpjsArSelSetup (f, total, total);
}


function lpjsArSelClearAll (f, e, total)
{
	var form = lpjsForm (f);
	for (i = 0; i < total; i++)
	{
		form[e+'['+i+']'].checked = false;
	}
	_lpjsArSelSetup (f, total, 0);	
}

function lpjsArSelDetCheckbox (f,e)
{
	var element = lpjsForm (f,e);
	if(element.checked)
	{
		_lpjsNumChecked++;
	}
	else
		_lpjsNumChecked--;
	
	// window.status = _lpjsNumChecked;
	
	_lpjsEnableDisableArSel (f, _lpjsNumChecked <= 0);
}


/*
function votecheck()
{
	with (document.voteForm)
	{
		if (votefor.value != "")
		{ 
			window.alert("Please pick a subject.");
			window.alert (votefor.value);			
			return false;
		}
		else
		{
			return true;
		}
	}
}
*/

function lpjsRandomPopup (path, sid)
{
	var element = lpjsForm ('f-rM', 'count');
	if (sid) sid = '&' +sid; else sid = "";
	if (element)
	{
		url = path + 'message?count=' + element.value + sid;
		lpjsMMMSingle (url);
	}
}


function lpjsSubmitDisable (form)
{    
	var e = lpjsForm (form, 'vote');
	if (e)
	{
		e.disabled = true;	
		e.enabled = false;	
	}
	else window.alert (form);
}

function lpjsSubmitEnable (form)
{   
	var e = lpjsForm (form, 'vote');
	if (e)
	{
		e.disabled = false;	
		e.enabled = true;	
	}
	else window.alert (form);
}


function _lpjsIsEmail (s)
{	
	if (s.indexOf("@") < 1 || s.indexOf("@") != s.lastIndexOf("@") || s.lastIndexOf(".") < s.lastIndexOf("@")+2  || s.lastIndexOf(".") > (s.length-3) || s.lastIndexOf(".") < (s.length-5)) return false;
	else return true;
}

function lpjsWriteIE (s, s2)
{
	if (document.all && !window.opera && lpjsWriteEnabled) document.write (s);
	else if (s2) document.write (s2);	
}


function lpjsWriteDivText(id, text)
{
	var e = document.getElementById (id);
	if (e) 
	{
		e.innerHTML = text;
		//e.text = '';
//		window.alert(text);
	}
}


function lpjsWrite (s, id)
{
	if (lpjsWriteEnabled)	
	{
		if (id) lpjsWriteDivText(id, s);
		else document.write (s);
	}
}

var _lpjsValidateBeginStr;
var _lpjsValidateStr="";
var _lpjsValidateForm="";

function lpjsValidateBegin (form, beginstr)
{
	_lpjsValidateForm = form;
	_lpjsValidateBeginStr = beginstr;
	_lpjsValidateStr = "";
}

function lpjsValidateEnd (endstr)
{
	if (_lpjsValidateStr)
	{
		s = _lpjsValidateBeginStr+"\n\n"+_lpjsValidateStr;
		if (endstr && endstr != '') s += "\n\n"+endstr;
		window.alert (s);
		return false;
	}
	return true;
}

function lpjsValidateAppend (text, id)
{
	if (_lpjsValidateStr == "" && id) id.focus ();
	_lpjsValidateStr += "- "+text+"\n";
}

function lpjsValidateField (id, text)
{
	// var val = document.getElementById (id);
	var val = lpjsForm (_lpjsValidateForm, id);
	if (val && lpjsStripTags (val.value) == "") lpjsValidateAppend (text, val);
//	if (val.value != "") window.alert (val.value);
	if (!val) window.alert ("Check id "+id);
}


function lpjsValidateEmail (id, text)
{
	// var val = document.getElementById (id);
	var val = lpjsForm (_lpjsValidateForm, id);
	if (val && !_lpjsIsEmail (val.value)) lpjsValidateAppend (text, val);
}



function _lpjsMyFix (s, first)
{
	var res = "";
	var pc = ' ';
	if (!first) first = 1;
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		var code = c.charCodeAt(0);
//		if (code > 1000) res += code;
//		if (c == '0') window.alert (code); // srdce ¦: 9829, // slunce 0 : 9788
		if (code == 9829) res += "<span id='myHeart'>"+c+"</span>";
		else if (code == 9788) res += "<span id='mySun'>"+c+"</span>";
		else 
		{
			if ((code <= 90 && code >= 65 && pc == '>') || code == 1041 || code == 1052 || code == 1044)
			{
				if (first)
				{
					first++;
					var fixClass = 'myFix';
					if (code > 1000) fixClass = 'myFixSpecial';
					res += "<span class='"+fixClass+"'>"+c+"</span>";
				}
				else
					res += c;
					
				if (c == 'S') first++;
			}
			else 
			{
				res += c;
			}
		}
		pc = c;
	}
	return res;
}

function _lpjsCheckSpace (c)
{
	switch (c)
	{
		case '\t':
		case ' ':
		case '\r':
		case '\n':
			return true;
		default:
			return false;
	}
}

function _lpjsTrim (s)
{
	while (_lpjsCheckSpace (s.charAt(0)))
		s = s.substr(1);
	while (_lpjsCheckSpace (s.charAt(s.length-1)))
		s = s.substr(0,s.length-1);
	return s.toString();
}

function _lpjsOlmFade (elid, colors, fix)
{
	var e = document.getElementById (elid);
	if (e)
	{
		s = _lpjsTrim (e.innerHTML);
		s = gradientstr(s, colors);
		s = _lpjsMyFix (s, fix);
		e.innerHTML = s;
	}
}

 function lpjsSetMonth(i, str)
 {
 	month[i-1] = str;
 }

 function casCE() { 
   nowL = new Date();
   now.setTime(nowL.getTime() + offset);
   var min = now.getMinutes();
   var sec = now.getSeconds();  
   var yer = now.getYear();
   if(yer<2000) yer += 1900;
   mytime = now.getHours() +  ((min < 10) ? ":0" : ":") + min + ((sec < 10) ? ":0" : ":") + sec;
   mydate = now.getDate() + ". " + month[now.getMonth()] + " " + yer;
   ct = document.getElementById ("ClockTime");
   if (ct && ct.innerHTML != mytime) ct.innerHTML = mytime;
   cd = document.getElementById ("ClockDate");
   if (cd && cd.innerHTML != mydate) cd.innerHTML = mydate;
       
    ti = nowL.getTime();
    delay += 1000 - (ti - tiOld);
    tiOld = ti;
    if (ct || cd) Timer = setTimeout("casCE()",delay);
  }


function lpjsInitClock ()
{
   tiOld = nowL.getTime(); setTimeout('casCE()',delay);
}

function lpjsInitOlmIntro ()
{
	_lpjsOlmFade ("olmFader", "E944A7 FFAAAA eeb077 ddbb00");
	_lpjsOlmFade ("olmFader2", "0000ff E944A7 FFAAAA eeb077 ddbb00"); 
	_lpjsOlmFade ("olmFader3", "aaaaaa cccccc");
    lpjsInitClock ();
}

function lpjsInitView ()
{
  lpjsInitToggle();
  
	_lpjsOlmFade ("olmFader", "FF99FF FFDDDD FFffff FFff77 FFee00");
	_lpjsOlmFade ("olmFader2", "9999FF cc99ff FF99FF ffbbff FFDDff FFffff FFee00");
	_lpjsOlmFade ("olmFader3", "dddddd ffffff"); 
	_lpjsInitFindDate ();	
	if (_lpjsNumTotal) lpjsArSelSetup ('f-m', 'arSel', _lpjsNumTotal);	
    lpjsInitClock ();
}


function lpjsInitToggle ()
{
	if (toggleGetById('toggleOpen'))
	{
				toggleGetById('toggleOpen').onclick = function(){
				toggleDiv(toggleGetById('toggleDiv'));
				}
				/*
				toggleGetById('toggleClose').onclick = function(){
				toggleDiv(toggleGetById('toggleDiv'));
				}*/			
				toggleDiv(toggleGetById('toggleDiv'));
	}
}

function lpjsInitPrint ()
{
	lpjsInitView ();
//	document.ondblclick=_lpjsMPrint;
}

function lpjsInitPda ()
{
	lpjsInitToggle();
}

function lpjsLt1OnLoad (run)
{
 	if (document.getElementById('ta'))
	{
		// initEditor ();
	}
	
	lpjsLoaded = true;
	
	OLloaded=1;	
	
	if (typeof start=='function') start();
	
	lpjsItemFocus ('nextImageLink');
}

function lpjsInit (hostDir)
{
	lpjsHostDir = hostDir;	
	// window.alert (lpjsHostDir);
}


function checkKey(e) {
  var code = window.Event ? e.which : event.keyCode;
  var key = String.fromCharCode(code);
  for (var i = 0; i < ar.length; i++) {
    if (key == ar[i].key) location.href = ar[i].url;
  }
}

function htmlescape(str){
    str = str.replace(/&/g, "&amp;" );
    str = str.replace(/</g, "&lt;" );
    str = str.replace(/>/g, "&gt;" );
    return str;
   }


/*
function hotKey(key, url) {
  this.key = key;
  this.url = url;
}

if (window.Event) document.captureEvents(Event.KEYPRESS)
document.onkeypress = checkKey;

var ar = new Array();
ar[ar.length] = new hotKey(10, "http://www.docjs.com/");
ar[ar.length] = new hotKey("m", "http://www.microsoft.com/");
ar[ar.length] = new hotKey("n", "http://www.netscape.com/");
*/


function lpjsFollowLink (a)
{
	if (a.target.length==0) window.location.href=a.href;
}


function lpjsDecodeEmail(mmail)
{
		var str = new String("") + mmail.replace(" zavinac ", "@");
		str = str.replace(/\$/igm, ".");
		return str;
}

function lpjsOpenMailClient(mmail)
{
	var mailto = "mail"+"to"+":";
	if (mmail) document.location = mailto + lpjsDecodeEmail(mmail);
}


function lpjsHighlight(element, color)
{
    element.style.backgroundColor = color;
}

function lpjsSetClassName(element, className)
{
    element.className = className;
}

function lpjsCheckFCKEditorSmileysCount (oEditor, maxCount)
{
	var html=oEditor.FCK.GetHTML();
    var m = html.match(/fckeditor\/editor\/images\/smiley/g); 
    if (m && m.length >= maxCount)
    {
        window.alert("Maximum allowed number of smileys in one post is "+maxCount);
        return false;
    }
    return true;
}

function lpjsStripTags(s)
{
  s=s.replace(/(<br\/?\s*>|<\/p>\s*<p>)/gi,'\n');
  return s.replace(/<\/?[^>]+>/gi,'');
}


function lpjsLinkClick(href)
{
	if (document.images)
	{
		img = new Image (1,1);
		url = lpjsHostDir+'/linkclick?url='+href;
		img.src = url;
//		window.alert (url);
	}
	return true;
}


var lpjsArticleFontSize =
(
	{
		Size:		1,
		CookieName: 	"lpjsFontSize=",
		CookieExpire:	120, //days
		ArticleSpot:	"middleBorder",
		LineHeights:	[145, 145, 145],
		Dir: "",
		SetSize:
			
			function(	FontSize)
			{                
				if(!document.getElementById(this.ArticleSpot + "-" + this.Size))
				{
					return;
				}

				if(!FontSize)
				{
					var FontSize = this.GetSize();
					if(FontSize==null)
					{
						FontSize = this.Size;
					}
					else
					{
						this.Size = FontSize;
					}
				}
				else
				{
					document.getElementById(this.ArticleSpot + "-" + this.Size).src = this.Dir+"/icon-size-" + this.Size + ".gif";
					this.Size = FontSize;
				}
				var date = new Date();
				date.setTime(date.getTime()+(this.CookieExpire*24*60*60*1000));
				var expires = "; expires=" + date.toGMTString();
				document.cookie = this.CookieName + FontSize + expires + "; path=/";

				var ArticlePlace = document.getElementById(this.ArticleSpot /*+ "-area"*/);
				if(ArticlePlace)
				{
					ArticlePlace.style.fontSize = ((FontSize-1)*15 + 100) + "%";
					// ArticlePlace.style.lineHeight = this.LineHeights[FontSize-1] + "%";
					document.getElementById(this.ArticleSpot + "-" + FontSize).src = this.Dir+"/icon-size-" + FontSize + "-active.gif";
					
					var ArticlePlaceSec = document.getElementById(this.ArticleSpot+"Sec");
					if(ArticlePlaceSec)	ArticlePlaceSec.style.fontSize = ((FontSize-1)*15 + 100) + "%";			
					
				var ArticlePlaceRest = document.getElementById(this.ArticleSpot+"Rest");
					if(ArticlePlaceRest)	ArticlePlaceRest.style.fontSize = ((FontSize-1)*15 + 100) + "%";								
				}
			},

		GetSize:
			function()
			{
				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(this.CookieName) == 0) return c.substring(this.CookieName.length,c.length);
				}
				return null;
			},

		ClearSize:
			function()
			{
				document.cookie = this.CookieName + "-1" + "; path=/";
			},


		Init:
			function(dir, cookieName, cookieExpire, articleSpot, size)
			{
				this.Dir = lpjsHostDir+dir;
//				window.alert(this.Dir);
				if (cookieName) 
				{
//					if (cookieName != this.CookieName) ClearSize ();
					this.CookieName = cookieName+'=';
				}
				if (cookieExpire) this.CookieExpire = cookieExpire;
				if (articleSpot) this.ArticleSpot = articleSpot;
				if (size) this.Size = size;
				this.SetSize ();
			}
	}
)
function toggleGetById(id)
{ 
	return document.getElementById(id);
}

function toggleDiv(element)
{ 
	var style = element.style.display;
	var newstyle = (style==='block' || style==='') ? 'none' : 'block'; 
	element.style.display = newstyle;
//	element.style.display = 'block'; 
	//toggleGetById('toggleDiv').style.display = 'block'; 

}

