 
// document.ready function that runs when the page has finished loading
// assumes the jQuery core library has been included on the page
$(function(){ 

    // create a wrapped set of all links in which the HREF ends in .pdf or .doc
    // add additional extensions by simply appending more .add() functions
    var $wrapped = $('a[href $= ".pdf"]')
                .add('a[href $= ".doc"]')
                ;
                
    // loop over the wrapped set with the each() function
    // the variable 'this' refers to the current element in the loop
    $wrapped.each(function(i) {
    
       // get the fully-qualified HREF of the link (will include protocol://hostname)
	   var href = this.href;
	   // get the link text
       var linktext = $(this).text();
	   
       // remove hard-coded http://www.stratus.com in HREF if it exists
       href = href.replace(/^http:\/\/www\.stratus\.com/,'');
       
       // if the HREF now does not begin with 'http' (meaning it is a local link)
       if ( ! href.match(/^http/) ) { 

           // remove the Eloqua redirect if it exists
           href = href.replace(/^.*\/elqNow\/elqRedir\.htm\?ref=/,'');
           
           // remove references to the /download/ handler (both methods: /index.cfm/path and /index.cfm?file=path)
           href = href.replace(/^.*\/download\/index.cfm/,'');
           href = href.replace(/^.*\/download\/?\?file=/,'');
                       
           // save the cleaned up HREF to a variable since it should now contain the absolute path to the file
           var filepath = href;
           
           // assuming we have the absolute path name in the HREF now (begins with a forward slash)
           if (href.match(/^\//)) {
           
               // update the HREF on the link to the absolute path name
               $(this).attr('href',href);
               
               // set the onClick handler 
               $(this).click(function() {
                  logFileDownload(filepath,linktext);
				  return true;
               });
           
           } // ...if the HREF is an absolute path
                
      } // ...if the HREF still begins with HTTP
                          
    });  //... loop over the wrapped set
    
}); // ... document.ready function

// logFileDownload() will be set as the onClick handler for file download links
// Currently it will log the file download to Goggle Analytics and Pardot Marketing Automation
//   path = the absolute path to the file (example: /pdf/avance/AvanceDataSheet.pdf)
//   linktext = text of the link (example: Availability White Paper)

function logFileDownload(path,linktext) {

	logToGoogle(path);
	logToPardot(path,linktext);
    
} // ... function logFileDownload()


// Google
function logToGoogle(path) {

    // use a try/catch block to gracefully fail on exceptions
    try {

       // call the Google Analytics page tracker    
       pageTracker._trackPageview(path);
      
    } catch(err) { }
	
}

// Pardot
function logToPardot(path,linktext) {

    // use a try/catch block to gracefully fail on exceptions
    try {

	   // call the Pardot page tracker
       var tmpTitle = document.title; 
	   document.title=linktext; 
	   piIncludeInActivities=true; 
	   piPoints=3; 
	   piTracker(path); 
	   document.title = tmpTitle;
      
    } catch(err) { }
	
}
