function ChkRooms(oBj) {
    switch (oBj.value) {
        case "1":
            document.getElementById('room_2').style.display = 'none';
            document.getElementById('room_3').style.display = 'none';
			document.getElementById('room_4').style.display = 'none';
            break;
        case "2":
            document.getElementById('room_2').style.display = '';
            document.getElementById('room_3').style.display = 'none';
			document.getElementById('room_4').style.display = 'none';
            break;
        case "3":
            document.getElementById('room_2').style.display = '';
            document.getElementById('room_3').style.display = '';
			document.getElementById('room_4').style.display = 'none';
            break;
		case "4":
            document.getElementById('room_2').style.display = '';
            document.getElementById('room_3').style.display = '';
			document.getElementById('room_4').style.display = '';
            break;
    }
}
/************************************************************************************/
/****************************** OFERTAS NAVEGADOR ***********************************/
/************************************************************************************/
var actual = 1;

function PrevOferta(total) {
    if (actual - 1 >= 1) {
        document.getElementById('oferta_' + actual).style.display = 'none';
        document.getElementById('oferta_' + (actual - 1)).style.display = '';
        actual--;
        document.getElementById('counter').innerHTML = actual + '/' + total;
    }
}
function NextOferta(total) {
    if (actual + 1 <= total) {
        document.getElementById('oferta_' + actual).style.display = 'none';
        document.getElementById('oferta_' + (actual + 1)).style.display = '';
        actual++;
        document.getElementById('counter').innerHTML = actual + '/' + total;
    }
}

function AllOferta(total) {
    var aOBJ = document.getElementsByName('ofert_ul');
    for (var j = 1; j <= aOBJ.length; j++) {
		document.getElementById('ofert_ul_' + j).className = 'depart_list_result clearfix';
		document.getElementById('inside_' + j).style.background = "#FFF";
		document.getElementById('inside_' + j).style.height = "auto";
		document.getElementById('off_price_box_' + j).className = "floatright absolute txtcenter";
    }
    for(var i=1;i<=total;i++)
    {
        document.getElementById('oferta_' + i).style.display = '';
    }
    document.getElementById('paginator').style.display = 'none';
    document.getElementById('total_ofers').innerHTML = '<a href="javascript:CollapseOferta(' + total + ');" title="Ocultar todas las ofertas">Ocultar</a>';
}

function CollapseOferta(total) {
    var aOBJ = document.getElementsByName('ofert_ul');
    for (var j = 1; j <= aOBJ.length; j++) {
		document.getElementById('ofert_ul_' + j).className = 'depart_list clearfix';
		var img = document.getElementById('inside_gif_' + j).value;
		document.getElementById('inside_' + j).style.background = "#fff" + ((img!='') ? " url('/vuelos-hoteles/images/" + img+ "')" : "");
		//document.getElementById('inside_' + j).style.borderbottom = "1px solid #999900";
		document.getElementById('inside_' + j).style.height = "200px";
		document.getElementById('off_price_box_' + j).className = "floatright txtcenter";
    }
    for(var i=1;i<=total;i++)
    {
        if(i != actual){
            document.getElementById('oferta_' + i).style.display = 'none';
        }
    }
    document.getElementById('paginator').style.display = '';
    document.getElementById('total_ofers').innerHTML = '<a href="javascript:AllOferta(' + total + ');" title="Ver todas las ofertas">Ver todas</a>';
}

