function valorLista (lista) {
   oplista = lista.options[lista.selectedIndex]
   return oplista.value
}
function textoLista (lista) {
   oplista = lista.options[lista.selectedIndex]
   return oplista.text
}
function selecValorLista (lista, dato) {
   for (var i = 0; i < lista.length; i++) {
      if (lista.options[i].value == dato) {
         lista.selectedIndex = i;
         return
      }
   }
// Si no encuentra la opción intenta buscar una nula
   for (var i = 0; i < lista.length; i++) {
      if (lista.options[i].value == "") {
         lista.selectedIndex = i;
         return
      }
   }
}
function selecTextoLista (lista, texto) {
   for (var i = 0; i < lista.length; i++) {
      if (lista.options[i].text == texto) {
         lista.selectedIndex = i;
         return
      }
   }
// Si no encuentra la opción intenta buscar una nula
   for (var i = 0; i < lista.length; i++) {
      if (lista.options[i].text == "") {
         lista.selectedIndex = i;
         return
      }
   }
}
function valorRadio (radio) {
  for (i=0; i < radio.length; i++) {
    if (radio[i].checked)
      return radio[i].value
  }
  return ""
}
function indiceRadio (radio) {
  if (radio.length)
    for (i=0; i < radio.length; i++) {
      if (radio[i].checked)
        return i+1
    }
  else
    if (radio.checked)
      return 1
  return ""
}
function estadoCheckBox (chbox, estado) {
  if (chbox.length)
    for (i=0; i <chbox.length; i++)
      chbox[i].checked = estado
  else
    chbox.checked = estado
}
function invertirCheckBox (chbox) {
  if (chbox.length)
    for (i=0; i <chbox.length; i++)
      chbox[i].checked = ! chbox[i].checked
  else
    chbox.checked = ! chbox.checked
}
function marcasCheckBox (chbox) {
  var n = 0
  if (chbox.length)
    for (i=0; i < chbox.length; i++) {
      if (chbox[i].checked)
        n++
    }
  else if (chbox.checked)
    n++
  return n
}
function submitOnClick(frm) {
  if (Validar(frm))
    frm.submit()
}
function botonOnClick (frm, validar) {
  eval ("var ok = "+validar+"(document."+frm.name+")")
    if (ok)
      frm.submit()
}
function esEnteroPositivo (p_str) {
  for (var i = 0; i < p_str.length; i++) {
    var v_pos = p_str.charAt(i)
    if (v_pos < "0" || v_pos > "9")
        return false
  }
  return true
}
function valNulo (campo, msg){
  if (campo.value == "") {
    campo.focus(); alert (msg); return false;
  }
  return true
}     
function valNuloLista (lista, msg) {
  if (!valorLista (lista)) {
    lista.focus(); alert (msg); return false;
  }
  return true
}     
function valLargoMin (campo, largo, msg) {
  if (campo.value.length < largo) {
    campo.focus(); alert (msg); return false;
  }
  return true
} 
function valLargoMax (campo, largo, msg) {
  if (campo.value.length > largo) {
    campo.focus(); alert (msg); return false;
  }
  return true
} 
function valAnio (campo, msg) {
  if (!esEnteroPositivo (campo.value)) {
    campo.focus(); alert (msg); return false;
  }
  return true
}
function anioOnChange (campo) {
  if (campo.value != "")
    if (esEnteroPositivo (campo.value)) {
      if (campo.value < 100)
        campo.value = (campo.value > 20) ? 1900 + Math.abs(campo.value):
          2000 + Math.abs(campo.value);
    } else {
       alert ("El Año ingresado es inválido")
       campo.focus()
    }
}
