// JavaScript Document
/////////////////// CLASE PARA AJAX ////////////////////////////////
	function createRequestObject() {
		var ro;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			ro = new XMLHttpRequest();
		}
		return ro;
	}
	
	var http = createRequestObject();
////////////////////////////////////////////////////////////////////////
///////////////////////Funcion Valida formulario////////////////////////
function ValidaForma()
                  {
                    var f = document.getElementById('forma');
					
                    for (i = 0; i < f.elements.length; i++)
					     {
                          if ((f.elements[i].type == "text" || f.elements[i].type == "password")  && f.elements[i].value == "") 
						       { 
                                alert("Por favor complete todos los campos del formulario"); 
								f.elements[i].focus(); 
                                return false;         
								}
								//alert(f.elements[i].name);
                        }
                    ValidaUsu();
				  }
				  
////////////////////////////////////////////////////////////////////////
/*function replace(texto,s1,s2){
	return texto.split(s1).join(s2);
}*/
///////////////////////Funcion Generar Usuario//////////////////////////
function ValidaUsu()
                  {
                    var f=document.getElementById('forma');
				    
				    http.open('get','ajax_consultas.php?op=1&usuario='+f.usuario.value+'&contra='+f.contra.value);
					http.onreadystatechange = Resp_ValidaUsu;
					http.send(null);
				  }			 

////////////////////////////////////////////////////////////////////////

   
			 

//////////////////////////////////////////////////////////////////////////////
function Resp_ValidaUsu()
            {
			
			  if(http.readyState==4)
			        {
					   //alert('si');
					  if(http.status==200)
					      {
						  // alert(http.responseText);
						   var respuesta=http.responseText;
							var arr_resp=respuesta.split('|');
							if(arr_resp[0]==0)
							    {
								  alert('Usuario y/o contraseña incorrectos');
								  limpiar();
								  return false;
								}
						else if(arr_resp[0]==-1)
							    {
								  alert('Acceso denegado desde esa ubicación.'+arr_resp[1]);
								  limpiar();
								  return false;
								}
							else if(arr_resp[0]==1){
							      location.replace('menu.php');
								  //alert("OK");
								}
							 else{
							      alert('Ha ocurrido un error.'+arr_resp[0]);
								   return false;
							     }		
						  }
						else{
						     alert('Intente de nuevo.');
							 return false;
						   }  
					}
			}

//////////////////////////////////////////////////////////////////////////////
function solonumeros(e){
    var key = window.event ? e.keyCode : e.which;
    if ((key<=32) || (key >=126)){
         
          var keychar=String.fromCharCode(key);
         reg=/\d/;
          return !reg.test(keychar);
    }

else{
    var keychar = String.fromCharCode(key);
    reg = /\d/;
    return reg.test(keychar);
    }
}

function limpiar(){
                 document.getElementById('usuario').value="";
				 document.getElementById('contra').value="";
				 foco();
				}
				
function foco(){
             document.getElementById('usuario').focus();
			 }
////////////////////////////////////////////////////////////////////////////////
function Envia_form(e){
    var key = window.event ? e.keyCode : e.which;
    if(key==13)
	    {
		  ValidaForma();
		  return(key!=13);  
		}
   }
////////////////////////////////////////////////////////////////////////////////	
function Si_cambio(id_serie,valorgcat,catosubcat){
   var formu = document.getElementById('forma');
   var nombrecamposel=catosubcat+id_serie;
   var nombrecampoband='sicambio'+id_serie;
	/*alert(nombrecampo);
	var coma = String.fromCharCode(34);
	var nuevonom=coma+nombrecampo+coma;
	alert(nuevonom);*/
	if(valorgcat==document.getElementById(nombrecamposel).value)
	   {
	   document.getElementById(nombrecampoband).value=0;
	   //alert(valorgcat+'--'+document.getElementById(nombrecampoband).value+'--'+document.getElementById(nombrecamposel).value+'--'+valorgcat.length+'--'+document.getElementById(nombrecamposel).value.length);
	  }
	  else{
		  document.getElementById(nombrecampoband).value=1;
	  // alert(valorgcat+'--'+document.getElementById(nombrecampoband).value+'--'+document.getElementById(nombrecamposel).value);
		  }
		  
	if(catosubcat=='categoria')
	    {
	     Cambia_selsubcat(document.getElementById(nombrecamposel).value,id_serie);
		}
  }