function changeOfert(oBj) {
    var Url = window.location.href;
    var aUrl = Url.split('?');
    if (Url.indexOf("?")!=-1) {
		var patron = /departure=[a-zA-Z]{3}/;
		var str = Url.match(patron);
		if (str!=null) Url = Url.replace(patron, 'departure=' + oBj.value);
		else Url = Url + '&departure=' + oBj.value;
		window.location.href = Url;
    } else {
		window.location.href = Url + '?departure=' + oBj.value;
    }
    //window.location.href = aUrl[0] + '?loc=' + oBj.value;
    //window.location.href = Url + '&departure=' + oBj.value;
}
/************************************************************************************/
/**************************** BUSCADOR **********************************************/
/************************************************************************************/
function changeNinos(oBj,op) {
    var oBjValue = oBj.value;
    var aOBjValue = oBjValue.split('-');
    if (aOBjValue.length > 1) {
        document.getElementById('childs_' + op).style.display = '';
        for (var j = 1; j <= 3; j++) {
            document.getElementById(oBj.name + '_nino_' + j).style.display = 'none';
        }
        for(var i=1;i<=aOBjValue[1];i++) {
            document.getElementById(oBj.name + '_nino_' + i).style.display = '';
        }
    } else {
        document.getElementById('childs_' + op).style.display = 'none';
        for (var j = 1; j <= 3; j++) {
            document.getElementById(oBj.name + '_nino_' + j).style.display = 'none';
        }
    }
}

/************************************************************************************/
/****************************** RESULTADOS BUSQUEDA *********************************/
/************************************************************************************/
function show_tab(sTab) {
    $(".tabbed_div").css("display", "none");
    $("#tab" + sTab).css("display", "block");

    $(".nav_box li").attr("class", "");
    $("#li" + sTab).attr("class", "selected");
}

function show_more(sDiv,menu) {
    $(".div_more").css("display", "none");
    $("#" + sDiv).css("display", "block");
    
    
	destination = $("#menu_more1").offset().top;
	$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
	
    
    if (menu == '1') {
        document.getElementById('menu_more1').className =  "unmedio opacity mr10";
        document.getElementById('menu_more2').className =  "unmedio ";
    }
    else {
        document.getElementById('menu_more1').className = "unmedio mr10";
        document.getElementById('menu_more2').className = "unmedio opacity ";
    }
}


function show_more_open_on_load(sDiv,menu) {
    $(".div_more").css("display", "none");
    $("#" + sDiv).css("display", "block");
    
    if (menu == '1') {
        document.getElementById('menu_more1').className =  "unmedio opacity mr10";
        document.getElementById('menu_more2').className =  "unmedio ";
    }
    else {
        document.getElementById('menu_more1').className = "unmedio mr10";
        document.getElementById('menu_more2').className = "unmedio opacity ";
    }
}


function SelectHotel(idHotel, pos, lang) {
	managePest(true, true);
	setTimeout("SelectHotel2('" + idHotel + "', " + pos+ ", '" + lang + "')", 3000);
	destination = $("#header").offset().top;
	$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
}



function SelectHotel2(idHotel, pos, lang) {
    var sId = new String(idHotel);
    var profileUrl = "/Vuelos-Hoteles/aspx/FichaHotel.aspx?codHotel=" + sId.replace('_', '.');
    var linkHotelTitle = "<a href=\"" + profileUrl + "\" target=\"_blank\">" + $("#nombre_hotel_" + idHotel).val() + "</a>";
    
    if(lang != "") {
		profileUrl += "&lang=" + lang;
    }
    
    ShowHiddenTab();
	$("#misel_h").val(sId);
	//$("#misel_h").val(pos);
    $("#sel_hotel_nombre").html(linkHotelTitle);
    $("#sel_hotel_ciudad").html($("#poblacion_hotel_" + idHotel).val());
    $("#sel_hotel_regimen").html($("#regimen_hotel_" + idHotel).val());
    $("#sel_hotel_noches").html($("#noches_hotel_" + idHotel).val());
    $("#sel_hotel_habitaciones").html($("#habitaciones_hotel_" + idHotel).val());
    $("#sel_hotel_imagen").attr('src', $("#imagen_hotel_" + idHotel).val());
    //$("#a_hotel_id").attr("href", "javascript:ShowFichaHotelDin('" + sId.replace('_', '.') + "')");
    $("#a_hotel_id").attr("href", profileUrl);
    PutSelStars($("#categoria_hotel_" + idHotel).val());
    //precioHolelSelect = $("#precio_hotel_" + idHotel).val();
    
     $("#misel_h_price").val($("#precio_hotel_" + idHotel).val());
    
    
    CalcularPrecio();
	managePest(false, true);
	
	$("#misel_h_pos").val(new String(pos));
}



