﻿//////////////////////////////////////////////////////////////////
///////////         FUNCIONES GENERICAS              /////////////
//////////////////////////////////////////////////////////////////

//OcultarPanelConfirmacion para las reservas de Expomundo
function OcultarPanelConfirmacion() {
    try
      {
          document.getElementById('ctl00_ContentPlaceHolder1_PanelReservaNoConfirmada').style.display = 'none';
          document.getElementById('ctl00_ContentPlaceHolder1_PanelReservaNoConfirmadaFondo').style.display = 'none';
      }
    catch(err)
      {
      //Handle errors here
      }
}

//Calcula la posicion en el eje X de un control HTML en la ventana  -- Utilizadas para posicionar el flyout de la cesta
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

//Calcula la posicion en el eje Y de un control HTML en la ventana -- Utilizadas para posicionar el flyout de la cesta
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

//////////////////////////////////////////////////////////////////
///////////    FUNCIONES PARA VALIDAR FORMULARIOS    /////////////
//////////////////////////////////////////////////////////////////

//Funcion que valida el Buscador de Vuelos en Vuelos.aspx
function ValidaBusquedaVuelos() {
    var origen = document.getElementById('ctl00_Contenido_ComOrg');
    var destino = document.getElementById('ctl00_Contenido_ComDes');
    var adultos = document.getElementById('ctl00_Contenido_txtA');
    var niños = document.getElementById('ctl00_Contenido_txtN');
    var bebes = document.getElementById('ctl00_Contenido_txtB');
    var numAdultos = 0;
    var numNiños = 0;
    var numBebes = 0;
    var fechaInicio = document.getElementById('_eo_ctl00_Contenido_txtFecIni_picker');
    var fechaFin = document.getElementById('_eo_ctl00_Contenido_txtFecFin_picker');

    if (adultos.value != '') {
        if (!isNaN(adultos.value)) {
            numAdultos = parseInt(adultos.value);
        }
    }
    else {
        numAdultos = 0;
    }
    if (niños.value != '') {
        if (!isNaN(niños.value)) {
            numNiños = parseInt(niños.value);
        }
    }
    else {
        numNiños = 0;
    }
    if (bebes.value != '') {
        if (!isNaN(bebes.value)) {
            numBebes = parseInt(bebes.value);
        }
    }
    else {
        numBebes = 0;
    }
    
    if (origen.value == '') {
        alert("Debe escoger el Origen del Viaje.");
        origen.focus();
        return false;
    }
    if (destino.value == '') {
        alert("Debe escoger el Destino del Viaje.");
        destino.focus();
        return false;
    }
    if ((numNiños + numAdultos + numBebes) < 1) {
        alert("Deberá viajar al menos un pasajero.");
        adultos.focus();
        return false;
    }
    else if (((numNiños + numAdultos + numBebes) == 1) && (numAdultos == 0) && (numBebes >= 1)) {
        alert("Los Bebés no pueden viajar sin Adultos.");
        adultos.focus();
        return false;
    }
    if (fechaInicio.value == '  /  /    ') {
        alert("Debe escoger la Fecha de Inicio del Viaje.");
        fechaInicio.focus();
        return false;
    }
    if (fechaFin.value == '  /  /    ') {
        alert("Debe escoger la Fecha de Fin del Viaje.");
        fechaFin.focus();
        return false;
    }

    //mostrar cargando
    document.getElementById('panel').style.display = 'block';
    document.getElementById('subpanel').style.display = 'block';
    return true;
}

//Funcion que valida el Buscador de Servicios en otrosServicios.aspx
function ValidaBusquedaServicios() {
    var pais = document.getElementById('ctl00_Contenido_ComPais');
    var ciudad = document.getElementById('ctl00_Contenido_ComCiudad');
    var fechaInicio = document.getElementById('_eo_ctl00_Contenido_txtFecIni_picker');
    var fechaFin = document.getElementById('_eo_ctl00_Contenido_txtFecFin_picker');

    if (pais.value == '') {
        alert("Debe escoger el País para el Servicio.");
        pais.focus();
        return false;
    }
    if (ciudad.value == '') {
        alert("Debe escoger la ciudad para el Servicio.");
        ciudad.focus();
        return false;
    }    
    if (fechaInicio.value == '  /  /    ') {
        alert("Debe escoger la Fecha de Inicio del Servicio.");
        fechaInicio.focus();
        return false;
    }
    if (fechaFin != null){
        if (fechaFin.value == '  /  /    ') {
            alert("Debe escoger la Fecha de Fin del Servicio.");
            fechaFin.focus();
            return false;
        }
    }
    return true;
}