////////////////////////////////////////////////////////////////////////////////
function Muestra_subcat(valcate)
         {
			 //alert(valcate);
			 http.open('get','ajax_consultas.php?op=3&catpadre='+valcate);
					http.onreadystatechange = Resp_Muestra_subcat;
					http.send(null);
			 }
///////////////////////////////////////////////////////////////////////////////////
function Resp_Muestra_subcat()
          {
			  if(http.readyState==4)
			     {
					 if(http.status==200)
					    {
							var resp=http.responseText;
							 //var arr_resp=resp.split('|');
							 //if(arr_resp[0]==1)
							   // {
									//alert(resp);
									document.getElementById('contentsc').innerHTML=resp;
								//	}
									document.getElementById('contentarchivo').innerHTML="<select class='cselect' name='archivos' id='archivos'><option value='' selected>Seleccionar</option></select>";
							}
					 }
			  }
//////////////////////////////////////////////////////////////////////////////////////
//	Modificacion hecha por Evert Noriega el 30 de Marzo de 2011
//	Para agregar Tramites Frecuentes por el Administrador
//	Esta modificacion incluye a los archivos frm_ y el editarfrecuentes.php
function Muestra_archivos(categoria, subcategoria){
	//alert(valcat);
	http.open('get','ajax_consultas.php?op=23&categoria='+categoria+'&subcategoria='+subcategoria);
	http.onreadystatechange = Resp_Muestra_archivos;
	http.send(null);
}
//			 																		//
function Resp_Muestra_archivos(){
	if(http.readyState==4){
		if(http.status==200){
			var resp=http.responseText;
			 //var arr_resp=resp.split('|');
			 //if(arr_resp[0]==1)
		   // {
				//alert(resp);
			document.getElementById('contentarchivo').innerHTML=resp;
			//	}
		}
	}
}
//			 																		//
function Agregar_frecuente(){
	var serie=document.getElementById("archivo").value;
	var orden=document.getElementById("txtOrden").value;
	if(document.getElementById("categoria").value=="")
		alert("Seleccione una categoria.");
	else if(document.getElementById("subcategoria").value=="")
		alert("Seleccione una subcategoria.");
	else if(document.getElementById("archivo").value=="")
		alert("Seleccione un archivo.");
	else if(document.getElementById("txtOrden").value==""||isNaN(document.getElementById("txtOrden").value))
		alert("Escriba un valor numerico para el Orden.");	
	else{
//		alert(document.getElementById("archivo").value);
		http.open('get','ajax_agregatramitefrecuente.php?serie='+serie+'&orden='+orden);
		http.onreadystatechange = Resp_Agregar_frecuente;
		http.send(null);
	}
}
//																					//		 																		//
function Resp_Agregar_frecuente(){
	if(http.readyState==4){
		if(http.status==200){
			var resp=http.responseText;
			if(resp=="1"){
				window.location.href="editarfrecuentes.php";
			}
			else if(resp=="0"){
				alert("El archivo ya existe en la lista.");
			}
		}
	}
}
//																					//
function quitaFrecuente(serie){
	http.open('get','ajax_eliminatramitefrecuente.php?serie='+serie);
	http.onreadystatechange = Resp_quitaFrecuente;
	http.send(null);
}
//																					//
function Resp_quitaFrecuente(){
	if(http.readyState==4){
		if(http.status==200){
			window.location.href="editarfrecuentes.php";
		}
	}
}
//																					//
function GuardaTamano(tramite){
	var tamano=document.getElementById("txtTamanoMenu").value;
	http.open('get','ajax_guardatamano.php?tramite='+tramite+'&tamano='+tamano);
	http.onreadystatechange = Resp_GuardaTamano;
	http.send(null);
}
//																					//
function Resp_GuardaTamano(){
	if(http.readyState==4){
		if(http.status==200){
			var resp=http.responseText;
			if(resp=="1"){
				alert("Se cambió el numero de elementos mostrados a "+document.getElementById("txtTamanoMenu").value);
			}
			else if(resp=="0"){
				alert("Ocurrio un error.");
			}
		}
	}
}
//																					//
function buscaDocumento(e, busqueda){
	evt = (e) ? e : event
	var dKey = (evt.which) ? evt.which : evt.keyCode;
	if(dKey==13){
		//var busqueda=document.getElementById("txtBuscar").value;
		window.location.href="documentos.php?op=buscar&subop="+busqueda;
	}
}
//																					//
function fKeyPress(e,tipo){
	evt = (e) ? e : event
	var dKey = (evt.which) ? evt.which : evt.keyCode;
	if(dKey==13) return;

	switch(tipo){
		case "N": //Numeros - Acepta únicamente numeros
			var arreglo="0123456789";
			if(dKey==8 || dKey==9)return; //Permite pulsacion de Backspace y Tab
			break;
			
		case "F": //Fecha - Acepta únicamente numeros y Diagonal
			var arreglo="0123456789/";
			if(dKey==8)return; //Permite pulsacion de Backspace y Tab
			break;
		
		case "A": //Alfanumerico - Acepta alfanumerico
			//var arreglo='AÁBCDEÉFGHIÍJGKLMNÑOÓPQRSTUÚVWXYZaábcdeéfghiíjklmnñoópqrstuúvwxyz0123456789:;,.-/"*&$#() ';
			var arreglo='ABCDEFGHIJGKLMNOPQRSTUVWXYZabcdefghiíjklmnopqrstuvwxyz0123456789';		
			if(dKey==8 || dKey==9 || dKey==44 || dKey==45 || dKey==46)return; //Permite pulsacion de Backspace, Tab, Coma, Punto y Guion
			break;
		
		case "S": //Alfabetico - Acepta letras y signos especificos
			var arreglo="AÁBCDEÉFGHIÍJGKLMNÑOÓPQRSTUÚVWXYZaábcdeéfghiíjklmnñoópqrstuúvwxyz,.-/ ";		
			if(dKey==8 || dKey==9 || dKey==44 || dKey==45 || dKey==46)return; //Permite pulsacion de Backspace, Tab, Coma, Punto y Guion
			break;
		
		case "L": //ABC - Acepta únicamente letras y espacio
			var arreglo="AÁBCDEÉFGHIÍJGKLMNÑOÓPQRSTUÚVWXYZaábcdeéfghiíjklmnñoópqrstuúvwxyz ";
			if(dKey==8 || dKey==9)return; //Permite pulsacion de Backspace y Tab
			break;
	}
	if (document.all) { //IE
		if(arreglo.indexOf(String.fromCharCode(dKey),0)!=-1){ event.returnValue = true;	}
		else{ event.returnValue = false; }
	}
	else { //Mozilla
		if(arreglo.indexOf(String.fromCharCode(dKey),0)==-1){ if (e.cancelable) { e.preventDefault(); }	}
	}
}
//	Hasta aqui llega la modificación de
//	Evert Noriega
//////////////////////////////////////////////////////////////////////////////////////
function Cambia_selsubcat(valcat,valseriecat)
         {
			  http.open('get','ajax_consultas.php?op=2&catpadre='+valcat+'&seriesubcat='+valseriecat);
					http.onreadystatechange = Resp_Cambia_selsubcat;
					http.send(null);
			 }