function managePest(hide, hotel) {
	
	document.getElementById("lightbox_content").style.display = (hide) ? '' : 'none';
	document.getElementById("pest_result").style.display = (hide) ? 'none' : '';
	document.getElementById("tit_espera_hotel").style.display = (hotel) ? '' : 'none';
	document.getElementById("tit_espera_vuelo").style.display = (hotel) ? 'none' : '';
}

function PutHotelDinamic(idHotel) {
    var sNameHotel = new String($("#nombre_hotel_" + idHotel).val());
    var sRegimenHotel = $("#regimen_hotel_" + idHotel).val()
    var sTextToUrl = txt2url(sNameHotel);
    $("#iframe_hotel_dinamic").attr("src", '/Vuelos-Hoteles/aspx/FichaHotel.aspx?codHotel=' + idHotel + '&r=' + sRegimenHotel + '.aspx');  
}

function ShowFichaHotelDin(idHotel) {
    PutHotelDinamic(idHotel);
    tb_show('Ver detalle del hotel', '##TB_inline?height=600&width=900&inlineId=pnl_hotel_dinamic&modal=true', false);    
}

function ShowFichaVueloBar() {
    tb_show('Ver detalle del vuelo', '#TB_inline?height=300&width=700&inlineId=pnl_vuelo_barato&modal=true', false);
}

function ShowFichaVueloDin() {
    //tb_show('Ver detalle del vuelo', '#TB_inline?height=300&width=700&inlineId=pnl_vuelo_dinamic&modal=true', false);
    //alert(flightId);
    tb_show('Ver detalle del vuelo', '/vuelos-hoteles/aspx/ajax.aspx?do=flightprofile&flightid=' + flightId + '&width=750&height=inherits&inlineId=pnl_vuelo_dinamic&modal=true', false);
}


var flightId;


function PutVueloDinamic(idVuelo) {
	//alert(idVuelo);
	
	flightId = $("#vuelo_id_" + idVuelo).val();

	//alert($("#ida_" + idVuelo).val());
    /*$("#din_ida").html($("#ida_" + idVuelo).val());
    $("#din_compania_ida").html($("#ida_compania_" + idVuelo).val());
    $("#din_duracion_ida").html($("#ida_duracion_" + idVuelo).val());
    $("#din_salida_ida").html($("#ida_salida_" + idVuelo).val());
    $("#din_llegada_ida").html($("#ida_llegada_" + idVuelo).val());

    $("#din_vuelta").html($("#vuelta_" + idVuelo).val());
    $("#din_compania_vuelta").html($("#vuelta_compania_" + idVuelo).val());
    $("#din_duracion_vuelta").html($("#vuelta_duracion_" + idVuelo).val());
    $("#din_salida_vuelta").html($("#vuelta_salida_" + idVuelo).val());
    $("#din_llegada_vuelta").html($("#vuelta_llegada_" + idVuelo).val());*/
}


function PutVueloStatic(type) {
	
	if(type == "longtime") {
		flightId = $("#mlarg_v").val();
	} else if(type == "luxury") {
		flightId = $("#mluj_v").val();
	} else {
		flightId = $("#mbar_v").val();
	}
	
    /*$("#din_ida").html($("#ida_" + type).val());
    $("#din_compania_ida").html($("#ida_compania_" + type).val());
    $("#din_duracion_ida").html($("#ida_duracion_" + type).val());
    $("#din_salida_ida").html($("#ida_salida_" + type).val());
    $("#din_llegada_ida").html($("#ida_llegada_" + type).val());

    $("#din_vuelta").html($("#vuelta_" + type).val());
    $("#din_compania_vuelta").html($("#vuelta_compania_" + type).val());
    $("#din_duracion_vuelta").html($("#vuelta_duracion_" + type).val());
    $("#din_salida_vuelta").html($("#vuelta_salida_" + type).val());
    $("#din_llegada_vuelta").html($("#vuelta_llegada_" + type).val());*/
}