//Funcion que valida el Buscador de Hoteles en Hoteles.aspx
function ValidaBusquedaHoteles() {
    var pais = document.getElementById('ctl00_Contenido_ComPais');
    var ciudad = document.getElementById('ctl00_Contenido_ComDes');
    var fechaInicio = document.getElementById('_eo_ctl00_Contenido_txtFecIni_picker');
    var fechaFin = document.getElementById('_eo_ctl00_Contenido_txtFecFin_picker');

    if (pais.value == '') {
        alert("Debe escoger el Pais del Hotel.");
        pais.focus();
        return false;
    }
    if (ciudad.value == '') {
        alert("Debe escoger la Ciudad del Hotel.");
        ciudad.focus();
        return false;
    }    
    if (fechaInicio.value == '  /  /    ') {
        alert("Debe escoger la Fecha de Entrada en el Hotel.");
        fechaInicio.focus();
        return false;
    }
    if (fechaFin.value == '  /  /    ') {
        alert("Debe escoger la Fecha de Salida del Hotel.");
        fechaFin.focus();
        return false;
    }

    return true;
}

//////////////////////////////////////////////////////////////
///////////    FUNCIONES PARA OTROS SERVICIOS    /////////////
//////////////////////////////////////////////////////////////

//Funcion que no permite reservar un tipo de servicio si este depende de otro servicio

function impedirReserva(tipoServicioNecesario) {
    if (tipoServicioNecesario == "hotel") {
        alert("Para Poder Contratar este Servicio es necesario tener ya hecha una reserva Hotelera.");
    }
    else {
        if (tipoServicioNecesario == "vuelo") {
            alert("Para Poder Contratar este Servicio es necesario tener ya hecha una reserva de Vuelos.");
        }
    }
    return false;
}

/*
Funcion que cierra una ventana
*/

function cerrar() {    
var ventana = window.self;
ventana.opener = window.self;
ventana.close();
}

/*
Funcion que muestra u oculta los datos de la autoFactura
*/
function autofactura(){
    if (document.getElementById("autofactura").style.display == "block"){
        document.getElementById("autofactura").style.display = "none";	//hide
    }else{
        document.getElementById("autofactura").style.display = "block";	//show
    }
}

////////////////////////////////////////////
////Funciones para el Buscador de vuelos////
////////////////////////////////////////////

//Funcion que muestra un mensaje de aviso si el destino elegido en el buscador de vuelos es CUBA
function mostrarMensajeCuba(obj) {
    if (obj.type == "radio") {
        if (obj.checked) {
            if (document.getElementById("ctl00_Contenido_ComDes").value.split(" - ")[1] == "9") {
                alert("Solo podrán reservar billetes de solo ida aquellos ciudadanos de nacionalidad Cubana que sean titulatrs del Permiso de Residencia en el Exterior (PRE). Cualquier otra nacionalidad deberá hacer una reserva aérea de Ida y vuelta. Así como aquellos ciudadanos cubanos que no tengan el permiso (PRE).");
            } //if destino = cuba
        }
    } //if checked solo ida
    else {
        if (obj.type == "select-one") {
            if (document.getElementById("ctl00_Contenido_ComDes").value.split(" - ")[1] == "9") {
                if (document.getElementById("ctl00_Contenido_checkIda").checked) {
                    alert("Solo podrán reservar billetes de solo ida aquellos ciudadanos de nacionalidad Cubana que sean titulatrs del Permiso de Residencia en el Exterior (PRE). Cualquier otra nacionalidad deberá hacer una reserva aérea de Ida y vuelta. Así como aquellos ciudadanos cubanos que no tengan el permiso (PRE).");
                } //if solo ida checked                
            } //if destino = cuba
        }
    }
}

