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------------------------------------*/

var tilecounter = 0;

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

		var zone = getZoneFromPath(location.pathname);

    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) {

	if(undefined==zone) zone = 'other';
	return zone;
/*
	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.dumpert.") >-1)
	{
	switch(topLevelDir(newPath)) // om te selecteren na laatste slash in URL
		{
			case '/':		    		          	zone = 'homepage';  break;
			
	  }
		switch (newPath) // om te selecteren na eerste slash in URL
		{
			case '/reiskrant/reisreportages/': 	zone='reisreportage'; break;
			
		}
	}
	return zone;
}
