// Omniture specific global-variable
var s_account = "";
var s_language = "";
var s_country = "";
var s;
// Statistics (dev or live) initialazed

var ibStattype = "";
var ibStatsInitialized = false;

var serverHost = "";
myLocation = document.location.href;
if (myLocation.indexOf('http://') == 0) {
	serverHost = myLocation.substr(myLocation.indexOf('http://')+7, myLocation.indexOf('/', myLocation.indexOf('http://')+7)-7);
} else if (myLocation.indexOf('https://') == 0) {
	serverHost = myLocation.substr(myLocation.indexOf('https://')+8, myLocation.indexOf('/', myLocation.indexOf('https://')+8)-8);
}

if (serverHost == "business.ikea.com") {
	ibStattype = "live";
} else if (serverHost.length > 0) {
	ibStattype = "dev";
}

try {
	if(sLocale!=undefined&&sLocale!=""&&sLocale!=null)
	{
		s_language = sLocale.substr(0, sLocale.indexOf("_")).toLowerCase();
		s_country = sLocale.substr(sLocale.indexOf("_")+1).toLowerCase();

		// UK is locale country on IB and GB on ikea.com
		if (s_country=="uk") {s_country="gb"}
		
		if (ibStattype == "dev") {
			s_account = "ikeasedev";
			ibStatsInitialized = true;	
		} else if (ibStattype == "live") {
			s_account = "ikea"+s_country+"prod,ikeaallprod";
			ibStatsInitialized = true;
		}
	}
	else
	{
		s_language = "";
		s_country = "";

		if (ibStattype == "dev") {
			s_account = "ikeasedev";
			ibStatsInitialized = true;	
		} else if (ibStattype == "live") {
			s_account = "ikeaallprod";
			ibStatsInitialized = true;
		}
	}

	//s=s_gi(s_account)
} catch(e) {
	if (ibStattype == "dev") {
		throw new Error(e);
	}
}

function fireClickTagOmniture( pageName, prop1, prop2, prop3, prop30, events, other ) {
	try {
		if (pageName == undefined) {return;}
		s.pageName = (pageName+"").toLowerCase().replace(/\//g,">");
		s.prop1 = (prop1+"").toLowerCase().replace(/\//g,">");
		s.prop2 = (prop2+"").toLowerCase().replace(/\//g,">");
		var filler = ( (prop3+"") != "" ) ? ">": "";
		s.prop3 = (prop2+"").toLowerCase()+filler+(prop3+"").toLowerCase().replace(/\//g,">");
		s.prop30 = (prop30+"").toLowerCase();
		s.events =(events+"").toLowerCase();
		
		for(var prop in other){
			if (prop != null && prop.length > 0 && other[prop] != null){
				s[prop] = other[prop];
			}
		}
		// Copy s.prop18 to eVar4;
		if (s["prop18"] != null) s["eVar4"] = s["prop18"];
		
		//alert( "s_account: "+s_account+"\n pageName: "+s.pageName+"\n prop1: "+s.prop1 +"\n prop2: "+ s.prop2 +"\n prop3: "+ s.prop3 +"\n prop30: "+ s.prop30 +"\n events: "+ s.events);
		s.t();
		
		// reset all potential 'other' attribute
		delete s["products"];
		delete s["prop18"];
		delete s["eVar4"];
		delete s["prop19"];
	} catch(e) {
		if (ibStattype == "dev") {
			throw new Error(e);
		}
	}
}
