
function lanza_request(url, funcion) {
	estados = "";
                http_request = false;

                if (window.XMLHttpRequest) { 
                    http_request = new XMLHttpRequest();
                    if (http_request.overrideMimeType) {
                        http_request.overrideMimeType('text/xml');
                    }
                } else if (window.ActiveXObject) { 
                    try {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch (e) {
                        try {
                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e) {}
                    }
                }

                if (!http_request) {
                    alert('Giving up :( Cannot create an XMLHTTP instance');
                    return false;
                }
                http_request.onreadystatechange = eval(funcion);
                http_request.open('GET', url, true);
                http_request.send(null);

            }

function lanza_request_POST(url, funcion, parametros) {
	estados = "";
                http_request = false;

                if (window.XMLHttpRequest) { 
                    http_request = new XMLHttpRequest();
                    if (http_request.overrideMimeType) {
                        http_request.overrideMimeType('text/xml');
                    }
                } else if (window.ActiveXObject) { 
                    try {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch (e) {
                        try {
                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e) {}
                    }
                }

                if (!http_request) {
                    alert('Giving up :( Cannot create an XMLHTTP instance');
                    return false;
                }
                http_request.onreadystatechange = eval(funcion);
                http_request.open('POST', url, true);
                http_request.send('paramentros='+parametros);

            }

function recibir_vuelos2(){
    switch(http_request.readyState) {
    case 0: // Uninitialized
        break;
    case 1: // Loading
        break;
    case 2: // Loaded
        break;
    case 3: // Interactive
        break;
    case 4: // Done!
	     if (http_request.status == 200) { // Respuesta OK
	      //alert(http_request.responseText);
		  procesar_vuelos2(http_request.responseText);
	     }
		 else {
	       alert('Se ha producido el error xml_1: '+http_request.status);
	     }
		break;
    default:
        break;
    }
	estados += http_request.readyState;

}

function recibir_hoteles(){
    switch(http_request.readyState) {
    case 0: // Uninitialized
        break;
    case 1: // Loading
        break;
    case 2: // Loaded
        break;
    case 3: // Interactive
        break;
    case 4: // Done!
	     if (http_request.status == 200) { // Respuesta OK
	      //alert(http_request.responseText);
		  procesar_hoteles(http_request.responseXML);
	     }
		 else {
	       alert('Se ha producido el error xml_1: '+http_request.status);
	     }
		break;
    default:
        break;
    }
	estados += http_request.readyState;

}


function recibir_confirmacion(){
    switch(http_request.readyState) {
    case 0: // Uninitialized
        break;
    case 1: // Loading
        break;
    case 2: // Loaded
        break;
    case 3: // Interactive
        break;
    case 4: // Done!
	     if (http_request.status == 200) { // Respuesta OK
	      //alert(http_request.responseText);
		  procesar_confirmacion(http_request.responseText);
	     }
		 else {
	       alert('Se ha producido el error xml_1: '+http_request.status);
	     }
		break;
    default:
        break;
    }
	estados += http_request.readyState;

}

function recibir_desglose2(){
	switch(http_request.readyState) {
    case 0: // Uninitialized
        break;
    case 1: // Loading
        break;
    case 2: // Loaded
        break;
    case 3: // Interactive
        break;
    case 4: // Done!
	     if (http_request.status == 200) { // Respuesta OK
	      //alert(http_request.responseText);
		  procesar_desglose2(http_request.responseText);
	     }
		 else {
	       alert('Se ha producido el error xml_1: '+http_request.status);
	     }
		break;
    default:
        break;
    }
	estados += http_request.readyState;
}




function procesar_vuelos2(xml){
	document.getElementById('capa_vuelos').innerHTML=xml;
	
	
	document.getElementById('waiting').style.display="none";
	document.getElementById('vuelos_viaje').style.display="block";
}

function ordenar_hotel(x,y){
	if ( parseFloat(x[1]) < parseFloat(y[1]) ) return -1; 
	if ( parseFloat(x[1]) > parseFloat(y[1]) ) return 1; 
	return 0; 
}

function procesar_hoteles(xml){
	var nodo_hoteles_paquetes=xml.getElementsByTagName("hoteles_paquetes")[0];
	var contenido="";
	
	
	var nodo_vuelos=nodo_hoteles_paquetes.getElementsByTagName("vuelos")[0];
	var i=0;
	var i_ida=0;
	while(nodo_vuelos.getElementsByTagName("vuelo")[i]!=null){
		var nodo_vuelo=nodo_vuelos.getElementsByTagName("vuelo")[i];
		var tiptra=nodo_vuelo.getElementsByTagName("tiptra")[0].firstChild.data;
		var numvue=nodo_vuelo.getElementsByTagName("numvue")[0].firstChild.data;
		var paxes=nodo_vuelo.getElementsByTagName("paxes")[0].firstChild.data;
		var aptori=nodo_vuelo.getElementsByTagName("aptori")[0].firstChild.data;
		var aptdes=nodo_vuelo.getElementsByTagName("aptdes")[0].firstChild.data;
		var fecsal=nodo_vuelo.getElementsByTagName("fecsal")[0].firstChild.data;
		var horsal=nodo_vuelo.getElementsByTagName("horsal")[0].firstChild.data;
		var horlle=nodo_vuelo.getElementsByTagName("horlle")[0].firstChild.data;
		if(tiptra=="I" && i_ida==0)
			document.getElementById('vac_fecha_viaje').value=fecsal;
		contenido+='<div style="float:left;display:inline;width:795px; background-color:#E5E5E5; height:17px; padding-bottom:3px; margin-top:5px; padding-top:3px; margin-left:5px;">';
			contenido+='<div style="float:left;display:inline;width:105px;" class="E-12-gris_oscuro-bold-Verdana">Viaje</div>';
			contenido+='<div style="float:left;display:inline;width:105px;" class="E-12-gris_oscuro-bold-Verdana">Fecha</div>';
			contenido+='<div style="float:left;display:inline;width:105px;" class="E-12-gris_oscuro-bold-Verdana">Nº de vuelo</div>';
			contenido+='<div style="float:left;display:inline;width:105px;" class="E-12-gris_oscuro-bold-Verdana">Salida</div>';
			contenido+='<div style="float:left;display:inline;width:105px;" class="E-12-gris_oscuro-bold-Verdana">Llegada</div>';
			contenido+='<div style="float:left;display:inline;width:205px;" class="E-12-gris_oscuro-bold-Verdana">Personas</div>';
		contenido+='</div>';
		contenido+='<div style="clear: both"></div>';
		contenido+='<div style="float:left;display:inline;width:795px; border-bottom:1px solid #E1E1E0; padding-bottom:3px; padding-top:1px; margin-left:5px;">';
			if(tiptra=="I"){
				contenido+='<div style="float:left;display:inline;width:105px;padding-top:2px;" class="E-12-gris_oscuro-bold-Verdana">IDA</div>';
				i_ida++;
			}
			if(tiptra=="V")
				contenido+='<div style="float:left;display:inline;width:105px;padding-top:2px;" class="E-12-gris_oscuro-bold-Verdana">VUELTA</div>';
			contenido+='<div style="float:left;display:inline;width:105px;padding-top:2px;" class="E-12-gris_oscuro-Verdana">'+fecsal+'</div>';
			contenido+='<div style="float:left;display:inline;width:105px;padding-top:2px;" class="E-12-gris_oscuro-Verdana">'+numvue+'</div>';
			contenido+='<div style="float:left;display:inline;width:105px;padding-top:2px;" class="E-12-gris_oscuro-Verdana">'+aptori+'. '+horsal+'h</div>';
			contenido+='<div style="float:left;display:inline;width:105px;padding-top:2px;" class="E-12-gris_oscuro-Verdana">'+aptdes+'. '+horlle+'h</div>';
			contenido+='<div style="float:left;display:inline;width:205px;padding-top:2px;" class="E-12-gris_oscuro-Verdana">'+paxes+'</div>';
		contenido+='</div>';
		contenido+='<div style="clear: both"></div>';
		i++;
	}
	document.getElementById('informacion_vuelos').innerHTML=contenido;
	contenido="";
	var nodo_hoteles=nodo_hoteles_paquetes.getElementsByTagName("hotpres")[0];
	var i=0;
	var hoteles=new Array();
	var indice_hotel=0;
	while(nodo_hoteles.getElementsByTagName("hotpre")[i]!=null){
		var encontrado_hotel=false;
		var indice_encontrado=null;
		var nodo_hotel=nodo_hoteles.getElementsByTagName("hotpre")[i];
		var codigo_hotel=nodo_hotel.getElementsByTagName("salcod")[0].firstChild.data;
		var categoria_hotel=nodo_hotel.getElementsByTagName("salcod")[0].getAttribute('catcod');
		var calnum_hotel=nodo_hotel.getElementsByTagName("calnum")[0].firstChild.data;
		var linnum_hotel=nodo_hotel.getElementsByTagName("linnum")[0].firstChild.data;
		var regimen_hotel=nodo_hotel.getElementsByTagName("regimen")[0].firstChild.data;
		var importe_hotel=nodo_hotel.getElementsByTagName("importe")[0].firstChild.data;
		importe_hotel=importe_hotel.replace(/\./gi,'');
		importe_hotel=importe_hotel.replace(/,/gi,'.');
		importe_hotel=parseFloat(importe_hotel);
		var estado_hotel=nodo_hotel.getElementsByTagName("estado")[0].firstChild.data;
		var porcen_hotel=nodo_hotel.getElementsByTagName("porcen")[0].firstChild.data;
		if((estado_hotel=="RQ" && hoteles_bajo_peticion) || estado_hotel!="RQ"){
			for(var j=0;j<hoteles.length && !encontrado_hotel;j++){
				if(hoteles[j][0]==codigo_hotel){
					encontrado_hotel=true;
					indice_encontrado=j;
				}
			}
			if(encontrado_hotel){
				if(hoteles[indice_encontrado][1]>importe_hotel)
					hoteles[indice_encontrado][1]=importe_hotel;
				var indice_hab=hoteles[indice_encontrado][4].length;
				hoteles[indice_encontrado][4][indice_hab]=new Array();
				hoteles[indice_encontrado][4][indice_hab][0]=linnum_hotel;
				hoteles[indice_encontrado][4][indice_hab][1]=regimen_hotel;
				hoteles[indice_encontrado][4][indice_hab][2]=importe_hotel;
				hoteles[indice_encontrado][4][indice_hab][3]=estado_hotel;
				hoteles[indice_encontrado][4][indice_hab][4]=porcen_hotel;
			}else{
				hoteles[indice_hotel]=new Array();
				hoteles[indice_hotel][0]=codigo_hotel;
				hoteles[indice_hotel][1]=importe_hotel;
				hoteles[indice_hotel][2]=categoria_hotel;
				hoteles[indice_hotel][3]=calnum_hotel;
				hoteles[indice_hotel][4]=new Array();
				hoteles[indice_hotel][4][0]=new Array();
				hoteles[indice_hotel][4][0][0]=linnum_hotel;
				hoteles[indice_hotel][4][0][1]=regimen_hotel;
				hoteles[indice_hotel][4][0][2]=importe_hotel;
				hoteles[indice_hotel][4][0][3]=estado_hotel;
				hoteles[indice_hotel][4][0][4]=porcen_hotel;
				
				indice_hotel++;
			}
		}
		
		i++;
	}
	hoteles=hoteles.sort(ordenar_hotel);
	
	contenido='<div style="float:left;display:inline;width:920px; margin-left:15px;">';
		contenido+='<div style="float:left;display:inline;width:440px;"><div style="float:left;display:inline;width:220px;" class="hotel_ok">OK = Reserva inmediata</div><div style="float:left;display:inline;width:220px;" class="hotel_rq">RQ = Petición disponibilidad</div></div>';
		contenido+='<div style="float:left;display:inline;width:190px;margin-left:5px;" class="E-12-gris_oscuro-bold-Verdana">Régimen</div>';
		contenido+='<div style="float:left;display:inline;width:100px;margin-left:5px;" class="E-12-gris_oscuro-bold-Verdana">Precio final</div>';
		contenido+='<div style="float:left;display:inline;width:150px;margin-left:5px;" class="E-12-gris_oscuro-bold-Verdana">Descuento <em style="font-size: 10px">(incluido)</em></div>';
	contenido+='</div>';
	contenido+='<div style="clear: both"></div>';
	for(i=0; i<hoteles.length; i++){
		var codigo=hoteles[i][0];
		var descuento=false;
		contenido+='<div style="float:left;display:inline;width:930px; margin-left:10px; margin-top:5px; margin-bottom:5px; border: 1px solid #E1E1E0; #~#COLOR_DE_FONDO#~#">';
			contenido+='<div style="width:920px; margin:5px auto 5px auto">';
				contenido+='<div style="float:left;display:inline;width:410px;">';
					contenido+='<div style="float:left;display:inline;height:78px;width:119px;margin:0px; overflow:hidden; ">';
						contenido+='<a href="javascript:void(0);" onclick="abrir_detalles(\''+codigo+'\')"><img border=0 width="119px" src="http://www.soltour.es/hoteles/'+codigo.toLowerCase()+'1.jpg" onerror="this.src=\'/paquetes-vacaciones/img/sin_img.jpg\'"/></a>';
					contenido+='</div>';
					contenido+='<div style="float:left;display:inline;margin-left:5px;">';
						contenido+='<div style="float:left;display:inline;margin:0px;width:285px;" class="E-12-gris_oscuro-bold-Verdana"><a class="E-12-gris_oscuro-bold-Verdana" href="javascript:void(0);" onclick="abrir_detalles(\''+codigo+'\')" >'+(hoteles_datos_aux[codigo][0]).toUpperCase()+'</a>&nbsp;';
						
						contenido+='</div>';
						contenido+='<div style="clear: both"></div>';
						contenido+='<div style="float:left;display:inline;margin:5px 0 0 0;width:285px;" class="E-12-gris-bold-Verdana">';
						var numero_estrellas=0;
						for(var k=0;k<hoteles[i][2].length;k++){
							if(hoteles[i][2].substring(k,k+1)=="*")
								numero_estrellas++;
						}
						for(k=0;k<numero_estrellas;k++){
							contenido+='<IMG border=0 src="/paquetes-vacaciones/img/star.gif">&nbsp;';
						}
						contenido+='&nbsp;&nbsp;<a class="E-12-gris_oscuro-bold-Verdana" href="javascript:void(0);" onclick="abrir_detalles(\''+codigo+'\')" >Más información</a>';
						contenido+='</div>';
						contenido+='<div style="clear: both"></div>';
						contenido+='<div style="float:left;display:inline;margin:5px 0 0 0;width:285px;" class="E-12-gris-bold-Verdana">';
						contenido+=hoteles_datos_aux[codigo][2]+' ('+hoteles_datos_aux[codigo][3]+')';
						contenido+='</div>';
						contenido+='<div style="clear: both"></div>';
						if(hoteles_datos_aux[codigo][1]=="S"){
							contenido+='<div style="float:left;display:inline;margin:5px 0 0 0;">';
								contenido+='<IMG border=0 src="/paquetes-vacaciones/img/dto/cara-nene.gif"> <STRONG class=E-12-azulito-Verdana>Niños gratis</STRONG>';
							contenido+='</div>';
							contenido+='<div style="clear: both"></div>';
						}
						if(hoteles_datos_aux[codigo][4]!="N"){
							contenido+='<div style="float:left;display:inline;margin:5px 0 0 0;">';
								contenido+='<IMG border=0 src="/paquetes-vacaciones/img/logo_bp_peq.png"> <STRONG class=E-12-azulito-Verdana>Hotel Bahia Principe</STRONG>';
							contenido+='</div>';
							contenido+='<div style="clear: both"></div>';
						}
					contenido+='</div>';
					contenido+='<div style="clear: both"></div>';
				contenido+='</div>';
				contenido+='<div style="float:left;display:inline;width:505px; margin-left:5px;">';
					for(j=0;j<hoteles[i][4].length;j++){
						contenido+='<div style="float:left;display:inline;width:505px;margin-top:5px;">';
							if(hoteles[i][4][j][3]=="OK")
								contenido+='<div style="float:left;display:inline;width:25px;margin-top:8px;" class="hotel_ok">'+hoteles[i][4][j][3]+'</div>';
							else
								contenido+='<div style="float:left;display:inline;width:25px;margin-top:8px;" class="hotel_rq">'+hoteles[i][4][j][3]+'</div>';
							contenido+='<div style="float:left;display:inline;width:190px;margin-left:5px;margin-top:8px;" class="E-12-gris_oscuro-Verdana">';
							switch(hoteles[i][4][j][1]){
								case "SA": contenido+='Sólo alojamiento';
											break;
								case "AD": contenido+='Alojamiento y desayuno';
											break;
								case "MP": contenido+='Media pensión';
											break;
								case "PC": contenido+='Pensión completa';
											break;
								case "TI": contenido+='Todo incluido';
											break;
								default: contenido+=hoteles[i][4][j][1];
							}
							contenido+='</div>';
							var precion_des_raton=hoteles[i][4][j][2];
							var descuento_raton=parseFloat(precion_des_raton)*(descuento_general_raton/100);
							contenido+='<div style="float:left;display:inline;width:100px;margin-left:5px;margin-top:2px;" class="E-12-gris_oscuro-Verdana">';
								contenido+='<div style="float:left;display:inline;width:100px;" align="right" class="hotel_precio">'+(Math.round((parseFloat(precion_des_raton)-descuento_raton)*100)/100)+' €</div>';
								contenido+='<div style="clear: both"></div>';
								contenido+='<div style="float:left;display:inline;" class="ver_desglose" onmouseover="this.style.cursor=\'pointer\';this.style.textDecoration=\'underline\';" onmouseout="this.style.textDecoration=\'none\';" onclick="obtener_descuento_hotel(event,curLeft(this),curTop(this),\''+hoteles[i][3]+'\',\''+hoteles[i][4][j][0]+'\')">Ver desglose</div>';
							contenido+='</div>';
							if(parseInt(hoteles[i][4][j][4])>0){
								contenido+='<div style="float:left;display:inline;width:50px;margin-left:15px;margin-top:8px;" class="hotel_descuento">'+hoteles[i][4][j][4]+'%</div>';
								descuento=true;
							}else
								contenido+='<div style="float:left;display:inline;width:50px;margin-left:15px;margin-top:8px;" class="hotel_descuento"></div>';
							contenido+='<div onclick="seleccionar_hotel(\''+hoteles[i][0]+'\',\''+hoteles[i][3]+'\',\''+hoteles[i][4][j][0]+'\')" onmouseover="this.style.cursor=\'pointer\'" style="float: left; margin-left: 5px; display: inline; width: 108px; height: 36px; background-image: url(/paquetes-vacaciones/img/boton_reservar.png);"/>';
							contenido+='</div>';
							contenido+='<div style="clear: both"></div>';
						contenido+='</div>';
						contenido+='<div style="clear: both"></div>';
					}
				contenido+='</div>';
				contenido+='<div style="clear: both"></div>';
			contenido+='</div>';
			contenido+='<div style="clear: both"></div>';
		contenido+='</div>';
		contenido+='<div style="clear: both"></div>';
		if(descuento){
			contenido=contenido.replace(/#~#COLOR_DE_FONDO#~#/gi,'background-color:#fff3e6;');
		}else{
			contenido=contenido.replace(/#~#COLOR_DE_FONDO#~#/gi,'');
		}
	}
	document.getElementById('capa_hoteles').innerHTML=contenido;
	
	var nodo_parametros=nodo_hoteles_paquetes.getElementsByTagName("parametros")[0];
	var vuelo_ida=nodo_parametros.getElementsByTagName("p_discri_ida")[0].firstChild.data;
	var vuelo_vuelta=nodo_parametros.getElementsByTagName("p_discri_vue")[0].firstChild.data;
	
	document.getElementById('vac_vuelo_ida').value=vuelo_ida;
	document.getElementById('vac_vuelo_vuelta').value=vuelo_vuelta;
	
	document.getElementById('waiting').style.display="none";
	document.getElementById('hoteles_viaje').style.display="block";
}
var confirmacion_general="OK";

function procesar_confirmacion(xml){
	
	document.getElementById('comfirmacion_datos').innerHTML=xml;
	document.getElementById('waiting').style.display="none";
	document.getElementById('confirmacion_viaje').style.display="block";
}

function procesar_desglose2(xml){
	document.getElementById('desglose_precio_viaje').innerHTML=xml;
}

