var win;
function abre_ventana(destino){
  win = window.open(destino,"_blank","height=490,width=580,left=200,top=50,scrollbars,statusbar");
}
function cierra_ventana(){
  if (win != null){
    win.close();
  }
}
//Abre LoV Provincia
function abre_lista_provincia(destino)
{
  destino = destino + '?P_CAMPONOM=DESPRO' + '&P_CAMPOCOD=CODPRO';
  win = window.open(destino,"js","height=400,width=720,left=50,top=50,scrollbars,statusbar");
}
//Abre LoV Población
function abre_lista_poblacion(destino)
{
  destino = destino + '?P_CAMPONOM=DESPOB' + '&P_CAMPOCOD=CODPOB' + '&PROVCOD='+ document.registro_notsendnull.CODPRO.value;
  win = window.open(destino,"js","height=400,width=720,left=50,top=50,scrollbars,statusbar");
}
//Abre LoV Puesto
function abre_lista_puesto(destino)
{
  destino = destino + '?P_CAMPOCOD=CODPUE' + '&P_CAMPODES=DESPUE';
  win = window.open(destino,"js","height=400,width=720,left=50,top=50,scrollbars,statusbar");
}
//Cierra LoV
function cierra_lista(){
  if (win != null){
    win.close();
  }
}
function abre_vacan(destino, valor){
  destino = destino + '?P_LOGIN=' + valor;
  win = window.open(destino,"js","height=110,width=500,left=200,top=50,scrollbars,statusbar");
}
function abre_lista_centro(destino){
  destino = destino + '?P_CAMPONOM=DESCEN' + '&P_CAMPOCOD=CODCEN';
  win = window.open(destino,"js","height=310,width=300,left=200,top=50");
}
function abre_lista_anexo_cv(destino){
  destino = destino + '?P_CAMPOEXT=EXTCV';
  win = window.open(destino,"js","height=200,width=500,left=200,top=50,scrollbars,statusbar");
}
function abre_lista_anexo_fo(destino){
  destino = destino + '?P_CAMPOEXT=EXTFO';
  win = window.open(destino,"js","height=200,width=500,left=200,top=50,scrollbars,statusbar");
}
function abre_lista_direccion(destino){
  destino = destino + '?P_CAMPONOMBRE=NOMBREVIA' + '&P_CAMPOTIPO=TIPOVIA' + '&P_CAMPONUMERO=NUMEROVIA' + '&P_CAMPOPUERTA=PUERTAVIA' + '&P_CAMPOPROVINCIA=CODPRO' + '&P_CAMPOPOBLACION=CODPOB' + '&P_CAMPOCODIGOPOSTAL=CODIGOPOSTAL' + '&P_NUEVO=1' + '&P_DIRECCION=DIRECCION';
  win = window.open(destino,"js","height=450,width=700,left=200,top=50,scrollbars,statusbar");
}
function registrar(){
  if (!document.control.ACEPCOND.checked) {
    alert ('<%=ltCondiciones%>');
  }else{
    if(validar(document.registro.NIFNIE) && checkEmail(document.registro.EMAIL) && con(document.registro.CONTRASENYA,4)){
      enviar_todo();
    }
  }
}
function abre_lopd2(){
  win = window.open("pemlopd2.jsp","js","height=550,width=700,left=80,top=50,scrollbars,statusbar,resizable");
}

function abre_lopd()
{
  win = window.open("pemlopd.jsp","js","height=500,width=550,left=200,top=50,scrollbars,statusbar,resizable");
}
function checkEmail(e){
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(e)){
    return (true)
  }
  alert('<%=ltCorreoNoValido%>')
}
function nie(nie){
  par = 0
  non = 0
  letras="X"
  let=nie.charAt(0)
  if (!isNaN(let)){
    nif=nie
    validar(nif)
    return false
  }
  if (nie.length!=9){
    alert('<%=ltNIE5%>')  
    return false
  }
  if (letras.indexOf(let.toUpperCase())==-1){
    alert('<%=ltNIE5%>')  
    return false
  }
  cnie=nie.substring(1,nie.length-1)
  let=nie.charAt(nie.length-1)
  if (!isNaN(let)){
    alert('<%=ltNIE5%>')  
    return false
  }else {
    cadena="TRWAGMYFPDXBNJZSQVHLCKET"
    posicion = cnie % 23
    letra = cadena.substring(posicion,posicion+1)
    if (letra!=let.toUpperCase()){
      alert('<%=ltNIE5%>')    
      return false
    }
  }
}
function validar(abc){
  dni=abc.substring(0,abc.length-1)
  let=abc.charAt(abc.length-1)
  if (!isNaN(let)) {
    alert('<%=ltNIE5%>')  
    return false
  }else {
    cadena="TRWAGMYFPDXBNJZSQVHLCKET"
    posicion = dni % 23
    letra = cadena.substring(posicion,posicion+1)
    if (letra!=let.toUpperCase())
    {
      alert('<%=ltNIE5%>')
      return false
    }
  }
}
function aMays(e, elemento) {
  tecla=(document.all) ? e.keyCode : e.which; 
  elemento.value = elemento.value.toUpperCase();
}

function desparseaXML(str)
{
if (str != null) return desparseaCierraEntidadXML(desparseaAbreEntidadXML(str));
else return "";
}


function desparseaAbreEntidadXML(str)
{
  resultado ="";
  resultado = desparseaCaracterHTML(str,"%3C","<");
  return resultado;
}

function desparseaCierraEntidadXML(str)
{
  resultado ="";
  resultado = desparseaCaracterHTML(str,"%3E",">");
  return resultado;
}

function desparseaCaracterHTML(str, strCaracterOrigen, strCaracterDestino)
{
  i=0;
  if (str != null)
  {
    resultado=str;
    i=str.indexOf(strCaracterOrigen);
    if (i>-1) 
    {
      resultado=str.substring(0,i)+strCaracterDestino+desparseaCaracterHTML(str.substring(i+3,str.length),strCaracterOrigen,strCaracterDestino);
    }
    return resultado;
  } else return "";
}
