var Ebl = {
	version: '1.0',
	stat : {
		DEBUG_ON: 1,
		DEBUG_OFF: 0,
		debug: (this.DEBUG_OFF == this.DEBUG_ON),
		params: {},
		init: function(statUrl, debugMode) {
         this.url = statUrl;
			this.debug = (debugMode == this.DEBUG_ON);
			if (!this.params["url"]) this.params["url"] = Ebl.replacePath(document.location.pathname);
			if (!this.params["referrer"]) this.params["referrer"] = document.referrer;
			if (!this.params["cc"]) this.params["cc"] = Ebl.detectSection() ;
			if (!this.params["security"]) this.params["security"] = Ebl.detectSecurity();
			if (!this.params["website"]) this.params["website"] = "DE";
			// if (!this.params["PERSNAVSID"]) this.params["PERSNAVSID"] = getCookieKey("PERSNAVSID");
			
			var qs = document.location.search;
			if (qs.length > 1) {
				qs = qs.substring(1, qs.length);
				if (qs) {
					for(var i=0; i < qs.split("&").length; i++) {
						var keyVal = qs.split("&")[i];
						this.params[keyVal.split("=")[0]]=keyVal.split("=")[1];
					}
				}
			}
		},
		
		addParams: function(params) {
			for (var key in params) {
				this.params[key] = params[key]
			}
		},
		
		addParam: function(key, value) {
			this.params[key] = value;
		},
		
		image: function() {
			var qstr = "";
			for (var key in this.params) {
				qstr += '&'+escape(key)+'='+escape(this.params[key]);
			}
			qstr = '?'+qstr.substr(1);
			if (this.debug) alert(qstr);
			if (document.images) {
				im = new Image();
				im.src = this.url+qstr;
			} else { 
      				document.write("<img src="+this.url+qstr+" width='1' height='1' />");
      			}
		},
		
		event: function(){
			Ebl.stat.image();
		}
	},
	
	addEvent: function(elem, evType, fn, useCapture){
		if (elem.addEventListener) {
			elem.addEventListener(evType, fn, useCapture);
			return true;
		}
		if (elem.attachEvent) {
			var r = elem.attachEvent('on'+evType, fn);
			return r;
		}
		elem['on'+evType] = fn;
		return 0;
	},
	
	detectSection: function() {
		var  arrSectionsReturn = new Array("nallo", "corporate", "career", "smallmedium","largecorporate", "aos", "ios", "myhome", "retailers", "partners",  "suppliers", "professionals", "greenwall", "vertiwall", "professionalswal", "smallmedium", "homepage", "enterprises");
		var arrSections = new Array("code/nallo", "corporate", "career", "smallmedium", "largecorporate", "aos", "ios", "myhome", "partners/retailers", "partners", "suppliers", "professionals", "greenwall", "vertiwall", "professionalswal", "smallrabit", "homepage", "enterprises");
		var strScriptName;
		var L;

		strScriptName = document.location.pathname;

		for (L=0;L<19;L++)  {
			if ( strScriptName.indexOf(arrSections[L]) > 0) {
				return arrSectionsReturn[L];
			}
		}
		return "corporate";
	},

	detectSecurity: function(){
		var arrSections = new Array("public", "private");
		var  arrSectionsReturn = new Array("Public", "Private");
		var strScriptName;
		var L;

		strScriptName = document.location.pathname;

		for (L=0;L<3;L++)  {
			if ( strScriptName.indexOf(arrSections[L]) > 0) {
				return arrSectionsReturn[L];
			}
		}
		return "Public";
	},

 	replacePath: function(str) {
  		str = str.replace(/_fr\.|_nl\.|_en\.|_de\./i,"_xx.")
 		while (str.indexOf("\\") != -1)
 			str = str.replace("\\","\/");
 		return str;
 	}
};

function getCookieValue(offset)
{
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function getCookieKey(key)
{
	var arg=key+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieValue(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;

	}
	return null;
}

Ebl.stat.init("https://"+document.location.host+"/protected/webanalytics/public/log.do");
//Ebl.stat.init("https://tertestde.electrabel.be/protected/webanalytics/public/log.do");
Ebl.addEvent(window,'load',Ebl.stat.event,false);