var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
				parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
var isMinIE4 = (document.all) ? 1 : 0;

function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; 
	if(d.images){ 
  		if(!d.MM_p) d.MM_p=new Array();
    	var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++)
    		if (a[i].indexOf("#")!=0){ 
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
				}
		}
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
   	if ((x=MM_findObj(a[i]))!=null){
		document.MM_sr[j++]=x; 
		if(!x.oSrc) x.oSrc=x.src; 
		x.src=a[i+2];
		}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_findObj(n, d) { //v4.0
  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=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
/*
function init() {
  var img;
  var x, y;
  img = getImage("placeholder");
  x = getImagePageLeft(img);
  y = getImagePageTop(img);
  myScroller1.create();
  myScroller1.hide();
  myScroller1.moveTo(x, y);
  myScroller1.setzIndex(30);
  myScroller1.show();
}
*/
function changetop(i) {
	l1=document.getElementById("Layer"+i)
	if (isMinNS4) {
		l1.style.top = window.pageYOffset+5;
		l1.style.left = window.innerWidth/2-185;
//		alert(window.innerWidth/2-240);
	}
	else if (isMinIE4) {
		l1.style.top =  document.body.scrollTop+5;
		l1.style.left = document.body.scrollWidth/2-185;
//		alert(document.body.scrollWidth);
//		alert (document.body.scrollTop);
	}
	else
		l1.style.top = window.pageYOffset+5;
}

function CurrencyPopup1(QueryString,w,h) {
	if (document.all) {
		if (window.CurrencyWindow1) {
			window.CurrencyWindow1.close();
		}
	}
	CurrencyWindow1 = window.open ('', 'CurrencyWindow1', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width='+w+',height='+h)
	CurrencyWindow1.focus()
	CurrencyWindow1.location.href = 'pic.php?'+QueryString
}

function stopBubble(e)
{
	if (e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;
}
function stopDefault(e)
{
	if (e.preventDefault) e.preventDefault();
	else e.returnValue = false;
}
/* opens window and cancels the event if successfull */
function openAWin(path,width,height,ev,namewin) 
{
	if (!ev) ev = window.event;
	if (!ev) { alert("No event in openAWin"); return false; }
	if (!openWin(path,width,height,namewin)) return null;
	stopDefault(ev); stopBubble(ev);
	return false;
}

function openWin(path,width,height,namewin)
{
	if(window.anewWin)
		window.anewWin.close();
	if(!namewin) namewin = 'nove_okno';
    if(!width || !height) anewWin = window.open(path,namewin,'menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
	else anewWin = window.open(path,namewin,"width="+width+",height="+height+",toolbar=0,directories=0,menubar=0,status=0,scrollbars=yes,resizable=yes");
	return anewWin;
}


/* -- bubliny -- */
function getID(id,doc)
{
  if (!doc) doc = document;
  if (document.all) return doc.all[id];
  else return doc.getElementById(id);
}

function getPosition(e) {
  e = e || window.event;
  var cursor = {x:0, y:0};
  if (e.pageX || e.pageY) {
	cursor.x = e.pageX;
	cursor.y = e.pageY;
  } 
  else {
	var de = document.documentElement;
	var b = document.body;
	cursor.x = e.clientX + 
	  (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
	cursor.y = e.clientY + 
	  (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
  }
  return cursor;
}

function move_position(evnt) {
  var bubl = getID('bubl');
  cursor = getPosition(evnt);
  cursor.x = cursor.x+5;
  cursor.y = cursor.y-25;
  
  bubl.style.left = cursor.x +'px';
  bubl.style.top = cursor.y + 'px';
  return true;
}

function visible_div(evnt,textik,move) {
	var bubl = getID('bubl');
	var p = "";
//	bubl.style.visibility="visible";
	bubl.style.display="block";
	if(!move) move_position(evnt);
	if(textik) bubl.innerHTML = textik;
}
function hidden_div() {
	var bubl = getID("bubl");
//	bubl.style.visibility="hidden";
	bubl.style.display="none";
}

/* -- /bubliny -- */

/* -- catcha functions --*/

function checkcaptchafill_simple(text_alert)
{
	var c_id = getID("c");
	var ct_id = getID("ct");
//	alert (MD5(ct_id.value));

	if(!trim(ct_id.value) || MD5(trim(ct_id.value)) != c_id.value) {
		return text_alert + "\n";
	}
	return "";
}


function checkcaptchafill(c, ct, alert_text, date_check, check_fields)
{
	var c_id = getID(c);
	var ct_id = getID(ct);
	var text_alert = "";
//	alert (MD5(ct_id.value));
	if(date_check == "date_from_to" ) 
		text_alert = testDate('date_from', 'date_to');

	if(!trim(ct_id.value) || MD5(trim(ct_id.value)) != c_id.value) {
		text_alert = text_alert + alert_text;
	}
	if(text_alert) {
		alert(text_alert);
		return false;
	}
	return true;
}

function trim(s)
{
  return rtrim(ltrim(s));
}

function ltrim(s)
{
  var l=0;
  while(l < s.length && s[l] == ' ')
  {	l++; }
  return s.substring(l, s.length);
}

function rtrim(s)
{
  var r=s.length -1;
  while(r > 0 && s[r] == ' ')
  {	r-=1;	}
  return s.substring(0, r+1);
}
/* -- /catcha functions --*/

// kontrola formulare
function checkform(captcha_alert, text_alert_pole, text_alert_povinne, frm) {
	var str_alert = "";
	var frstpovinne = false;
	// nejsou-li povinne argumenty preskoci se - neni co kontrolovat...
	for (i=4; i < arguments.length; i++) {
		// rozdelim na - vcetne prazdnych znaku
		var re1=/\s*-\s*/;
//		var re1="-";
		var args = arguments[i].split(re1);
		if(frm[args[0]]) {
			// kontrola opakovaneho zadani pole a pole_verify
			if(frm[args[0]+"_verify"] && trim(frm[args[0]].value) != trim(frm[args[0]+"_verify"].value))
				str_alert += args[2] + "\n";
			if(frm[args[0]].value == '') {
				if(!frstpovinne)
					frstpovinne = args[0];
				str_alert += text_alert_pole + " '"+ args[1] + "' " + text_alert_povinne + "\n";
			}
		}
	}
	// je-li definovana captcha
	if(frm["c"] && captcha_alert)
		str_alert += checkcaptchafill_simple(captcha_alert);
	// vystup alert
	if(str_alert) {
		if(frm && frm[frstpovinne])
			frm[frstpovinne].focus();
		alert(str_alert);
		return false;
	}
}
