
/* JS: mod_login_main*/
function mod_login_on_submit() {
	var form;
	if (form = document.getElementById('form_id_login')) {
		var inputs = form.elements;	var err = '';
		for (var i = 0; i < inputs.length; i++) {
			if ((inputs[i].name == 'ed_login') && (inputs[i].value == '')) {
				err = err + "Zadejte uživatelské jméno.";
			}
			if ((inputs[i].name == 'ed_password') && (inputs[i].value == '')) {
				err = err + "Zadejte heslo.";
			}
		}
		if (err != '') {alert(err);	return false;} else {return true;}
	}
}

/* JS: new_window*/

function openwin(elm, isImage) {

    if (!isImage) {
      window.open(elm.getAttribute("href"), "_blank");
      return true;
    }


    var msgWindow = window.open(elm.getAttribute("href"), "_blank", "toolbar=no");
    msgWindow.document.write("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>");
    msgWindow.document.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>");
    msgWindow.document.write("<html>");
    msgWindow.document.write("<meta http-equiv='content-type' content='text/html; charset=utf-8'>");
    msgWindow.document.write("<head>");
    msgWindow.document.write("<title>Picture</title>");
    msgWindow.document.write("<style media='screen,tv,projection' type='text/css'> html, body {margin:0;padding:0} a, img {border: 0px solid #fff}</style>");
    msgWindow.document.write("<script type='text/javascript'>");
    msgWindow.document.writeln("    function getInnerHeight() { ");
    msgWindow.document.writeln("           if (window.innerHeight) {");
    msgWindow.document.writeln("             return window.innerHeight;");
    msgWindow.document.writeln("           } else {");
    msgWindow.document.writeln("             return document.documentElement.offsetHeight;"); // document.body.clientHeight;
    msgWindow.document.writeln("           }");
    msgWindow.document.writeln("    }");
    msgWindow.document.writeln("    function getInnerWidth() { ");
    msgWindow.document.writeln("           if (window.innerWidth) {");
    msgWindow.document.writeln("             return window.innerWidth;");
    msgWindow.document.writeln("           } else {");
    msgWindow.document.writeln("             return document.documentElement.offsetWidth;"); //document.body.clientWidth;
    msgWindow.document.writeln("           }");
    msgWindow.document.writeln("    }");
    msgWindow.document.writeln("    function imgSize(controlHeight,fotoMargin) {");
    msgWindow.document.writeln("      image=document.getElementById('image_elm');");
    msgWindow.document.writeln("      if (screen.height <= (image.height + 31)) {");
    msgWindow.document.writeln("        window.resizeTo(image.width + 12,screen.height - 100);");
    msgWindow.document.writeln("      } else {");
    msgWindow.document.writeln("        window.resizeTo(image.width+2*fotoMargin,image.height+controlHeight+fotoMargin);");
    msgWindow.document.writeln("        controlx = image.width+2*fotoMargin - getInnerWidth();");
    msgWindow.document.writeln("        controly = image.height+controlHeight+fotoMargin - getInnerHeight();");
    msgWindow.document.writeln("        window.resizeTo(image.width + controlx+2*fotoMargin, image.height + controly+controlHeight+fotoMargin);");
    msgWindow.document.writeln("      }");
    msgWindow.document.writeln("    }");
    msgWindow.document.write("</script>");
    msgWindow.document.write("</head>");
    msgWindow.document.write("<body style='margin:0;padding:0;background:#fff' onload='imgSize(0,0);'>");
    msgWindow.document.write("<a style='border:0px solid #fff;' href='#' onclick='window.close();'><img src='"+elm.getAttribute("href")+"' style='border:0px solid #fff;' id='image_elm' alt=''></a>");
    msgWindow.document.write("</body>");
    msgWindow.document.write("</html>");
    msgWindow.document.close();
    msgWindow.focus();
    return true;
}

function open_win_external(elm) {
    window.open(elm.getAttribute("href"), "_blank");
    return true;
}

/* JS: pulldown*/
var visibleId=new Array();
var menuDelay = 100;

if (document.getElementById) {
	document.onmousemove = openMenu;
}

function findX(obj) {
    var x = 0;
    while (obj.offsetParent) {
        x += obj.offsetLeft
        obj = obj.offsetParent;
    }
    return x;
}

function openMenu(event) {
	evnt = eval((document.all)?"window.event.srcElement":"event.target");
    if (visibleId.length>0 && // nejake submenu je viditelne
        !ancestorId(evnt, "nav")){ // mys je zcela mimo #nav
        for (i=visibleId.length;i>0;i--){
            hideEl(document.getElementById(visibleId[i-1]));
        }
        visibleId=new Array();
    }
    if (visibleId.length>0 && // je co schovavat
        ancestorId(evnt, "nav") && // mys je pres nejakeho potomka #nav
        evnt.tagName.toLowerCase() == "a" &&
        visibleId[visibleId.length-1].substring(6) != evnt.parentNode.id.substring(7) &&
        !ancestorId(evnt.parentNode, visibleId[visibleId.length-1])  // neni to ale potomek viditelneho menu
        ) {
        hideEl(document.getElementById(visibleId[visibleId.length-1]));
        visibleId = visibleId.slice(0,visibleId.length-1);
    }
    
    if (evnt.parentNode &&
        evnt.parentNode.id &&
        evnt.tagName.toLowerCase()=="a" &&
        ancestorId(evnt, "nav") &&
        evnt.parentNode.className.toLowerCase().indexOf("p_menu_item_")>=0
        ){
            x = findX(evnt.parentNode);
            li = evnt.parentNode;
            ul = document.getElementById("p_sub_"+li.id.substring(7));
            if (ul && ul.style && ul.style.visibility!="visible"){
               visibleId[visibleId.length]=ul.id;
               ul.style.visibility="visible";
               ul.style.display="block";
               if (ul.className.indexOf("p_menu_inner_0")>=0) /* vypocitat pozici prvni roletky (vnorene maji pozici relativni) */
                    ul.style.left=x-findX(document.getElementById("nav"));
            }
    }
}

function ancestorId(element, id){
   var ancestor = element;
   while (ancestor.parentNode){
      if (ancestor.id==id){
         return true;
      }
      ancestor = ancestor.parentNode;
   }
   return false;
}

function hide(elementId){
    element = document.getElementById(elementId);
    cTimer=setTimeout("hideEl(element)",menuDelay);

}

function hideEl(element){
    if (element && element.style){
        element.style.visibility="hidden";
        element.style.display="block";
    }
}

function show(elementId){
    element = document.getElementById(elementId);
    if (element && element.style){
        element.style.visibility="visible";
        element.style.display="block";
    }
}

function toggle(elementId){
    element = document.getElementById(elementId);
    if (element && element.style){
        if (element.style.visibility!="visible"){
            show(element);
        } else {
            hide(element);
        }
    }
}
