/*
 * JavaScript for building tour list with Dojo
 */
function tourDetails(tourIdUrl){
  if ( IsEmpty (tourIdUrl) ) {
    alert('Please select a tour.');
    document.tourselectform.tourselect.focus();
  } else {
    var tourIdUrlArray = tourIdUrl.split(";");
    var t_id = tourIdUrlArray[0];
    var t_url = tourIdUrlArray[1];;
    
    location.href='/tours/' + t_url + '-main/?tourId=' + t_id;
    return false;
  }
}

function getXrTourList(){
  dojo.xhrGet( {
    // URL - location of the data you want to get
    url: "/app/tourListBuilder",
    handleAs: "text",
    timeout: 3000, // Time in milliseconds
    load: function(response, ioArgs) {
       processRequest(response);
    },

    // The ERROR function will be called in an error case.
    error: function(response, ioArgs) {
       var userMessageElement = dojo.byId("djtourlist");
       userMessageElement.innerHTML = "Sorry, we cannot show the tour list now.";
    }
  });
}

function getXrTourListAtHome(){
  dojo.xhrGet( {
    // URL - location of the data you want to get
    url: "/app/tourListBuilder?home=yes",
    handleAs: "text",
    timeout: 3000, // Time in milliseconds
    load: function(response, ioArgs) {
       processRequest(response);
    },

    // The ERROR function will be called in an error case.
    error: function(response, ioArgs) {
       var userMessageElement = dojo.byId("djtourlist");
       userMessageElement.innerHTML = "Sorry, we cannot show the tour list now.";
    }
  });
}

function processRequest(data) {
  var userMessageElement = dojo.byId("djtourlist");
  userMessageElement.innerHTML = data;
}