///////////////////////////////////////////////////////////////////////////////////
function Resp_Cambia_selsubcat()
          {
			  if(http.readyState==4)
			     {
					 if(http.status==200)
					    {
							var resp=http.responseText;
							 var arr_resp=resp.split('|');
							 if(arr_resp[0]==1)
							    {
									//alert(resp);
									document.getElementById(arr_resp[1]).innerHTML=arr_resp[2];
									}
							}
					 }
			  }
/////////////////////////////////////////////////////////////////////////////////
function Valida_forma_subir_arch()
          {
			  if(document.getElementById('fichero').value=='')
			     {
					 alert('Seleccione un archivo');
					 document.getElementById('fichero').focus();
					 return false;
				}
			  if(document.getElementById('titulo').value=='')
			    {
				     alert('Titulo del documento obligatorio');
					 document.getElementById('titulo').focus();
					 return false;
				}
			 if(document.getElementById('categoria').value=='')
			    {
					 alert('Seleccione una categoria');
					 document.getElementById('categoria').focus();
					 return false;
				}
			  if(document.getElementById('subcategoria').value=='')
			    {
					 alert('Seleccione una subcategoria');
					 document.getElementById('subcategoria').focus();
					 return false;
				}
			  document.getElementById('forma').submit();
			  }
 ////////////////////////////////////////////////////////////////////
 function Checar_tipo_usu(chktipousu)
          {
			 // alert(chktipousuid);
			 /* switch(chktipousuid)
			          {
						  case 'tiposuno':
						        document.getElementById('tiposdos').checked=false;
						  break;
						  case 'tiposdos':
						        document.getElementById('tiposuno').checked=false;
						  break;
					  }*/
			  document.getElementById('tipousualta').value=chktipousu;
			  }
 ///////////////////////////////////////////////////////////////////
 function Limpia_forma_alta()
          {
			  document.getElementById('tipousualta').value='';
			  document.getElementById('tiposuno').checked=false;
			  document.getElementById('tiposdos').checked=false;
			  document.getElementById('nombres').value='';
			  document.getElementById('usuarioalta').value='';
			  document.getElementById('contrasenaalta').value='';
			  document.getElementById('confcontrasenaalta').value='';
			  document.getElementById('nombres').focus();
			  }
 //////////////////////////////////////////////////////////////////
 function Valida_forma_alta()
          {
			  if(document.getElementById('tipousualta').value=='')
			     {
					 alert('Seleccione un tipo de usuario');
					 return false;
				}
			  if(document.getElementById('nombres').value=='')
			    {
				     alert('Nombre de usuario obligatorio');
					 document.getElementById('nombres').focus();
					 return false;
				}
			 if(document.getElementById('usuarioalta').value=='')
			    {
					 alert('Id de usuario obligatorio');
					 document.getElementById('usuarioalta').focus();
					 return false;
				}
			  if(document.getElementById('contrasenaalta').value=='')
			    {
					 alert('Contraseña de usuario obligatoria');
					 document.getElementById('contrasenaalta').focus();
					 return false;
				}
				if(document.getElementById('confcontrasenaalta').value=='')
			    {
					 alert('Confirmar contraseña');
					 document.getElementById('confcontrasenaalta').focus();
					 return false;
				}
				if((document.getElementById('contrasenaalta').value)!=(document.getElementById('confcontrasenaalta').value))
			    {
					 alert('Confirmacion de contraseña incorrecta');
					 document.getElementById('confcontrasenaalta').focus();
					 return false;
				}
			  
			    http.open('get','ajax_consultas.php?op=6&tipousualta='+document.getElementById('tipousualta').value+'&nombres='+document.getElementById('nombres').value+'&usuarioalta='+document.getElementById('usuarioalta').value+'&contrasenaalta='+document.getElementById('contrasenaalta').value);
				http.onreadystatechange=Resp_Valida_forma_alta;
				http.send(null);
			  //document.getElementById('formaalta').submit();
			  }
 ////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////
