var currentMenu = -1;
var currentSubMenu = -1;
var info = null;

function overSubMenu(id){
  currentSubMenu = id;
  showSubMenu(id);
}
function outSubMenu(id){
  currentSubMenu = -1;
  hideSubMenu(id);
}
function showSubMenu(id){
  if(currentSubMenu == currentMenu){
    button = document.getElementById("btn" + id);
    submenu = document.getElementById("submenu" + id);
    if(button != null && submenu != null){
      submenu.top = button.offsetTop;
	   switch(id){
	     case 0:submenu.style.width = "130px";break;
		 case 1:submenu.style.width = "70px";break;
		 case 3:submenu.style.width = "110px";break;
		 case 4:submenu.style.width = "160px";break;
		 default: submenu.style.width = "0px";break;	   
	   }
      submenu.className = "submenu";
    } 		
  }else{
    hideMenu(id);
	 currentSubMenu = -1;
  }	   
}
function hideSubMenu(id){
  submenu = document.getElementById("submenu" + id);
  if(submenu != null){
  	submenu.className = "hidden";
  } 		
}
function overMenu(id){
  image = document.getElementById('menuImg'+id);
  src = image.src;
  idx = src.lastIndexOf(".jpg");
  currentMenu = id;
  if(idx > 0){
    if(src.charAt(idx - 1) != "O"){
      image.src = src.substr(0, idx) + "O" + src.substr(idx);
      window.setTimeout("overSubMenu("+id+")", 500);				
  	 }
  }
}
function outMenu(id){
  window.setTimeout("hideMenu("+id+")", 100);
  currentMenu = -1; 
}
function hideMenu(id){
  if(currentMenu != id){	      
    image = document.getElementById('menuImg'+id);
    src = image.src;
    idx = src.lastIndexOf("O.jpg");
    if(idx > 0){
      image.src = src.substr(0, idx) + src.substr(idx + 1);
    }
    hideSubMenu(id);
  } 	
}
function showInfo(msg){
  if(info == null){
    info = document.getElementById("info");
  }
  if(info != null){
    info.innerHTML = info.innerHTML + ' - ' + msg;
  }
}
function setCookie( name, value, expires, path, domain, secure ){
  var today = new Date();
  today.setTime( today.getTime() );
  if(expires){
    expires = expires * 1000 * 60 * 60 * 24;
  }
  var expires_date = new Date( today.getTime() + (expires) );
  document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
    ( ( path ) ? ";path=" + path : "" ) + 
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}
function getCookie( name ){
  var start = document.cookie.indexOf( name + "=" );
  var len = start + name.length + 1;
  if((!start)&&(name != document.cookie.substring(0, name.length))){
    return null;
  }
  if(start == -1)return null;
  var end = document.cookie.indexOf( ";", len );
  if(end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len, end));
}
function positionDetailPhoto(){  
  img = document.getElementById("dtl");
  phto = document.getElementById("photo");
  bd = document.getElementById("body");
  c = document.getElementById("separator");
  if(img.offsetWidth > 100){
    phto.style.left = (bd.offsetWidth - img.offsetWidth)/2 +"px";
	 setCookie("detail", phto.style.left, "1", "/", "", "");
    c.style.height = (phto.offsetHeight + 20) + "px";
  }else{
    if(getCookie("detail") != null){
      phto.style.left = getCookie("detail");
	 }
  }
 
  window.setTimeout("positionDetailPhoto()", 500);
}
function showAddComm(){
  document.getElementById("addNew").className = "";
  document.getElementById("addBtn").className = "hidden";  
}
function validateEmail(email){
  if(email.length <= 0)return false;
  var splitted = email.match("^(.+)@(.+)$");
  if(splitted == null)return false;
  if(splitted[1] != null){
    var regexp_user=/^\"?[\w-_\.]*\"?$/;
    if(splitted[1].match(regexp_user) == null) return false;
  }
  if(splitted[2] != null){
    var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
    if(splitted[2].match(regexp_domain) == null){
      var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
      if(splitted[2].match(regexp_ip) == null) return false;
    }
    return true;
  }
}
function checkComm(){
  document.forms[0].elements['text'].value = decEmoticon(tinyMCE.getContent('komentar'));
  if(document.forms[0].elements['meno'].value.replace(/^\s+|\s+$/g,"").length == 0){
    alert('Prosím zadajte \'Meno\'.');
    return false;
  }
  if(!validateEmail(document.forms[0].elements['email'].value)){
    alert('Prosím zadajte \'Váš email\' v správnom tvare.');
    return false;
  }
  if(document.forms[0].elements['text'].value.replace(/^\s+|\s+$/g,"").length == 0){
    alert('Prosím napíšte svoj \'Komentár\'.');
    return false;
  }
  if(document.forms[0].elements['podm'].checked == false){
    alert('Prosím potvrďte svoj súhlas s podmienkami.');
    return false;
  }
  return true; 
}