//Funcion que Cambia el NIT de un Vuelo????
function cambiarNIT(ctrl) {
    var posicionGrid = ctrl.id.split("_")[3];
    var filaEnTabla = ctrl.id.split("_")[5].substring(3, 5);
    //var TablaVuelos = document.getElementById('ctl00_Contenido_GridContenedor_' + posicionGrid + '_' + 'grdVuelosIda');
    var TablaVuelos = ctrl.parentNode.parentNode.parentNode.parentNode;
    var tr = TablaVuelos.rows[filaEnTabla - 1];
    var td = tr.childNodes[1];
    var item = td.firstChild;
    var valor = ctrl[ctrl.selectedIndex].value;
    item.nodeValue = valor;
}

//Funcion que Cambia el NIT de un Vuelo????
function cambiarNITyPRECIO(ctrl) {
    var posicionGrid = ctrl.id.split("_")[3];
    var filaEnTabla = ctrl.id.split("_")[5].substring(3, 5);
    //var TablaVuelos = document.getElementById('ctl00_Contenido_GridContenedor_' + posicionGrid + '_' + 'grdVuelosIda');
    var TablaVuelos = ctrl.parentNode.parentNode.parentNode.parentNode;
    var tr = TablaVuelos.rows[filaEnTabla - 1];
    var td = tr.childNodes[1];
    var item = td.firstChild;
    var valor = ctrl[ctrl.selectedIndex].value.split("_")[0];
    item.nodeValue = valor;
    ctrl.parentNode.parentNode.childNodes[16].childNodes[0].nodeValue = ctrl[ctrl.selectedIndex].value.split("_")[1];
}

//Función que se le pasa un RadioButton y lo descheeckea y le quita los estilos de la fila de la tabla
function quitarCheck(item,i) {
    if (item.checked) {
        item.checked = false;
        //Comprobamos si la fila es par o impar por el estilo alterno de las lineas
        if ((i % 2) == 0) {
            item.parentNode.parentNode.style.backgroundColor = '#EDF3F8';
            item.parentNode.parentNode.style.color = '#555555';
            item.parentNode.parentNode.style.fontSize = '9.8px';
        }
        else {
            item.parentNode.parentNode.style.backgroundColor = 'white';
            item.parentNode.parentNode.style.color = 'black';
            item.parentNode.parentNode.style.fontSize = '9.8px';
        }
        item.parentNode.parentNode.style.fontWeight = 'normal';
        item.parentNode.parentNode.style.border = 'solid 0px black';
        item.parentNode.parentNode.style.fontSize = '9.8px';
    }
}

function deseleccionarOtrasTablas(spanChk, Parent){    
    var lista = spanChk.id.split('_');
    var comienzo = lista[0]+'_'+lista[1]+'_'+lista[2]+'_ctl0';
    var cadTabla = '_'+lista[4];
    var cadItem = '_' +lista[6];
    var item = document.getElementById(comienzo + '0' + cadTabla + '_ctl00' + cadItem);
    var tabla = document.getElementById(comienzo + '0' + cadTabla);    
    for (i = 0; (tabla != null) || (i < 6); i++){        
        for (j = 0; (item != null) || ((item == null) && (j < 4)); j++){
            if ((item != null) && (tabla.id != Parent.id)){
                quitarCheck(item,j+1);
            }
            item = document.getElementById(comienzo + i + cadTabla+ '_ctl0' + (j + 1) + cadItem);
        }
        tabla = document.getElementById(comienzo + (i + 1) + cadTabla);
    }
}