function Resp_Valida_forma_alta()
         {
			 if(http.readyState==4)
			     {
					 if(http.status==200)
					     {
						   	 var resp=http.responseText;
							 
							 if(resp==1)
							     {
									alert("Alta exitosa");
									Limpia_forma_alta();
									 }
							  else{
								    alert('Ocurrio un error al dar alta.\n');
								  }	 	 
						 }
				 }
		  }
//////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 function Confirma_borrar(valtipoborra,valsubtipoborra,valserieborra,valnombreborra){
  var resp = window.confirm("¿Seguro que desea borrar el archivo:"+valnombreborra+"?");
	
	if(resp)
	     {
			 //alert('ok');
		    http.open('get','ajax_consultas.php?op=4&tipodborrar='+valtipoborra+'&subtipodborrar='+valsubtipoborra+'&seriedborrar='+valserieborra);
					http.onreadystatechange = Resp_Confirma_borrar;
					http.send(null);
		 }
	
}
//////////////////////////////////////////////////////////////////////
function Resp_Confirma_borrar()
         {
			 if(http.readyState==4)
			     {
					 if(http.status==200)
					     {
						   	 var resp=http.responseText;
							 var arr_resp=resp.split('|');
							 if(arr_resp[0]==1)
							     {
									//alert(resp);
									Genera_tabla_docs(arr_resp[1],arr_resp[2]);
									
									 }
							  else{
								    alert('Ocurrio un error al tratar de borrar.\n');
								  }	 	 
						 }
				 }
		  }
