// Define an object that contains the Ajax functions we want to call - this helps isolate our code from any
// other Javascript on the page so we do not get namespace clashes
var crawlerajax = {

   // Populate part of the page with the response
   populatepage : function () {
      // A random value to show passing information from Javascript to PHP
      e107HelperAjax.addParm('rand',   Math.random());

      this.sendRequest('update');
   },

   // Shows two types of popups
   // - a 'please wait' is displayed when the request is sent, desigend to be used if you want to tel lthe user that something
   //   is happenign that may take a few seconds
   // - a timed message, designed to be used to indicate a reponse has been received
   popups : function () {
      // The message popup displayed before the Ajax request is sent
      e107Helper.message('ajaxdemomessage', 'Please wait...');

      // Don't forget to tell the PHP the ID of the message so it can be killed on receipt of the response
      e107HelperAjax.addParm('messageid', 'ajaxdemomessage');

      this.sendRequest('popups');
   },
   
   // This function set's the action parameter and sends the Ajax request
   sendRequest : function (action) {
      // All parameters are passed to the PHP code as POST variables
      e107HelperAjax.addParm('action', action);          // We're using 'action' so the PHP code knows what each ajax request is
      e107HelperAjax.post('ajaxdemo_handler.php');       // The PHP code to run (i.e. the relative URL)
   }
}