//Función que comprueba los checks de las tablas de vuelos y checkea o descheckea según sea necesario
function CheckOtherIsCheckedByGVIDMore(spanChk, grid) {
    var Parent = spanChk.parentNode.parentNode.parentNode.parentNode;
    var IsChecked = spanChk.checked;
    var numJouChecked = -1;
    var numSegChecked = -1;
    var servPolarChecked = "";
    //si le hemos puesto el valor de la etiqueta 'Numjou' = 'si' quiere decir que el vuelo no es compatible con el numjou 
    //del tramo elegido anteriormente
    if (spanChk.numjou == "si") {
        spanChk.checked = false;
        alert('Este vuelo no es compatible con los ya elegidos');
        return true;
    }

    if (IsChecked) {
        //Comprobamos que no haya ningun radiobutton de otra tabla seleccinado
        deseleccionarOtrasTablas(spanChk, Parent);
        //Comprobamos si el radioButton esta checkeado y ponemos estilos de checkeado a toda la <tr> de la tabla
        numJouChecked = spanChk.parentNode.parentNode.cells[20].innerHTML;
        numSegChecked = spanChk.parentNode.parentNode.cells[21].innerHTML;
        servPolarChecked = spanChk.parentNode.parentNode.cells[2].innerHTML.split(' ')[0];
        spanChk.parentNode.parentNode.style.border = 'solid 1px #005193';
        spanChk.parentNode.parentNode.style.fontWeight = 'bold';
        spanChk.parentNode.parentNode.style.fontSize = '9.8px';
    }
    var CurrentRdbID = spanChk.id;
    var Chk = spanChk;    
    var tr, td, item;
    for (i = 0; i < Parent.rows.length; i++) {
        tr = Parent.rows[i];
        td = null;
        item = null;
        //Detectamos si el explorador es IE o cualquier otro
        if ((BrowserDetect.browser == "Explorer")) {
            td = tr.childNodes[0];
            item = td.childNodes[0];
        } else {
            td = tr.childNodes[1];
            item = td.childNodes[1];
        }
        //A continuación comprobamos si hay algún otro tramo similar checkeado para descheckearlo 
        //y quitarle los estilos
        if (item != null) {
            var numJouItem = tr.cells[20].innerHTML;
            var numSegItem = tr.cells[21].innerHTML;
            var servPolarItem = tr.cells[2].innerHTML.split(' ')[0];
            if (item.id != CurrentRdbID && item.type == "radio") {
                //0.Comprobamos el numJou y el numSeg de la fila actual 
                //    si <> NUMJOU => descheckeamos y inhabilitamos check
                if ((numJouItem != numJouChecked) && (servPolarItem == servPolarChecked)) {
                    quitarCheck(item,i);
                    if (numSegItem != 1) {
                        //item.disabled = true;
                        item.numjou = "si";
                    }
                }
                else {
                    if ((numJouItem == numJouChecked) && (servPolarItem == servPolarChecked)) {
                        //quitarCheck(item);
                        item.disabled = false;
                        item.numjou = "";
                    }
                }
            }
        }
    }
}

