/**********************************************************************
 * Added by BLUE to have global variables for													*
 * Sihouette tagging																									*
 *																																		*
 * Note: The value for global_te_sitecode is unique										*
 * for each environment so please change it accordingly								*
 * before uploading to j&j staging or j&j live												*
 *																																		*
 * CN Brand Site 																											*
 * AGENDA Staging Site Code: 12639																		*
 * J&J Staging Site Code: 31763																				*
 * J&J Live Site Code: 82161																					*
 **********************************************************************/
 var global_te_server = "adsfac.sg/MultiSilhouette";
 var global_te_sitecode = "82161";
 var global_tv = "1";
 var global_js = "1";
 var global_nojs = "0";

/********************************************************
 * Copyright Facilitate Digital 2006                    *
 * Version 2.0.4                                          *
 * http://www.facilitatedigital.com                     *
 ********************************************************/
 
var NI_SE = "", NI_SC = "", NI_ST = "", NI_SV = "", NI_IW = 0;
var ni_TrackLinks = true;

function ni_TrackHit(server, siteCode, description, section, service, trigger, amount, adCampaign, title, url, layer, basketAdd, basketRemove, parameters, identifier, products)
{ 
   NI_SE = server; NI_SC = siteCode; NI_ST = section; NI_SV = service;
   function CB()
   {
      var cb="", key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";            
      for (i=0;i<5;i++) cb += key.charAt(Math.floor(Math.random()*52));      
      return cb;
   }

   function A(B,C)
   {
      if (typeof(C) != "undefined" && C != "") return "&"+B+"="+escape(C);
      else return "";
   }
   
   if (typeof(NI_PAGE) != "undefined")
   {
     if (url.indexOf("?") > 0) url += "&ni_page=" + NI_PAGE;
     else url += "?ni_page=" + NI_PAGE;
   }
	
   var p = "http"+(document.URL.indexOf('https:')==0?'s':''); 	
   var t = new Date();	
   var u = p+"://"+server+"/Hit.aspx?tv=1&sc="+siteCode;
   u+=A("lo",description);
   u+=A("du",url);
   u+=A("st",section);
   u+=A("sv",service);
   u+=A("ac",adCampaign);
   u+=A("tr",trigger);
   u+=A("ta",amount);
   u+=A("ti",title);
   u+=A("tz",t.getTimezoneOffset());
   u+=A("ch",t.getHours());
   u+=A("cb",CB());	
   u+=A("ru",window.document.referrer);
   u+=A("js","1");
   u+=A("ul",navigator.appName=="Netscape" ? navigator.language : navigator.userLanguage);
   u+=A("ba", basketAdd);
   u+=A("br", basketRemove);
   u+=A("pm", parameters);
   u+=A("id", identifier);
   u+=A("pr", products);
	
   if (typeof(screen)=="object")
   {
      u+=A("sr",screen.width+"x"+screen.height);	
   }
	
	if (layer == 1)
	{
	  if (NI_IW == 0) { document.write('<div style="position:absolute;width:1px;height:1px;overflow:hidden"><IMG name="ni_tag" id="ni_tag" border="0" width="1" height="1" src="'+u+'"></div>'); NI_IW = 1; }
	  else { u+=A("ir","1"); document.images.ni_tag.src = u; }
 	}
 	else
 	{
 	  document.write('<IMG name="ni_tag" id="ni_tag" border="0" width="1" height="1" src="'+u+'">'); NI_IW = 2;
 	}
}

/* The following function may be used any number of times in a page to load a file and track a hit 
 * against that file.  This is useful when the file being loaded is not html, 
 * or is not under your control, so can't have an Silhouette tracking code inserted into it.
 *
 * E.g. <a href="javascript:ni_LoadUrl('Catalogue.pdf', 'Catalogue')">Download catalogue</a>
 *
 * If you consider clicking on the link to be the completion of a transaction, use the 'Sale' trigger
 * E.g. <a href="javascript:ni_LoadUrl('Catalogue.pdf', 'Catalogue', 'Sale')">Download catalogue</a>
 */

function ni_LoadUrl(url, title, trigger)
{  
  ni_TrackHit(NI_SE, NI_SC, "", NI_ST, NI_SV, trigger, "", "", title, url, NI_IW, "", "", "", "", "");
  // document.location.href = url;
}

/* The following functions are used to track links to content that cannot be coded with JavaScript
 * The code attachs a JavaScript event to files which either have or do not have a certain extension
 * To exclude files with HTM(L), ASP(X) or CFM extensions use the following condition in line 123:
 * 		if (!/\/$|.htm|.asp|.cfm|\#$/.test(links[i].href))
 * To include files with PDF, DOC or XLS extensions use the following condition in line 123:
 *    if (/\/$|.pdf|.doc|.xls|\#$/.test(links[i].href))
 */

function ni_TrackAttachment(event)
{
	var link = event.srcElement || event.target;
	while(link.tagName!='A') link=link.parentNode;
	var linkText = link.innerHTML.replace(/\<.+?\>/g,"");
	if (typeof(ni_LoadUrl)!='undefined')
		ni_LoadUrl(link.href, escape(linkText))
	else
	{           
		var img = new Image(1,1);
		img.src = 'http://syd.facilitatedigital.com/Hit.aspx?tv=1&sc='+ NI_SC +'&js=1&du='+escape(link.href)+'&ti='+escape(linkText);
	}
}

function ni_ObserveEvent(el,evnt,fnc,capture)
{
	if (el.attachEvent) el.attachEvent('on'+evnt,fnc);
	else if (el.addEventListener) el.addEventListener(evnt,fnc,capture);
}

  // Attach to all non webpage links
if (ni_TrackLinks)
{
	var links = document.getElementsByTagName('A');
	for (var i=0; i<links.length; i++)
		{
			if (/\/$|.pdf|.doc|.txt|\#$/.test(links[i].href))
				ni_ObserveEvent(links[i], 'click', ni_TrackAttachment, true);
		}
}
function removetrackquerystring(url,excludeparam)
{
	url = new String(url);
	amendedurl = new String(url);
	var amendedQueryString = new Array();
	if(url.indexOf('?') != -1)
	{
		var querystring = url.substring((url.indexOf('?') + 1), url.length);
		if(querystring.search(/&/) != -1)
		{
			var querystringSplit = querystring.split('&');
			amendedurl = url.substring(0,(url.indexOf("?")+1));
			for (var i = 0; i < querystringSplit.length; i++)
			{
					var pair = querystringSplit[i].split('=');
					var name = pair[0];
					//var value = pair[1]; /*Not used at the moment*/
					if(name != excludeparam)
					{
						amendedQueryString.push(querystringSplit[i]);
					} 
			}
			amendedurl = amendedurl + amendedQueryString.join('%26');
		}
		else if(querystring.search(excludeparam) != -1)
		{
			amendedurl = url.substring(0,(url.indexOf("?")));
		}
	}
	amendedurl=(amendedurl.lastIndexOf("/")==(amendedurl.length-1))?amendedurl:amendedurl + "/";
	return amendedurl;
}
