var referenciaEstilo;
var capaVisible;
var navegador;
var ocultar = true;

var isNav4, isNav6, isIE4;
var Resituar = true;      

setBrowser();

window.onresize = resetMenus;

function setBrowser()
{
    if (navigator.appVersion.charAt(0) == "4")
    {
        if (navigator.appName.indexOf("Explorer") >= 0)
        {
            isIE4 = true;
        }
        else
        {
            isNav4 = true;
        }
    }
    else if (navigator.appVersion.charAt(0) > "4")
    {
        isNav6 = true;
    }
} 

if (navigator.appName == "Netscape") {
       if (navigator.appCodeName == "Mozilla") {
	referenciaEstilo = "style.";
	capaVisible = "visible";
	navegador="Explorer";
      } else {
	referenciaEstilo = "";
	capaVisible="show";
	navegador= "Netscape";
      }
} else {
	referenciaEstilo = "style.";
	capaVisible = "visible";
	navegador="Explorer";
}

function Left(s, n){
	// Devuelve los n primeros caracteres de la cadena
	if(n>s.length)
		n=s.length;
		
	return s.substring(0, n);
}

function ocultarTodo() {   
   if (ocultar == true) 
      for (i=0; ele=document.getElementsByTagName('div')[i]; i++)
         if (Left(ele.id,4) == 'menu')
            ele.style.visibility = 'hidden';
}

function ocultarCapas(nExcepto, nExcepto2) {   
   for (i=0; ele=document.getElementsByTagName('div')[i]; i++)
      if (nExcepto != ele.id)
         if (nExcepto2 != ele.id)
            if (ele.id != 'menu0')
               ele.style.visibility = 'hidden';
}

function ocultarPrincipal (nombreCapa) {
   eval (referenciaCapa(nombreCapa)+referenciaEstilo+'visibility="hidden"');         	
}

function ocultarRetardoTodo(){
   setTimeout("ocultarTodo()",500)
}

function ocultarRetardo(nombreCapa){
   setTimeout("ocultarCapa('" + nombreCapa + "')",3500)
}

function ocultarCapa (nombreCapa) {
	eval (referenciaCapa(nombreCapa)+referenciaEstilo+'visibility="hidden"');         	
}

function mostrarCapa (nombreCapa) {
	eval (referenciaCapa(nombreCapa)+referenciaEstilo+'visibility="' + capaVisible + '"');	
}

function referenciaCapa (nombreCapa) {
	if (navegador=="Netscape") 
		return "document.layers['"+nombreCapa+"'].";
	else
		return "document.all['"+nombreCapa+"'].";
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  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 MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function P7_autoLayers() { //v1.4 by PVII
 var g,b,k,f,args=P7_autoLayers.arguments;a=parseInt(args[0]);if(isNaN(a))a=0;
 if(!document.p7setc){p7c=new Array();document.p7setc=true;for(var u=0;u<10;u++){
 p7c[u]=new Array();}}for(k=0;k<p7c[a].length;k++){if((g=MM_findObj(p7c[a][k]))!=null){
 b=(document.layers)?g:g.style;b.visibility="hidden";}}for(k=1;k<args.length;k++){
 if((g=MM_findObj(args[k]))!=null){b=(document.layers)?g:g.style;b.visibility="visible";f=false;
 for(var j=0;j<p7c[a].length;j++){if(args[k]==p7c[a][j]) {f=true;}}
 if(!f){p7c[a][p7c[a].length++]=args[k];}}}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}

function resetMenus(){
   if (Resituar == false)
      ocultarTodo();
   Resituar = true;
}

function ResituarMenus(x, y, baseX, baseY, desplazamiento) {
   if (Resituar == true) {            
      for (i=0; ele=document.getElementsByTagName('div')[i]; i++) {
         if (Left(ele.id,4) == 'menu') {
            if (ele.id == 'menu0') {
               moveIdTo( ele.id, x + baseX, getAbsoluteTop(ele.id))
            } else {
               moveIdTo( ele.id, x + baseX + desplazamiento, getAbsoluteTop(ele.id) );
            }
         }
      }
      Resituar = false;      
   }
}

function moveIdTo( id, x, y )
{
    generic_move( id, x, y, false );
}

function moveIdBy( id, x, y)
{
    generic_move( id, x, y, true );
} 

function getIdProperty( id, property )
{
    if (isNav6)
    {
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            if (styleObject[property])
            {
                return styleObject[ property ];
            }
        }
        styleObject = getStyleBySelector( "#" + id );
        return (styleObject != null) ?
            styleObject[property] :
            null;
    }
    else if (isNav4)
    {
        return document[id][property];
    }
    else
    {
        return document.all[id].style[property];
    }
}

function setIdProperty( id, property, value )
{
    if (isNav6)
    {
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            styleObject[ property ] = value;
        }
        
        /*
		styleObject = getStyleBySelector( "#" + id );
        if (styleObject != null)
        {
            styleObject[property] = value;
        }
		*/
    }
    else if (isNav4)
    {
        document[id][property] = value;
    }
    else if (isIE4)
    {
         document.all[id].style[property] = value;
    }
} 

function generic_move( id, xValue, yValue, additive )
{
    var left = getIdProperty(id, "left");
    var top = getIdProperty(id, "top");
    var leftMatch, topMatch;

    if (isNav4)
    {
        leftMatch = new Array( 0, left, "");
        topMatch = new Array( 0, top, "");
    }
    else if (isNav6 || isIE4 )
    {
        var splitexp = /([-0-9.]+)(\w+)/;
        leftMatch = splitexp.exec( left );
        topMatch = splitexp.exec( top );
        if (leftMatch == null || topMatch == null)
        {
            leftMatch = new Array(0, 0, "px");
            topMatch = new Array(0, 0, "px");
        }
    }
    left = ((additive) ? parseFloat( leftMatch[1] ) : 0) + xValue;
    top = ((additive) ? parseFloat( topMatch[1] ) : 0) + yValue;
    setIdProperty( id, "left", left + leftMatch[2] );
    setIdProperty( id, "top", top + topMatch[2] );
} 

function disableAnchor(obj, disable){
  if(disable){
    var href = obj.getAttribute("href");
    if(href && href != "" && href != null){
       obj.setAttribute('href_bak', href);
    }
    obj.removeAttribute('href');
    obj.style.color="gray";
  }
  else{
    obj.setAttribute('href', obj.attributes['href_bak'].nodeValue);
    obj.style.color="blue";
  }
}

function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

function resize() {
   var i=0;
   if (document.layers) i=40;
   if (document.images[0]) window.resizeTo(document.images[0].width +30, document.images[0].height+115-i);
   self.focus();
}