//Funcion que comprueba que se haya seleccionado un vuelo de cada tramo de un paquete
function SeleccionCompletaTramos(ctrl, numTramos, grid, nitSeleccionadoId) {
    //var contTramos = 0;
    var todoCorrecto = 1;
    var idaSeleccionada = 0;
    var vueltaSeleccionada = 0;
    var nitSeleccionado = '';
    //vamos asacar del objeto boton que ha hecho la llamada el nombre del grid que tenemos que controlar.
    var posicionGrid = ctrl.id.split("_")[3];
    var TablaVuelos = document.getElementById(ctrl.parentNode.parentNode.parentNode.parentNode.parentNode.id + '_' + posicionGrid + '_' + grid);
    if (TablaVuelos == null)
        TablaVuelos = document.getElementById(ctrl.parentNode.parentNode.parentNode.parentNode.parentNode.id + '_' + grid + '_' + posicionGrid);
    var tr, td, item;
    //Comprobamos y contamos en todas las filas, cuales estan seleccionadas
    for (i = 1; ((i < TablaVuelos.rows.length) && (todoCorrecto)); i++) {
        tr = TablaVuelos.rows[i];
        //diferenciamos si el navegador es IE o cualquier otro
        if ((BrowserDetect.browser == "Explorer")) {
            td = tr.childNodes[0];
            item = td.childNodes[0];
            if (item.type == "radio") {
                if (item.checked) {
                    if (tr.cells[4].innerHTML == 'Outbound'){
                        idaSeleccionada = 1;
                    }
                    else if (tr.cells[4].innerHTML == 'Return'){
                        vueltaSeleccionada = 1;
                    }
                    //contTramos++;
                    var trAux, tdAux, itemAux;
                    for (j=1; ((j < TablaVuelos.rows.length) && (todoCorrecto)); j++) {
                        trAux = TablaVuelos.rows[j];
                        tdAux = trAux.childNodes[0];
                        itemAux = tdAux.childNodes[0];
                        if (itemAux.type == "radio") {
                            //Comprobamos que los numjou sean iguales y  que el Check este seleccionado
                            if (trAux.cells[20].innerHTML == tr.cells[20].innerHTML) {
                                if (itemAux.checked) {
                                    todoCorrecto = 1;                                    
                                }
                                else{
                                    //No esta Seleccionado...Tienen que estar todos los NumJou's Seleccionados para poder continuar con la 
                                    //reserva del vuelo.Salimos de la funcion.
                                    todoCorrecto = 0;
                                }
                            }
                        }
                    }
                    if (todoCorrecto){
                        nitSeleccionado += tr.childNodes[1].childNodes[0].nodeValue + ';';
                    }
                }
            }
        } else {
            td = tr.childNodes[1];
            item = td.childNodes[1];
            if (item.type == "radio") {
                if (item.checked) {
                   if (tr.cells[4].innerHTML == 'Outbound'){
                        idaSeleccionada = 1;
                    }
                    else if (tr.cells[4].innerHTML == 'Return'){
                        vueltaSeleccionada = 1;
                    }
                    //contTramos++;
                    for (j=1; ((j < TablaVuelos.rows.length) && (todoCorrecto)); j++) {
                        trAux = TablaVuelos.rows[j];
                        tdAux = trAux.childNodes[1];
                        itemAux = tdAux.childNodes[1];
                        if (itemAux.type == "radio") {
                            //Comprobamos que los numjou sean iguales y  que el Check este seleccionado
                            if (trAux.cells[20].innerHTML == tr.cells[20].innerHTML) {
                                if (itemAux.checked) {
                                    todoCorrecto = 1;                                    
                                }
                                else{
                                    //No esta Seleccionado...Tienen que estar todos los NumJou's Seleccionados para poder continuar con la 
                                    //reserva del vuelo.Salimos de la funcion.
                                    todoCorrecto = 0;
                                }
                            }
                        }                        
                    }
                    if (todoCorrecto){
                        nitSeleccionado += tr.childNodes[2].childNodes[0].nodeValue + ';';
                    }
                }
            }
        }
    }
    //if (contTramos == numTramos) {
    if ((todoCorrecto && idaSeleccionada && vueltaSeleccionada) || ((numTramos == 1) && idaSeleccionada )) {
        document.getElementById(nitSeleccionadoId).value = nitSeleccionado;
        return true;
    }
    else
        alert("Debe seleccionar un vuelo por cada tramo compatible.");
    return false;
}

////////////////////////////////////////////////////////////
////Funciones de la cesta de la compra en Maestra.Master////
////////////////////////////////////////////////////////////

//Funcion que llama al metodo borrar de .NET desde Javascript
function borrar(numero) {
//    PageMethods.borrar(numero, OnOK);
	llamar(numero);
}

function actualizarCestaCompra(){
    $.ajax({
	  type: "POST",
	  data: "" ,
	  url: "DefaultMaster.aspx/ActualizarCodigoCesta",
	  contentType: "application/json; charset=utf-8",
	  dataType: "json",
	  success: resultado,
	  error: errores
	  }); 
}

