if (soporta.DOM) {fShow="visible";fHide="hidden";}
if (soporta.IE4) {fShow="visible";fHide="hidden";}
if (soporta.NS4) {fShow="show";   fHide="hide";}
HTMLstr="";
lastMenu = null;
MenuBorde = 1;
MenuEstilo();

function MenuEstilo() {
 if (soporta.DOM) {
  G_L('<STYLE TYPE="text/css">');
  G_L('BODY { margin-top: 0; }');
  G_L('#MainTable { position: relative; }');
  G_L('</STYLE>');
 }

 var EstiloMenu = '';
 MenuColorBorde = LetraClaraColor;
 EstiloMenu += ' text-decoration: none; font-weight: bold; font-size: '+TamPeq+'; font-family: Verdana; color: '+LetraClaraColor+';';
 EstiloMenu += ' background-color: '+FondoOscuroColor+';';
 EstiloMenu += ' border-color: '+MenuColorBorde+';';
 var EstiloMenuBorde = '';
 if (ie4 || ns5) {
  EstiloMenuBorde += ' border-style: outset;';
  EstiloMenuBorde += ' border-width: '+ MenuBorde +'px;';
  EstiloMenuBorde += ' padding: 1px;';
 }
 G_L('<STYLE>');
 G_L('.clsMenu          { '+EstiloMenu+' }');
 G_L('TD.clsMenu        { '+EstiloMenu+EstiloMenuBorde+' }');
 G_L('A.clsMenu         { '+EstiloMenu+'border-style: none; }');
 G_L('A.clsMenu:link    { '+EstiloMenu+'border-style: none; }');
 G_L('A.clsMenu:visited { '+EstiloMenu+'border-style: none; }');
 G_L('A.clsMenu:hover   { '+EstiloMenu+'border-style: none; }');
 G_L('A.clsMenu:active  { '+EstiloMenu+'border-style: none; }');
 G_L('</STYLE>');

}
function Menu() {
 this.addItem    = addItem;
 this.addSubItem = addSubItem;
 this.showMenu   = showMenu;

 HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->\n";
 if (soporta.NS4) { HTMLstr += "<LAYER ID='MainTable' CLASS=\"clsMenu\">\n";
 } else if (soporta.DOM || soporta.IE4) HTMLstr += "<DIV ID='MainTable' CLASS=\"clsMenu\">\n";

 HTMLstr += "<TABLE CLASS=\"clsMenu\" WIDTH='100%' BORDER='"+MenuBorde+"'>\n";
 HTMLstr += "<TR>";
 HTMLstr += "<!-- MAIN MENU STARTS -->\n";
 HTMLstr += "<!-- MAIN_MENU -->\n";
 HTMLstr += "<!-- MAIN MENU ENDS -->\n";
 HTMLstr += "</TR>\n";
 HTMLstr += "</TABLE>\n";

 HTMLstr += "<!-- SUB MENU STARTS -->\n";
 HTMLstr += "<!-- SUB_MENU -->\n";
 HTMLstr += "<!-- SUB MENU ENDS -->\n";

 if (soporta.NS4) { HTMLstr+= "</LAYER>\n";
 } else if (soporta.DOM || soporta.IE4) HTMLstr+= "</DIV>\n";

 HTMLstr += "<!-- MENU PANE DECALARATION ENDS -->\n";

}
function addOption(idItem, text, location) {
 var MENUoption="";
 MENUoption += "<A CLASS=\"clsMenu\" ";
 if (location == null) location=".";
 MENUoption += "href='"+location+"' ";
 MENUoption += "onmouseover=\"displaySubMenu('"+idItem+"')\" ";
 if (location==".") MENUoption += "onclick=\"return false;\" "
 MENUoption += ">&nbsp;";
 MENUoption += text;
 MENUoption += "</A>\n";
 return MENUoption;
}
function addItem(idItem, text, titulo, location, altLocation) {
 if (HTMLstr.indexOf("<!-- ITEM "+idItem+" -->") != -1) {  alert(idItem + " ya existente");  return; }
 var MENUitem = "";
 MENUitem += "\n<!-- ITEM "+idItem+" -->\n";
 MENUitem += "<TD CLASS=\"clsMenu\">\n";

 if (soporta.NS4) { MENUitem += "<ILAYER ID='"+idItem+"' CLASS=\"clsMenu\">\n";
 } else             MENUitem += "<DIV ID=" +idItem+" CLASS=\"clsMenu\">\n";

 MENUitem += addOption(idItem, text, location);

 if (soporta.NS4) {  MENUitem += "</ILAYER>\n";
 } else              MENUitem += "</DIV>\n";

 MENUitem += "</TD>\n";
 MENUitem += "<!-- END OF ITEM "+idItem+" -->\n\n";
 MENUitem += "<!-- MAIN_MENU -->\n";

 HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);

 addCajaSubItem(idItem);

}
function addCajaSubItem(idParent) {
 var CAJAStr = "";
 Lookup = "<!-- ITEM "+idParent+" -->";
 if (HTMLstr.indexOf(Lookup) == -1) {  alert(idParent + " no encontrado");  return; }
 Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
 if (HTMLstr.indexOf(Lookup) == -1) {
  CAJAStr += "\n";
  if (soporta.DOM || soporta.IE4) { CAJAStr += "<DIV id='"+idParent+"submenu' style='position:absolute; visibility: hidden;'>\n";
  } else if (soporta.NS4) {         CAJAStr += "<LAYER id="+idParent+"submenu visibility="+fHide+"'>\n"; }

  CAJAStr += "<TABLE CLASS=\"clsMenu\" BORDER='"+MenuBorde+"'>\n";
  CAJAStr += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
  CAJAStr += "</TABLE>\n";

  if (soporta.DOM || soporta.IE4) { CAJAStr += "</DIV>\n";
  } else if (soporta.NS4) { CAJAStr += "</LAYER>\n"; }

  CAJAStr += "<!-- SUB_MENU -->\n";
  HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->\n", CAJAStr);
 }
}
function addSubItem(idParent, text, hint, location) {
 var MENUitem = "";

 Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
 MENUitem = "<TR><TD CLASS=\"clsMenu\"><A CLASS=clsMenu";
 if (hint != null) MENUitem +=" title='"+hint+"'";
 MENUitem +=" HREF='"+location+"'>"+text+"</A><BR></TD></TR>\n";
 MENUitem += Lookup;
 HTMLstr = HTMLstr.replace(Lookup, MENUitem);

}
function hideAll() {
 if (lastMenu != null) {
  lastMenu.Visible(fHide);
 }
}
function displaySubMenu(idMainMenu) {
 var supmenu = new Panel('MainTable');;
 var menu = new Panel(idMainMenu);
 var submenu = new Panel(idMainMenu+"submenu");
var TopeSuperior=0;
var TopeIzquierdo=0;
 TopeIzquierdo = calculaSumaIzq(menu)-calculaSumaIzq(supmenu);
 TopeSuperior =  calculaSumaSup(menu)-calculaSumaSup(supmenu);
 if (ns)  { TopeIzquierdo-=5; TopeSuperior+=17; }
 if (ie4) { TopeIzquierdo-=4; TopeSuperior+=18; }

 if (lastMenu != null && lastMenu != submenu) hideAll();
 submenu.Izq(TopeIzquierdo);
 submenu.Sup(TopeSuperior);
 submenu.Visible(fShow);
 lastMenu = submenu;
}
function calculaSumaSup(idItem) {
 var Suma = 0;
 var item = idItem;
 do {
  if (soporta.DOM || soporta.IE4) { Suma += item.offsetTop; item = item.offsetParent; } else
  if (soporta.NS4) {                Suma += item.pageY;     item = item.ParentLayer; }
 } while (item != null);
 return Suma;
}
function calculaSumaIzq(idItem) {
 var Suma = 0;
 var item = idItem;
 do
 {
  if (soporta.DOM || soporta.IE4) { Suma += item.offsetLeft; item = item.offsetParent; } else
  if (soporta.NS4) {                Suma += item.pageX;      item = item.ParentLayer; }
 } while (item != null);
 return Suma;
}
function showMenu() { document.writeln(HTMLstr); }
function UpdateIt(){
 ActivaEventos();
var TopeSuperior=0; TopeIzquierdo=0;
 var MenuPrincipal=new Panel("MainTable");
 if (MenuPrincipal != null) {
  if (ns)         { TopeSuperior=window.pageYOffset; TopeIzquierdo=window.pageXOffset;
  } else if (ie4) { TopeSuperior=document.body.scrollTop; TopeIzquierdo=document.body.scrollLeft }
  MenuPrincipal.Sup(TopeSuperior);
  MenuPrincipal.Izq(TopeIzquierdo);
  setTimeout("UpdateIt()", 200);
 }
}
function ActivaEventos() {
 if (ie4) {
  document.body.onclick=hideAll;
  document.body.onscroll=hideAll;
  document.body.onmousemove=EventoRaton;
 } else if (ns) {
  window.captureEvents(Event.MOUSEMOVE);
  window.onmousemove=EventoRaton;
 }
}
function EventoRaton(e) {
 if (lastMenu != null) {
  if (ie4) { var x = window.event.clientX; var y = window.event.clientY; }
  if (ns)  { var x = e.pageX;              var y = e.pageY; }

  if (ns) { x-=window.pageXOffset; y-=window.pageYOffset; }

  if (x > (lastMenu.Izq()+lastMenu.Anc()) || x < lastMenu.Izq()) hideAll();
  else if (y > lastMenu.Sup()+lastMenu.Alt()+20) hideAll();
 }
}
}






