  // Al presionar una tecla, verifica si es dentro de las permitidas, caso contrario NO escribe en el cuadro
function JSpermiteChar(elEvento, permitidos) {
  // Variables que definen los caracteres permitidos
  var numeros = "0123456789";
  var caracteres = " abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ";
  var numeros_caracteres = numeros + caracteres;
  var teclas_especiales = [8, 37, 39, 46];
  // 8 = BackSpace, 46 = Supr, 37 = flecha izquierda, 39 = flecha derecha
 
  // Seleccionar los caracteres a partir del parámetro de la función
  switch(permitidos) {
    case 'num':
      permitidos = numeros;
      break;
    case 'car':
      permitidos = caracteres;
      break;
    case 'num_car':
      permitidos = numeros_caracteres;
      break;
  }
 
  // Obtener la tecla pulsada 
  var evento = elEvento || window.event;
  var codigoCaracter = evento.charCode || evento.keyCode;
  var caracter = String.fromCharCode(codigoCaracter);
 
  // Comprobar si la tecla pulsada es alguna de las teclas especiales
  // (teclas de borrado y flechas horizontales)
  var tecla_especial = false;
  for(var i in teclas_especiales) {
    if(codigoCaracter == teclas_especiales[i]) {
      tecla_especial = true;
      break;
    }
  }
 
  // Comprobar si la tecla pulsada se encuentra en los caracteres permitidos
  // o si es una tecla especial
  return permitidos.indexOf(caracter) != -1 || tecla_especial;
}



// "MM_jumpMenu(this,parent.frames['mostrar'])"
function MM_jumpMenu(lista, destino)
{ //v3.0
var ind = lista.selectedIndex
window.open(lista.options[ind].value, destino);
}

function SaltarAunaPagina(lista, destino)
{ //v1.0
var ind = lista.selectedIndex;
destino.location = lista.options[ind].value;
}

function SaltarEnEsteFrameAunaPagina(lista)
{ //v1.0
var ind = lista.selectedIndex;
location = lista.options[ind].value;
}

function foco(elemento)
{
elemento.style.border = "1px solid #000000";
}

function no_foco(elemento)
{
elemento.style.border = "1px solid #CCCCCC";
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function compruebaCookie()
{
if (!document.cookie){
   alert("Activa los cookies")
   return false;
   }
}

function leeCookie(valor)
{
var dato;
var plant = new RegExp("("+valor+"=)([^;]*)(;*)")
dato = document.cookie.search(plant)
return RegExp.$2;
}

//Crea un cookie. Los argumentos son el nombre, el valor y el número de días que 
//de vida que tendrá ese cookie
function creaCookie(nombre, valor, dias)
{
var expira = new Date();
expira.setDate(expira.getDate() + dias);
var cadexp =expira.toGMTString();
document.cookie = nombre+"="+valor + ";expires="+cadexp;
}

//Borra el cookie indicado en el argumento, poniéndole una fecha de caducidad ya pasada.
function borraCookie(nombre)
{
document.cookie = nombre+"= ; expires= Thu, 01-Jan-70 00:00:01 GMT"
}

function cambiaEstado(iden)
{
var elhtml = document.getElementById(iden);
if (elhtml.style.display == 'block')
elhtml.style.display = 'none';
else
elhtml.style.display = 'block';
}

function MostrarYocultar2elemNEW1(iden1,iden2)
{
var elhtml1 = document.getElementById(iden1);
var elhtml2 = document.getElementById(iden2);
elhtml1.style.display = 'none';
elhtml2.style.display = 'block';
}

function MostrarYocultar2elemNEW2(iden1,iden2)
{
var elhtml1 = document.getElementById(iden1);
var elhtml2 = document.getElementById(iden2);
elhtml2.style.display = 'none';
elhtml1.style.display = 'block';
}

function subRayar(elem, sn)
{
if (sn)
elem.style.textDecoration="underline"
else
elem.style.textDecoration="none"
} 

// "javascript:MultiTarget2(page1,frame1,page2,frame2);"
function MultiTarget2(page1,frame1,page2,frame2)
{
window.open(page1, frame1);
window.open(page2, frame2);
}

// "javascript:UnSoloTarget(page1,frame1);"
function UnSoloTarget(page1,frame1)
{
window.open(page1, frame1);
}

function maximaLongitud(texto,maxlong,avisocant) {
var tecla, in_value, out_value;
avisocant.value = texto.value.length;
if (texto.value.length > maxlong) {
in_value = texto.value;
out_value = in_value.substring(0,maxlong);
texto.value = out_value;
avisocant.value = texto.value.length;
alert("La cantidad máxima de caracteres permitidos en este dato es " + maxlong);
texto.focus();
return false;
}
return true;
}

function isEmailAddress(theElement)
{
var s = theElement.value;
var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (s.length == 0 ) return true;
if (filter.test(s))
return true;
else
alert("La dirección de E-mail es INCORRECTA.");
theElement.select();
theElement.focus();
return false;
}