//funcion que llama a un metodo mediante Ajax
function llamar(num)
{  
   $.ajax({
	  type: "POST",
	  data: "{ num: " + num + "}" ,
	  url: "DefaultMaster.aspx/Borrar",
	  contentType: "application/json; charset=utf-8",
	  dataType: "json",
	  success: resultado,
	  error: errores
	  });   
}  
//Funcion que sustituye el codigo HTML de la Cesta de La compra con con el codigo de la cesta modificado        
function resultado(msg) {
	//msg.d tiene el resultado devuelto por el método
	var etiqueta = $get("cuerpoCesta");
	etiqueta.innerHTML = msg.d;
	//$("#lblMensajes").append(msg.d);
	//$("#lblMensajes").append("<br />");
	//$('#num3').val(msg.d);
}
function errores(msg) {
	//msg.responseText tiene el mensaje de error enviado por el servidor
	alert('Error: ' + msg.responseText);
}

//Funcion  que muestra la advertencia de que se va a borrar UN SOLO servicio de la cesta de la compra
function mostrarAdvertencia(num) {
    document.getElementById("numServOculto").value = num;
    document.getElementById("panel").style.display = "block";
    document.getElementById("ctl00_CestaCompra_MensajeBorrarServicio").style.display = "block";
}

//Funcion que se ejecuta al pulsar el boton 'Cancelar' del panel de Advertencia de borrar Servicio
function cancelarBorrarServicio(text) {
    document.getElementById("panel").style.display = "none";
    document.getElementById('ctl00_CestaCompra_' + text).style.display = "none";
}

//Funcion que se ejecuta al pulsar el boton 'Aceptar' del panel de Advertencia de borrar Servicio
function aceptarBorrarServicio(num) {
    borrar(num);
    document.getElementById("panel").style.display = "none";
    document.getElementById("ctl00_CestaCompra_MensajeBorrarServicio").style.display = "none";
}

//Funcion  que muestra la advertencia de que se van a borrar TODOS los servicios de la cesta de la compra
function mostrarAdvertenciaTodos() {
    document.getElementById("panel").style.display = "block";
    document.getElementById("ctl00_CestaCompra_MensajeBorrarTodosServicios").style.display = "block";
}

//Funcion que despliega el Flyout con el resumen del servicio
function desplegarFlyout(num, e){	
	// Este codigo dota de la funcionalidad del FlyOut al pasar el boton sobre cada incono de mas informacion de cada servicio 
	// de la cesta de la compra

	//a cada capa 'infoX' le dotamos con la funcionalidad cuando hacemos MouseOver  -- hecho con javascript y JQuery

	//$('#info' + num).mouseover(function (e) {
		var y = findPosY(e); //e.pageY;
		var x = findPosX(e); //e.pageX;
		var h = (window.innerWidth === undefined) ? (document.documentElement === undefined) ? document.getElementsByTagName('body')[0].clientWidth : document.documentElement.clientWidth : window.innerWidth;
		//alert(y);
		//'Calculamos la posicion del icono de mas info, para que la capa con la informacion del servicio 
		//   aparezca hacia la izquierda en la misma posicion que el icono
		document.getElementById('capaInfo' + num).style.top = (y + 16) + 'px';
		document.getElementById('capaInfo' + num).style.right = (h - x) + 'px';
		$('#capaInfo' + num).show('slow');
	//});
}

//Funcion que despliega el Flyout con el resumen del servicio
function ocultarFlyout(num){
	/// Al quetar el raton de encima desparezca la capa
	//$('#info" + num + "').mouseout(function () {
		$('#capaInfo' + num).hide('slow');
	//});	
}

////////////////////////////////////////////
////Funciones ussadas en FichaHotel.aspx////
////////////////////////////////////////////

