
// version 1.2



 function addmenu(name,url)
 {
     var n;

     this.OptionMax = this.OptionMax + 1;

     n= this.OptionMax -1;  

     this.strOption[n] = name;
     this.strOptionLink[n]=url;


 }




function createmenu()
  {

    var n;
    var color;
    var vx;
    var vdat;
    var vn;


    if (this.OptionSelect == -2) {
     vdat = window.location.href;
     for (vx=0; vx < this.OptionMax; vx++)
     {
      if ( vdat.indexOf(this.strOptionLink[vx]) > 0 ) {
        this.OptionSelect  = vx;
        break;
      }
     }
    }


    if ( this.mode == "v")   //menú vertical
    {

            document.write("<table width='" + this.strSize + "'  border='" + this.vborderSize + "'  bordercolor='"+ this.vborderColor + "' cellpadding='0' cellspacing='0' style='border-collapse: collapse' >");
           
            for (n=0; n < this.OptionMax; n++)
            {
            
                
               // color de la celda  ----------------------------------------------------
               if ( n == this.OptionSelect ){
                  color = this.strColorSelect;
               }else{
                   color = this.strColorOut;
               }
               


               //  si es un título ----------------------------------------------------------
               if ( this.strOption[n].substr(0,1) == "&" ){
               
	                 this.strOption[n] = this.strOption[n].substr(1);
	                 document.write("<tr id='" + this.nameTR  + n +"' bgcolor='"+ this.strColorFix +"'>");
	                 document.write("<td  class='" + this.vClass + "' height='" +  this.rowSize + "'>");
	                 document.write("&nbsp;&nbsp;&nbsp;<b>" + this.strOption[n] + "</b>" );
	                 document.write("</td>");
	                 document.write("</tr>");
	                 
	                 
               }else{

                 if (this.strOption[n].substr(0,1) == ">"){              // datos submenú 

	                     if ( n == this.OptionSelect ){
	                          color = this.strColorSelect;
	                     }else{
	                          color = this.strColorOut;
	                     }
                             
                          document.write("<tr id='" + this.nameTR  + n +"' onMouseOver='" + this.name + ".mover(this)' onMouseOut='" + this.name + ".mout1(this)'   onClick='" + this.name + ".mclick(this)'  bgcolor ='"+ color +"' >");
                          document.write("<td class='" + this.vClass + "'  height='"+ this.rowSize + "'>");
                          
                          if (this.strOption[n].substr(1,1)!=">"){
                              document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img border='0' src='images/cuad.gif'>&nbsp;" + this.strOption[n].substr(1));
                          }else{
                              document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img border='0' src='images/cuad.gif'>&nbsp;" + this.strOption[n].substr(2) );
                          }
                          
                          document.write("</td>");
                          document.write("</tr>");
                          
                          document.getElementById(this.nameTR+n).style.display="none";
	                      document.getElementById(this.nameTR+n).style.visibility="hidden";



                  }else{ 

                          if ( this.strOption[n] == "" ){
	                         document.write("<tr id='" + this.nameTR  + n +"' bgcolor='"+ color +"'>");
	                         document.write("<td  class='" + this.vClass + "' height='" +  this.rowSize + "'>");
	                         document.write("&nbsp;");
	                         document.write("</td>");
	                         document.write("</tr>");
	                         
                          }else{    // opción normal
	                         
	                         document.write("<tr id='" + this.nameTR  + n +"' onMouseOver='" + this.name + ".mover(this)' onMouseOut='" + this.name + ".mout(this)'   onClick='" + this.name + ".mclick(this)'  bgcolor ='"+ color +"' >");
                             document.write("<td class='" + this.vClass + "'  height='"+ this.rowSize + "'>");
	                         document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img border='0' src='images/cuad.gif'>&nbsp;"+ this.strOption[n]);
	                         
	                         if (this.strOptionLink[n].substr(0,1) == ">" ){
	                            document.write("&nbsp;<img src='images/c.gif' id='i" + this.nameTR  + n + "'>");
                             }

                             document.write("</td>");
                             document.write("</tr>");
	                 
                          }
                      
                          
                  }// else datos submenú 
                  
                  
              }  //si es un título
              
            } //for
            
            document.write("</table><br /><br />");




    }else{ // menú horizontal

             

            document.write("<table width='" +  this.colSizeTot + "'  height='" +  this.rowSize + "' border='" + this.vborderSize + "'  bordercolor='"+ this.vborderColor + "' cellpadding='0' cellspacing='0' style='border-collapse: collapse' >");
            document.write("<tr width='" +  this.colSizeTot + "' id='" + this.nameTR  + n +"' bgcolor='"+ this.strColorFix +"' height='" +  this.rowSize + "' >");


            for (n=0; n < this.OptionMax; n++)
            {

               if ( this.strOption[n] > "" )
               {

               if ( n == this.OptionSelect ){
                color = this.strColorSelect;
               }else{
                color = this.strColorOut;
               }

               document.write("<td align='center' width='" +  this.colSize + "' class='" + this.vClass + "' id='" + this.nameTR  + n +"' onMouseOver='" + this.name + ".mover(this)' onMouseOut='" + this.name + ".mout(this)' onClick='" + this.name + ".mclick(this)' bgcolor ='"+ color +"' >");

               if (!document.getElementById)
               {
                 document.write("&nbsp;&nbsp;" + "<a href='" + this.strOptionLink[n] + "'>" + this.strOption[n] + "</a>");
               }else{
                 document.write("<img border='0' src='images/cuad.gif'>&nbsp;" +  this.strOption[n]);
               }

               document.write("</td>");

               }
            }


            document.write("</tr>");
            document.write("</table>");



            }

  
  }



  
  function mover(ssrc) {
   var src;
   
      
   if (!document.getElementById){
    
    } else
       {
    
    src =  document.getElementById(ssrc.id);
    
    src.bgColor = this.strColorOver;

    src.style.cursor = "pointer";


    }
    
  }
  




  function mout(ssrc) {
   var color;
   
   if (!document.getElementById)
   {
   }else{

   src =  document.getElementById(ssrc.id);

   n = parseInt( src.id.substr(2) );
   
    if ( n  ==  this.OptionSelect  )
    {
        color = this.strColorSelect;
    }else{
        color = this.strColorOut;        //"transparent";
    }

    src.bgColor = color;
    src.style.cursor ="default";
    
    }
    
  }


  function mout1(ssrc) {
   var color;
   
   if (!document.getElementById)
   {
   }else{

   src =  document.getElementById(ssrc.id);

      
    if ( parseInt(src.id.substr(2))  ==  this.OptionSelect  )
    {
       color = this.strColorSelect;
    }else{
        color = this.strColorOut;
    }

    src.bgColor = color;
    src.style.cursor ="default";
    
    }
    
  }




  function expandm(op) {
  var n;
  var n1;
  var z;

     //-------------------------------------------------------------------------------------
     // expande o contre el menú definido en op ---------------------------
     //-------------------------------------------------------------------------------------
       
     n = op;
      
     if (  this.strOptionLink[n].substr(0,1)  == ">"  ){      //indica que es un menú

 
        if (  this.strOptionLink[n].substr(0,2)  == ">0" ){
                    // expandir
                    this.strOptionLink[n]  = this.strOptionLink[n].replace(">0",">1");
                    document.getElementById("i" + this.nameTR  + n ).src="images/ca.gif";
         }else{
                   //contraer
                    this.strOptionLink[n]  = this.strOptionLink[n].replace(">1",">0");
                   document.getElementById("i" + this.nameTR  + n ).src="images/c.gif";
         }

        //-----------------------------------------------------------------

        for (z=0; z < this.OptionMax; z++){

           if (  this.strOptionLink[z].substr(0,1)  == ">" ){


                 //-----------------------------------------------------------------

                 if (z != n){
	    this.strOptionLink[z]  = this.strOptionLink[z].replace(">1",">0");
	    document.getElementById("i"+this.nameTR+z).src="images/c.gif";
                  }

                  //-----------------------------------------------------------------

                   for (n1= z+1; n1 < this.OptionMax; n1++){

	               if (  this.strOption[n1].substr(0,1)  == ">"  ){
                
                		        if (z==n  &&  this.strOptionLink[n].substr(0,2) == ">1" ){
	                              document.getElementById (this.nameTR  + n1 ).style.display = "block";
                  	            document.getElementById (this.nameTR  + n1 ).style.visibility = "visible";
	                         }else{
                 		             document.getElementById (this.nameTR  + n1 ).style.display = "none";
	                               document.getElementById (this.nameTR  + n1 ).style.visibility = "hidden";
                 		        }

                                   }else{

                                             break;

                                    }

                      }

                      //---------------------------------------------------------------


                }

              }
                   
        }


  }





  function mclick(ssrc) {
  var n;
  var n1;
  var z;
    

    if (!document.getElementById){
    }else{

       
      n = parseInt( document.getElementById(ssrc.id).id.substr(2) );


      if (  this.strOptionLink[n].substr(0,1)  == ">" ){


            if  (this.strOptionLink[n].substr(2) > "" ) {

                  location.href =this.strOptionLink[n].substr(2);

            }else{

                 if (  this.strOptionLink[n].substr(0,2)  == ">0" ){
                      // expandir menú
                      this.strOptionLink[n]  = this.strOptionLink[n].replace(">0",">1");
                      document.getElementById("i" + this.nameTR  + n ).src="images/ca.gif";

                 }else{
                      // contraer menú
                      this.strOptionLink[n]  = this.strOptionLink[n].replace(">1",">0");
                      document.getElementById("i" + this.nameTR  + n ).src="images/c.gif";

                 }

               //-----------------------------------------------------------------

               for (z=0; z < this.OptionMax; z++){

                           if (  this.strOptionLink[z].substr(0,1)  == ">" ){

                                  //-------------------------------------------------------------------------------------
                                  // pone a 0 todos los menús menos el seleccionado ---------------
                                  //-------------------------------------------------------------------------------------

                                  if (z != n){
                                     this.strOptionLink[z]  = this.strOptionLink[z].replace(">1",">0");
                                     document.getElementById("i"+this.nameTR+z).src="images/c.gif";
                                  }

                                  //-------------------------------------------------------------------------------------
                                  // expande/contrae  los sub-menús ---------------------------------------
                                  //-------------------------------------------------------------------------------------

                                  for (n1= z+1; n1 < this.OptionMax; n1++){

	                           if (  this.strOption[n1].substr(0,1)  == ">" ){
                
		                        if ( z==n && this.strOptionLink[n].substr(0,2) == ">1" ){

                 			        document.getElementById (this.nameTR  + n1 ).style.display = "block";
		                                document.getElementById (this.nameTR  + n1 ).style.visibility = "visible";

                 			       }else{

	  	                                document.getElementById (this.nameTR  + n1 ).style.display = "none";
                			        document.getElementById (this.nameTR  + n1 ).style.visibility = "hidden";

	                 		       }

	                            }else{
	
                 		                         break;

                         	         }

                                     }

                                    //---------------------------------------------------------------

                     }

              }
                   
        }

       }else{

            if  (this.strOptionLink[n] > "" ) {
                  location.href = this.strOptionLink[n];
            }

        }



    }

    
  }
 
  
  




  function selectm(op) {
   var src;
   var n;
       
   if (!document.getElementById){
    
    } else {

 
          if (op > -1  ){
          
             //------------------------------------

           n=op;

            if (  this.strOption[n].substr(0,1)  == ">" ){

           for (z=n; z >= 0; z--){
               if (  this.strOptionLink[z].substr(0,1)  == ">" ){
                   break;
               }
           }

           if (z>=0){
   
           if (  this.strOptionLink[z].substr(0,1)  == ">" ){

              this.strOptionLink[z]  = this.strOptionLink[z].replace(">0",">1");
              document.getElementById("i" + this.nameTR  + z ).src="images/ca.gif";


               for (n1= z+1; n1 < this.OptionMax; n1++){
                     if (  this.strOption[n1].substr(0,1)  == ">" ){
                        document.getElementById (this.nameTR  + n1 ).style.display = "block";
                        document.getElementById (this.nameTR  + n1 ).style.visibility = "visible";
                     }else{
                         break;
                     }
                 }
               
               
              }
               }
            }
             //------------------------------------

             this.OptionSelect = op;
             document.getElementById( this.nameTR  + op ).bgColor = this.strColorSelect;

           }
      

     }
    
  }




  function selecthref(page) {
   var src;
   var n;
   var op;
   var hreft;




   if (!document.getElementById){

    } else {

      // localizar op
      op = -1;
      d=window.location.href;



      //-----------------------------------------------------------------
      // Buscar el nombre de la página en las opciones
      //-----------------------------------------------------------------


        for (z=0; z < this.OptionMax; z++){

              if ( this.strOptionLink[z].substr(0,2)  == ">0" ){

                    hreft = this.strOptionLink[z].substr(2);

              }else{

                    hreft = this.strOptionLink[z];
              }


              if (  this.strOptionLink[z].indexOf(page)  != -1 ){
                   op=z;
                   break;
              }


         }



          if (op  >  -1  ){

                             //-----------------------------------------------------------------------------------  
	           // si está en un sub-menú
                             // localizar nodo raíz
                             //-----------------------------------------------------------------------------------  
	            if (  this.strOption[op].substr(0,1)  == ">" ){

                                    n=op;

		for (z=n; z >= 0; z--)
                {
		   if (  this.strOptionLink[z].substr(0,1)  ==  ">"  )
                   {
	              break;
		   }
          	}

                             }else{
                                     z=op;
                             }   


	           if ( z >= 0 ){


  		         if (  this.strOptionLink[z].substr(0,1)  == ">" ){

		                  this.strOptionLink[z]  = this.strOptionLink[z].replace( ">0" , ">1" );
		                  document.getElementById("i" + this.nameTR  + z ).src="images/ca.gif";
		                  for (n1= z+1; n1 < this.OptionMax; n1++){
   		                        if (  this.strOption[n1].substr(0,1)  == ">" ){
		                              document.getElementById (this.nameTR  + n1 ).style.display = "block";
		                              document.getElementById (this.nameTR  + n1 ).style.visibility = "visible";
		                        }else{
  		                              break;
		                        }
 		                    }
	                                }

                             }


                              this.OptionSelect = op;
                              document.getElementById( this.nameTR  + op ).bgColor = this.strColorSelect;

           }

     }

  }




function menuClass()
{
  this.name;
  this.mode = "v";
  this.nameTR="op";
  this.vborderSize=0;
  this.vClass;
  this.strSize="100%";
  this.rowSize=20;
  this.colSize=50;
  this.colSizeTot=150;
  
  this.vborderColor="000000";
  this.strColorOver;
  this.strColorOut;
   this.strColorSelect;
  this.strColorFix;
  
  this.strOption= new Array();
  this.strOptionLink= new Array();
  this.OptionSelect=-1;
  this.OptionMax;
  this.strHelp= new Array();
  this.mclick = mclick;
  this.mout = mout;
  this.mout1 = mout1;
  this.mover = mover;
  this.createmenu = createmenu;
  this.selectm = selectm;
  this.selecthref =  selecthref;
  this.addmenu = addmenu;
 }