//////////////////////////////////////////////////////////////
function Genera_tabla_docs(nomtipo,nomsumtipo)
          {
			   http.open('get','ajax_consultas.php?op=5&valop='+nomtipo+'&valsubop='+nomsumtipo+"&ms="+new Date().getTime());
					http.onreadystatechange = Resp_Genera_tabla_docs;
					http.send(null);
			  }
//////////////////////////////////////////////////////////////
function Resp_Genera_tabla_docs()
          {
			  if(http.readyState==4)
			     {
					 if(http.status==200)
					      {
							  var resp=http.responseText;
							  document.getElementById('respuestadocs').innerHTML=resp;
							  }
					 }
			  
			  }
/////////////codigo del menu//////////////////////////////////

/**********************************************************************************   
SlideMenu 
*   Copyright (C) 2001 Thomas Brattli
*   This script was released at DHTMLCentral.com
*********************************************************************************/
function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=lib_bwcheck()
//Opera didn't seem to like the padding in the layers, it messes up the background-images, so here's a version without it.
if(bw.opera5) document.write("<style>DIV.clSlide{padding:0px; background-image:url(' ')}\nDIV.clSlideSub{padding:0px; background-image:url(' ')}\nDIV.clSlideSub2{padding:0px; background-image:url(' ')}</style>")