function SelectVuelo(idVuelo, code) {
	managePest(true, false);
	setTimeout("SelectVuelo2('" + idVuelo + "', '" + code + "')", 3000);
	destination = $("#header").offset().top;
	$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
}
function SelectVuelo2(idVuelo, code) {
    ShowHiddenTab();
    
    var linkEscalasIda = "<a href=\"javascript:PutVueloDinamic('" + idVuelo + "');javascript:ShowFichaVueloDin('" + idVuelo + "');\">" + $("#ida_escalas_" + idVuelo).val() + "</a>"
    var linkEscalasVuelta = "<a href=\"javascript:PutVueloDinamic('" + idVuelo + "');javascript:ShowFichaVueloDin('" + idVuelo + "');\">" + $("#vuelta_escalas_" + idVuelo).val() + "</a>"
    
	$("#misel_v").val(code);
    //$("#sel_ida").html($("#ida_" + idVuelo).val());
    $("#sel_ida").html($("#ida_" + idVuelo).val() + " " + linkEscalasIda);
    $("#sel_ida_salida").html($("#ida_salida_" + idVuelo).val());
    $("#sel_ida_llegada").html($("#ida_llegada_" + idVuelo).val());
    //$("#sel_vuelta").html($("#vuelta_" + idVuelo).val());
    $("#sel_vuelta").html($("#vuelta_" + idVuelo).val() + " " + linkEscalasVuelta);
    $("#sel_vuelta_salida").html($("#vuelta_salida_" + idVuelo).val());
    $("#sel_vuelta_llegada").html($("#vuelta_llegada_" + idVuelo).val());
    $("#a_vuelo_id").attr("href", "javascript:ShowFichaVueloDin('" + idVuelo + "')");
    //precioVueloSelect = $("#precio_vuelo_" + idVuelo).val();
    
    
    $("#misel_v_price").val($("#precio_vuelo_" + idVuelo).val());
    
    //alert("por aqui!!");
    
    CalcularPrecio();    
	managePest(false, false);
}

function ShowHiddenTab() {
    $("#li0").css("display", "");
    show_tab('0');
}

var hotelBasePrice = null;
var flightBasePrice = null;

function CalcularPrecio() {
	/*precioHotelSelect = $("#misel_h").val();
	precioHotelSelect = $("#precio_hotel_" + precioHotelSelect).val();
	precioVueloSelect = "#vuelo_" + $("#misel_v").val();
	precioVueloSelect = $(precioVueloSelect).val();
	precioVueloSelect = precioVueloSelect.replace(",",".");
	precioHotelSelect = precioHotelSelect.replace(",",".");*/
	
	var hotelPrice = $("#misel_h_price").val().replace(",", ".");
    var flightPrice = $("#misel_v_price").val().replace(",", ".");
    
	/*v1 = parseFloat(precioHotelSelect);
	v2 = parseFloat(precioVueloSelect);*/
	
	v1 = parseFloat(flightPrice);
	v2 = parseFloat(hotelPrice);
	v = v1 + v2;
	
	
	//Ñapa para mostrar precio por pasajero
	var adults = $("#adults").val();
	var childrens = $("#childrens").val();
	var infants = $("#infants").val();
	
	var passengers = parseInt(adults) + parseInt(childrens) + parseInt(infants);
	//alert(passengers);
	v = v / passengers;
	
	
	v = Math.round(v*100)/100;
	_total = new String(v);
	_total = _total.replace(".",",");
	
	
    $("#sel_price").html(_total);
    //$("#sel_price").html("+" + (parseFloat(precioVueloSelect) + parseFloat(precioHolelSelect) - parseFloat(precioHotelBarato) - parseFloat(precioVueloBarato)));
    //$("#sel_final_price").html(parseFloat(precioVueloSelect) + parseFloat(precioHolelSelect));
    asignePrice();
}


