	var escolegiado = false;
	var dtCh= "/";
	var minYear;
	var maxYear;
  var childActive = null 
  var menuActive = null
  var lastHighlight = null
  var active = false
	
	function ValidoCP(cadena){ 
    CPValido=true 
    
    //si no tiene 5 caracteres no es válido 
   if (cadena.length != 5) 
         CPValido=false 
      else{ 
         for (i=0;i<5;i++){ 
       			
            CActual = cadena.charAt(i) 
            if (!validarEntero(CActual)){ 
               CPValido=false 
               break; 
            } 
         } 
      } 
  	return CPValido 
	}
	
	function UserValido(cadena){ 
		cadena = trim(cadena)
		
		if (cadena.length < 6) {
		 	return false 
    } else { 
    	for (i=0;i<cadena.length;i++) { 
    		CActual = cadena.charAt(i)
     	 	if (trim(CActual)==''){ 
     	 		return false
     	   	break; 
    		} 
    	}
    } 
  	return true
	}
	
	function validarEntero(valor){ 
      //intento convertir a entero. 
      //si era un entero no le afecta, si no lo era lo intenta convertir 
       valor = parseInt(valor) 
			
      //Compruebo si es un valor numérico 
      if (isNaN(valor)) { 
         //entonces (no es numero) devuelvo el valor cadena vacia 
         return false 
      		
      }else{ 
         //En caso contrario (Si era un número) devuelvo el valor 
         return true 
      } 
	} 

	function colegiado(formulario){
		
		if(document.forms[formulario].tipousuario.checked ){
			escolegiado = true;	
		}else{
			escolegiado = false;	
		}
	}
	
	function rellenarAnyos(masAnyos){
	       
	        var anio;
	        cadena = "";
	        ahora  = new Date();
					ahoraYear = ahora.getYear();
					cadena = "<option  SELECTED> A&ntilde;o </option>";
					maxYear = ahoraYear;
	        for (i=0; i<masAnyos; i++)
	        {
	        		anio = ahoraYear - i;
	            cadena += "<option value ='" + anio +"'>" + anio + "</option>";
	           
	        }
	        minYear = anio;
	        return cadena;
	}     
	
	function validar_formulario(formulario){
		
		var anio; 
		var dia;
		var mes; 
		
		colegiado("form1");
		
	  if((document.forms['form1'].anio.value!='')||
	  	 (document.forms['form1'].dia.value!='')||
	  	 (document.forms['form1'].mes.value!='')){	
					
					anio =  document.forms['form1'].anio.value; 
					dia = document.forms['form1'].dia.value; 
					mes = document.forms['form1'].mes.value; 
					document.forms['form1'].fechanacimiento.value =dia + '/'+ mes +'/' + anio  ;
		
		}
		// ********************************************************************
		// NOMBRE
		// ********************************************************************
		if (
				(trim(document.forms['form1'].nombreusuario.value) == "")  || 
				(document.forms['form1'].nombreusuario.value == null) || 
				(isNaN(document.forms['form1'].nombreusuario.value)==false)
			 ) { 
							alert('Introduzca un nombre valido');
							document.forms['form1'].nombreusuario.focus();	
							
		// ********************************************************************
		// APELLIDO 1
		// ********************************************************************
		} else if (
							(trim(document.forms['form1'].apellido1.value) == "")  || 
							(document.forms['form1'].apellido1.value == null) || 
							(isNaN(document.forms['form1'].apellido1.value)==false)
			 			 ) { 
							alert('Introduzca un primer apellido valido');
							document.forms['form1'].apellido1.focus();	
							
		// ********************************************************************
		// APELLIDO 2 
		// ********************************************************************
		} else if (
							(trim(document.forms['form1'].apellido2.value) == "")  || 
							(document.forms['form1'].apellido2.value == null) || 
							(isNaN(document.forms['form1'].apellido2.value)==false)
			 		  ) {
							alert('Introduzca un segundo apellido valido');
							document.forms['form1'].apellido2.focus();	
							
		// ********************************************************************
		// DIRECCION
		// ********************************************************************
		} else if (
							(trim(document.forms['form1'].direccion.value) == "") || 
							(document.forms['form1'].direccion.value == null) || 
							(isNaN(document.forms['form1'].direccion.value)==false)
			 			) {
							alert('Introduzca una direccion valida');
							document.forms['form1'].direccion.focus();	
							
		// ********************************************************************
		// LOCALIDAD
		// ********************************************************************
		} else if (
							(trim(document.forms['form1'].localidad.value) == "") || 
							(document.forms['form1'].localidad.value == null) || 
							(isNaN(document.forms['form1'].localidad.value)==false)
			 			) {
							alert('Introduzca una localidad valida');
							document.forms['form1'].localidad.focus();
							
		// ********************************************************************
		// CODIGO POSTAL
		// ********************************************************************
		} else if (
							(trim(document.forms['form1'].cp.value)== "") ||
							(!ValidoCP(document.forms['form1'].cp.value))
						){
							alert('Introduzca un codigo postal valido');
							document.forms['form1'].cp.focus();
							
		// ********************************************************************
		// PROVINCIA
		// ********************************************************************
		} else if (document.forms['form1'].provincia.value == "") {
							alert('Introduzca la provincia');
							document.forms['form1'].provincia.focus();	
							
		// ********************************************************************
		// PROVINCIA - PAIS
		// ********************************************************************
		}	else if (
								(
									(document.forms['form1'].provincia.value == "100") &&
									(document.forms['form1'].pais.value == "724")
								) ||
								(
									(document.forms['form1'].provincia.value != "100") &&
									(document.forms['form1'].pais.value != "724")
								)
							) {
							alert('La provincia y pais no corresponden');
							
		// ********************************************************************
		// NIF
		// ********************************************************************
		} else if (!validar_nif(document.forms['form1'].nif.value)) {    
							document.forms['form1'].nif.focus();
							alert("Su NIF o NIE no es valido");	
							
		// ********************************************************************
		// FECHA NACIMIENTO
		// ********************************************************************
		} else if (
							(document.forms['form1'].fechanacimiento.value != "")  &&
				  		(isDate(document.forms['form1'].fechanacimiento.value,'form1') == false)
				  	) {
							alert ("Introduzca una fecha valida");
							
		// ********************************************************************
		// EMIL PERSONAL
		// ********************************************************************
		} else if(!esMailValido(document.forms['form1'].email.value)) {
							alert('Introduzca un e-mail valido');
							document.forms['form1'].email.focus();	
								
		// ********************************************************************
		// TELEFONO
		// ********************************************************************
		} else if ( 
								(trim(document.forms['form1'].telefono.value) != "") && 
								(
									(document.forms['form1'].telefono.value.length < 9) || 
									(isNaN(document.forms['form1'].telefono.value) != false)
								)
							) {
	 						alert("El telefono debe ser numerico de 9. Puede dejarlo en blanco si lo desea."); 
							document.forms['form1'].telefono.focus();
							
		// ********************************************************************
		// LOGIN
		// ********************************************************************
		} else if (
								(formulario=="registro") && 
								(
									(trim(document.forms['form1'].login.value) == "")  || 
									(document.forms['form1'].login.value == null) ||
									(!UserValido(document.forms['form1'].login.value))
								)
		 		 			) {
								alert('Introduzca NOMBRE USUARIO. Minimo 6 caracteres. Sin espacios en blanco');
								document.forms['form1'].login.focus();	
								
		// ********************************************************************
		// PASSWORD
		// ********************************************************************
		} else if (
								(formulario=="registro") && 
								(
									(trim(document.forms['form1'].contrasena.value) == "")  || 
									(document.forms['form1'].contrasena.value == null) ||
									(!UserValido(document.forms['form1'].contrasena.value))
								)
			 			 	) {
								alert('Introduzca PASSWORD. Minimo 6 caracteres. Sin espacios en blanco');
								document.forms['form1'].contrasena.focus();	
								 
		// ********************************************************************
		// PASSWORD 2
		// ********************************************************************
		} else if (
								(formulario=="registro") && 
								(
									document.forms['form1'].logincontrasena2.value != document.forms['form1'].contrasena.value
			 			 		)
			 			 	) {
								alert('Verifique que las passwords coinciden');
								document.forms['form1'].logincontrasena2.focus();
							
		} else {
						if (
								(!escolegiado) &&
								(
									(document.forms['form1'].provinciacolegio.value != "") ||
									(document.forms['form1'].numerocolegiado.value != "") ||
									(document.forms['form1'].emailcolegio.value != "")
								)
							 ){
							 	alert('Si no es colegiado, no debe introducir ni mail-colegio, ni numero-colegiado, ni provincia-colegio');
								document.forms['form1'].emailcolegio.focus();
					
							// ********************************************************************
							// EMAIL COLEGIO
							// ********************************************************************
						} else if( 
												(escolegiado)&&
												(!esMailValido(document.forms['form1'].emailcolegio.value)) &&
												(document.forms['form1'].emailcolegio.value != "")
											) {
												alert('Introduzca correctamente su email del colegio');
												document.forms['form1'].emailcolegio.focus();
												
							// ********************************************************************
							// NUMERO COLEGIADO
							// ********************************************************************
						} else if(
												(escolegiado) &&
												(trim(document.forms['form1'].numerocolegiado.value) == "")
											){
												alert('Introduzca correctamente su numero de colegiado');
												document.forms['form1'].numerocolegiado.focus();
												
							// ********************************************************************
							// PROVINCIA COLEGIO
							// ********************************************************************
						} else if(
												(escolegiado) &&
												(document.forms['form1'].provinciacolegio.value == "")
											){
								alert('Introduzca la provincia en la que esta colegiado');
								document.forms['form1'].provinciacolegio.focus();
						} else {
							document.forms['form1'].submit();
						}
		}
		
	}

	

		
	function trim(cadena) {
   		nCadena = rightTrim(cadena);
   		nCadena = leftTrim(nCadena)
   		return nCadena;
	}

	function rightTrim(cadena) {
	   while( (''+cadena.charAt(cadena.length-1)==' ') 
	         || (''+cadena.charAt(cadena.length-1)=="\n"))
	      cadena=cadena.substring(0,cadena.length-1);
	   return cadena;
	}



	function leftTrim(cadena) {
	   while( (''+cadena.charAt(0)==' ')
	         || (''+cadena.charAt(cadena.length-1)=="\n"))
	      cadena=cadena.substring(1,cadena.length);
	   return cadena;
	}
	function validar_nif ( nif ) {
	 var v_nif = trim(nif);
	 var v_tipo = 0;
	 var v_valido = 0;
	 var v_Aux = "";
	  if(v_nif.length>10){
	  	return false;
	  }
	  
	  //Por el primer caracter, comprobamos si se trata de un NIF o un NIE
	  // En v_nif hay que quitar los espacios por la izquierda.
	  while ( v_nif.charAt(0) == " ") {
	    v_nif = v_nif.substr ( 1 , v_nif.length - 1 );
	  }
	  v_Aux = v_nif.charAt( 0 );
	  if ( v_Aux >= 0 && v_Aux <= 9 ) {
	    // Es un NIF
	    v_tipo = 1;
	  }
	  else if ( v_Aux >= "X" ) {
	    // Es un NIE
	    v_tipo = 2;
	  }
	  else {
	    v_tipo = 0;
	    v_valido = 1;
	  }
	  
	  //Tratamos los NIF
	  if ( v_tipo == 1 ) {
	    var v_Tabla_Letras = "TRWAGMYFPDXBNJZSQVHLCKE";
	    var v_Letra_NIF = null;
	    var v_Numero_NIF = "";
	  
	    // Este bucle separa el nmero del NIF (v_Numero_NIF) y la letra (v_Letra_NIF).
	    // Tambin quita todos los caracteres que no son numricos, y se queda con la
	    // ltima letra, si existe.
	    for ( i = 0; i < v_nif.length-1; i++ ) {
	      v_Aux = v_nif.charAt( i );
	    
	      if ( v_Aux >= 0 && v_Aux <= 9 ) {
	        v_Numero_NIF += "" + v_Aux;
	      }else {
	        v_valido = 2;
	      }
	    }
	    v_Aux =  v_nif.charAt(v_nif.length-1).toUpperCase();
	   
	    if ( v_Aux >= "A" && v_Aux <= "Z" ) {
	          v_Letra_NIF = v_Aux;
	    }
	  
	    if ( v_Numero_NIF.length > 8 ) {
	      v_valido = 2;
	    }
	    else {
	      if ( v_Numero_NIF.length < 8 ) {
	        while ( v_Numero_NIF.length < 8 ) {
	          v_Numero_NIF = "0" + v_Numero_NIF;
	        }
	      }
	      if ( v_Letra_NIF != null ) {
	        v_nif = v_Numero_NIF + "" + v_Letra_NIF;
	      }
	      else {
	        v_valido = 2;
	      }
	    }
	  }
	  
	  //Tratamos los NIE
	  if ( v_tipo == 2 ) {
	    var v_Letra_NIE1 = null;
	    var v_Letra_NIE2 = null;
	    var v_Numero_NIE = "";
	    var v_nie = "";
	  
	    // Este bucle separa el nmero del NIE (v_Numero_NIE) y las letras (v_Letra_NIE1 y v_Letra_NIE2).
	    v_Letra_NIE1 = v_nif.charAt( 0 ).toUpperCase();
	    
	    for ( i = 1; i < v_nif.length-1; i++ ) {
	      v_Aux = v_nif.charAt( i );
	    
	      if ( v_Aux >= 0 && v_Aux <= 9 ) {
	        v_Numero_NIE += "" + v_Aux;
	      }else {
	        v_valido = 3;
	      }
	    }
	    v_Aux =  v_nif.charAt(v_nif.length-1).toUpperCase();
	   
	    if ( v_Aux >= "A" && v_Aux <= "Z" ) {
	          v_Letra_NIE2 = v_Aux;
	    }
	
	    if ( v_Numero_NIE.length <= 7 ) {
	      while ( v_Numero_NIE.length < 7 ) {
	        v_Numero_NIE = "0" + v_Numero_NIE;
	      }
	      if ( v_Letra_NIE1 == "X" ) {
	        if ( v_Letra_NIE2 != null ) {
	          v_nie = v_Letra_NIE1 + "" + v_Numero_NIE + "" + v_Letra_NIE2;
	        }
	        else {
	          v_valido = 3;
	        }
	      }
	      else {
	        v_valido = 3;
	      }
	    }
	    else {
	      v_valido = 3;
	    }
	  }
	  
	  if ( v_tipo == 0 ) {
	//    alert("ERROR EN EL TIPO DE NIF/NIE");
	    return false;
	  }
	  else {
	    if ( v_valido == 2 ) {
	//      alert("ERROR EN EL FORMATO DE NIF");
	      return false;
	    }
	    else {
	      if ( v_valido == 3 ) {
	//        alert("ERROR EN EL FORMATO DE NIE");
	        return false;
	      }
	      else {
	      //La validacion de formato es correcta, validamos ahora la letra del NIF
	        if ( v_tipo == 1 ) {
	          // Ahora, en v_Aux, metemos la letra correcta del nmero V_Numero_NIF.
	          v_Aux = v_Tabla_Letras.charAt ( v_Numero_NIF % 23 );
	          if ( v_Letra_NIF != v_Aux ) {
	//            alert("LA LETRA DEL NIF NO ES VALIDA");
	            return false;
	          }
	          else {
	            return true;
	          }
	        }
	        else {
	          return true;
	        }
	      }
	    }
	  }
	}

	
	
	function esMailValido(cadena){
    	
    	var s = cadena;
    	tieneEspacio = false;
    	tieneArroba = false;
    	primeroArroba = 0;
    	tienePunto = false;
    	segundoPunto = 0;
    	texArray = new Array();

    	for (i = 0;  i < s.length;  i++){
        	if (s.charAt(i) == ' '){
            	tieneEspacio = true;
			}else if (s.charAt(i) == '@'){
            	tieneArroba = true;
            	primeroArroba = i;
        	}else if (s.charAt(i) == '.'){
            	tienePunto = true;
            	segundoPunto = i;
        	}else{
            	texArray[i]=0;
            }	
    	}

    	return((texArray[primeroArroba-1]==0 )&&
    		   (texArray[segundoPunto-1]==0 )&& 
           	   (texArray[segundoPunto+1]==0 )&& 
           	   (tieneEspacio == false )&&  
               (tieneArroba == true )&&  
               (tienePunto == true ) &&  
               (primeroArroba<segundoPunto ));
   	}
	function isInteger(s){
		var i;
    	for (i = 0; i < s.length; i++){   
        	
        	var c = s.charAt(i);
        	if (((c < "0") || (c > "9"))) return false;
    	}
    	return true;
	}

	function stripCharsInBag(s, bag){
		var i;
	    var returnString = "";
		for (i = 0; i < s.length; i++){   
        	var c = s.charAt(i);
        	if (bag.indexOf(c) == -1) returnString += c;
    	}
    	return returnString;
	}

	function daysInFebruary (year){
		return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
	function DaysArray(n) {
		for (var i = 1; i <= n; i++) {
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
   		} 
   		return this
	}

	function isDate(dtStr,formulario){
		
		var daysInMonth = DaysArray(12);
		var pos1=dtStr.indexOf(dtCh);
		var pos2=dtStr.indexOf(dtCh,pos1+1);
		
		var strDay=dtStr.substring(0,pos1);
		var strMonth=dtStr.substring(pos1+1,pos2);
		var strYear=dtStr.substring(pos2+1);  
		
		
		strYr=strYear
		
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
		
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr)
		if (pos1==-1 || pos2==-1){
			alert("El formato fecha deberia ser: dd/mm/yyyy")
			return false
		}
		if (strMonth.length<1 || month<1 || month>12){
			alert("Introduzca un mes valido.");
			document.forms[formulario].mes.focus();
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			alert("Introduzca un dia valido.");
			document.forms[formulario].dia.focus();
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			alert("Introduzca un año valido.");
			document.forms[formulario].anio.focus();
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			document.forms[formulario].dia.focus();
			alert("Introduzca una fecha valida.")
			return false
		}
		return true
	}
	
	    function getReal(el) {
      // Find a table cell element in the parent chain */
      temp = el
      while ((temp!=null) && (temp.tagName!="TABLE") && (temp.className!="root") && (temp.id!="menuBar")) {
        if (temp.tagName=="TD")
          el = temp
        temp = temp.parentElement
      }
      return el
    }

    function raiseMenu(el) {
    }

    function clearHighlight(el) {
      if (el==null) return
    }

    function sinkMenu(el) {
    }

    function menuHandler(menuItem) {
      return true
    }

    function getOffsetPos(which,el,tagName) {
      var pos = 0 
      while (el.tagName!=tagName) {
        pos+=el["offset" + which]
        el = el.offsetParent
      }
      return pos	
    }

    function getRootTable(el) {
      el = el.offsetParent
      if (el.tagName=="TR") 
        el = el.offsetParent
      return el
    }

    function getElement(el,tagName) {
      while ((el!=null) && (el.tagName!=tagName) )
        el = el.parentElement
      return el
    }

    function processClick() {
      var el = getReal(event.srcElement)
      if ((getRootTable(el).id=="menuBar") && (active)) {        
        cleanupMenu(menuActive)
        clearHighlight(menuActive)
        active=false
        lastHighlight=null
        doHighlight(el)
      }
      else {
        if ((el.className=="root") || (!menuHandler(el)))
          doMenuDown(el)
        else {
          if (el._childItem==null) 
            el._childItem = getChildren(el)
          if (el._childItem!=null)  return;
          if ((el.id!="break") && (el.className!="disabled") && (el.className!="disabledhighlight") && (el.className!="clear"))  {
            if (menuHandler(el)) {
              cleanupMenu(menuActive)
              clearHighlight(menuActive)
              active=false
              lastHighlight=null
            }
          }
        }
      }
    }

    function getChildren(el) {
      var tList = el.children.tags("TABLE")
      var i = 0
      while ((i<tList.length) && (tList[i].tagName!="TABLE"))
        i++
      if (i==tList.length)
        return null
      else
        return tList[i]
    }

    function doMenuDown(el) {
      if (el._childItem==null) 
        el._childItem = getChildren(el)
      if ((el._childItem!=null) && (el.className!="disabled") && (el.className!="disabledhighlight")) {
        ch = el._childItem
        if (ch.style.display=="block") {
          removeHighlight(ch.active)
          return
        }
        ch.style.display = "block"
        if (el.className=="root") {
          ch.style.pixelTop = el.offsetHeight + el.offsetTop + 2
          ch.style.pixelLeft = el.offsetLeft + 1
	  if (ch.style.pixelWidth==0)
            ch.style.pixelWidth = ch.rows[0].offsetWidth+15
          sinkMenu(el)
          active = true
          menuActive = el
        } else {
          childActive = el
          ch.style.pixelTop = getOffsetPos("Top",el,"TABLE") -3 
          ch.style.pixelLeft = el.offsetLeft + el.offsetWidth
	  if (ch.style.pixelWidth==0)
            ch.style.pixelWidth = ch.offsetWidth+15
        }     
      }
    }
 
    function doHighlight(el) {
      el = getReal(el)
      if ("root"==el.className) {
        if ((menuActive!=null) && (menuActive!=el)) {
          clearHighlight(menuActive)
        }
        if (!active) {
          raiseMenu(el)
        }          
        else 
          sinkMenu(el)
        if ((active) && (menuActive!=el)) {
          cleanupMenu(menuActive)          
          doMenuDown(el)
        }
        menuActive = el  
        lastHighlight=null
      }
      else {
        if (childActive!=null) 
          if (!childActive.contains(el)) 
            closeMenu(childActive, el)    

        if (("TD"==el.tagName) && ("clear"!=el.className)) {
          var ch = getRootTable(el)         
          if (ch.active!=null) {
            if (ch.active!=el) {
              if (ch.active.className=="disabledhighlight")  
                ch.active.className="disabled"
              else
                ch.active.className=""
              }
            }
          ch.active = el
          lastHighlight = el
          if ((el.className=="disabled") || (el.className=="disabledhighlight") || (el.id=="break")) 
            el.className = "disabledhighlight"
          else {
            if (el.id!="break") {
              el.className = "highlight"
              if (el._childItem==null) 
                el._childItem = getChildren(el)
              if (el._childItem!=null) {
                doMenuDown(el)
              }
            }  
          }
        }
      }
    }

    function removeHighlight(el) {
      if (el!=null)
        if ((el.className=="disabled") || (el.className=="disabledhighlight"))  
          el.className="disabled"
        else
          el.className=""
    }

    function cleanupMenu(el) {
      if (el==null) return
      for (var i = 0; i < el.all.length; i++) {
        var item = el.all[i]
        if (item.tagName=="TABLE")
         item.style.display = ""
        removeHighlight(item.active)
        item.active=null
      }
    }


    function closeMenu(ch, el) {
      var start = ch
      while (ch.className!="root") {
          ch = ch.parentElement
          if (((!ch.contains(el)) && (ch.className!="root"))) {
            start=ch
          }
      }
      cleanupMenu(start)
    }
 
    function checkMenu() {      
      if (document.all.menuBar==null) return
      if ((!document.all.menuBar.contains(event.srcElement)) && (menuActive!=null)) {
        clearHighlight(menuActive)
        closeMenu(menuActive)
        active = false
        menuActive=null
        choiceActive = null
      }
    }

    function doCheckOut() {
      var el = event.toElement      
      if ((!active) && (menuActive!=null) && (!menuActive.contains(el))) {
        clearHighlight(menuActive)
        menuActive=null
      }
    }


    function processKey() {
      if (active) {
        switch (event.keyCode) {
         case 13: lastHighlight.click(); break;
         case 39:  // right
           if ((lastHighlight==null) || (lastHighlight._childItem==null)) {
             var idx = menuActive.cellIndex
//             if (idx==menuActive.offsetParent.cells.length-2)
             if (idx==getElement(menuActive,"TR").cells.length-2)
               idx = 0
             else
               idx++
             newItem = getElement(menuActive,"TR").cells[idx]
           } else
           {
             newItem = lastHighlight._childItem.rows[0].cells[0]
           }
           doHighlight(newItem)
           break; 
         case 37: //left
           if ((lastHighlight==null) || (getElement(getRootTable(lastHighlight),"TR").id=="menuBar")) {
             var idx = menuActive.cellIndex
             if (idx==0)
               idx = getElement(menuActive,"TR").cells.length-2
             else
               idx--
             newItem = getElement(menuActive,"TR").cells[idx]
           } else
           {
             newItem = getElement(lastHighlight,"TR")
             while (newItem.tagName!="TD")
               newItem = newItem.parentElement
           }
           doHighlight(newItem)
           break; 
         case 40: // down
            if (lastHighlight==null) {
              itemCell = menuActive._childItem
              curCell=0
              curRow = 0
            }
            else {
              itemCell = getRootTable(lastHighlight)
              if (lastHighlight.cellIndex==getElement(lastHighlight,"TR").cells.length-1) {
                curCell = 0
                curRow = getElement(lastHighlight,"TR").rowIndex+1
                if (getElement(lastHighlight,"TR").rowIndex==itemCell.rows.length-1)
                  curRow = 0
              } else {
                curCell = lastHighlight.cellIndex+1
                curRow = getElement(lastHighlight,"TR").rowIndex
              }
            }
            doHighlight(itemCell.rows[curRow].cells[curCell])
            break;
         case 38: // up
            if (lastHighlight==null) {
              itemCell = menuActive._childItem
              curRow = itemCell.rows.length-1
              curCell= itemCell.rows[curRow].cells.length-1

            }
            else {
              itemCell = getRootTable(lastHighlight)
              if (lastHighlight.cellIndex==0) {
                curRow = getElement(lastHighlight,"TR").rowIndex-1
                if (curRow==-1)
                  curRow = itemCell.rows.length-1
                curCell= itemCell.rows[curRow].cells.length-1

              } else {
                curCell = lastHighlight.cellIndex - 1
                curRow = getElement(lastHighlight,"TR").rowIndex
              }
            }
            doHighlight(itemCell.rows[curRow].cells[curCell])
            break;
           if (lastHighlight==null) {
              curCell = menuActive._childItem
              curRow = curCell.rows.length-1
            }
            else {
              curCell = getRootTable(lastHighlight)
              if (getElement(lastHighlight,"TR").rowIndex==0)
                curRow = curCell.rows.length-1
              else
                curRow = getElement(lastHighlight,"TR").rowIndex-1
            }
            doHighlight(curCell.rows[curRow].cells[0])
            break;
        }
      }
    }

	function MyRedirect( strSource ) {
    if (document.all.navLink.href!=strSource ) {
      document.all.navLink.href = strSource
      document.all.navLink.click()
    }
	}
	
    