var DEBUG = false;	// LIVE
//var DEBUG = true;	// TEST

var DISABLE_BANNERS = false;

var random = Math.round(Math.random()*100000000);

function topLevelDir(fullpath) {
   topleveldir=fullpath;
   if (typeof fullpath != 'undefined')
   {
      firstslash=fullpath.indexOf('/');
      if (firstslash!=-1)
      {
		   	secondslash=fullpath.substring(firstslash+1).indexOf('/');
				if (secondslash != -1) { topleveldir=fullpath.substring(firstslash+1,secondslash+1); }
      }
   }
   return topleveldir;
}


function showBanner(size) {
	if (DISABLE_BANNERS == true){ return; }
	showDartBanner(size);
	return;
}

/*-----------------------DART------------------------------------*/
// overleg nieuwe zones met Marcel Groot m.groot@telegraaf.nl

var tilecounter = 0;

function showDartBanner(size) {
    var prefix = "http://ad.nl.doubleclick.net/";
    var domain = "P3851.autovisie.nl/";

		//var zone = getZoneFromPath(location.pathname);
		
		var zone = getZone();

    if (typeof segQS == 'undefined') { segQS = ''; }

    var specific = zone + ";sz=" + size + ";" + segQS + ";tile=" + (++tilecounter) + ";ord=" + random + "?";

		size = size.toLowerCase();

    var xIndex = size ? size.indexOf("x") : '';
    var imgSize = '';
    var width;
    var Height;

    if(size &&  xIndex != -1) {
        width = size.substr(0, xIndex);
        height = size.substr(xIndex+1, size.length);
        imgSize = 'width="' + width + '" height="' + height + '"';
    }

    if (DEBUG == false) {
		var tag = '<script language="JavaScript" src="' + prefix + 'adj/' + domain + specific + '" type="text/javascript"></script>\n';
		document.write(tag);
		document.write("<!--" + prefix + 'adj/' + domain + specific+"-->");
    } else {
		var mytag = 'zone=' + zone ;
		document.write("<div style=\"width: "+width+"px; height: "+height
			+"px; border: 1px solid black; background-color: #cccccc; color: #777777; font-family:Arial; text-align: center;\">"
		  +mytag+"</div>");
    }
}

function stringEndsWith(str, strmatch) { return str.lastIndexOf(strmatch)==str.length-strmatch.length; }

// translate the current path to a configured zone

function getZoneFromPath(path) {
	var zone = 'other';
	var originalPath = path;
	if (path.indexOf(".html") != -1){
		xIndex = (path.substring(1, path.length)).lastIndexOf("/");
		path = path.substring(0, xIndex);
	}
	xIndex = (path.substring(1, path.length)).lastIndexOf("/");
	path = path.substring(0, xIndex+2);
	zone = matchZoneWithPath(path);
	while (path!= "" && path!="/" && zone=="other") {
		xIndex = path.substring(0, path.length-1).lastIndexOf("/");
		path = path.substring(0, xIndex+1);
		zone = matchZoneWithPath(path);
		if (path=="/") { zone='other'; }
	}
	if (originalPath.indexOf(".html") != -1 || originalPath.indexOf(".ece") != -1 ) { zone = zone + '_artikel'; }
	return zone;
}

//match the path with the corresponding zone

function matchZoneWithPath(newPath) {
	var zone = 'other';
	if (document.location.href.indexOf("www.autovisie.") >-1)
	{
	switch(topLevelDir(newPath)) // om te selecteren na laatste slash in URL
		{
			
	  }
		switch (newPath) // om te selecteren na eerste slash in URL
		{
			//case '/nieuws/stadstreek/': 	zone='stadstreek'; break;

		}
	}
	return zone;
}



/**** Replacement by Ben Tumminaro (TTG) *****/

	function getZone(){
	
		var zone = 'other' // default
	
		var loc = document.location.href; 
		var folders = loc.split('/');
		
			// array folders:
			// [0] 	[1]	[2]		[3]
			// http	(empty)	domain name	top folder
		
		var topFolder = folders[3]; 
		var bottomFolder = folders[folders.length-2];
		
		if(stringEndsWith(bottomFolder.toLowerCase(), 'autovisie.nl')){
			zone= 'homepage'; 			
		}
		else{
			if(folders[2]=='forum.autovisie.nl'){
				zone='forum';
			}
			else{

				switch(topFolder){
					case 'nieuws' : zone = 'nieuws'; break;
					case 'expertise' : zone = 'expertise'; break;
					case 'petrol_plaza' : zone = 'petrol_plaza'; break;
					case 'magazine' : zone = 'magazine'; break;
					case 'mijn_autovisie' : zone = 'mijn_autovisie'; break;
					case 'abonnementen' : zone = 'abonneeservice'; break;
					case 'service' : zone = 'abonneeservice'; break;
					case 'routeplanner' : zone = 'routeplanner'; break;
					case 'nieuwsbrief' : zone = 'nieuwsbrief'; break;


					case 'vrouw' : zone = 'actie'; break;  
					case 'spits' : zone = 'actie'; break;  
					case 'tem' : zone = 'actie'; break;  
					case 'avjb' : zone = 'actie'; break;  
					case 'lotto' : zone = 'actie'; break;  
					case 'porsche' : zone = 'actie'; break;  
					case 'pirelli' : zone = 'actie'; break; 
					case 'notebook' : zone = 'actie'; break;
				}
			}
		}
		
		return zone;
	}


