var regemail = /^[+]*[_a-z0-9-]+(\.[_a-z0-9-]+)*@([0-9a-z][0-9a-z-]*\.)+[a-z]{2,3}$/i;

/* nastavovani cookies */

function setPermCookie(co)
{
  var expdate = new Date ();
  expdate.setTime (expdate.getTime() + (1000 * 60));  // uchovej 1 minutu
  var stav = getPermCookie();
  if ( ! stav ) stav = "";
  if ( stav.indexOf(co) == -1 ) {
//    alert ("Nyni v cookie " + prefixObr + ": " + stav + "     Pridavam: " + co);
    document.cookie = prefixObr + "=" + stav + co + "," +"; expires=" + expdate.toGMTString() +  "; path=/";
  }
}

function delPermCookie(co)
{
  var expdate = new Date ();
  expdate.setTime (expdate.getTime() + (1000 * 300));  // uchovej 5 minut
  var stav = getPermCookie();
  if ( ! stav ) stav = "";
  if ( stav.indexOf(co) > -1 ) {
    var osekany = stav.split(co + ",");
    var novy = osekany.join("");
//    alert ("Rusim " + co + ", nova osekana cookie " + prefixObr + ": " + novy);
    document.cookie = prefixObr + "=" + novy + "; expires=" + expdate.toGMTString() +  "; path=/";
  }
}

function getPermCookie()
{
    var arg = prefixObr + '=';
    var alen = arg.length;
    
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return getPermCookieVal (j);    
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;   
    }
return null;
}

function getPermCookieVal(offset)
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
/* nastavovani cookies */

function Is() {
  var agt=navigator.userAgent.toLowerCase();
  this.ie=((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1))?1:0;
  this.dom=document.getElementById?1:0;
  this.ie4=(document.all && !this.dom)?1:0; 
  this.ns4=(document.layers && !this.dom)?1:0; 
  this.bw=(this.dom || this.ie4 || this.ns4);
  return this;
}
function makeObject(id,visibility) {
  this.el=is.dom?document.getElementById(id):is.ie4?document.all[id]:is.ns4?document.layers[id]:0;
  this.css=is.ns4?this.el:this.el.style;
  this.y=is.ie?this.css.pixelTop:this.css.top;
  this.h=is.ns4?this.el.clip.height:this.el.offsetHeight;
  this.css.visibility=visibility!='visible'?'hidden':visibility;
  return this;
}
function isVisible(v) {
  return v.substr(0,3)!="hid";
}
function menuMove() {
  var pos=parseInt(menu[0].y,10);
  for(i=0;i<menu.length;i++) {
    if(is.ie) menu[i].css.pixelTop=pos;
    else menu[i].css.top=pos;
    if(isVisible(menu[i].css.visibility)) pos+=menu[i].h;
  }
}
function menuToggle(menu,image,add) {
  var css=is.dom?document.getElementById(menu).style:is.ie4?document.all[menu].style:is.ns4?document.layers[menu]:0;
  if(isVisible(css.visibility)) {
    if ( add ) delPermCookie(menu);
    css.visibility="hidden";
    image.src=plus.src;
  } else {
    if ( add ) setPermCookie(menu);
    css.visibility="visible";
    image.src=minus.src;
  }
  menuMove();
}
if(document.images) {
  plus=new Image();
  plus.src="/images/"+prefixObr+"_plus.gif";
  minus=new Image();
  minus.src="/images/"+prefixObr+"_minus.gif";
}
var is=new Is();
var menu=new Array();

function polsko() {
  window.open('./polsko.htm','POLSKO','toolbar=0,scrollbars=no,width=200,height=300');
}

function maps(map) {
  window.open('/maps.htm?map='+map,'detail','toolbar=0,scrollbars=no,width=400,height=285');
}

function WinPopUp(href,width,height,left,top) {
   if(!width) width=350;
   if(!height) height=260;
   if(!left) left=Math.floor((screen.width-10-width)/2);
   if(!top) top=Math.floor((screen.height-30-height)/2);
   w=window.open(href, "reklama", "resizable=no,toolbar=no,location=no,scrollbars=no,width="+width+",height="+height+",left="+left+",top="+top);
   if(w) w.focus();
}

//funkce na pohyb a zavreni DIVu

var selectedObj=null;
var offsetX,offsetY;