/************************************************************************************
Making cross-browser objects
************************************************************************************/
function makeMenuObj(obj,nest){
	nest=(!nest) ? "":'document.'+nest+'.'										
   	this.css=bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+"document.layers." +obj):0;		
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;	
	this.ref=bw.dom || bw.ie4? document:bw.ns4?eval(nest+"document.layers." +obj+".document"):0;		
	this.x=(bw.ns4 || bw.ns5)? this.css.left:this.css.offsetLeft;
	this.y=(bw.ns4 || bw.ns5)? this.css.top:this.css.offsetTop;		
	this.hideIt=b_hideIt; this.showIt=b_showIt; this.movey=b_movey
	this.moveIt=b_moveIt; this.moveBy=b_moveBy; this.status=0; 
	this.bgImg=b_bgImg;	this.obj = obj + "Object"; eval(this.obj + "=this"); 
	this.clipTo=b_clipTo;
	return this
}
function b_showIt(){this.css.visibility="visible"; this.status=1}
function b_hideIt(){this.css.visibility="hidden"; this.status=0}
function b_movey(y){this.y=y; this.css.top=this.y}	
function b_moveIt(x,y){this.x=x; this.y=y; this.css.left=this.x;this.css.top=this.y}
function b_moveBy(x,y){this.x=this.x+x; this.y=this.y+y; this.css.left=this.x;this.css.top=this.y}
function b_bgImg(img){if(bw.ie||bw.dom)this.css.backgroundImage="url("+img+")"
else this.css.background.src=img
}
function b_clipTo(t,r,b,l,w){if(bw.ns4){this.css.clip.top=t;this.css.clip.right=r
this.css.clip.bottom=b;this.css.clip.left=l
}else{this.css.clip="rect("+t+","+r+","+b+","+l+")"; if(w){this.css.width=r; this.css.height=b}}}
/********************************************************************************
Initiating page, making objects..
********************************************************************************/
function SlideMenuInit(){
	oSlideMenu=new makeMenuObj('divSlideCont')
	oSlideMenu.moveIt(menux,menuy)
	oSlide=new Array()
	for(i=0;i<menus.length;i++){
		oSlide[i]=new makeMenuObj('divSlide'+i,'divSlideCont')
		oSlide[i].subs=menus[i].subs
		oSlide[i].sub=new Array()
		oSlide[i].moveIt(0,mainheight*i)
		oSlide[i].starty=oSlide[i].y
    if(bw.opera) oSlide[i].css.paddingLeft="10px"
		if(!menus[i].seperator) oSlide[i].bgImg(level0_regular)
		for(j=0;j<oSlide[i].subs;j++){
			oSlide[i].sub[j]=new makeMenuObj('divSlideSub'+i+"_"+j,'divSlideCont')
			oSlide[i].sub[j].moveIt(10,oSlide[i].y+subheight*j+between)
			oSlide[i].sub[j].starty=oSlide[i].sub[j].y
			oSlide[i][j]=new Array()
			oSlide[i][j].subs=menus[i][j].subs
			oSlide[i][j].sub=new Array()
			img=level1_round
			if(oSlide[i][j].subs!=0){
				if(j!=oSlide[i].subs-1) img=level1_sub
				else img=level1_sub_round
				oSlide[i].sub[j].css.color="white"
			}else{
				if(j!=oSlide[i].subs-1)img=level1_regular
			}
			oSlide[i].sub[j].origimg=img
			oSlide[i].sub[j].bgImg(img)
			for(a=0;a<oSlide[i][j].subs;a++){
				oSlide[i][j].sub[a]=new makeMenuObj('divSlideSub'+i+"_"+j+"_"+a,'divSlideCont')
				oSlide[i][j].sub[a].moveIt(20,oSlide[i].sub[j].y+subheight*a+between-2)
				oSlide[i][j].sub[a].starty=oSlide[i][j].sub[a].y			
				oSlide[i][j][a]=new Array()
				oSlide[i][j][a].subs=menus[i][j][a].subs
				oSlide[i][j][a].sub=new Array()
				if(a!=oSlide[i][j].subs-1) img=level2_regular
				else img=level2_round
				oSlide[i][j].sub[a].origimg=img
				oSlide[i][j].sub[a].bgImg(img)
			}
		}
	}
	oSlideMenu.showIt()
}
/********************************************************************************
Variables
********************************************************************************/
var active=-1;var going;var isthere; var sactive=-1; var sisthere=-1; var s2active=-1; var s2isthere=-1
/********************************************************************************
Switch menu function.
********************************************************************************/
function swmenu(num,snum,s2num){
	if(snum!=-1){
		if(oSlide[num][snum].subs==0) return
	}
	if(s2num!=-1){
		if(oSlide[num][snum][s2num].subs==0) return
	}
	if((num!=active || snum!=sactive || s2num!=s2active) && !going){going=true;isthere=0;sisthere=0;moveUp(num,snum,s2num)}
	
}
/********************************************************************************
Moving the menus upward to their original position.
********************************************************************************/
function moveUp(num,snum){
	if(snum==-1){
		for(i=0;i<oSlide.length;i++){
			if(oSlide[i].y>oSlide[i].starty+pxspeed && active!=i) oSlide[i].moveBy(0,-pxspeed)
			else{if(active!=i) oSlide[i].moveIt(oSlide[i].x,oSlide[i].starty); isthere=i}
		}
		
		if(isthere<oSlide.length-1) setTimeout("moveUp("+num+","+snum+")",timspeed)
		else swmenu2(num,snum)
	}else{
		if(num==oSlide.length-1) isthere=num
	
		if(sactive!=-1){ //Is out!
			//Slide subs
			j=0
			for(i=sactive+1;i<oSlide[num].sub.length;i++){
				j++
				if(oSlide[num].sub[i].y>oSlide[num].sub[i].starty+pxspeed) oSlide[num].sub[i].moveBy(0,-pxspeed)
				else{oSlide[num].sub[i].moveIt(oSlide[num].sub[i].x,oSlide[num].sub[i].starty); sisthere=i}
			}
			//Slide main
			for(i=num+1;i<oSlide.length;i++){
				if(oSlide[i].y>oSlide[i].starty + oSlide[num].sub[sactive].y +subheight*j )  oSlide[i].moveBy(0,-pxspeed)
				else{oSlide[i].moveIt(oSlide[i].x,oSlide[i].starty + oSlide[num].sub[sactive].y +subheight*j ); isthere=i}
			}
		}else{ //Slide to the one clicked
			for(i=num+1;i<oSlide.length;i++){
				if(oSlide[i].y>oSlide[i].starty + snum*between+between)  oSlide[i].moveBy(0,-pxspeed)
				else{oSlide[i].moveIt(oSlide[i].x,oSlide[i].starty + snum*between+between); isthere=i}
			}
		}
		if(isthere<oSlide.length-1 || (sactive!=-1 && sisthere<oSlide[num].sub.length-1 && sactive!=oSlide[num].sub.length-1)) setTimeout("moveUp("+num+","+snum+")",timspeed)
		else swmenu2(num,snum)
	}
}
/********************************************************************************
Switch menu 2, stuff that happens before the menus are moved down again.
********************************************************************************/
function swmenu2(num,snum){
	isthere=0;
	sisthere=0;
	if(active>-1 && snum==-1){
		//Hiding submenus
		for(j=0;j<oSlide[active].subs;j++){oSlide[active].sub[j].hideIt()}
		oSlide[active].bgImg(level0_regular)
		oSlide[active].moveIt(0,oSlide[active].starty)
	}
	if(sactive>-1){
		//Hiding submenus
		for(j=0;j<oSlide[active][sactive].sub.length;j++){oSlide[active][sactive].sub[j].hideIt()}
		oSlide[active].sub[sactive].bgImg(oSlide[active].sub[sactive].origimg)
		oSlide[active].sub[sactive].moveIt(10,oSlide[active].sub[sactive].starty)
		//Move back to place
		for(i=sactive+1;i<oSlide[active].sub.length;i++){
			oSlide[active].sub[i].moveIt(oSlide[active].sub[i].x,oSlide[active].sub[i].starty)
		}
	}
	active=num
	//Showing submenus
	if(snum>-1){
		sactive=snum
		for(j=0;j<oSlide[num][snum].sub.length;j++){oSlide[num][snum].sub[j].showIt()}
		oSlide[num].sub[snum].moveBy(10,3)
		oSlide[num].sub[snum].bgImg(level1_round2)
	}else{
		sactive=-1
		for(j=0;j<oSlide[active].subs;j++){oSlide[active].sub[j].showIt()}
		oSlide[num].moveBy(10,3)
		oSlide[num].bgImg(level0_round)
	}
	if(num!=oSlide.length-1) moveDown(num,snum)
	else{
		isthere=num
		moveDown(num,snum)
	}
}
/********************************************************************************
Moving the menus down
********************************************************************************/
function moveDown(num,snum){
	//if(num==oSlide.length-1) isthere=num
	for(i=num+1;i<oSlide.length;i++){
		if(snum==-1){
			if(oSlide[i].y<(oSlide[num].subs-1)*subheight+oSlide[i].starty+between-pxspeed) oSlide[i].moveBy(0,pxspeed)
			else{oSlide[i].moveIt(oSlide[i].x,(oSlide[num].subs-1)*subheight+oSlide[i].starty+between); isthere=i}
		}else{
			if(oSlide[i].y<(oSlide[num].subs-1)*subheight+oSlide[i].starty+between-pxspeed + (oSlide[num][snum].subs-1)*subheight+between)  oSlide[i].moveBy(0,pxspeed)
			else{oSlide[i].moveIt(oSlide[i].x,(oSlide[num].subs-1)*subheight+oSlide[i].starty+between  + (oSlide[num][snum].subs-1)*subheight+between); isthere=i}
		}
	}
	if(snum!=-1){
		for(i=snum+1;i<oSlide[num].sub.length;i++){		
			if(oSlide[num].sub[i].y<(oSlide[num][snum].subs-1)*subheight+oSlide[num].sub[i].starty+between-pxspeed) oSlide[num].sub[i].moveBy(0,pxspeed)
			else{oSlide[num].sub[i].moveIt(oSlide[num].sub[i].x,(oSlide[num][snum].subs-1)*subheight+oSlide[num].sub[i].starty+between); sisthere=i}
		}
	}
	if(snum==-1){
		if(isthere<oSlide.length-1) setTimeout("moveDown("+num+","+snum+")",timspeed)
		else going=false
	}else{
		if(isthere<oSlide.length-1 || (sisthere<oSlide[num].sub.length-1 && snum!=oSlide[num].sub.length-1)) setTimeout("moveDown("+num+","+snum+")",timspeed)
		else going=false
	}
}
var test=0
/********************************************************************************
Functions to write out the layers...
********************************************************************************/
menus=new Array(); var a=0; var b=0; var c=0; var d=0
function makeMenu(type,text,lnk,target,end){
	str=""; tg="";
  if(target) tg='target="'+target+'"'
  if(!lnk) lnk="#"
  self.status=lnk
	if(a==0) str='<div id="divSlideCont">\n'
	if(type=="top"){
		menus[a]=new Array();
		if(text=="seperator"){
			str+='\t<div id="divSlide'+a+'" class="clSlide"></div>\n'
			menus[a].seperator=1
		}else{
      str+='\t<div id="divSlide'+a+'" class="clSlide"><a href="'+lnk+'" '+tg+' onclick="swmenu('+a+',-1,-1); if(bw.ie || bw.ns6) this.blur(); '
      if(lnk=="#") str+='return false'
      str+='" class="clSlideLinks"> '+text+'</a><br></div>\n'
		}
    menus[a].subs=0; a++; b=0
	}else if(type=="sub"){
		str+='\t\t<div id="divSlideSub'+(a-1)+'_'+(b)+'" class="clSlideSub"><a '+tg+' onclick="swmenu('+(a-1)+','+b+',-1); if(bw.ie || bw.ns6) this.blur(); '
    if(lnk=="#") str+='return false'
    str+='" href="'+lnk+'" class="clSlideSubLinks">  '+text+'</a><br></div>\n'
		b++; menus[a-1].subs=b; menus[a-1][b-1]=new Array(); c=0; menus[a-1][b-1].subs=0
	}else if(type=="sub2"){
		str+='\t\t<div id="divSlideSub'+(a-1)+'_'+(b-1)+'_'+c+'" class="clSlideSub2"><a '+tg+' href="'+lnk+'" class="clSlideSub2Links">  '+text+'</a><br></div>\n'
		c++; menus[a-1][b-1].subs=c; menus[a-1][b-1][c-1]=new Array(); d=0; menus[a-1][b-1][c-1].subs=0
	}
	if(end) str+="</div>"
	document.write(str)
}
function preLoadBackgrounds(){
  for(i=0;i<arguments.length;i++){
    this[i]=new Image()
    this[i].src=arguments[i]
  }
  return this
}

