﻿// Archivo JScript

//--------------------------------------------AJAX----------------------------------------
var xmlHttp

//variable para poner el valor del div que recibe el valor de la tarifa
var div_posmaster

function saca_tarifas()
{
    borra_div_tarifas();
    if (document.getElementById("fecha_sal").value == "")
    {
        alert("Choose the arrival date to the hotel");
        return;
    }
    if (document.getElementById("fecha_reg").value == "")
    {
        alert("Choose the check-out date from the hotel");
        return;
    }
    if (document.getElementById("noches").value == "")
    {
        if (document.getElementById("fecha_sal").value != "" && document.getElementById("fecha_reg").value != "")
            calcula_noches();
        else
        {
            alert("Please write how many nights you will be staying.");
            return;
        }
    }
    document.getElementById('cargando').style.display = 'block';
    muestra_tarifa();
}

function muestra_tarifa()
{
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not suport AJAX! change browser so you can vie the prices and fares");
        return;
    }
    var url = "consola_web.aspx";
    url += "?c_personas=" + document.getElementById("c_personas").value;
    url += "&fecha_ini=" + document.getElementById("fecha_sal").value;
    url += "&noches=" + document.getElementById("noches").value;
    //extra para que cada vez que llame la funcion sea una llamada distinta
    url += "&sid=" + Math.random();

    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 

function stateChanged() 
{ 
    if (xmlHttp.readyState==4)
    { 
        datos = xmlHttp.responseText;
        //alert(datos);
        while (datos.length != 0)
        {
            var div_pos = datos.substr(0,datos.indexOf("@"));
            datos = datos.substr(datos.indexOf("@")+1);
            var tarifa = parseFloat(datos.substr(0,datos.indexOf("@")));
            datos = datos.substr(datos.indexOf("@")+1);
            if (tarifa >= 0)
            {
                var adultos = parseInt(document.getElementById("c_personas").value,0);
                var noches = parseInt(document.getElementById("noches").value);
                var precio = tarifa / ((adultos) * noches);
                precio = precio.toFixed(2);
                var el_precio = precio.toString();
                if (el_precio.indexOf(".") != -1)
                {
                    el_precio = el_precio.substring(0,el_precio.indexOf(".")+3);
                }

                var cont_text = "<span style='font-family: Arial; font-size: 12pt;'>$ " + el_precio + "</span>";
                cont_text += "<input type=\"radio\" name =\"paquete\" value=\"" + div_pos.substr(4) + "" + tarifa  + "\" onclick=\"aparece_submit('" + div_pos.substr(4) + "'); selected_div_tarifas('" + div_pos + "'); msg_res('" + precio + "')\" >";
			    cont_text += "<br/><span style='font-family: Arial; font-size: 7pt;'> per Person <br/> per Night </span>";

                document.getElementById(div_pos).innerHTML=cont_text;
            }
            else
                document.getElementById(div_pos).innerHTML= "<span style='font-family: Arial; font-size: 9pt;'>N/D</span>";
        }
        document.getElementById('cargando').style.display = 'none';
    }
}

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function modcanht() {                               
                   var page="http://wbe.thebelair.com.mx/ssl/wbe/ctrl_resv_ht.asp?cve_corp=TBACUN&cve_hote=TBACUN&ssl=1&origen=TBE&cve_idi=2"
                   newwin=window.open("","","resizable,location=no,scrollbars=yes,width=800,height=600,top=0,left=0")
                   newwin.location=page;                   
                   }

