
var capaCargandoMuestra="";
var navegadorActual=window.navigator.appName;


function mostrarCVV()
{
	document.getElementById("cvv").style.visibility = "visible";
}

function ocultarCVV()
{
	document.getElementById("cvv").style.visibility = "hidden";
}

function abrirCapa(idCapa)
{
    document.getElementById(idCapa).style.visibility = "visible";	
}

function cerrarCapa(idCapa){
	document.getElementById(idCapa).style.visibility = "hidden";	
}

function InfoVuelo(elem,idioma)
{
    var Vuelo;
    var Operadora;
    var Calse;
    var direccion;
    var Origen;
    var Destino;
    var FechaSalida 
    
     Clase = document.getElementById("ctl00_MainContentPlaceHolder_DataGridVuelosVuelta_ctl02_Clase");
    //Clase = elem.document.activeElement.parentElement.childNodes[1].innerText; //ctl00_MainContentPlaceHolder_DataGridVuelosVuelta_ctl02_Clase
   
    Vuelo = document.getElementById("ctl00_MainContentPlaceHolder_DataGridVuelosVuelta_ctl02_HyLVuelo");
    //Vuelo = elem.document.activeElement.parentElement.childNodes[3].innerText;//ctl00_MainContentPlaceHolder_DataGridVuelosVuelta_ctl02_HyLVuelo
    Longitud = Vuelo.innerText.length;
    Vuelo = Vuelo.innerText.substring(2,Longitud);
    
    Operadora = document.getElementById("ctl00_MainContentPlaceHolder_DataGridVuelosVuelta_ctl02_Linea");
    //Operadora=elem.document.activeElement.parentElement.childNodes[5].innerText;//ctl00_MainContentPlaceHolder_DataGridVuelosVuelta_ctl02_Linea
    FechaSalida = document.getElementById("ctl00_MainContentPlaceHolder_DataGridVuelosVuelta_ctl02_Fecha_Salida");
    //FormatoFecha = FechaSalida.innerText();
    //FechaSalida=elem.document.activeElement.parentElement.childNodes[7].innerText;//ctl00_MainContentPlaceHolder_DataGridVuelosVuelta_ctl02_Fecha_Salida
    Origen=document.getElementById("ctl00_MainContentPlaceHolder_DataGridVuelosVuelta_ctl02_Origen");
    //Origen=elem.document.activeElement.parentElement.childNodes[9].innerText;//ctl00_MainContentPlaceHolder_DataGridVuelosVuelta_ctl02_Origen
    Destino=document.getElementById("ctl00_MainContentPlaceHolder_DataGridVuelosVuelta_ctl02_Destino");
    //Destino=elem.document.activeElement.parentElement.childNodes[11].innerText;//ctl00_MainContentPlaceHolder_DataGridVuelosVuelta_ctl02_Destino
           
    posOrigen = Origen.innerText.indexOf("(");
    Origen = Origen.innerText.substring(posOrigen+1,posOrigen+4);
    posDestino = Destino.innerText.indexOf("(");
    Destino = Destino.innerText.substring(posDestino+1,posDestino+4);
    
     if (posOrigen != -1 && posDestino != -1)
     {
         direccion = "PopUpInfoVuelo_" + idioma + "_.aspx";
         direccion += "?Vuelo=" + Vuelo;
         direccion += "&Operadora=" + Operadora.innerText;
         direccion += "&Clase=" + Clase.innerText;
         direccion += "&Origen=" + Origen;
         direccion += "&Destino=" + Destino;
         direccion += "&FechaSalida=" + FechaSalida.title.substring(0,10);
         InfoVueloDireccion(elem,direccion);
     }

    //window.open(direccion,"Mensajes","Title=Info Vuelo width=700,height=400,toolbars=no,menubar=no,scrollbars=yes,resizable=yes");
}
 
 function InfoVueloDireccion(elem,direccion)
{
   abrirCapa("capaInfoVuelo");
   window.open(direccion,"infoVuelo","toolbars=no,menubar=no,scrollbars=no,resizable=no");
}
      