function dragDiv(event) {
    if(window.event) event=window.event;
    if(selectedObj) {
	if(document.all) {
            selectedObj.pixelLeft=event.clientX - offsetX;
            selectedObj.pixelTop=event.clientY - offsetY;
        } else {
            selectedObj.left=event.clientX - offsetX;
            selectedObj.top=event.clientY - offsetY;
        }
        return false;
    }
}

function releaseDiv() {
    if (selectedObj) {
        selectedObj.zIndex=1;
        selectedObj=null;
    }
}

function engageDiv(id,event) {
    if(document.getElementById) {
        var obj=document.getElementById(id);
        if(obj.style) {
            selectedObj=obj.style;
            selectedObj.zIndex=2;
            if(document.all) {
                offsetX=event.clientX-selectedObj.pixelLeft;
                offsetY=event.clientY-selectedObj.pixelTop;
            } else {
                offsetX=event.clientX-parseInt(selectedObj.left,10);
                offsetY=event.clientY-parseInt(selectedObj.top,10);
            }
            return false;
        }
    }
}

function closeDiv(id) {
    if(document.getElementById) {
        var obj=document.getElementById(id);
        if(obj.style) {
            selectedObj=obj.style;
            selectedObj.display="none";
            selectedObj=null;
            return false;
        }
    } else if(document.layers) {
        document.layers[id].visibility="hide";
        return false;
    }
}

document.onmousemove=dragDiv;
document.onmouseup=releaseDiv;

//konec funkce na pohyb a zavreni DIVu


//reloads the window if Nav4 resized
function MM_reloadPage(init)
{
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function zoom(lng, dir, img) {
    var titulek = (lng == 'cs') ? 'Foto' : 'Photo';
    var address = '/' + lng + "/photo.htm?directory=" + dir + "&image=" + img;
    var w = null;
	if(parseInt(navigator.appVersion) >= 2 ) {
		if(parseInt(navigator.appVersion) >= 4 ) {
    		w = window.open(address, titulek,'toolbar=0,scrollbars=0,width=500,height=400,left='+Math.floor((screen.width-500)/2)+',top='+Math.floor((screen.height-400)/2));
	    }
		else
			w = window.open(address, titulek,'toolbar=0,scrollbars=0,width=500,height=400');
		if(w) w.focus(); 
	}
}

function FormControl(ctrl,FC){
 var Message,Field,value,i;
 var RetVal=true;

 for (i=0; i<FC.length && RetVal; i++){
  Field=eval("ctrl."+FC[i][0]);
  if (Field) {
   value=Field.value;
   checked=Field.checked;
   if(!eval(FC[i][1])){
    Message=FC[i][2];
    RetVal=false;
   }
  }
 }
 if(!RetVal){
  alert(Message);
  Field.focus();
  if (Field.type=="text" || Field.type=="password"){
   Field.select();
  }
 }
 return RetVal;
}

function NapisteFormControl() {
 ctrl=document.forms["Napiste"];

 var fc = new Array();
 fc[fc.length] = new Array("name","value>''","Vyplňte prosím položku Jméno a firma!");
 fc[fc.length] = new Array("email","value.search(regemail)!=-1","Vyplňte prosím platnou e-mailovou adresu!");
 fc[fc.length] = new Array("message","value>''","Vyplňte prosím položku Text zprávy!");

 return FormControl(ctrl,fc);
}

function showNextLevel(idmenu,level){
	jQ('#menu'+idmenu).show();
	
	if(level == 1){
		for(i=0; i<newmenu.length; i++) {
			if(i != idmenu) {
				jQ("#"+newmenu[i]).hide();
			}
		}
		for(i=0; i<newmenu_second.length; i++) jQ("#"+newmenu_second[i]).hide();
		for(i=0; i<newmenu_third.length; i++) jQ("#"+newmenu_third[i]).hide();
	}else if(level == 2){
		for(i=0; i<newmenu_second.length; i++) {
			if(i != idmenu) {
				jQ("#"+newmenu_second[i]).hide();
			}
		}
		for(i=0; i<newmenu_third.length; i++) jQ("#"+newmenu_third[i]).hide();
	}else if(level == 3){
		for(i=0; i<newmenu_third.length; i++){
			if(i != idmenu) jQ("#"+newmenu_third[i]).hide();
		}
	}
}