function asignePrice() {

	//var hotelPrice = $("#precio_hotel_" + $("#misel_h").val()).val().replace(",", ".");
	//var flightPrice = $("#precio_vuelo_" + $("#misel_v").val()).val().replace(",", ".");
	var hotelPrice = $("#misel_h_price").val().replace(",", ".");
    var flightPrice = $("#misel_v_price").val().replace(",", ".");
    
    
    //alert(hotelPrice + "\n" + flightPrice);
	
	
	var hotelsCount = $("#allHotelsCounter").val();
	var flightsCount = $("#allFlightsCounter").val();
	var i;
	var myFlightPrice;
	var myHotelPrice;
	var myFlightPrice;
	var flightHotelPrice;
	var myFlightHotelPrice;
	var flightHotelPriceDiference;
	var diference;
	var signed;
	var adults = parseInt($("#adults").val());
	var childrens = parseInt($("#childrens").val());
	var infants = parseInt($("#infants").val());
	
	hotelPrice = parseFloat(hotelPrice);
	flightPrice = parseFloat(flightPrice);
	flightHotelPrice = hotelPrice + flightPrice;
	
	
	for(i = 1; i <= hotelsCount; i++) {
		myHotelPrice = parseFloat($("#precio_hotel_" + i).val().replace(",", "."));
		
		myFlightHotelPrice = flightPrice + myHotelPrice;
		flightHotelPriceDiference = flightHotelPrice - myFlightHotelPrice;
		diference = Math.round((-flightHotelPriceDiference / (adults + childrens + infants)) * 100) / 100;
		myFlightHotelPrice = Math.round((myFlightHotelPrice / (adults + childrens + infants)) * 100) / 100; ;
				
		if(diference == 0) {
			signed = "";
		} else if(diference < 0) {
			signed = "";
		} else {
			signed = "+";
		}
		
		//$("#hotel_layer_hotel_priceplus_" + i).html(signed + diference + " &euro;");
		$("#hotel_layer_hotel_pricetxt_" + i).html(myFlightHotelPrice);
	}
	
	
	for(i = 1; i <= flightsCount; i++) {
		myFlightPrice = parseFloat($("#precio_vuelo_" + i).val().replace(",", "."));
		
		myFlightHotelPrice = myFlightPrice + hotelPrice;
		flightHotelPriceDiference = flightHotelPrice - myFlightHotelPrice;
		diference = Math.round((-flightHotelPriceDiference / (adults + childrens + infants)) * 100) / 100;
		myFlightHotelPrice = Math.round((myFlightHotelPrice / (adults + childrens + infants)) * 100) / 100; ;
				
		if(diference == 0) {
			signed = "";
		} else if(diference < 0) {
			signed = "";
		} else {
			signed = "+";
		}
		
		//$("#hotel_layer_flight_priceplus_" + i).html(signed + diference + " &euro;");
		$("#hotel_layer_flight_pricetxt_" + i).html(myFlightHotelPrice);
	}
}



function PutSelStars(sNumber) {
    if (sNumber && sNumber.toString().toLowerCase() != 'sin especificar') {
        $("#sel_stars").attr("src", "/vuelos-hoteles/images_" + sSite + "/star_" + sNumber + ".jpg");
        $("#sel_stars").css("display", "block"); 
    }
    else $("#sel_stars").css("display", "none");
}

