// Tracking.js
// revised by Vinh Lu // 02/01/2012



function ShowInteraction(URL,Type,Label,Value)
	{
	TrackInteraction2(URL,Type,Label,Value,"false");
	}


function TrackInteraction(URL,Type,Label,Value)
	{
	TrackInteraction2(URL,Type,Label,Value,"true");
	}


	function TrackInteraction2(URL,Type,Label,Value,writetoDB)
		{
			var track = new RemoteMethod('Tracking.epi?kNtBzmUK9zU');
			track.MethodName = 'TrackInteraction';
		
			var t_r = "";
			if (typeof T_R != "undefined")
				t_r = T_R;
		
			var t_c = "";
			if (typeof T_C != "undefined")
				t_c = T_C;
		
			var t_t = "";
			if (typeof T_T != "undefined")
				t_t = T_T;
		
			var t_l = "";
			if (typeof T_L != "undefined")
				t_l = T_L;
		
			var t_v = "";
			if (typeof T_V != "undefined")
				t_v = T_V;
		
			if(URL == null && Type == null && Label == null && Value == null)
				track.AddArguments(location.href, t_r, t_t, t_l, t_v, t_c, writetoDB);
			else
				track.AddArguments(URL, location.href, Type, Label, Value, t_c, writetoDB);
			track.Invoke();
		}




function TrackPage(pageLabel, contextVals) 
	{ 
		if(contextVals == null)
			TrackEventInteraction(window.location.href, "PAGE", pageLabel, "", ""); 
		else
			TrackEventInteraction(window.location.href, "PAGE", pageLabel, "", contextVals); 
	} 


function TrackInput(fieldLabel, fieldValue, fieldParent) 
	{ 
		if(fieldParent == null)
			TrackEventInteraction(window.location.href, "INPUT", fieldLabel, fieldValue, "");
		else
			TrackEventInteraction(window.location.href, "INPUT", fieldLabel, fieldValue, fieldParent); 
	} 


function TrackAsset(assetID, area) 
	{ 
	   TrackEventInteraction(window.location.href, "ASSET", "Asset", assetID, area); 
	} 


function TrackLink(targetURL, targetLabel) 
	{ 
	   TrackEventInteraction(window.location.href, "CLICK", targetLabel, targetURL, ""); 
	}


/* 
Additional Tracking Function to differentiate the following 
1. Acutal Asset Views vs Just Attempt to View Asset on Nurture
2. Registration Cancellation From Nurture
*/
function TrackAssetView(assetID, area) 
	{ 
	   TrackEventInteraction(window.location.href, "ASSETCLICK", "Asset", assetID, area); 
	} 


function TrackRegCancel(targetURL, targetLabel) 
	{ 
	   TrackEventInteraction(window.location.href, "FORM CLICK", targetLabel, targetURL, ""); 
	}


/*Additional Tracking Function to track the Contact Form Submission */
function TrackFormSubmit(targetURL, targetLabel) 
	{  
	  TrackEventInteraction(window.location.href, "FORMSUBMIT", targetLabel, targetURL, ""); 
	} 
	
	
function TrackImage(targetURL, targetLabel) 
	{ 
	   TrackEventInteraction2(window.location.href, "CLICK", targetLabel, targetURL, "",getOmnitureCode()+"-SAPLogo","true"); 
	}
	

/* Additionl Tracking function added to implement SAPCOM-222 Changes */ 
function ShowEventInteraction(url, eventType, label, value, context) 
	{ 
		TrackEventInteraction2(url, eventType, label, value, context,"","false");
	}
	
	
	function TrackEventInteraction(url, eventType, label, value, context) 
		{ 
			TrackEventInteraction2(url, eventType, label, value, context,"","true");
		} 
		
	
	function TrackEventInteraction2(url, eventType, label, value, context,omniCode,writetoDB) 
		{ 
		   //alert('in event call call')
		   var pageSource = ""; 
		   if (typeof PAGESOURCE != "undefined") 
				pageSource = PAGESOURCE; 
		   
		   var market = ""; 
		   if (typeof MARKET != "undefined")
			   market = MARKET;
		
		   var t_r = "";
		   if (typeof T_R != "undefined")
			   t_r = T_R;
		
		   var t_c = "";
		   if (typeof T_C != "undefined")
			   t_c = T_C;
		   
		   try
			{
			   var track = new RemoteMethod('Tracking.epi?kNtBzmUK9zU' + omniCode); 
			   track.MethodName = 'TrackEventInteraction';
			   track.AddArguments(url, t_r, eventType, label, value, t_c, context, pageSource, market, writetoDB); 
			   track.Invoke(); 
			}
		   catch(err)
		   {
				alert(err);
		   }
		   //alert ('call finished');
		}


function getOmnitureCode()
	{
	  if (window.location.href.indexOf("mena",1) > 1)
		return '&_s_icmp=NurXV';
	  if (window.location.href.indexOf("usa",1) > 1)
		return '&_s_icmp=NurUS';
	  if (window.location.href.indexOf("brazil",1) > 1)
		return '&_s_icmp=NurBR';	
	}


/* TrackingTNTRecipe added 2/1/2012 from (trackinghelper.js) */ 
function TrackTNTRecipe(RecipeName) {
    PAGESOURCE = "TNT";
    var SrvCall = "current:s_t";
    ShowEventInteraction(window.location.href, "TNT", "Recipe", RecipeName, SrvCall);
	}
function ShowEventInteraction(url, eventType, label, value, context) {
    var _writetodb = "false";
    if (typeof writeToDB != "undefined")
        _writetodb = writeToDB;

    _coreTrackEventInteraction(url, eventType, label, value, context, "", _writetodb);
	}
function _coreTrackEventInteraction(url, eventType, label, value, context, omniCode, writetoDB) {
		var pageSource = "";
		if (typeof PAGESOURCE != "undefined")
			pageSource = PAGESOURCE;
	
		var market = "";
		if (typeof MARKET != "undefined")
			market = MARKET;
	
		var t_r = "";
		if (typeof T_R != "undefined")
			t_r = T_R;
	
		var t_c = "";
		if (typeof T_C != "undefined")
			t_c = T_C;
	
		try {
			var track = new RemoteMethod('Tracking.epi?kNtBzmUK9zU' + omniCode);
			track.MethodName = 'TrackEventInteraction';
			track.AddArguments(url, t_r, eventType, label, value, t_c, context, pageSource, market, writetoDB);
			track.Invoke();
		}
		catch (err) {
		}
	}