function mostrarCapaTasas(TasasValor)
{
    abrirCapa('capaTasas');
    mostrarObj('capaTasas');

    var direccion = TasasValor.split("@");  
        
    var NivelTasa = new Array();
    cadena = "<table border='0' cellpadding='0' cellspacing='0'>" +
                "<tr id='trCapaAvisos'>" +
                "<td>Concepto</td>" +
                "<td>Tasas</td>" +
                "</tr>	" ;

    // recorremos las tasas para sumar las que sean del mimo tipo.
    for(i=0;i<(direccion.length-1);i++)
    {   
        var ElementoTasa = new Array();
        ElementoTasa = direccion[i].split('#');
        Repetido = new Boolean(false);

        if (NivelTasa.length != 0)
        {
            for(j=0;j<(NivelTasa.length);j++)
            {
                if (NivelTasa[j][2] == ElementoTasa[2])
                {
                    var s = "";
                    s= String(NivelTasa[j][1]);
                    NivelTasa[j][1] = parseFloat(s.replace(",", ".")) + parseFloat(ElementoTasa[1].replace(",", "."));
                    Repetido = true;
                }
            }    
        }   
        else
        {
            NivelTasa[0] = ElementoTasa;
            Repetido = true;
        }
        
        if (Repetido == false)
        {      
            NivelTasa[NivelTasa.length] = ElementoTasa;     	
        }	
    }
         	
    for(i=0;i<(NivelTasa.length);i++)
    {       
        if (NivelTasa[i][2] != null)
        {
            cadena=cadena+ "<tr>" +
                "<td>" + NivelTasa[i][1] + NivelTasa[i][3] + "</td>" +
                "<td>" + NivelTasa[i][2] + "</td>" +
                "</tr>";		
        }			         
    }         						
    
    cadena=cadena+"</table>";

    tasas.innerHTML=cadena;					

    ocultarObj("cargTasas");				
    mostrarObj("avisTasas");
}
    
 //llamada a la web de Autochecking
function Autocheck(elem)
{
    var Datos;
    var Direccion;

    Datos = document.getElementById("ctl00_MainContentPlaceHolder_DatosAutocheCk");
    Direccion = "https://172.22.2.155/webcki_handling/busquedaLoader.do";
    Direccion = Direccion + Datos.value;
    alert(Direccion);
    window.open(Direccion,"InfoVuelo","width=700,height=400,toolbars=no,menubar=no,scrollbars=yes,resizable=yes");
}     
    
function ChecKValDatos(elem)
{
    var ValDatos=document.getElementById('ctl00_MainContentPlaceHolder_UC_Datos_Resumen_Reserva1_ChkRevDatos');
    var BtnSiguiente = document.getElementById('ctl00_MainContentPlaceHolder_BtnSiguientePaso3');
    
    if (ValDatos.checked == true)
    {
        BtnSiguiente.disabled = false;
    }
    else
    {
        BtnSiguiente.disabled = true;
    }    
}

//esta función valida que el numero de tarjeta sea coherente
function ValidarTarjeta() 
{ 
 correcto=true;
 var numero = $get('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_TxtNumTarjeta').value;
 if(numero !=''){
      
     if (isNaN(numero)&&((numero.length !=16))){//&&(numero.length !=18){
      correcto=false;
      }
      var suma = 0;
      for (i=numero.length;i > 0; i--) {
       //Si la posición es impar
       if (i % 2 == 1) {
         var doble = "" + (parseInt(numero.substring(i - 1, i)) * 2);
       //Si el doble tiene más dos cifras (o sea es mayor que 9)
         if (doble.length == 2) {
          doble = parseInt(doble.substring(0,1)) + parseInt(doble.substring(1,2));
         }
       suma += parseInt(doble);
       }
         //Si la posición es par
        else {
           suma += parseInt(numero.substring(i - 1, i));
        }
        
      }//for
       //Si la suma total no es divisible por 10 entonces el número no es válido
      if (suma % 10 != 0) {
        correcto=false;
        
      }
    }//if si es distinto de null
    else{
     correcto=false;
    }
    
  return correcto;
 
}//function validarTarjeta

//validar codigo de seguridad dependiendo del combo elegido
//arguments1-->el valor del combo --arguments2-->valor de la caja de texto
function ValidarCVV(arguments1,arguments2)
{

//voy a considera longitud 6 para las 2 hasta que sepamos los requisitos
//esto es lo que estaba puesto
    correcto=true;
    if (arguments1 == "EX"){
        correcto=(arguments2.length==6);
    }
    else{
        //american Express
        correcto=(arguments2.length==6);
    }
    return (correcto);
}//ValidarCVV

