var xmlHttp=null; // Defines that xmlHttp is a new variable.
try
{
  // Firefox, Opera 8.0+, Safari, IE7+
  xmlHttp = new XMLHttpRequest(); // xmlHttp is now a XMLHttpRequest.
}
catch (e)
{
  // Internet Explorer
  try
  {
    xmlHttp=new ActiveXObject( "Msxml2.XMLHTTP" );
  }
  catch (e)
  {
    xmlHttp=new ActiveXObject( "Microsoft.XMLHTTP" );
  }
}

function button1()
{
  xmlHttp.open( "GET","HomeData.html" );
  xmlHttp.onreadystatechange = replaceContent;
  xmlHttp.send(null);
}

function button2()
{
  xmlHttp.open( "GET","RoomsAndRatesData.html" );
  xmlHttp.onreadystatechange = replaceContent;
  xmlHttp.send(null);
}

function button3()
{
  xmlHttp.open( "GET","EnquiriesData.html" );
  xmlHttp.onreadystatechange = replaceContent;
  xmlHttp.send(null);
}

function button4()
{
  xmlHttp.open( "GET","AttractionsData.html" );
  xmlHttp.onreadystatechange = replaceContent;
  xmlHttp.send(null);
}

function button5()
{
  xmlHttp.open( "GET","DirectionsData.html" );
  xmlHttp.onreadystatechange = replaceContent;
  xmlHttp.send(null);
}

function privacy()
{
  xmlHttp.open( "GET", "PrivacyPolicyData.html" );
  xmlHttp.onreadystatechange = replaceContent;
  xmlHttp.send(null);
}

function replaceContent()
{
  if ( xmlHttp.readyState == 4 )
  {
    try
    {
      if ( xmlHttp.status == 200 )
      {
        document.getElementById("replace").innerHTML =
         xmlHttp.responseText;
      }
    }
    catch (e)
    {
      document.getElementById("replace").innerHTML =
        "Error on Ajax return call : " + e.description;
    }
  }
}
  
function emailEnquiry()
{
  document.body.style.cursor = "wait";
  var file = 'EmailEnquiry';
  var str = getFormValues();
  xmlHttp.open( "POST", file, true );
  xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  xmlHttp.onreadystatechange = formSubmitted;
  xmlHttp.send(str);
}

function getFormValues()
{
  return "name=" + escape(document.getElementById('enquiry').name.value) + "&" +
        "email=" + escape(document.getElementById('enquiry').email.value) + "&" +
        "phone=" + escape(document.getElementById('enquiry').phone.value) + "&" +
        "arrivalDate=" + escape(document.getElementById('enquiry').arrivalDate.value) + "&" +
        "departureDate=" + escape(document.getElementById('enquiry').departureDate.value) + "&" +
        "number=" + document.getElementById('enquiry').number.value + "&" +
        "comments=" + escape(document.getElementById('enquiry').comments.value); 
}
  
function formSubmitted()
{
  if ( xmlHttp.readyState == 4 )
  {
    try
    {
      if ( xmlHttp.status == 200 )
      {
        document.body.style.cursor = "default";
        alert( xmlHttp.responseText );
        var pattern = /success/i;
        if ( pattern.test( xmlHttp.responseText ) )
        {
          document.getElementById('enquiry').reset();
        }
      }
    }
    catch (e)
    {
      document.body.style.cursor = "default";
      alert( "Enquiry could not be sent: " + e.description );
    }
  }
}

function setupArrivalDateCalendar()
{
  Calendar.setup({
        inputField     :    "arrival_date",     // id of the input field
        ifFormat       :    "%A, %B %d, %Y",     // format of the input field (even if hidden, this format will be honored)
        button         :    "arrival_date",  // trigger button (well, IMG in our case)
        singleClick    :    true
    });
}

function setupDepartureDateCalendar()
{
  Calendar.setup({
        inputField     :    "departure_date",     // id of the input field
        ifFormat       :    "%A, %B %d, %Y",     // format of the input field (even if hidden, this format will be honored)
        button         :    "departure_date",  // trigger button (well, IMG in our case)
        singleClick    :    true
    });
}