//Variables to set
between=28 //The pixel between the menus and the submenus
mainheight=25 //The height of the mainmenus
subheight=22 //The height of the submenus
pxspeed=13 //The pixel speed of the animation
timspeed=15 //The timer speed of the animation
menuy=280 //The top placement of the menu.
menux=500 //The left placement of the menu
//Images - Play with these
level0_regular="imgsmenu/level0_regular.gif"
level0_round="imgsmenu/level0_round.gif"
level1_regular="imgsmenu/level1_regular.gif"
level1_round="imgsmenu/level1_round.gif"
level1_sub="imgsmenu/level1_sub.gif"
level1_sub_round="imgsmenu/level1_sub_round.gif"
level1_round2="imgsmenu/level1_round2.gif"
level2_regular="imgsmenu/level2_regular.gif"
level2_round="imgsmenu/level2_round.gif"

//Leave this line
preLoadBackgrounds(level0_regular,level0_round,level1_regular,level1_round,level1_sub,level1_sub_round,level1_round2,level2_regular,level2_round)

//There are 3 different types of menus you can make
//top = Main menus
//sub = Sub menus
//sub2 = SubSub menus

//You control the look of the menus in the stylesheet

//makeMenu('TYPE','TEXT','LINK','TARGET', 'END (THE LAST MENU)')

/////////////////////////////fin codigo////////////////////////////////////////////////////////////////////////////
