var ns = (navigator.appName.indexOf('Netscape')>-1);
var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1);
var SLOMenuItems = new Array(
   ["sNasledniki",  "1", "Diagram potomcev"],
   ["sPredniki",    "2", "Diagram prednikov"],
   ["sParametri",   "3", "Parametri diagramov"],
   ["sOsebniPod",   "4", "Osebni podatki"]);
var USAMenuItems = new Array(
   ["sNasledniki",  "1", "Diagram of descendants"],
   ["sPredniki",    "2", "Diagram of ancestors"],
   ["sParametri",   "3", "Diagram's parameters"],
   ["sOsebniPod",   "4", "Individual info"]);
var CSKMenuItems = new Array(
   ["sNasledniki",  "1", "Diagram of descendants"],
   ["sPredniki",    "2", "Diagram of ancestors"],
   ["sParametri",   "3", "Diagram's parameters"],
   ["sOsebniPod",   "4", "Osobní informace"]);

var oseba="1";
var Lang;
var Fam;
var brskalnik="0";

function Done(ID, Page) {
  var tempwin = window.open("/cgi-bin/GenHTML.exe?Page="+Page+"&ID="+ID,"tempwin","width=100,height=100");
  tempwin.close();
}
function createMenu(menuName, menuItems) {
   var divHTML = '<DIV ID="' + menuName + 'MenuDiv" CLASS="DivMenu"';
   divHTML = divHTML + 'onmouseout="return hideMenu(' + menuName.length + ',event)">';
   var tableHTML = '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1 ID="' + 
      menuName + 'Table"><TBODY ID="' + menuName + 'TableBody">';
   var tableRowHTML = "";
   var rowCount;
   var totalNoRows = menuItems.length;
   for (rowCount = 0; rowCount < totalNoRows; rowCount++)
   {
      tableRowHTML = tableRowHTML + '<TR ID="' + menuName + 
         menuItems[rowCount][0] +  'TR"><TD ID="' + menuName + 
         menuItems[rowCount][0];
      tableRowHTML = tableRowHTML + '" onclick="goPage(\'' + menuItems[rowCount][1] + '\')"';
      tableRowHTML = tableRowHTML + 'CLASS="TDMenu">' + menuItems[rowCount][2] +
         '</TD></TR>';
   }
  
   return divHTML + tableHTML + tableRowHTML + '</TBODY></TABLE></DIV>';
}
function showMenu(e, aOseba, L, F) {
  oseba=aOseba;  
  Lang = L;
  Fam = F;
  switch (Lang) { 
  case "Slovenski":    
      var menuToShow = document.getElementById('SLOMenuDiv');
      break;
  case "English":
      var menuToShow = document.getElementById('USAMenuDiv');
      break;
  case "Czech":
      var menuToShow = document.getElementById('CSKMenuDiv');
      break;
  default:  
      Lang = "English";
      var menuToShow = document.getElementById('USAMenuDiv');
      break;
  }  
  var H = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
  menuToShow.style.left = e.clientX + document.body.scrollLeft;
  var T = e.clientY + document.body.scrollTop;
  if (e.clientY + 70 > H) {
    T = T - (e.clientY + 70 - H);  //225 popravi na višino DIV-a
  }
  menuToShow.style.top = T;
  menuToShow.style.visibility = "visible";
}
function hideMenu(menuIDLength, e) {   
  var toElementID;
   if (ns) {
      var mouseLastIn = e.relatedTarget;       
   } else {
      var mouseLastIn =  event.toElement; 
   }
//   window.alert("1:"+mouseLastIn.id);
  switch (Lang) { 
  case "Slovenski":    
      var menuToHide = document.getElementById('SLOMenuDiv');
      break;
  case "English":
      var menuToHide = document.getElementById('USAMenuDiv');
      break;
  case "Czech":
      var menuToHide = document.getElementById('CSKMenuDiv');
      break;
  }  
  if (mouseLastIn != null) {
     if (mouseLastIn.nodeType == 3) {
        mouseLastIn = mouseLastIn.parentNode; 
     }
     toElementID = mouseLastIn.id;
  } else {  
      return false;
  }
//   window.alert("2:"+toElementID);
  if (typeof(toElementID) == "undefined") {
     toElementID = "UNDEF";
  }
  toElementID = toElementID.substr(0,menuIDLength);
//   window.alert("3:"+toElementID+" : "+menuToHide.id);
  var divMenuID = menuToHide.id;
//   window.alert("4:"+divMenuID);
   divMenuID = divMenuID.substr(0,menuIDLength);
//   window.alert("5:"+divMenuID+" : "+menuIDLength);
  if (toElementID != divMenuID) {
     menuToHide.style.left = -200 + 'px';
     menuToHide.style.top = -1000 + 'px';
  }
}
function document_onmouseover(e) {
   if (ns) {
      var srcElement = e.target;
   } else {
      var srcElement = event.srcElement;
   } 
   if (srcElement.nodeType == 3) {
       srcElement = srcElement.parentNode; 
   }
   if (srcElement.tagName=="TD" && srcElement.className=="TDMenu") {
      srcElement.style.color = "white";
      srcElement.style.backgroundColor = "darkblue"
   }
}
function document_onmouseout(e) {
    if (ns) {
      var srcElement = e.target;
   } else {
      var srcElement = event.srcElement;
   }
   if (srcElement.nodeType == 3) {
      srcElement = srcElement.parentNode; 
   }
   if (srcElement.tagName == "TD" && srcElement.className=="TDMenu") {
      srcElement.style.color ="darkblue";
      srcElement.style.backgroundColor = "rgb(207,207,207)";  
   }
}
function goPage(src) {
  switch (Lang) { 
  case "Slovenski":    
      document.getElementById('SLOMenuDiv').style.visibility = "hidden";
      break;
  case "English":
      document.getElementById('USAMenuDiv').style.visibility = "hidden";
      break;
  case "Czech":
      document.getElementById('CSKMenuDiv').style.visibility = "hidden";
      break;
  }  
   if (ie) {
      brskalnik="0";       
   } else {
      brskalnik="1"; 
   }
  switch (src) { 
  case "1":
      document.location.href="/cgi-bin/GenHTML.exe?Br="+brskalnik+"&Page=1&ID="+oseba+"&Lang="+Lang+"&Fam="+Fam;
      break;
  case "2":
      document.location.href="/cgi-bin/GenHTML.exe?Br="+brskalnik+"&Page=20&ID="+oseba+"&Lang="+Lang+"&Fam="+Fam;
      break;
  case "3":  
      switch (Lang) { 
      case "Slovenski":    
          window.open("/genealogy/Slovenski/Parametri.html","Parametri","height=300,width=600");
          break;
      case "English":
          window.open("/genealogy/English/Parametri.html","Parametri","height=300,width=600");
          break;
      case "Czech":
          window.open("/genealogy/Czech/Parametri.html","Parametri","height=300,width=600");
          break;
      break;
	  }
  case "4":
      document.location.href="/genealogy/getperson.php?personID="+oseba+"&tree=Kosnk";	
      break;
  }
}