function PutDinStars(sNumber) {
    if (sNumber.toString().toLowerCase() != 'sin especificar') {
        $("#din_stars").attr("src", "/vuelos-hoteles/images" + sSite + "/star_" + sNumber + ".jpg");
        $("#din_stars").css("display", "block");
    }
    else $("#din_stars").css("display", "none");
}

function txt2url(sString) {
    sString = sString.toLowerCase();
    sString = sString.split(" ").join("-");
    return sString;
}


/************************************************************************************************/
/************************** MAPAS DE GOOGLE *****************************************************/
/************************************************************************************************/

var map_g;
//var points = new Array();
var iWith = 620;

function map_zoom_to_points_g(points) {
    if (points.length > 0) {
        var bounds = new GLatLngBounds();
        for (var i = 0; i < points.length; i++) {
            bounds.extend(points[i]);
        }
        var center = bounds.getCenter();
        var zoom_level = map_g.getBoundsZoomLevel(bounds);
        map_g.setZoom(zoom_level);
        map_center_g(_lat(center), _lon(center));
    }
}
function _lat(point) {
    return point.lat();
}
function _lon(point) {
    return point.lng();
}
function new_point(lat, lon) {
    var point = new GLatLng(lat, lon);

    return point;
}
function initialize_g() {
    var locs_g = new Array;
    if (GBrowserIsCompatible()) {
        map_g = new GMap2(document.getElementById("map_hoteles"), { size: new GSize(iWith, 400) });
        map_g.setCenter(new GLatLng(40.346544, -3.713379), 4);
        map_g.addControl(new GSmallMapControl())
        map_g.addControl(new GMapTypeControl());
        var points_g = document.getElementsByName("map_points");
        for (var i = 0; i < points_g.length; i++) {
            var point = points_g[i].value.split(',');
            var Gpoint = new GLatLng(point[0], point[1]);
            var marker = createMarker(Gpoint, point[2]);
            map_g.addOverlay(marker);
            locs_g.push(new_point(point[0], point[1]));
        }
        map_zoom_to_points_g(locs_g);
    }
}
function createMarker(point, idHotel) {
    var marker = new GMarker(point);
    var sHTML = generateHtmlHotel(idHotel);
    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(sHTML, { maxWidth: 450 }); });    
    return marker;
}
function map_center_g(lat, lon) {
    map_g.panTo(new_point(lat, lon));
}

function SearchByMap() {
//    var newLink = document.createElement('a');
//    newLink.setAttribute('href', 'javascript:SearchByList();');
//    newLink.title = 'Volver a ver resultados en listado';
//    var linkText = document.createTextNode('Volver a ver resultados en listado');
//    newLink.appendChild(linkText);
//    document.getElementById("sidebar_map").innerHTML = "";
//    document.getElementById("sidebar_map").appendChild(newLink);
	document.getElementById("sh_by_list").style.display="";
	document.getElementById("sh_by_map").style.display="none";

    document.getElementById("map_hoteles_frame").style.display = '';
    document.getElementById("list_hoteles").style.display = 'none';
    initialize_g();
}
function SearchByList() {
    //var newLink = document.createElement('a');
    //newLink.setAttribute('href', 'javascript:SearchByMap();');
    //newLink.title = 'Localiza estos hoteles en Google Maps';
    //var linkText = document.createTextNode('Localiza estos hoteles en Google Maps');
    //newLink.appendChild(linkText);
    //document.getElementById("sidebar_map").innerHTML = "";
    //document.getElementById("sidebar_map").appendChild(newLink);
	document.getElementById("sh_by_list").style.display="none";
	document.getElementById("sh_by_map").style.display="";
	
    document.getElementById("map_hoteles_frame").style.display = 'none';
    document.getElementById("list_hoteles").style.display = '';
}

