/****************************************
 * Numeric Analytics tagging framework
****************************************/
var _numeric_ = new Object;

// ******************   CONFIG *********************************
_numeric_.config=new Object;
_numeric_.config.openScrpt = '<scr' + 'ipt language="JavaScript" type="text/javascript" src="';
_numeric_.config.closeScrpt = '"></scr' + 'ipt>';
var host = location.hostname;
if ((host == "publish.estore.sephoraus.com") || (host == "10.186.84.59") || (host == "preview.estore.sephoraus.com") || (host == "10.186.85.36") || (host == "qa.estore.sephoraus.com") || (host == "10.186.85.15") || (host == "sandbox.qa.estore.sephoraus.com") ) {
	_numeric_.config.baseUrl ="//"+location.hostname+"/numeric/";
} else if ((host == "hdev.sephora.com") || (host == "apd01.sephoraus.com") || (host == "apd01") || (host == "10.186.85.131")) {
	var devport = location.port;
	_numeric_.config.baseUrl ="//"+location.hostname+":"+devport+"/numeric/";
} else {
	_numeric_.config.baseUrl ="//www.sephora.com/numeric/";
}


// ******************   CONFIG *********************************

// ******************   UTILS *********************************
_numeric_.utils=new Object;
_numeric_.utils.loadScriptLibrary = function(src, targetElement) { 
	try{
		if (_numeric_.scriptElement == null) {
			_numeric_.scriptElement = document.createElement('script');
			_numeric_.scriptElement.type = 'text/javascript'; 
		}
	
		if (targetElement == null){
			if (_numeric_.headElement == null)
				_numeric_.headElement = document.getElementsByTagName('body')[0];
			targetElement = _numeric_.headElement;
		}
		var library = _numeric_.scriptElement.cloneNode(true);
		library.src = src;
		targetElement.appendChild(library);
	}catch(e){}
}
_numeric_.utils.getEventTarget = function(e)
	{
		try {
			var targ;
			if (!e) {
				var e = window.event;
			}
			if (e.target) {
				targ = e.target;
			} 
			else if (e.srcElement) {
				targ = e.srcElement;
			}
			if (targ.nodeType == 3) {
				targ = targ.parentNode;
			}
			return targ;
		} catch(e) {}
	}
_numeric_.utils.getEventTargetName = function(e)
	{
		try {
			var targ;
			if (!e) {
				var e = window.event;
			}

			if (e.target) {
				targ = e.target;
			} 
			else if (e.srcElement) {
				targ = e.srcElement;
			}

			if (targ.nodeType == 3) {
				targ = targ.parentNode;
			}
			return targ.tagName;
		} catch(e) {}
	}
_numeric_.utils.addOnloadEvent = function(func){
		try{
			if(window.attachEvent){
				window.attachEvent("onload",func);
			}
			if(window.addEventListener){
				window.addEventListener("load",func,false);
			}
			return this;
		}catch(e){}
	}
		_numeric_.utils.addOnClickEvent = function(func, El){
		try{
			if(El.attachEvent){
				El.attachEvent("onClick",func);
			}
			if(El.addEventListener){
				El.addEventListener("click",func,false);
			}
			return this;
		}catch(e){}
	}
_numeric_.utils.addOnSubmitEvent = function(func, El){
		try{
			if(El.attachEvent){
				El.attachEvent("onSubmit",func);
			}
			if(El.addEventListener){
				El.addEventListener("submit",func,false);
			}
			return this;
		}catch(e){}
	}
_numeric_.utils.queryStringToHash = function(str){
		try{
			var qs=[];
			var a=str.indexOf("?")>-1?str.split("?")[1].split("&"):str.split("&");
			for(var x=0;x<a.length;x++){
				var b=a[x].split("=");
				qs[b[0]]=b[1];
			}
			return qs;
		}catch(e){}
	}
// ******************   UTILS *********************************


//Call vender code
//Omniture
//_numeric_.utils.loadScriptLibrary(_numeric_.config.baseUrl +"s_code.js",  document.getElementsByTagName('head')[0]);

//Google Analytics
//_numeric_.utils.loadScriptLibrary("ga.js",  document.getElementsByTagName('head')[0]);


_numeric_.analyticsCallBack = function() {
	_numeric_.utils.loadScriptLibrary(_numeric_.config.baseUrl +"s_code.js",  document.getElementsByTagName('head')[0]);
	//_numeric_.utils.loadScriptLibrary("gaWidget.js",  document.getElementsByTagName('head')[0]);
}

_numeric_.utils.addOnloadEvent(_numeric_.analyticsCallBack);
	
