
//trim function to remove spaces from left or right of string
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
//jQuery bind to the DOM ready event so that all elements are available
	$(document).ready( function() {
		
		
		
		//jQuery Select all link elements
		$("a").each(function(){
		
		//jQuery Bind to each link click event
			$(this).click(function(){
				
				//Get values for Google
				var docTitle = document.title;
				var linkText = $(this).text();
				var linkRef = $(this).attr('href');
				
				//Declare search type for IF condition				
				var pdf = ".pdf";
				var wmv = ".wmv";
				var doc = ".doc";
				var xls = ".xls";
				var rtf = ".rtf";
				
				
				//Check if the Link contains a type of search download.
				//Note this can be expanded to other element events.
						if(linkRef.search(pdf) != -1 || linkRef.search(wmv) != -1 ||linkRef.search(doc) != -1 || linkRef.search(xls) != -1 || linkRef.search(rtf) != -1  )
						{
						 
						 //Reformat the link values into usable information
						 //Get page title for company information
						 docTitle = docTitle.substr(0,6);
						 
						 //If this is a video remove extra information in the text 
						 if(linkRef.search(wmv) != -1)
						 {
						  if(linkText.search("|") != -1)
						    {
						 		linkText = linkText.substr(linkText.indexOf("|") + 2);
						 	}
						  }
						 //This will remove the type of file and location of the file formatting
						linkRef = linkRef.substring(linkRef.lastIndexOf('/') + 1, linkRef.lastIndexOf("."));
						
						//Text Trim of title and linkText
						 linkText = linkText.trim();
						 docTitle = docTitle.trim();
							//Uncomment to the view click event labels prior to sending to google
							//Used for debugging issues 
							//alert(docTitle);	
						   // alert(linkText);
						   //alert(linkRef);
							
						
							//set the page to be sent to google
							var strDownloadPage = ""
							
							//switch download page to file name if this has generic text display.
							//The last condition was due to a page formatting issue, better safe then sorry 
							if(linkText == "View the webcast" || linkText == "Download the slides" || linkText == "View the webcast" )
							{
								strDownloadPage =  '/'+ docTitle.toLowerCase() + '/' +'downloads/'+ linkRef;	
							}
							else
							{
								strDownloadPage =  '/'+ docTitle.toLowerCase() + '/' +'downloads/'+ linkText;	
							}
							
							
							//Uncomment to view the onClick event page to be sent to ga
							//alert(strDownloadPage);
							
							//The send event to google 
							pageTracker._trackPageview(strDownloadPage);	
							
						}
						
						//Uncomment this to prevent the page from posting back the onClick event
						//Saves a lot of time when checking the link information
						//return false;			
				
			});
			
			//Click event for a possible right click and save or right click and open in another window/tab
			//This will only check if they used the right mouse button on the link it can not determine what action they used.
			//This event is universal to all browsers
			$(this).mousedown(function(e){
			 //The event type for the mouse in the browser browser left=1 center=2 right=3 
			 if(e.which == 3)
			 {
				//Get values for Google
				var docTitle = $("title").text();
				var linkText = $(this).text();
				var linkRef = $(this).attr('href');
				
				//Declare search type for IF condition				
				var pdf = ".pdf";
				var wmv = ".wmv";
			    var doc = ".doc";
				var xls = ".xls";
				var rtf = ".rtf";
				
				
				//Check if the Link contains a type of search download.
				//Note this can be expanded to other element events.
						if(linkRef.search(pdf) != -1 || linkRef.search(wmv) != -1 ||linkRef.search(doc) != -1 || linkRef.search(xls) != -1 || linkRef.search(rtf) != -1  )
						{
						 
						 //Reformat the link values into usable information
						 //Get page title for company information
						 docTitle = docTitle.substr(0,6);
						 
						 //If this is a video remove extra information in the text 
						 if(linkRef.search(wmv) != -1)
						 {
						 	if(linkText.search("|") != -1)
						    {
						 		linkText = linkText.substr(linkText.indexOf("|") + 2);
						 	}
						 }
						 //This will remove the type of file and location of the file formatting
						linkRef = linkRef.substring(linkRef.lastIndexOf('/') + 1, linkRef.lastIndexOf("."));
						 
						 //Text Trim of title and linkText
						linkText = linkText.trim();
						 docTitle = docTitle.trim();
						 
							//Uncomment to the view click event labels prior to sending to google
							//Used for debugging issues 
							//alert(docTitle);	
						    //alert(linkText);
							//alert(linkRef);
							
							
							//set the page to be sent to google
							var strDownloadPage = ""
							
							//switch download page to file name if this has generic text display.
							//The last condition was due to a page formatting issue, better safe then sorry
							if(linkText == "View the webcast" || linkText == "Download the slides" || linkText == "View the webcast" )
							{
								strDownloadPage =  '/'+ docTitle.toLowerCase() + '/' +'downloads/'+ linkRef;	
							}
							else
							{
								strDownloadPage =  '/'+ docTitle.toLowerCase() + '/' +'downloads/'+ linkText;	
							}
							
							
							//Uncomment to view the click event page to be sent to google
							//alert(strDownloadPage);
							
							//The send event to google 
							pageTracker._trackPageview(strDownloadPage);	
							
						}
				}
						
						//Uncomment this to prevent the page from posting back the onClick event
						//Saves a lot of time when checking the link information
						//return false;	
				
				
			});
			

			
			
		});
		
	});
	

