﻿function verInfoHotel(pro,idH)
{
    window.open('verInfoHotel.aspx?proveedor='+pro+'&idHotel='+idH,'infoHotel','scrollbars=yes,width=610,height=750,left=0,top=10,screenX=0,screenY=10');
}

function comprobarNombre(dato)
{
    var res = "";
    var datos = dato.toString().split(";")
    var g,cant,cont;
    cont = 0;
    for (i=1;i<=4;i++)
    {
        cant = parseInt(datos[cont++]) + parseInt(datos[cont++]);
        for (j=1;j<=cant;j++){
            g = document.getElementById("nombre" + i + '' + j);
            if (g.value == ""){
                alert("Rellena todos los datos de los pasajeros.")
                return false;
            }else
                res += g.value + ",";
            g = document.getElementById("apellido" + i + '' + j);
            if (g.value == ""){
                alert("Rellena todos los datos de los pasajeros.")
                return false;
            }else
                res += g.value + ";";
        }
    }
 
    var selFinal = document.getElementById("ctl00_ContentPlaceHolder1_TextBox1");
    selFinal.value = res;
    
    return true;
}

function comprobarChequeo(idHotel,s0,s1,s2,s3,p)
{
    var res,dato,nombre,valor;
    res = "";
    
    if (p != "G"){ // !=GULLIUVERT        
        for (i=0;i<4;i++){
            valor = eval("s"+i);
            if (valor != "-1"){
                nombre = "SuppliersGroup" + idHotel + "" + valor;
                dato = document.getElementsByName(nombre);
                for (j=0; j < dato.length; j++){
                    if (dato[j].checked)
                        res += dato[j].value + ";";
                }
            }else{
                break;
            }
        }    
    }else{ //GULLIVERT
        nombre = "SuppliersGroup" + idHotel + "0";
        dato = document.getElementsByName(nombre);
        res += dato[0].value + ";";
    }
            
    var selFinal = document.getElementById("ctl00_ContentPlaceHolder1_seleccion2");
    selFinal.value = res + "$" + p;
}


function ShowHide(id) {
    if(document.getElementById(id).style["display"] != "none"){
        document.getElementById(id).style["display"] = "none";
    } else {
        document.getElementById(id).style["display"] = "";
    }
}

function validarBusquedaHotel() {
    var pais = document.getElementById('ctl00_ContentPlaceHolder1_pais').value;
    var destinos = document.getElementById('ctl00_ContentPlaceHolder1_destinos').value;
    var fechaEntrada = document.getElementById('ctl00_ContentPlaceHolder1_fechaEntrada').value;
    var fechaSalida = document.getElementById('ctl00_ContentPlaceHolder1_fechaSalida').value;
    var hayError = false
    var mensaje = "Los campos ";
    if (pais == ""){
        mensaje += " Pais, "; hayError =true ;}
    if (destinos == "" || destinos == "[Cargando Destinos...]" ){
        mensaje += " Destino, "; hayError =true ;}
    if (fechaEntrada == "") {       
        mensaje += " Fecha de entrada, "; hayError =true ;}
    if (fechaSalida == ""){
        mensaje += " Fecha de salida, "  ; hayError =true ;}      
    mensaje += " son necesarios para realizar la búsqueda"
    
    if (hayError){
        alert(mensaje)
        return false
    }
    else
        return true
    
//    if (pais == "" || destinos == "" || fechaEntrada == "" || fechaSalida == "" )
//    {
//        alert ("Los campos 'País', 'Destino', 'Fecha de entrada' y 'Fecha de salida' son necesarios para realizar la búsqueda");
//        return false;
//    }
//    else
//    {
//        return true;   
//    }
//    alert(document.getElementById('ctl00_ContentPlaceHolder1_pais').value);
//    alert(document.getElementById('ctl00_ContentPlaceHolder1_destinos').value);
//    alert(document.getElementById('ctl00_ContentPlaceHolder1_fechaEntrada').value);
//    alert(document.getElementById('ctl00_ContentPlaceHolder1_fechaSalida').value);
}


function hola() {
    valor = document.getElementById("ctl00_emailNews").value;
    alert(valor);
}

//** NEWSLETTER ************************************************************
function validarEmail() {
    valor = document.getElementById("ctl00_emailNews").value;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
		//alert("La dirección de email " + valor + " es correcta.") 
		verificaUsuario();
		document.getElementById("ctl00_emailNews").value = "";
		return (true);
		
	} else {
		alert("La dirección de email es incorrecta.");
		document.getElementById("ctl00_emailNews").value = "";
		document.getElementById("ctl00_emailNews").focus();
		return (false);
		
		
	}
}

function handleHttpResponse() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos
             results = http.responseText.split(",");
			 alert (results);
             //document.getElementById("campoMensaje").innerHTML = results[0];
             enProceso = false;
          }
       }
    }
}

function verificaUsuario() {
    if (!enProceso && http) {
       var valor = escape(document.getElementById("ctl00_emailNews").value);
       //var url = "./consulta.asp?emailUsuario="+ valor;
       var url = "./consulta.aspx?emailUsuario="+ valor;
       http.open("GET", url, true);
       http.onreadystatechange = handleHttpResponse;
       enProceso = true;
       http.send(null);
    }
}
function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
       try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
          try {
             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) { xmlhttp = false; }
       }
    @else
    xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
       try {
          xmlhttp = new XMLHttpRequest();
       } catch (e) { xmlhttp = false; }
    }
    return xmlhttp;
}

//var enProceso = false; // lo usamos para ver si hay un proceso activo
var http = getHTTPObject(); // Creamos el objeto XMLHttpRequest

//** FIN NEWSLETTER ********************************************************



//** CONSULTA DE PRECIO ANTERIOR *******************************************


function handleHttpResponse2() {
    var contador = 0;
    if (http2.readyState == 4) { 
       if (http2.status == 200) { 
          if (http2.responseText.indexOf('invalid') == -1) {
             // Armamos un array, usando la coma para separar elementos
             results = http2.responseText.split(",");
			 //alert (results[0]);
			 contador = results[1];
			 //alert(contador);
			 //alert(results[0]);
             document.getElementById("mensaje"+contador).innerHTML = results[0];
             enProceso = false;
          }
       }
    }
}

function consultaPrecio(fecha, numDest, descri, contador, precioEnviar, TipoOrigen, Folleto) {
    if (!enProceso && http2) {
       //var url = "./consulta.asp?emailUsuario="+ valor;
       var url = "./consultaPreciosAnteriores.aspx?fecha="+ fecha+"&numDest="+numDest+"&descri="+descri+"&contador="+contador+"&precioEnviar="+precioEnviar+"&TipoOrigen="+TipoOrigen+"&Folleto="+Folleto;
       http2.open("GET", url, true);
       //var conta = contador;
       http2.onreadystatechange = handleHttpResponse2;
       enProceso = true;
       http2.send(null);
    }
}


var enProceso = false; // lo usamos para ver si hay un proceso activo
var http2 = getHTTPObject(); // Creamos el objeto XMLHttpRequest




//** FIN CONSULTA DE PRECIO ANTERIOR **************************************

//** DETECTOR DE NAVEGADOR Y VERSIÓN **************************************

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();



//** FIN DETECTOR DE NAVEGADOR Y VERSIÓN ***********************************


function autofactura(){
		
	var obj = document.all.autofactura.style;
	
	if (obj.visibility == "visible"){
		obj.visibility = "hidden";	//hide
	}else{
		obj.visibility = "visible";	//show
	}
			
}