// JavaScript Document

function gaFormObj(pagePath,GAPath, func){
	this.PagePath  = pagePath;
	this.GAPath = GAPath;	
	this.SubmitFunc = func;
}

function LinkObj(Linkpath,domain,hook){
	this.Linkpath = Linkpath;
	this.hookID = hook;
	this.domain = domain;
}

/*Define any custom functions */
// Generic tracking function
var SubmitFunc = function(event){
				if(Page_ClientValidate()){									
					_gaq.push(['_trackPageview',FormList[event.data.id].GAPath]);
					//alert(i);
					//alert(FormList[i].GAPath);
				}
			};
	// Contact us tracking
	var SubmitContactUsFunc = function(event){
			if(Page_ClientValidate()){	
			
				var topic = jQuery("select[name$='ddlTopic'] :selected").text();
				_gaq.push(['_trackPageview',FormList[event.data.id].GAPath + topic + ".html"]);
				//alert(FormList[i].GAPath + topic + ".html");
				}
	};
	// Unsubscribe tracking
	var UnSubscribeLiftpodAtWork = function(){
		//alert('test');
			if(Page_ClientValidate()){
				//alert("Unsubscribed");				
				_gaq.push(['_trackEvent','LiftPod@Work','Liftpod@Work-Unsubscribe','Liftpod@Work-Unsubscribe']);				
			}
	};
		
/* Define form list */
	var FormList = new Array;
	//FormList[1] = new gaFormObj('http://qa.jlg.godfrey.com/en-US/ContactUss.html','/JLG-ContactUs/Submission/',null);
	//First on is just for local testing purposes.
	FormList[0] = new gaFormObj('http://qa.jlg.godfrey.com/en-US/ContactUs.html','/jlg/Complete/ContactUs/topic/',SubmitContactUsFunc);
	FormList[1] = new gaFormObj('http://www.jlg.com/en-US/ContactUs.html','/jlg/Complete/ContactUs/topic/',SubmitContactUsFunc);	
	FormList[2] = new gaFormObj('http://jlg.com/en-US/ContactUs.html','/jlg/Complete/ContactUs/topic/',SubmitContactUsFunc);
	FormList[3] = new gaFormObj('http://www.liftpod.com/en-US/ContactUs.html','/liftpod/Complete/ContactUs/topic/',SubmitContactUsFunc);
	FormList[4] = new gaFormObj('http://liftpod.com/en-US/ContactUs.html','/liftpod/Complete/ContactUs/topic/',SubmitContactUsFunc);
	FormList[5] = new gaFormObj('http://www.liftpod.com/en-US/subscribe.html','/liftpod/subscribe.aspx?complete=1',null);
	FormList[6] = new gaFormObj('http://liftpod.com/en-US/subscribe.html','/liftpod/subscribe.aspx?complete=1',null);
	FormList[7] = new gaFormObj('http://www.liftpod.com/en-US/unsubscribe.html','',UnSubscribeLiftpodAtWork);
	FormList[8] = new gaFormObj('http://liftpod.com/en-US/unsubscribe.html','',UnSubscribeLiftpodAtWork);	
	
	var LinkTrackingList = new Array;
	//LiftPod Brochure
	LinkTrackingList[0] = new LinkObj('http://www.liftpod.com/en-US/Component.Display.html?RefId=74328645-ae4c-4d74-9eab-828063e79ec0','Liftpod',0);
	//FS60 Spec Sheet
	LinkTrackingList[1] = new LinkObj('http://www.liftpod.com/en-US/Component.Display.html?RefId=77007a97-3b7f-4fd8-b716-06cfbc42b1de','Liftpod',0);
	//FS80 Spec Sheet
	LinkTrackingList[2] = new LinkObj('http://www.liftpod.com/en-US/Component.Display.html?RefId=e4a1d7b6-23b7-4af5-be64-3b4d0f2972fb','Liftpod',0);
	//YouTube
	LinkTrackingList[3] = new LinkObj('http://www.youtube.com/user/LiftPod','',1);
	// Manual tracking URL
	LinkTrackingList[4] = new LinkObj('http://csapps.jlg.com/OnlineManuals/browse.aspx?path=JLG/JLG%20LiftPOD&title=PDF%20Manuals&refkey=http%3a%2f%2fwww.jlg.com%2fen-US%2fMyJLG.html&link=','',2);
	//Locator Tracking
	LinkTrackingList[5] = new LinkObj('http://locator.jlg.com/','',3);
	
	
jQuery(document).ready(function () {	
	// loop through list of forms to track, going in reverse since its faster to count to 0.
	for(i= FormList.length -1; i >=0; i--){
		var currentgaFormObjd = FormList[i];
		// check if current page matches, array item
		if(currentgaFormObjd.PagePath.toLowerCase() == window.location.toString().toLowerCase()){			
				var formID = '';				
				if(jQuery("#form1").length > 0){
					formID = "#form1";
				}
				else if(jQuery("#Form1").length > 0){
					formID = "#Form1";
				}				
			if(currentgaFormObjd.SubmitFunc == null){						
				jQuery(formID).bind('submit',{id:i},SubmitFunc);			
				jQuery("input[name$='imgbtnSubmit']").click(function(){
					jQuery(formID).unbind('submit',SubmitFunc);
				});
			}else {
				jQuery(formID).bind('submit',{id:i},currentgaFormObjd.SubmitFunc);			
				jQuery("input[name$='imgbtnSubmit']").click(function(){
					jQuery(formID).unbind('submit',currentgaFormObjd.SubmitFunc);
				});				
			}
			break;
		}
	}
	
	//Loop through all of the links on the page
	jQuery("a").each(function(){
		//Loop through the links in the array
		for(j = LinkTrackingList.length-1; j>=0; j--){
			if(jQuery(this).attr("href").toLowerCase() == LinkTrackingList[j].Linkpath.toLowerCase()){
				if(LinkTrackingList[j].hookID ==0){	
					var domain = LinkTrackingList[j].domain;				
					jQuery(this).bind('click',{domain:LinkTrackingList[j].domain},function(event){
						var pageName = location.toString().split('/');
						_gaq.push(['_trackEvent',event.data.domain + '-PDF-Download',pageName[pageName.length-1] + '-' + jQuery(this).text().replace(/\s/g,"-"),jQuery(this).text().replace(/\s/g,"-")]);						
					});
				}else if(LinkTrackingList[j].hookID == 1){	
					//You Tube tracking
					jQuery(this).bind('click',function(){
						var pageName = location.toString().split('/');
						_gaq.push(['_trackPageview',"/outgoing-link/YouTube/From-" + pageName[pageName.length-1]]);
						return true;
					});
				}else if(LinkTrackingList[j].hookID == 2){	
					//You Tube tracking
					jQuery(this).bind('click',function(){
						var pageName = location.toString().split('/');
						_gaq.push(['_trackPageview',"/outgoing-link/Operator-Service-Parts-Manual/From-" + pageName[pageName.length-1]]);
						return true;
					});
				}else if(LinkTrackingList[j].hookID == 3){					
					//Dealer locator tracking
					jQuery(this).bind('click',function(){
						var pageName = location.toString().split('/');
						_gaq.push(['_trackPageview',"/outgoing-link/JLG-Dealer-Locator/From-" + pageName[pageName.length-1]]);						
						return true;
					});					
				}
				
			}			
		}		
	});
	
});






