﻿// Validación generica de un combos 
function ValidarCombo(ComboId,DivId){

	var comboBox = document.getElementById(ComboId);

    if (comboBox != null){

        var index = comboBox.selectedIndex;

        if ((index == 0) && ((comboBox.value == '') || (comboBox.value == ' '))) {
            MostrarDivError(DivId);
            return false; 
        }else {
            if ((comboBox.value== '') || (comboBox.value== ' '))
            {	
               MostrarDivError(DivId);
                return false; 		
            }    
            else
            {    
               OcultarDivError(DivId);
            }    
        }      
    }        
}

// Validacion selección error
function ValidarSeleccionTrsError(ComboId,DivId){

	var comboBox = document.getElementById('Flt_' + ComboId);
	
    if (comboBox != null){

        var index = comboBox.selectedIndex;  
		
        if (index > 0){        
		
            OcultarDivError(DivId);
        }      
    }        
}

// Validación generica de un combos 
function ValidarComboTRS3(ComboId){

	var comboBox = document.getElementById(ComboId);

    if (comboBox != null){

        var index = comboBox.selectedIndex;  

        if ((index == 0) && ((comboBox.value== '') || (comboBox.value== ' '))){           
            return false; 
        }else
        {
            if ((comboBox.value== '') || (comboBox.value== ' '))  return false; 	
  
        }      
    }
}

// Validación generica para validar valor obligatorio control Asp
function ValidarControlASPTRS3(ControlId1,ControlId2,DivId){
    
    var correct1 = false;
    var correct2 = false;
    var control1= document.getElementById(ControlId1);
    var control2= document.getElementById(ControlId2);
    
    if (control1!=null){
        if (control1.value!='') correct1=true;   
    }
    
    if (control2!=null){
        if (control2.value!='') correct2=true;   
    }

    if ((correct1) && (correct2)) OcultarDivError(DivId); 
    
}

function validarEntero(valor){ 
   
      //Compruebo si es un valor numérico 
      if (isNaN(valor)) { 
            //entonces (no es numero) devuelvo el valor cadena vacia 
            return false;
      }else{ 
            //En caso contrario (Si era un número) devuelvo el valor 
            return true; 
      } 
} 



// Validación generica para validar valor obligatorio control Asp
function ValidarControlASP(ControlId,DivId){
    var control= document.getElementById(ControlId);
    
    if (control!=null){
        if (control.value==''){
            MostrarDivError(DivId);
            return false;
        }else{
            OcultarDivError(DivId);
        }
    }
}

function MostrarDivError(DivId){
    var divcontrol = document.getElementById(DivId);
    if (divcontrol!=null)
        divcontrol.style.display='Block';
        
    return;
}

function OcultarDivError(DivId){

    var divcontrol = document.getElementById(DivId);
    
    if (divcontrol!=null)
        divcontrol.style.display='none';
        
    return;
}

var ServicioGuardado = false;

function ValidarTRS3(){

    var Correct = true;
    
    if (ValidarCombo('ddlgoingdestination_city','divErrorPlace')==false)
        Correct = false;
        
    if (ValidarCombo('DDLGoingDepartureCity','divErrorPlaceOrigin')==false)
        Correct = false;

    if (ValidarControlASP('TxtFCarrierO', 'divErrorFlightCodeOrigin') == false)
        Correct = false;

    if (ValidarControlASP('TxtFdestCodeO', 'divErrorFlightCodeOrigin') == false)
        Correct = false;

    if (ValidarControlASP('TxtFdestCarrierO', 'divErrorFlightCodedestination') == false)
        Correct = false;

    if (ValidarControlASP('TxtFdestCodeO', 'divErrorFlightCodedestination') == false)
        Correct = false;

    if (ValidarControlASP('TxtFCarrierOV', 'divErrorFlightCodeDepartureBack') == false)
        Correct = false;

    if (ValidarControlASP('TxtFCodeOV', 'divErrorFlightCodeDepartureBack') == false)
        Correct = false;

    if (ValidarControlASP('TxtFdestCarrierOV', 'divErrorFlightCodeDestinationBack') == false)
        Correct = false;

    if (ValidarControlASP('TxtFdestCodeOV', 'divErrorFlightCodeDestinationBack') == false)
        Correct = false;
    
    if (Correct == false) {
        MostrarDivError('divErrorPage1');
        MostrarDivError('divErrorPage2');
    }else{
        OcultarDivError('divErrorPage1');
        OcultarDivError('divErrorPage2');
    }
    
    if (ServicioGuardado == true)
        Correct=false;
    
    if (Correct == true)
        ServicioGuardado=true;
    
    return Correct;            
}

