// **********************************
// **                              **
// **   JS FUNCTIONS for xom-tom   **
// **  (handles hidden menus etc.) **
// **   (c) Tomas Hnatovsky 2006   **
// **                              **
// **********************************
// **                              **
// **   Please respect this code   **
// **  authorship. It took a long  **
// **        time to write.        **
// **                              **
// **********************************

// ** Handles image info **
// ************************
function find(n, d) {
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=find(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); kam = document.getElementById("mid"); x.style.left=kam.offsetLeft+"px"; result0=navigator.userAgent.search(/Opera/); result1=navigator.userAgent.search(/Konqueror/); var v = 0; if(result0 != -1) {v = 20;} if(result1 != -1) {v = 20;} x.style.top=kam.offsetTop+kam.offsetHeight+v+"px"; x.style.width=kam.offsetWidth-10+"px"; return x;
}

// Shows image info
function show() {
	var i,p,v,obj,args=show.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=find(args[i]))!=null) { v=args[i+2];
		if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
		obj.visibility=v;
		obj.display="inline"; }
}

// ** Initialization of image **
// *****************************
function initImage() {
	imageId = 'photo';
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	image.style.visibility = "visible";
	fadeIn(imageId,0);
}

// ** Handles fading in **
// ***********************
function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 50);
		}
	}
}

// ** Handles opacity **
// *********************
function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/101;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

// ** Hides&shows comment form **
// ******************************
function odhal() {
	var spodek = document.getElementById('formDole');
	if (spodek.style.visibility == "visible") {
		spodek.style.visibility="hidden";
		spodek.style.display="none";
	}
	else {
		spodek.style.visibility="visible";
		spodek.style.display="inline";
	}
}

// ** Onload initialisation **
// ***************************
document.write("<style type='text/css'>#photo {visibility:hidden;} #formDole {visibility: hidden; display: none; text-align: center;}</style>");
window.onload = function() {initImage()}
//h=kam.offsetLeft+kam.offsetWidth-213; v=kam.offsetTop; result0=navigator.userAgent.search(/Opera/); result1=navigator.userAgent.search(/Konqueror/); v=v+10; if(result0 != -1) {v = v+20;} if(result1 != -1) {v = v+20;} he=kam.offsetHeight-23; x.style.height=he+"px"; x.style.left=h+"px"; x.style.top=v+"px";

//  ** Adding code into text **
//  ***************************
// © JR & jarcec 2005
function tagy(prvni,druhy){
	var textarea = document.getElementById("dolef");

	if (textarea.setSelectionRange) {
	var zacatek = textarea.selectionStart;
	var konec = textarea.selectionEnd;

	textarea.value = textarea.value.substring(0, zacatek) + prvni + textarea.value.substring(zacatek, konec) + druhy + textarea.value.substring(konec);
	setCaretToPos(textarea, zacatek + prvni.length + druhy.length + (konec-zacatek));
	}

	else if (document.selection) {
	textarea.focus();

	document.selection.createRange().text = prvni + document.selection.createRange().text + druhy;
	}
}

// ** Adding link to comment **
// ****************************
function kom (cislo) {
	pole = document.getElementById("dolef");
	pole.value=pole.value+cislo;
    return false;
}
