/*
Avanza con la tecla ENTER 
*/
function fn(form,field) {
         var next  = 0
         var found = false
         var f     = form
         if (event.keyCode != 13) {
             return
         }
         for (var i = 0; i < f.length; i++) {
              if (field.id == f.item(i).id) {
                  next  = i + 1;
                  found = true
                  break;
              }
         }
         if (f.length > next) {
             while (found) {
                    if (f.item(next).disabled == false && f.item(next).type != 'hidden') {
                        f.cControlA.value = f.item(next).id
                        f.item(next).focus();
                        f.item(next).select();
                        break;
                    } else {
                           if (next < f.length-1 ) {
                               next = next + 1;
                           } else {
                                  break;
                           }
                    }
             }
         }
}

/*
Aceptar solo numeros 
onKeyPress="return soloNumeros(event)" 
*/
function teclaVirtual(valor,form,control) {
         var Campo = document.getElementById(control);
         if (valor == "") {
             Campo.value = "";
         } else {
                if (Campo.value != "") {
                    Campo.value = Campo.value + valor;
                } else {
                       Campo.value = valor;
                }
         }
}
/*
Aceptar solo numeros 
onKeyPress="return soloNumeros(event)" 
*/
function soloNumeros(e) { 
         tecla = (document.all) ? e.keyCode : e.which;
         if (tecla == 8 || tecla == 9) {
             return true;
         }
         patron =/[0-9\.]/;
         te = String.fromCharCode(tecla);
         return patron.test(te);
} 
/*
Elimina Espacios (trim()) 
*/
function trim(cadena) {
         for (i = 0; i < cadena.length; )   {
              if (cadena.charAt(i) == " ") {
                  cadena = cadena.substring(i+1, cadena.length)
              } else {
                      break;
              }
         }

         for (i = cadena.length-1; i >= 0; i = cadena.length-1) {
              if (cadena.charAt(i) == " ") {
                  cadena = cadena.substring(0,i);
              } else {
                      break;
              }
         }
         return cadena
}
/*
Carga Fecha Actual 
*/
MesesN = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
MesesP = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12");

function FechaActual(pForm,pFec1,pFec2,pFec3,pFec4,pHora) {
         var Ahora    = new Date()
         var Hour     = Ahora.getHours()
         var Minute   = Ahora.getMinutes()
         var HoraPas  = "" + Hour 
         var FechaPas = ""
         with (document.forms[pForm]) {
               if (Ahora.getDate() < 10) {
                   FechaPas = "0" + Ahora.getDate() + "-" + MesesN[Ahora.getMonth()] + "-" + Ahora.getYear()
               } else {
			          FechaPas = Ahora.getDate() + "-" + MesesN[Ahora.getMonth()] + "-" + Ahora.getYear()
			   }
			   
               if (Hour < 10) {
                   HoraPas = "0" + Hour
			   }
			   
               if (Hour == 0) {
                   HoraPas = "00";
			   }
			   
               HoraPas += ((Minute < 10) ? ":0" : ":") + Minute
			   
			   if (pFec1 == null || pFec1 == "") {
			   } else {
			          Fecha1 = eval(pFec1)
				      if (Fecha1.value == "") {
                          Fecha1.value = FechaPas
				      }
			   }
			   if (pFec2 == null || pFec2 == "") {
			   } else {
			          Fecha2 = eval(pFec2)
				      if (Fecha2.value == "") {
                          Fecha2.value = FechaPas
				      }
			   }
			   if (pFec3 == null || pFec3 == "") {
			   } else {
			          Fecha3 = eval(pFec3)
				      if (Fecha3.value == "") {
                          Fecha3.value = FechaPas
				      }
			   }
			   if (pFec4 == null || pFec4 == "") {
			   } else {
			          Fecha4 = eval(pFec4)
				      if (Fecha4.value == "") {
                          Fecha4.value = FechaPas
				      }
			   }
			   if (pHora == null || pHora == "") {
			   } else {
			          Hora1 = eval(pHora)
                      Hora1.value = HoraPas
			   }
         }
}
