//document.oncontextmenu=function(){return false}

function gInicio () {
  var sAux = top.location.href
  if (sAux != this.parent.location.href) top.location.href = this.parent.location.href
  else {
    top.gT = top
    gT = top.gT
    gT.aZs = new Array (3)
    var nPos = sAux.indexOf ('/', sAux.indexOf ('//') + 2) + 1
    gT.sURL = sAux.substring (0, nPos)
    gT.sURLWeb = gT.sURL + 'Web/'
    gT.sURLApp = gT.sURL + sAux.substring (nPos, sAux.indexOf ('/', nPos) + 1)
    gT.sURLSrvls = gT.sURLApp + 'servlet/'
    gT.bZS = 1
  }
}

function siCond (e, f, t) {
  eval ('if (typeof ' + e + '=="undefined") setTimeout("siCond(\'' + e + '\',\'' + f + '\',' + t + ')",' + t + ');else{' + f + '}')
}

function esIdentificador (t) {

  return /^(\w+)$/.test (t)
}

function esNatural (t) {
  return /^(0|[1-9]\d*)$/.test (t)
}

function esImagen (t) {
  if (!(/^.*[\/\*\?"<>\|].*$/.test (t.toLowerCase ())))
    return /^([a-z]:\\([^\\]+\\)*[^\\]+.(gif|jp[e]?g))$/.test (t.toLowerCase ())
  return false
}

function esGIF (t) {
  /(\.gif)$/.test (t.toLowerCase ())
}

function esFecha (t) {
  if (/^((0?[1-9]|[12]\d|3[01])\/(0?[1-9]|1[012])\/\d{4})$/.test (t)) {
    var asPs = t.split (/\//)
    if (asPs[2] < 1752 || asPs[2] > 9999) return false
    if (asPs[1] == 2 && (asPs[0] > 29 || (asPs[0] == 29 && !(asPs[2] % 4 == 0 && (asPs[2] % 100 != 0 || asPs[2] % 400 == 0))))) return false
    if ((asPs[1] == 4 || asPs[1] == 6 || asPs[1] == 9 || asPs[1] == 11) && asPs[0] > 30) return false
    return true
  }
  return false
}

function esFechaEuskera (t) {
  if (/^(\d{4}\/(0?[1-9]|1[012])\/(0?[1-9]|[12]\d|3[01]))$/.test (t)) {
    var asPs = t.split (/\//)
    if (asPs[0] < 1752 || asPs[0] > 9999) return false
    if (asPs[1] == 2 && (asPs[2] > 29 || (asPs[2] == 29 && !(asPs[0] % 4 == 0 && (asPs[0] % 100 != 0 || asPs[0] % 400 == 0))))) return false
    if ((asPs[1] == 4 || asPs[1] == 6 || asPs[1] == 9 || asPs[1] == 11) && asPs[2] > 30) return false
    return true
  }
  return false
}

function nChequeados (c) {
  var nNs = 0
  if (eval ('typeof ' + c + '!="undefined"')) {
    if (eval ('typeof ' + c + '.length=="undefined"')) {
      if (eval (c + '.checked')) nNs = 1
    }
    else {
      var nL = eval (c + '.length')
      for (var i = 0; i < nL; i++) if (eval (c + '[i].checked')) nNs++
    }
  }
  return nNs
}

String.prototype.trim = function() {
  var i = 0
  var j = this.length - 1
  while (i < this.length && (this.charAt (i) == ' ' || this.charCodeAt (i) == 10 || this.charCodeAt (i) == 13)) i++
  while (j > i && (this.charAt (j) == ' ' || this.charCodeAt (j) == 10 || this.charCodeAt (j) == 13)) j--
  if (j >= i) return this.substring (i, j + 1)
  return ''
}


function letraCorrecta (dni)
{
  var letras = new Array ()
  letras[0] = "T"
  letras[1] = "R"
  letras[2] = "W"
  letras[3] = "A"
  letras[4] = "G"
  letras[5] = "M"
  letras[6] = "Y"
  letras[7] = "F"
  letras[8] = "P"
  letras[9] = "D"
  letras[10] = "X"
  letras[11] = "B"
  letras[12] = "N"
  letras[13] = "J"
  letras[14] = "Z"
  letras[15] = "S"
  letras[16] = "Q"
  letras[17] = "V"
  letras[18] = "H"
  letras[19] = "L"
  letras[20] = "C"
  letras[21] = "K"
  letras[22] = "E"

  return letraDNI = letras[dni % 23];
}

function addElemento (etiqueta, valor, elemento)
{
  var optionNuevo = new Option (etiqueta, valor)
  elemento.options[elemento.length] = optionNuevo
}

function removeElements (elemento)
{
  for (i = 0; i < elemento.length; i++) {
    elemento.options[i] = null
    i--;
  }
}

function aFecha (t) {
  if (esFecha (t)) {
    var asPs = t.split (/\//)
    if (asPs[0].substring (0, 1) == '0') asPs[0] = asPs[0].substring (asPs[0].length - 1, asPs[0].length)
    if (asPs[1].substring (0, 1) == '0') asPs[1] = asPs[1].substring (asPs[1].length - 1, asPs[1].length)
    //alert("asPs[0]="+asPs[0]+" asPs[1]-1="+eval(asPs[1])+" +asPs[2]="+asPs[2])
    if (asPs.length > 0) return eval ('new Date(' + asPs[2] + ',' + eval (asPs[1] + '-1') + ',' + asPs[0] + ',23,59,59)')
  }
  else return null
}

function aFechaddmmyyyy (t) {
  if (esFechaEuskera (t)) {
    var asPs = t.split (/\//)
    if (asPs[2].substring (0, 1) == '0') asPs[2] = asPs[2].substring (asPs[2].length - 1, asPs[2].length)
    if (asPs[1].substring (0, 1) == '0') asPs[1] = asPs[1].substring (asPs[1].length - 1, asPs[1].length)
    //alert("asPs[0]="+asPs[0]+" asPs[1]-1="+eval(asPs[1])+" +asPs[2]="+asPs[2])
    if (asPs.length > 0) return eval ('new Date(' + asPs[0] + ',' + eval (asPs[1] + '-1') + ',' + asPs[2] + ',23,59,59)')
  }
  else return null
}

function formateaFecha (input) {
  fecha = input.value
  if (!esFecha (fecha))
    if (fecha.length == 8) {
      var fechaBarras = fecha.substr (0, 2) + '/' + fecha.substr (2, 2) + '/' + fecha.substr (4, 4)
      if (esFecha (fechaBarras))
        input.value = fechaBarras
    } else if (fecha.length == 4) {
      var fechaBarras = '01/01/' + fecha
      if (esFecha (fechaBarras))
        input.value = fechaBarras
    }
  return fecha
}

function esCPValido (auxCP)
{
  auxCP = quitarCerosPorDelante (auxCP)
  return (esNatural (auxCP))
}

function quitarCerosPorDelante (sNumero)
{
  for (; sNumero.charAt (0) == '0';)
    sNumero = sNumero.substring (1, sNumero.length)

  return sNumero
}

function esDNI_Pasaporte_Valido (t)
{
  return /^([\w-]+)$/.test (t)
}

function esDNI_Valido (t)
{
  return /^([0-9]+)$/.test (t)
}

function esNIE_Valido (t)
{
  return /^([0-9]+)$/.test (t)
}