// JavaScript Document
var xmlhttp;
var xmlhttpDescription;
var xmlhttpTotalPrice;
var xmlhttpBookingTotalPrice;
var xmlhttpshowTotalPrice;

function getTotalPrice(arr_date,nights,property,beds,qty){
  xmlhttpTotalPrice=GetXmlHttpObject();
  if (xmlhttpTotalPrice==null){
    //alert ("Your browser does not support XMLHTTP!");
    return;
  }
  var url="../includes/ajax-booking-total-price.php?arr_date="+arr_date+"&nights="+nights+"&property="+property+"&beds="+beds+"&qty="+qty;
  xmlhttpTotalPrice.onreadystatechange=stateChangedTotalPrice;
  xmlhttpTotalPrice.open("GET",url,true);
  xmlhttpTotalPrice.send(null);
}

function bookingGetTotalPrice(arr_date,nights,property,beds,qty){
  xmlhttpBookingTotalPrice=GetXmlHttpObject();
  if (xmlhttpBookingTotalPrice==null){
    //alert ("Your browser does not support XMLHTTP!");
    return;
  }
  var url="../includes/ajax-booking-total-price.php?arr_date="+arr_date+"&nights="+nights+"&property="+property+"&beds="+beds+"&qty="+qty+"&show=yes";
  xmlhttpBookingTotalPrice.onreadystatechange=stateChangedBookingTotalPrice;
  xmlhttpBookingTotalPrice.open("GET",url,true);
  xmlhttpBookingTotalPrice.send(null);
}

function showTotalPrice(arr_date,nights,property,beds,qty){
  xmlhttpshowTotalPrice=GetXmlHttpObject();
  if (xmlhttpshowTotalPrice==null){
    //alert ("Your browser does not support XMLHTTP!");
    return;
  }
  var url="../includes/ajax-total-price.php?arr_date="+arr_date+"&nights="+nights+"&property="+property+"&beds="+beds+"&qty="+qty+"&show=yes";
  xmlhttpshowTotalPrice.onreadystatechange=stateChangedshowTotalPrice;
  xmlhttpshowTotalPrice.open("GET",url,true);
  xmlhttpshowTotalPrice.send(null);
}

function getDescription(property,beds){
  xmlhttpDescription=GetXmlHttpObject();
  if (xmlhttpDescription==null){
    //alert ("Your browser does not support XMLHTTP!");
    return;
  }
  var url="../includes/ajax-description.php?property="+property+"&beds="+beds;
  xmlhttpDescription.onreadystatechange=stateChangedDescription;
  xmlhttpDescription.open("GET",url,true);
  xmlhttpDescription.send(null);
}

function getPrices(arr_date,nights,property,beds,qty){
  document.getElementById('calendarPrices').style.display='none';
  document.getElementById('calendarPrices').style.visibility='hidden';
  document.getElementById('calendarPricesLoading').style.display='block';
  document.getElementById('calendarPricesLoading').style.visibility='visible';
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null){
    alert ("Your browser does not support XMLHTTP!");
    return;
  }
  var url="../includes/ajax-prices.php?arr_date="+arr_date+"&nights="+nights+"&property="+property+"&beds="+beds+"&qty="+qty;
  xmlhttp.onreadystatechange=stateChanged;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  // Get the apartment description and then the total proce for the stay
  getDescription(property,beds);
  getTotalPrice(arr_date,nights,property,beds,qty);
}

function stateChanged(){
  if (xmlhttp.readyState==4){
    document.getElementById('calendarPricesLoading').style.display='none';
    document.getElementById('calendarPricesLoading').style.visibility='hidden';
    document.getElementById('calendarPrices').style.display='block';
    document.getElementById('calendarPrices').style.visibility='visible';
    document.getElementById('calendarPrices').innerHTML=xmlhttp.responseText;
  }
}

function stateChangedDescription(){
  if (xmlhttpDescription.readyState==4){
    document.getElementById('ApartmentDescription').innerHTML=xmlhttpDescription.responseText;
  }
}

function stateChangedTotalPrice(){
  if (xmlhttpTotalPrice.readyState==4){
    document.getElementById('TotalPrice').innerHTML=xmlhttpTotalPrice.responseText;
    reCalcPrice();
  } else {
  }
}

function stateChangedBookingTotalPrice(){
  if (xmlhttpBookingTotalPrice.readyState==4){
    document.getElementById('TotalPrice').innerHTML=xmlhttpBookingTotalPrice.responseText;
    reCalcBookingPrice();
  } else {
  }
}

function stateChangedshowTotalPrice(){
  if (xmlhttpTotalPrice.readyState==4){
    document.getElementById('showTotalPrice').innerHTML=xmlhttpshowTotalPrice.responseText;
  }
}