function ValidarErroresTRS3() {

    var Correct = true;

    if (ValidarComboTRS3('ddlgoingdestination_city') == false)
        Correct = false;

    if (ValidarComboTRS3('DDLGoingDepartureCity') == false)
        Correct = false;

    if (ValidarComboTRS3('txtFlightCarrierOrigin') == false)
        Correct = false;

    if (ValidarComboTRS3('txtFlightCodeOrigin') == false)
        Correct = false;

    if (ValidarComboTRS3('txtFlightCarrierDestination') == false)
        Correct = false;

    if (ValidarComboTRS3('txtFlightCodeDestination') == false)
        Correct = false;

    if (ValidarComboTRS3('txtFlightCarrierDepartureback') == false)
        Correct = false;

    if (ValidarComboTRS3('txtFlightCodeDepartureback') == false)
        Correct = false;

    if (ValidarComboTRS3('txtFlightCarrierDestinationBack') == false)
        Correct = false;

    if (ValidarComboTRS3('txtFlightCodeDestinationBack') == false)
        Correct = false;

    if (Correct == true) {
        OcultarDivError('divErrorPage1');
        OcultarDivError('divErrorPage2');
    }
}


function ValidarBuscarTRS(){
   
    //Se valida que el combo de destinos esté informado
    if (ValidarCombo('Flt_ddlcountry','divErrorTrsCountry') == false)
        return false; 
   
    //Se valida que el combo de la localización de origen esté informado
    if (ValidarCombo('Flt_ddldepartureplaces','divErrorTrsDeparture') == false)
        return false;
    
    //Se valida que el combo de la localización de destino esté informado
    if (ValidarCombo('Flt_ddldestinationplaces','divErrorTrsdestination') == false)
        return false;
        
    //Se valida que el origen y el destino del traslado no sean iguales
    if (ValidarOrigenDestinoTraslado()==false)
        return false;
    
    //Se validan que las fechas de busqueda sean correctas
    if (ValidarFechasBuscarTrs()== false)
        return false;
     
}

function ValidarOrigenDestinoTraslado(){
    var Origen = document.getElementById('Flt_ddldepartureplaces');
    var Destino = document.getElementById('Flt_ddldestinationplaces'); 
    var ValorOrigen;
    var ValorDestino;
   
    if (Origen!=null && Destino!=null){
        ValorOrigen = Origen.value;
        ValorDestino = Destino.value;
        
        if (ValorOrigen == ValorDestino){
            MostrarDivError('DivErrorOriginDestination');
            return false;
        }else{
            OcultarDivError('DivErrorOriginDestination');
        }
    }
    
}

function ValidarFechasBuscarTrs(){
   
    var DiaLlegada = document.getElementById('Flt_ddlbeginday'); 
    var MesLlegada = document.getElementById('Flt_ddlBeginMonth'); 
    var DiaSalida = document.getElementById('Flt_ddlfinalday'); 
    var MesSalida = document.getElementById('Flt_ddlfinalMonth'); 
    var HoraLlegada = document.getElementById('Flt_ddldeparturehour'); 
    var MinutoLlegada = document.getElementById('Flt_ddldepartureminutes'); 
    var HoraSalida = document.getElementById('Flt_ddldestinationhour'); 
    var MinutoSalida = document.getElementById('Flt_ddldestinationminutes');
    var Mes;
    var Dia; 
	var Hora;
    var Minuto;
    var AuxDay = new Date();
    var Hoy = new Date(AuxDay.getFullYear(),AuxDay.getMonth(),AuxDay.getDate(),00,00);

    //Si se ha informado la fecha de salida se validará que el intervalo de fechas sea correcto
    Mes = MesLlegada.value;   
    Dia = DiaLlegada.value;   
    Hora = HoraLlegada.value;
    Minuto = MinutoLlegada.value;   

    var FechaInicio = new Date(Mes);
    var FechaLlegada = new Date(FechaInicio.getFullYear(),FechaInicio.getMonth(),Dia,Hora,Minuto);

    if (FechaLlegada < Hoy){
        MostrarDivError('DivErrorBeginDateTrs');
        return false;
    }else{
        OcultarDivError('DivErrorBeginDateTrs');
    }

    //Se valida que la fecha de llegada cumpla la fecha de release    
    var FechaRelease = GetDateRelease();
    if (FechaLlegada < FechaRelease){
        MostrarDivError('DivErrorTrsDateRelease');
        return false;
    }else{
        OcultarDivError('DivErrorTrsDateRelease');
    }

    //Si se ha informado la fecha de salida se validará que el intervalo de fechas sea correcto     
     if (MesSalida.selectedIndex > 0){
		Mes = MesSalida.value;      
		Dia = DiaSalida.value;   
		Hora = HoraSalida.value;
		Minuto = MinutoSalida.value; 
		var FechaFin = new Date(Mes);   		
    	var FechaSalida = new Date(FechaFin.getFullYear(),FechaFin.getMonth(),Dia,Hora,Minuto);	    
        if (FechaSalida < Hoy){
            MostrarDivError('DivErrorEndDateTrs');
            return false;
        }else{
            OcultarDivError('DivErrorEndDateTrs');
        }
    
        if (FechaLlegada > FechaSalida){
            MostrarDivError('DivErrorTrsDateInterval');
            return false;
        }else{
            OcultarDivError('DivErrorTrsDateInterval');
        }        
    }  
}

