// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function check_accept_text_scroll_pos(text_element_id, check_element_id) {
  if ($(text_element_id).scrollTop + $(text_element_id).clientHeight == $(text_element_id).scrollHeight) {
    $(check_element_id).disabled = false;
  }
}

function accessTrack(target) {
  googleTrack(target);
  
  // Tracks using Google and Eloqua, but not Unica.
  // There were problems with Unica during the auto-download. When calling
  // accessTrack outside of an HTML event handler, the unicaTrack function would
  // cause an attempt to download the 'virtual' (fake filename) resource instead of
  // just reporting it to Unica.
  //unicaTrack(target);
  
  eloquaTrack(target);
}

function googleTrack(target) {
  pageTracker._trackPageview(target);
}

// Note that the Unica tracking method expects the argument to be an object that 
// contains an 'href' property. 
function unicaTrack(target) {
  var target_obj = new Object();
  target_obj["href"] = target;
  ntptLinkTag(target_obj);
}

// Eloqua does not support tracking download links the way we want them to. Instead, 
// they tell you to use their 'elqRedir.htm' page to redirect to the download file. 
// The logic for construction of the url was taken from the 'elqRedir.htm' page, and 
// enhanced to make the server request in Javascript.
function eloquaTrack(target) {
  // Try to find the ELOQUA cookie and extract the Eloqua GUID from it.
  var eloquaCookie = document.cookie.match ( 'ELOQUA=GUID=([^;]*)(;|$)' );
  var guidParam = '';
  // If we have the ELOQUA cookie, build the PURLGUID param to send to Eloqua.
  if (eloquaCookie != null && eloquaCookie.length >= 2 && eloquaCookie[1].length == 32) {
      var guid = eloquaCookie[1].slice(0,8);
      guid += '-';
      guid += eloquaCookie[1].slice(8,12);
      guid += '-';
      guid += eloquaCookie[1].slice(12,16);
      guid += '-';
      guid += eloquaCookie[1].slice(16,20);
      guid += '-';
      guid += eloquaCookie[1].slice(20,32);
      guid = guid.toLowerCase();
      guidParam = '&PURLGUID=' + guid;
  }

  var url = elqCurE + '?pps=10&siteid=' + elqSiteID + guidParam + '&elq=' + elqQString('elq','',0) + '&ref=' + eloquaEscape(target) + '&ref2=' + eloquaEscape(self.location.href) + '&ms=' + elqMs;
  var img = new Image(1, 1);
  img.src = url;
}

function eloquaEscape(url) {
  return elqReplace(elqReplace(url,'&','%26'),'#','%23');
}