function generateHtmlHotel(id) {
    var priceHotel = document.getElementById("precio_hotel_" + id).value;
    var sHTML = '<div class="bocata_map">';
    var hab = $("#habitaciones_hotel_" + id).val();
    sHTML += '<h2 class="bocata_map_title">' + document.getElementById("nombre_hotel_" + id).value + '</h2>';
    sHTML += '<div class="bocata_map_star"><img src="/vuelos-hoteles/images_' + sSite + '/star_' + document.getElementById("categoria_hotel_" + id).value + '.jpg" alt="" /></div>';
    sHTML += '<br class="clear" />';
    sHTML += '<div class="bocata_map_hotel_info">';
    sHTML += '<img src="/vuelos-hoteles/images/common/img_hotel.jpg" alt="" class="left" />';
    sHTML += '<ul>';
    sHTML += '<li>Régimen: ' + document.getElementById("regimen_hotel_" + id).value  + '</li>';
    sHTML += '<li>Noches: ' + document.getElementById("noches_hotel_" + id).value  + '</li>';                
    sHTML += '<li>' + hab + '</li>';                
    sHTML += '</ul>'; 
    sHTML += '</div>';         
    sHTML += '</div>';
    sHTML += '<div class="bocata_map_prices">';
    sHTML += '<div class="bocata_map_price_plus">+' + ((parseFloat(priceHotel) - parseFloat(precioHotelBarato)) * 100) / 100 + '&#8364;</div>';
    sHTML += '<div class="bocata_map_price_txt">Precio final: ' + priceHotel + '&#8364;</div>';
    sHTML += '<div class="btn png_bg">';
    sHTML += '<a href="#" onclick="javascript:SelectHotel(' + id + ')" title="" class="png_bg">Quiero este hotel</a>';
    sHTML += '<span class="png_bg"></span>';
    sHTML += '</div>'; 
    sHTML += '</div>';
    return sHTML;
}
/************************************************************************************************/
/************************** VALIDADOR ***********************************************************/
/************************************************************************************************/

function validator() {
    /*
    var aDateSalida = document.getElementById(DateDepart).value.split('/');
    var aDateLlegada = document.getElementById(DateReturn).value.split('/');
    var dHoy = new Date();
    var dHoySinHoras = new Date(dHoy.getFullYear(), dHoy.getMonth(), dHoy.getDate());
    var dSalida = new Date(aDateSalida[2], aDateSalida[1] - 1, aDateSalida[0]);
    var dLlegada = new Date(aDateLlegada[2], aDateLlegada[1] - 1, aDateLlegada[0]);
    */
    var o1, o2;
    o1 = document.getElementById("Origin");
    o2 = document.getElementById("Destination");
    if (o1.value == '' || o1.value == 'Origen') return alert('Debes seleccionar el origen.');
    if (o2.value == '' || o2.value == 'Destino') return alert('Debes seleccionar el destino.');
    
    //if (dSalida.getTime() < dHoySinHoras.getTime()) return alert('La salida no puede ser anterior al dia de hoy.');
    //if (dSalida.getTime() >= dLlegada.getTime()) return alert('La llegada debe ser mayor que el dia de salida.');
	document.getElementById("page").style.display="none";
    document.forms[1].submit();
	document.getElementById("lightbox_content").style.display="block";
}


function offertBuyButton(departure, arrival, dateGo, dateReturn) {
	var formUrl = "resultados.aspx?";
	
	formUrl += "&Origin=" + departure;
	formUrl += "&Destination=" + arrival;
	formUrl += "&date_depart=" + dateGo;
	formUrl += "&date_return=" + dateReturn;
	formUrl += "&habitaciones=1";
	formUrl += "&user_rooms_1=2";
	formUrl += "&childs_rooms_1=0";

	document.getElementById("page").style.display="none";
	document.getElementById("lightbox_content").style.display="block";	
	document.getElementById("formAuxiliar").action = formUrl;
	
	document.getElementById("formAuxiliar").submit();
}