// Función que retorna el día de release una reserva
function GetDateRelease(){
    var fecha = new Date();
    var dia = fecha.getDate();
    var mes = fecha.getMonth();
    var year = fecha.getFullYear();

    for(ind = 0; ind < 3; ind++)
    {
        if (dia == ObtenerDiasMes(mes,year)){
            if (mes==11){
                mes=00;
                dia=01;
                year++;                            
            }else{
                mes++;
                dia = 01;
            }
        }else{
        dia++;
        }
    }

    var fecharelease = new Date(year, mes, dia, 00, 00);
 
    return fecharelease;
}

// Función obtiene los días de un mes
function ObtenerDiasMes($m,$y){ 
    if($m == 01){
        if (($y % 4 == 0) && (($y % 100 != 0) || ($y % 400 == 0))) {            
            return 29;
        } else {
            return 28; 
        } 
    }
    if ($m == 3 || $m == 5 || $m == 8 || $m == 10) {
        return 30;
    } else {
        return 31; 
    } 
} 

function ValidarBuscarEXC(){

	//Se valida que el combo de paises esté informado
    if (ValidarCombo('Flt_ddlcountryExc', 'divErrorExcCountry') == false)
        return false;
    
    //Se valida que el combo del destino esté informado
    if (ValidarCombo('Flt_ddlcityExc','divErrorExcCity') == false)
        return false;
        
    //Se validan que las fechas de busqueda sean correctas
    if (ValidarFechasBuscarExc()== false)
        return false;
}

function ValidarFechasBuscarExc(){

    var DiaLlegada = document.getElementById('Flt_ddlbegindayExc'); 
    var MesLlegada = document.getElementById('Flt_ddlBeginMonthExc'); 
    var DiaSalida = document.getElementById('Flt_ddlfinaldayExc'); 
    var MesSalida = document.getElementById('Flt_ddlfinalMonthExc'); 
    var Mes;
    var Dia; 
    var AuxDay = new Date();
    var Hoy = new Date(AuxDay.getFullYear(),AuxDay.getMonth(),AuxDay.getDate(),00,00);
    
    //Si se ha informado la fecha de salida se validará que el intervalo de fechas sea correcto
    Mes = MesLlegada.value;   
    Dia = DiaLlegada.value;     
    var FechaInicio = new Date(Mes);
    var FechaLlegada = new Date(FechaInicio.getFullYear(),FechaInicio.getMonth(),Dia,00,00);
    
    Mes = MesSalida.value;      
    Dia = DiaSalida.value;    
    var FechaFin = new Date(Mes);        
    var FechaSalida = new Date(FechaFin.getFullYear(),FechaFin.getMonth(),Dia,00,00);
        
    if (FechaLlegada < Hoy){
        MostrarDivError('DivErrorBeginDateExc');
        return false;
    }else{
        OcultarDivError('DivErrorBeginDateExc');
    }
    
    if (FechaSalida < Hoy){
        MostrarDivError('DivErrorEndDateExc');
        return false;
    }else{
        OcultarDivError('DivErrorEndDateExc');
    }
        
    if (FechaLlegada > FechaSalida){
        MostrarDivError('DivErrorExcDateInterval');
        return false;
    }else{
        OcultarDivError('DivErrorExcDateInterval');
    }   

    //Se valida que la fecha de llegada cumpla la fecha de release    
    var FechaRelease = GetDateRelease();
    
    if (FechaLlegada < FechaRelease){
        MostrarDivError('divErrorFechaRelease');
        return false;
    }else{
        OcultarDivError('divErrorFechaRelease');
    }  
         
}