function ValidarTipoTarjeta()
{
    var DrpTipoTarjeta = $get('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_DropDTipTarjeta').value;
    var num_cvv=$get('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_TxtCVV').value;
    var ok=false;
  
    if((num_cvv!="")&&(DrpTipoTarjeta != ""))
    {
       // ok=ValidarCVV(DrpTipoTarjeta,num_cvv);
       ok=true;
    }
    
    return ok;
}//validartipo tarjeta

function CheckCondicionesPago()
{
    var ok = false;
    var Condiciones =document.getElementById('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_chkCondicionesPago');
    var BtnPago = document.getElementById("ctl00_MainContentPlaceHolder_BtnPagoTarjeta");
    var provincia =document.getElementById('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_txtProvincia');
    var localidad =document.getElementById('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_txtLocalidad');
    var pasarelaNombre  =document.getElementById('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_txtNombrePas');
    
    if(pasarelaNombre == null)
    {
        if (Condiciones.checked == true)
        {      
            ok = ValidarTarjeta();
            if (ok)
            {
                ok = false;
                ok = ValidarTipoTarjeta();
                if (ok)
                {
                   ok = false;
                   ok=ValidarNombreApe();
                   if(ok)
                   {
                        BtnPago.disabled = false;
                   }
                   else
                   {
                        Condiciones.checked = false;
                        BuscarErrorCache(event,"86500003");//_VALIDACION_PAGO_NOMBREAPE
                   }    
                }
                else
                {
                    Condiciones.checked = false;
                    BuscarErrorCache(event,"86500002");//_VALIDACION_PAGO_CVV
                }
            }
            else
            {
                Condiciones.checked = false;
                BuscarErrorCache(event,"86500001");//_VALIDACION_PAGO_NUMTARJETA
            }
        }
        else
        {
            BtnPago.disabled = true;
        }
   }
   else
   {
        var apellidosPasarela  =  document.getElementById('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_txtApellidosPas');
        var emailPasarela  =  document.getElementById('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_txtEmailPas');
        var tarjetaPasarela = document.getElementById('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_egp_CardId');
        
        if(tarjetaPasarela.value!='' && apellidosPasarela.value!='' && emailPasarela.value!='' && Condiciones.checked == true)
        {
            BtnPago.disabled = false;
        }else
        {
            BtnPago.disabled = true;
        }
   }
}
        
function Autocheck(elem)
{
    var a;
}

function ValFechaCaducidad(elem)
{
    var mesAux;
    var anioAux;
    var fecha = new Date();
    
    if (elem.id == 'ctl00_MainContentPlaceHolder_UC_Datos_Pago1_DropDMesCaducidad')
    {
        mesAux = elem;
        anioAux = $get('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_DropDAnioCaducidad');
    }
    else
    {
        mesAux = $get('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_DropDMesCaducidad');
        anioAux = elem;
    }
    
    if ((mesAux.selectedIndex < fecha.getMonth()) && (anioAux.options[anioAux.selectedIndex].text == fecha.getFullYear()))
    {
        mesAux.selectedIndex = fecha.getMonth();            
    }
}

function ValidarTarjCli()
{
    return true;
}

function ValidarNombreApe() 
{
    var result = false;

    var cajanombre =$get('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_TxtTitular').value;
    
    if (ValidarCaracteres(cajanombre))
    {
        var cajaapellido =$get('ctl00_MainContentPlaceHolder_UC_Datos_Pago1_txtApellido').value;    
        
        if (ValidarCaracteres(cajaapellido))
        {
            result = true;
        }
    }
    
    return result;
}

function ValidarCaracteres(value)
{
    var ok=true;

    var longitud=value.length;
    
    if((value !='')&&(isNaN(value))&&((longitud>2)&&(longitud<=24)))
    {
        var i=0;
        while((i<=longitud-1)&&(ok))
        {
            if (!comprueba_letra(value.charAt(i)))
            {
                ok=false;
            }
            i++;
        }
    }
    else 
    {
        ok=false;
    }

    return ok;
}