//Funcion que valida el formulario de FichaHotel
function validaHabitacion1(numHabitacion) {
    var aco = document.getElementById("ctl00_Contenido_Acomodacion_" + numHabitacion);
    var reg = document.getElementById("ctl00_Contenido_Regimen_" + numHabitacion);
    var ad = document.getElementById("ctl00_Contenido_Adultos_" + numHabitacion);
    var nñ = document.getElementById("ctl00_Contenido_Niños_" + numHabitacion);

    if (aco.value == '-1') {
        alert("Debe escoger el tipo de acomodación para la habitación " + numHabitacion + ".");
        aco.focus();
        return false;
    }
    if (reg.value == '-1') {
        alert("Debe escoger el tipo de régimen para la habitación " + numHabitacion + ".");
        reg.focus();
        return false;
    }
    if (!isNaN(ad.value)) {
        if (parseInt(ad.value) < 1) {
            alert("El número de Adultos debe ser mayor que 1 para la habitación " + numHabitacion + ".");
            ad.focus();
            return false;
        }
    }
    else {
        alert("El número de Adultos debe ser mayor que 1 para la habitación " + numHabitacion + ".");
        ad.focus();
        return false;
    }
    if (!isNaN(nñ.value)) {
        if (parseInt(nñ.value) < 0) {
            alert("El número de Niños debe ser mayor o igual que 0 para la habitación " + numHabitacion + ".");
            nñ.focus();
            return false;
        }
    }
    else {
        alert("El número de Niños debe ser mayor o igual que 0 para la habitación " + numHabitacion + ".");
        nñ.focus();
        return false;
    }
    if (!isNaN(bb.value)) {
        if (parseInt(bb.value) < 0) {
            alert("El número de Bebés debe ser mayor o igual que 0 para la habitación " + numHabitacion + ".");
            bb.focus();
            return false;
        }
    }
    else {
        alert("El número de Bebés debe ser mayor o igual que 0 para la habitación " + numHabitacion + ".");
        bb.focus();
        return false;
    }

    return true;
}

//Esta funcion muestra u oculta el numero de habitaciones que se quieren reservar en FichaHotel.aspx
function activaHabitaciones(max) {
    var cmbHabitaciones = document.getElementById("ctl00_Contenido_cmbNumHabitaciones");

    for (i = 1; i <= max; i++) {
        if (i <= parseInt(cmbHabitaciones.value)) {
            document.getElementById("habitacion_" + i).style.display = "block";
        }
        else {
            document.getElementById("habitacion_" + i).style.display = "none";
        }
    }
    return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
////Esto es una funcion que me ha pasado Jorge para que funcione en los diferentes navegadores.////
///////////////////////////////////////////////////////////////////////////////////////////////////

var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i = 0; i < data.length; i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
    },
    dataBrowser: [
                        {
                            string: navigator.userAgent,
                            subString: "Chrome",
                            identity: "Chrome"
                        },
                        { string: navigator.userAgent,
                            subString: "OmniWeb",
                            versionSearch: "OmniWeb/",
                            identity: "OmniWeb"
                        },
                        {
                            string: navigator.vendor,
                            subString: "Apple",
                            identity: "Safari",
                            versionSearch: "Version"
                        },
                        {
                            prop: window.opera,
                            identity: "Opera"
                        },
                        {
                            string: navigator.vendor,
                            subString: "iCab",
                            identity: "iCab"
                        },
                        {
                            string: navigator.vendor,
                            subString: "KDE",
                            identity: "Konqueror"
                        },
                        {
                            string: navigator.userAgent,
                            subString: "Firefox",
                            identity: "Firefox"
                        },
                        {
                            string: navigator.vendor,
                            subString: "Camino",
                            identity: "Camino"
                        },
                        { // for newer Netscapes (6+)
                            string: navigator.userAgent,
                            subString: "Netscape",
                            identity: "Netscape"
                        },
                        {
                            string: navigator.userAgent,
                            subString: "MSIE",
                            identity: "Explorer",
                            versionSearch: "MSIE"
                        },
                        {
                            string: navigator.userAgent,
                            subString: "Gecko",
                            identity: "Mozilla",
                            versionSearch: "rv"
                        },
                        { // for older Netscapes (4-)
                            string: navigator.userAgent,
                            subString: "Mozilla",
                            identity: "Netscape",
                            versionSearch: "Mozilla"
                        }
                        ],
    dataOS: [
                        {
                            string: navigator.platform,
                            subString: "Win",
                            identity: "Windows"
                        },
                        {
                            string: navigator.platform,
                            subString: "Mac",
                            identity: "Mac"
                        },
                        {
                            string: navigator.userAgent,
                            subString: "iPhone",
                            identity: "iPhone/iPod"
                        },
                        {
                            string: navigator.platform,
                            subString: "Linux",
                            identity: "Linux"
                        }
                    ]
};
BrowserDetect.init();