//Función que valida si un valor es una fecha
function isDate(sDate) {
    var scratch = new Date(sDate);
    if (scratch.toString() == "NaN" || scratch.toString() == "Invalid Date") {
        return false;
    } else {
        return true;
    }
}

//Función que valida los valores de la página EXC4
function ValidarEXC4(){
    var ReturnValue = true;

  
    //Se validan los números de pax
    if (validarPaxEXC4()==false)
    ReturnValue = false;

    //Se valida que el combo de idioma
    if (ValidarCombo('ddlLanguage','DivErrorLanguage') == false)
    ReturnValue = false;

    //Se valida que el combo de la localización
    if (ValidarCombo('ddlLocation','DivErrorLocation') == false)
    ReturnValue = false;

    //Se valida que la fecha seleccionada tenga operativa
    if (ValidarFechaOperativa() == false)
    ReturnValue = false;

    return ReturnValue;
}


function ValidarFechaOperativa(){
    var SelDate = document.getElementById('lbldate');

    if (SelDate.innerText==''){
   		MostrarDivError('DivErrorDayOperative');
		return false;
	}else{
		OcultarDivError('DivErrorDayOperative');
	}
  
	return true;
}
   
function validarPaxEXC4(){
    var ReturnValue = true;
	var Adults = document.getElementById('txtAd');
	var Children = document.getElementById('txtNi');
	var Babies = document.getElementById('txtBa');
    
    var strAdultos = "0";
    var strChildren = "0";
    var strBabys = "0";
    strAdultos=Adults.value;
    strChildren=Children.value;
    strBabies=Babies.value;

	if ((validarEntero(Adults.value)==false) || (strAdultos.indexOf('.')!=0 && strAdultos.indexOf('.')>0)) {
	        MostrarDivError('DivErrorAdults');
            ReturnValue = false;	
	}else{
            OcultarDivError('DivErrorAdults');
        }
	
	if ((validarEntero(Children.value)==false) || (strChildren.indexOf('.')!=0 && strChildren.indexOf('.')>0)){
	        MostrarDivError('DivErrorChildren');
            ReturnValue = false;	
	}else{
            OcultarDivError('DivErrorChildren');
        }
        
    if ((validarEntero(Babies.value)==false) || (strBabies.indexOf('.')!=0 && strBabies.indexOf('.')>0)){
	        MostrarDivError('DivErrorBabies');
            ReturnValue = false;	
	}else{
            OcultarDivError('DivErrorBabies');
        }
        
    if (((Adults.value < 1)|| (Children.value < 0) || (Babies.value < 0)) || (Adults.value + Children.value <= 0)){
    	    MostrarDivError('DivErrorPaxNumber');
            ReturnValue = false;	
	}else{
            OcultarDivError('DivErrorPaxNumber');
        }
		
	return ReturnValue;
}

 var winPop;
 function OpenForm(xURL,swidth, sheight){
   var centerWidth = (window.screen.width - swidth) / 2;
   var centerHeight = (window.screen.height - sheight) / 2;
   winPop = window.open(xURL, 'Message', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + swidth + ',height=' + sheight + ',left=' + centerWidth + ',top=' + centerHeight);
   winPop.focus();
}
        
function isEmail(email) {
	var result = false; var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) result= true;
	return result;
}

function disableLink(id) {

    // Comprobamos si se está haciendo una validación
    if (typeof (Page_ClientValidate) == 'function') {
        // Si se está haciendo una validación, volver si ésta da resultado false
        if (Page_ClientValidate() == false) { return false; }
    }

    id.style.visibility = 'hidden';
    
    return true;
}


function HideCalendar(){
	
	//Ocultar calendario fecha desde.
	OcultarDivError('Flt_CalendarFrom_PnlCalendar');
	
	//Ocultar calendario fecha hasta.
	OcultarDivError('Flt_CalendarTo_PnlCalendar');
	
}

//Evita que al pulsar se lance el submit.
function Press(e) { 
  tecla = (document.all) ? e.keyCode :e.which; 
  return (tecla!=13); 
}

// FUNCIONES HOTELES//
function ValidarBuscarHOT(){

	//Se valida que el combo de paises esté informado
    if (ValidarCombo('Flt_ddlcountryHot','divErrorHotCountry') == false)
        return false;

    //Se validan que las fechas de busqueda sean correctas
    if (ValidarFechasBuscarHot()== false)
        return false;        
}

