// Boxy-related event-specific javascript stuff
function etapBoxyPleaseWaitMessage() {
  return new Boxy("<p id='pleaseWaitMessage'>Please Wait... <img src='images/spinner.gif'/></p>", {title: "Working"});
}

function etapBoxyReload(box, url, pleaseWaitHtml) {
  // Set "Please Wait" message
  box.setContent(pleaseWaitHtml ? pleaseWaitHtml : "<p id='pleaseWaitMessage'>Please Wait... <img src='images/spinner.gif'/></p>");
  
  // Form AJAX options
  var ajax = {
      url: url,
      type: "GET",
      dataType: "html",
      cache: false,
      success: function(html) {
        html = jQuery(html);
        box.setContent(html);
      }
  }
  
  // Exec AJAX request
  jQuery.ajax(ajax);
}

// Utility used to open the "all sponsors" popup
function etapViewAllSponsors(ref) {
  self.viewAllBoxy = new Boxy("", 
      {
        title: 'All Sponsors',
        unloadOnHide: true,
        afterShow: function() {
          var pos = $('#etapAppContentMat').position();
          this.moveTo(pos.left ? pos.left : 100 /*best guess*/, 50);
        }
      });
  etapSwitchSponsorPage("viewAllSponsors.do?objectRef=" + ref);
  return self.viewAllBoxy;
}

// Utility used by paging in the "allSponsors.xml" template
function etapSwitchSponsorPage(url) {
  if (self.viewAllBoxy) etapBoxyReload(self.viewAllBoxy, url, "<p id='sponsorsPleaseWaitMessage'>Please Wait... <img src='images/spinner.gif'/></p>");
}
