// corelio advertising by adhese.com

var adheseCookie;
var adheseLoc;
var adheseRand;

function getAdheseLoc() {
	var l = location.pathname;
	if (l.charAt(0)=='/') l = l.substring(1,l.length);
	if (l.charAt(l.length-1)=='/') l = l.substring(0,l.length-1);
	var m = undefined;	
	if (l.indexOf('/')!=-1) {
		l = l.substring(0,l.lastIndexOf('/'));
		m = l.split('/');
	} else {
		m = new Array();
		m[0] = l;
	}
	var loc = "_";
	if (location.hostname.indexOf("xpats.preview.spotter.be")!=-1 || location.hostname.indexOf("xpats.spotter.be")!=-1) {
		loc += 'xpats_classifieds_';
		return loc;
	} else if (location.hostname.indexOf("xpats")!=-1 || location.hostname.indexOf("212.123.12.143") != -1) {
		loc += 'xpats_' + m[0] + '_';
		return loc;
	} else if (location.hostname.indexOf("spotter")!=-1) {
		if (location.hostname.indexOf("auto")!=-1) {
			if (location.pathname == '/nl/default.aspx') {
				loc += 'nl_auto-spotter-home_';
			} else if (location.pathname.substr(0,3) == "/nl") {
				var brand = getMetaTagValue('CarBrand');
				if (brand != "") {
					loc += 'nl_auto-spotter-'+ brand.replace(/\s/gi,'-') +'_';
				} else if (location.pathname.indexOf("/Spot_")!=-1) {
					loc += 'nl_auto-spotter-detail_';
				} else {
					loc += 'nl_auto-spotter_';
				}
			} else if (location.pathname.substr(0,3) == "/nl") {
				loc += 'nl_auto-spotter_';
			} else if (location.pathname == "/fr/default.aspx") {
				loc += 'fr_auto-spotter-home_';
			} else if (location.pathname.substr(0,3) == "/fr") {
				var brand = getMetaTagValue('CarBrand');
				if (brand != "") {
					loc += 'fr_auto-spotter-'+ brand.replace(/\s/gi,'-') +'_';
				} else if (location.pathname.indexOf("/Spot_")!=-1) {
					loc += 'fr_auto-spotter-detail_';
				} else {
					loc += 'fr_auto-spotter_';
				}
			}
		} else 	if (location.hostname.indexOf("immo")!=-1) {
			if (location.pathname == '/nl/default.aspx') {
				loc += 'nl_immo-spotter-home_';
			} else if (location.pathname.substr(0,3) == "/nl") {
				if (location.pathname.indexOf("/Spot_")!=-1) loc += 'nl_immo-spotter-detail_';
				else loc += 'nl_immo-spotter_';
			} else if (location.pathname == "/fr/default.aspx") {
				loc += 'fr_immo-spotter-home_';
			} else if (location.pathname.substr(0,3) == "/fr") {
				if (location.pathname.indexOf("/Spot_")!=-1) loc += 'fr_immo-spotter-detail_';
				else loc += 'fr_immo-spotter_';
			}
		} else 	if (location.hostname.indexOf("travel")!=-1) {
			if (location.pathname == '/nl/default.aspx') {
				loc += 'nl_travel-spotter-home_';
			} else if (location.pathname.substr(0,3) == "/nl") {
				if (location.pathname.indexOf("/Spot_")!=-1) loc += 'nl_travel-spotter-detail_';
				else loc += 'nl_travel-spotter_';
			} else if (location.pathname == "/fr/default.aspx") {
				loc += 'fr_travel-spotter-home_';
			} else if (location.pathname.substr(0,3) == "/fr") {
				if (location.pathname.indexOf("/Spot_")!=-1) loc += 'fr_travel-spotter-detail_';
				else loc += 'fr_travel-spotter_';
			}
		} else 	if (location.hostname.indexOf("relation")!=-1) {
			if (location.pathname == '/nl/default.aspx') {
				loc += 'nl_relation-spotter-home_';
			} else if (location.pathname.substr(0,3) == "/nl") {
				if (location.pathname.indexOf("/Spot_")!=-1) loc += 'nl_relatie-spotter-detail_';
				else loc += 'nl_relatie-spotter_';
			} else if (location.pathname == "/fr/default.aspx") {
				loc += 'fr_relatie-spotter-home_';
			} else if (location.pathname.substr(0,3) == "/fr") {
				if (location.pathname.indexOf("/Spot_")!=-1) loc += 'fr_relatie-spotter-detail_';
				else loc += 'fr_relatie-spotter_';
			}
		} else 	if (location.hostname.indexOf("job")!=-1) {
			if (location.pathname.substr(0,3) == "/nl" || location.pathname.indexOf("/jobspotter/nl")!=-1  || location.pathname.indexOf("/jobspotter.test/nl")!=-1 ) loc += 'nl_job-spotter_';
			if (location.pathname.substr(0,3) == "/fr" || location.pathname.indexOf("/jobspotter/fr")!=-1  || location.pathname.indexOf("/jobspotter.test/fr")!=-1 ) loc += 'fr_job-spotter_';
		} else 	if (location.pathname == "/nl/index.aspx" || location.pathname == "/nl/") {
			if (location.pathname.substr(0,3) == "/nl") loc += 'nl_home-spotter_';
		} else 	if (location.pathname == "/fr/index.aspx" || location.pathname == "/fr/") {
			if (location.pathname.substr(0,3) == "/fr") loc += 'fr_home-spotter_';
		} else {
			if (location.pathname == '/nl/default.aspx') {
				loc += 'nl_varia-spotter-home_';
			} else if (location.pathname.substr(0,3) == "/nl") {
				if (location.pathname.indexOf("/Spot_")!=-1) loc += 'nl_varia-spotter-detail_';
				else loc += 'nl_varia-spotter_';
			} else if (location.pathname == "/fr/default.aspx") {
				loc += 'fr_varia-spotter-home_';
			} else if (location.pathname.substr(0,3) == "/fr") {
				if (location.pathname.indexOf("/Spot_")!=-1) loc += 'fr_varia-spotter-detail_';
				else loc += 'fr_varia-spotter_';
			}
		}
		return loc;
	} else if (location.hostname.indexOf("passe-partout")!=-1) {
		var f1 = "";
		if (document.getElementById('whereHiddenField'))
			f1 = document.getElementById('whereHiddenField').value.split('|')[0];
		var f2 = "";
		if (document.getElementById('whatHiddenField'))
			f2 = document.getElementById('whatHiddenField').value.split('|')[0].replace(/\//gi,'-');
		return "_" + f1 + "_" + f2 + "_";
		
	} else {
		if (m!=undefined) {
			for (var x=0; x<m.length; x++) {
				loc += m[x] + '_';
			}
		}
		return loc;
	}
}

function getMetaTagValue(n) {
	var m = document.getElementsByTagName("META");
	for (var x=0; x<m.length; x++) {
		if (m[x].name == n) {
			return m[x].content;
		}
	}
	return "";
}


function articleTrack() {
	var d = getTrackingData();
	if (d.length>1) {
		var s1 = "";
		var s2 = "";
		var s3 = "";
		var s4 = "";
		for (var x=0; x<d.length; x++) {
			if(d[x][0]=="s1") s1 = d[x][1];
			else if(d[x][0]=="WT.Sec") s2 = d[x][1];
			else if(d[x][0]=="WT.SSec") s3 = d[x][1];
			else if(d[x][0]=="referrer") s4 = d[x][1];
		}
		var img = new Image();
		img.src = "http://track.corelio.adhese.be/log/" + s1 + "/" + s2 + "/" + s3 + "/" + s4 + "/" + location.protocol + "//" + location.hostname + location.pathname;
		img.width=1;
		img.height=1;
		document.getElementsByTagName("BODY")[0].appendChild(img);
	}	
}

function getTrackingData() {
	var m = document.getElementsByTagName("META");
	var kk = new Array();
	for (var x=0; x<m.length; x++) {
		if (m[x].name == "s1") {
			kk.push( new Array(m[x].name, escape(m[x].content.replace(/,|\s|\//gi,'_'))) );
		} else 	if (m[x].name == "WT.Sec") {
			kk.push( new Array(m[x].name, escape(m[x].content.replace(/,|\s|\//gi,'_'))) );
		} else 	if (m[x].name == "WT.SSec") {
			kk.push( new Array(m[x].name, escape(m[x].content.replace(/,|\s|\//gi,'_'))) );
		}
	}
	kk.push( new Array("referrer", escape(document.referrer.replace(/,|\s|\//gi,'_'))) );
	return kk;
}

function initPageAdhese() {
	if(typeof(adheseRand) == 'undefined') {
		adheseRand = Math.round(Math.random()*100);
	}
	adheseLoc = getAdheseLoc();
}

function initAdhese(templateId) {
	if (location.hostname.indexOf("passe-partout")!=-1)
		adheseLoc = getAdheseLoc();
	tagAdhese(adheseLoc, templateId);
}

function tagAdhese(h, t) {
	document.write('<scr' + 'ipt type="text/javascript" src="http://ads.adhese.be/ad/'+ h +'/'+ t +'/' + adheseRand + '/?t=' + new Date().getTime() + '"><\/scr' + 'ipt>');
}
//init overall / once per page load
initPageAdhese();
