//2005-04-25 - Created by Martijn de Haan - version 2.0

//function name changed from ccl_sage_ev() to ccl_ga_ev() for processing pagetagged actions and sending EventTypes to Google Server for GDMT #15596 for CCL 4.7 Version
function ccl_ga_ev(EventType){
   	var paramGA = EventType;
	
	//Added for GDMT #15596 for CCL 4.7 Version. IF condition added to hide the weblink URLs from the event names.
	if((paramGA.indexOf("/") != -1)){
	var actionSeparator = paramGA.indexOf("/");
	var action= paramGA.substring(0, actionSeparator);
	send_request("", action);		//e.g. for event type tags referer is not required
	}
    if((paramGA.indexOf("/") == -1)){
    send_request("", paramGA);
    }

}

//function used for generic pagetagging, send urls to Sage
function ccl_sage_url(){

//Below code commented for GDMT #15596 for CCL 4.7 Version to disable double calls to Google Server

/*var param = "/CCL/GENERIC_TAG" + document.URL.split(location.host)[1];
var ref = document.referrer;
send_request(ref, param); */
}

//function used for external and download links (edl) both eventtype and generic tagging.
//These user actions are not captured by ccl_sage_url as there is no page loaded that include the function call to ccl_sage_url.
function ccl_sage_edl(EventType, url){
if(EventType!=""){
ccl_ga_ev(EventType);
}
}
//Below code commented for GDMT #15596 for CCL 4.7 Version to disable double calls to Google Server

/*var ref = escape(document.URL);		//external links/downloads should use current url as 'referer' 
var param = "/CCL/GENERIC_TAG/EXTERNAL_DOWNLOAD_LINK/" + url;
send_request(ref, param); */



//function used for processing pagetagged actions that should only be reported once per session (e.g. CCL_LOGIN on PageEndInclude.jsp)
function report_once(EventType){
	//check if action is reported before in this session
	if (readCookie(EventType)==""){
		//report the action
		ccl_ga_ev(EventType)
		//store action in cookie to prevent reporting again
		document.cookie = EventType + "=true; path=/; domain=.shell.com";
		
	}
}

//send_request invokes a request with parameters to sage for reporting web stats
function send_request (ref, paramGA){

      //Added for GDMT #15596 for CCL 4.7 Version for Google Analytics Event Handling 
      if(readCookie('CCLid')==""){
	     _gaq.push(['_trackEvent', 'CCL', paramGA, 'anonymous', 1]); //to track non-CCL users
	 
	 }else{
    	 _gaq.push(['_trackEvent', 'CCL', paramGA, readCookie('CCLid'), 1]); //to track CCL users
	 
	      }
	

	
	 
   	//Below code commented for GDMT #15596 for CCL 4.7 Version to disable calls to Sage

	/*
	var st_ai=proto=st_pg=st_rs=st_cd=st_rf=st_hn=st_ce=st_v="";
	var l=location;
	var n=navigator;
	if (l.protocol == "https:") {
		proto = "https:"; 
	}else{
		proto = "http:";
	}	
	var st_dd="www.report.shell.com";
	var st_ci="784";
	var st_di="d699";
	st_ce=n.cookieEnabled;
	st_rf = escape(ref);
	st_hn=l.host; 	
    var st_tai="v:1.2.8";
	var st_us = escape(custom_param); 
	var user = readCookie('CCLid');	
	if(user==""){
		st_ai= "sr_id:" + "anonymous"	
	}else{
		st_ai= "sr_id:" + escape(user);
	}
	var st_iu=proto+"//"+st_dd+"/" + (new Date()).getTime() + "/JS?ci="+st_ci+"&di="+st_di+"&pg="+st_pg+"&us="+st_us+"&qs=&rf="+st_rf+"&rs="+st_rs+"&cd="+st_cd+"&hn="+st_hn+"&ce="+st_ce+"&jv="+st_v+"&tai="+st_tai+"&ai="+st_ai;
	var iXz=new Image();
	iXz.src=st_iu;
	*/
}

//readCookie returns the value for a cookie name. If not found then "" is returned.
//NOTE that this function is ALSO called from TrustedUserView2.jsp and ...
function readCookie(prefix ){
	var checkenv="";
	var dc = document.cookie;
	prefix = prefix + "=";
	var begin = dc.indexOf(prefix);
	
	if (begin > -1){
		var end;
		var urlchangepass;
		var checkenv;
		end = dc.indexOf(";", begin);
		if (end == -1) {
			end = dc.length;
		}
		checkenv = dc.substring(begin + prefix.length, end);
	}

	return checkenv;
}