Date.prototype.AddMinutes = function(iMinutes) {
    this.setTime(this.getTime() + parseInt(iMinutes * 60000));
}
Date.prototype.AddHours = function(iHours) {
    this.setTime(this.getTime() + parseInt(iHours * 3600000));
}
Date.prototype.AddDays = function(iDays) {
    this.setTime(this.getTime() + parseInt(iDays * 86400000));
}

/************************************************************************************************/
/************************** AJAX HOTELES Y VUELOS ***********************************************/
/************************************************************************************************/

function preloadHoteles(oBj) {
    if(oBj.name == 'chkCat0')
    {
        var aOrden = document.getElementsByName('chkCat');
        for (var i = 0; i < aOrden.length; i++) {
            if (aOrden[i].checked) aOrden[i].checked = false;
        }   
    }
    else document.getElementById('chkCat0').checked = false;
    loadHoteles();
}

function loadHoteles() {
    var aOrden = document.getElementsByName('ord_hoteles');
    var sOrdenFinal = '';
    for (var i = 0; i < aOrden.length; i++) {
        if (aOrden[i].checked) sOrdenFinal = aOrden[i].value;
    }    
    var sCats = '';
    var aOrden = document.getElementsByName('chkCat');
    for (var i = 0; i < aOrden.length; i++) {
        if (aOrden[i].checked) sCats += '&'+ aOrden[i].id + '=1';
        else sCats += '&'+ aOrden[i].id + '=0';
    }   
    if(document.getElementById('chkCat0').checked) sCats += '&chkCat0=1';
    else sCats += '&chkCat0=0';
    
    var sUrl = 'do=hotels&hotel_minimum=' + document.getElementById('hotel_minimum').value;
    sUrl += '&hotel_maximum=' + document.getElementById('hotel_maximum').value;
    sUrl += sCats;
    sUrl += '&ord_hoteles=' + sOrdenFinal;
    //$("#texto_hoteles").load("ajax.aspx?" + sUrl, function() { asignePrice(); }, initialize_g);
    $("#texto_hoteles").load("ajax.aspx?" + sUrl, function() { asignePrice(); });
}

function loadVuelos() {
	
    var aOrden = document.getElementsByName('ord_vuelos');
    var sOrdenFinal = '';
    for (var i = 0; i < aOrden.length; i++) {
        if (aOrden[i].checked) sOrdenFinal = aOrden[i].value;
    }   
    
    
    var nonStopFlights = "false";
    if(document.getElementById("nonStopFlightFilter").checked == true) {
		nonStopFlights = "true";
    }
         
    var sUrl = 'do=vuelos&vuelo_ida_min=' + document.getElementById('vuelo_ida_min').value;
    sUrl += '&vuelo_ida_max=' + document.getElementById('vuelo_ida_max').value;
    sUrl += '&vuelo_vuelta_min=' + document.getElementById('vuelo_vuelta_min').value;
    sUrl += '&vuelo_vuelta_max=' + document.getElementById('vuelo_vuelta_max').value;
    sUrl += '&vuelo_minimum=' + document.getElementById('vuelo_minimum').value;
    sUrl += '&vuelo_maximum=' + document.getElementById('vuelo_maximum').value;
    sUrl += '&ord_vuelos=' + sOrdenFinal;
    sUrl += "&vuelo_directo=" + nonStopFlights;
    
    $("#texto_vuelos").load("ajax.aspx?" + sUrl, function() { asignePrice(); });
}


function selectTrip(prefix) {
	//$("#myhotel").val($("#" + prefix + "_h").val());
	//var url = "2dopaso.aspx?hotel=" + $("#" + prefix + "_h").val() + "&vuelo=" + $("#" + prefix + "_v").val();
	var url = "2dopaso.aspx?myhotel=" + $("#" + prefix + "_h_pos").val() + "&hotel=" + $("#" + prefix + "_h").val() + "&vuelo=" + $("#" + prefix + "_v").val();
	document.location.href=url;
}