function ValidarFechasBuscarHot(){

    var DiaLlegada = document.getElementById('Flt_ddlbegindayHot'); 
    var MesLlegada = document.getElementById('Flt_ddlBeginMonthHot'); 
    var DiaSalida = document.getElementById('Flt_ddlfinaldayHot'); 
    var MesSalida = document.getElementById('Flt_ddlfinalMonthHot'); 
    var Mes;
    var Dia; 
    var AuxDay = new Date();
    var Hoy = new Date(AuxDay.getFullYear(),AuxDay.getMonth(),AuxDay.getDate(),00,00);
    
    //Si se ha informado la fecha de salida se validará que el intervalo de fechas sea correcto
    Mes = MesLlegada.value;   
    Dia = DiaLlegada.value;     
    var FechaInicio = new Date(Mes);
    var FechaLlegada = new Date(FechaInicio.getFullYear(),FechaInicio.getMonth(),Dia,00,00);
    
    Mes = MesSalida.value;      
    Dia = DiaSalida.value;    
    var FechaFin = new Date(Mes);        
    var FechaSalida = new Date(FechaFin.getFullYear(),FechaFin.getMonth(),Dia,00,00);
        
    if (FechaLlegada < Hoy){
        MostrarDivError('DivErrorBeginDateHot');
        return false;
    }else{
        OcultarDivError('DivErrorBeginDateHot');
    }
    
    if (FechaSalida < Hoy){
        MostrarDivError('DivErrorEndDateHot');
        return false;
    }else{
        OcultarDivError('DivErrorEndDateHot');
    }
    
    if (FechaLlegada >= FechaSalida) {
        MostrarDivError('DivErrorHotDateInterval');
        return false;
    } else {
        OcultarDivError('DivErrorHotDateInterval');
    }   
         
}

function validarPaxesHot(){

	var Adultos = document.getElementById('Flt_txtadultos');
	var Ninos = document.getElementById('Flt_txtninos');
    var strAdultos ="0";
    var strNinos = "0";
    strAdultos=Adultos.value;
    strNinos=Ninos.value;
     
	if ((validarEntero(Adultos.value)==false) || ((strAdultos.indexOf('.')!=0 && strAdultos.indexOf('.')>0) || (strAdultos.indexOf(',')!=0 && strAdultos.indexOf(',')>0))){
	        MostrarDivError('DivErrorAdultos');
            return false;	
	}else{
            OcultarDivError('DivErrorAdultos');
        }
	
	if ((validarEntero(Ninos.value)==false)  || ((strNinos.indexOf('.')!=0 && strNinos.indexOf('.')>0) || (strNinos.indexOf(',')!=0 && strNinos.indexOf(',')>0))){
	        MostrarDivError('DivErrorNinos');
            return false;	
	}else{
            OcultarDivError('DivErrorNinos');
        }
        
    if (Adultos.value <= 0 || Adultos.value > 999){
    	    MostrarDivError('DivErrorAdultos');
            return false;	
	}else{
            OcultarDivError('DivErrorAdultos');
        }
	
	if (Ninos.value < 0 || Ninos.value > 999){
    	    MostrarDivError('DivErrorNinos');
            return false;	
	}else{
            OcultarDivError('DivErrorNinos');
        }
}


function validarRoomNumber(){

	var Room = document.getElementById('Flt_TxtRoomNumber');
	var strRoom ="0";    
    strRoom=Room.value;    
     
	if ((validarEntero(Room.value)==false) || ((strRoom.indexOf('.')!=0 && strRoom.indexOf('.')>0) || (strRoom.indexOf(',')!=0 && strRoom.indexOf(',')>0))){
	        MostrarDivError('DivErrorRoomNumber');
            return false;	
	}else{
            OcultarDivError('DivErrorRoomNumber');
        }	
       
    if (Room.value <= 0 || Room.value > 99){
    	    MostrarDivError('DivErrorRoomNumber');
            return false;	
	}else{
            OcultarDivError('DivErrorRoomNumber');
        }
	
}

function openNewsletter(Email){
	OpenForm(Email,450, 440);
}

function copyName(){
    var name = document.getElementById('TxtNamePax');
 
    if (name!=null){
        name.value = document.getElementById('txtnombre').value;
    }    
}

function copySurName() {
    var name = document.getElementById('TxtSurNamePax');

    if (name != null) {
        name.value = document.getElementById('txtapellidos').value;
    }
}

function copySurIDNumber() {
    var name = document.getElementById('TxtNIFPax');

    if (name != null) {
        name.value = document.getElementById('txtdni').value;
    }
}