// ---------------------------------------------------------------------------------------------------------

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

// ---------------------------------------------------------------------------------------------------------

var DISABLE_BANNERS = false;
var DISABLE_VIDEOBANNERS = false;
var DISABLE_DART = false; // DART banners

// ---------------------------------------------------------------------------------------------------------

var BANNERCOUNT245=0;

var random = Math.round(Math.random()*100000000);
var domain = "P3851.autotekoop.nl/";

// ---------------------------------------------------------------------------------------------------------

function geturlpara ( queryString, parameterName ) {
  var parameterName = parameterName + "=";

  if ( queryString.length > 0 ) {
    begin = queryString.indexOf ( parameterName );

    if ( begin != -1 ) {
      begin += parameterName.length;
      end = queryString.indexOf ( "&" , begin );

      if ( end == -1 ) {
        end = queryString.length
      }

      return unescape ( queryString.substring ( begin, end ) );
    }
    return "null";
  }
}

// ---------------------------------------------------------------------------------------------------------

//var gallery = geturlpara(unescape(document.location.href.toLowerCase()), 'gallery' );

// ---------------------------------------------------------------------------------------------------------

function showBanner(size, obj) {

  if (DISABLE_BANNERS == true || block == true)  { return; }

  if (DISABLE_DART == false)
  {
    showDartBanner(size);
    return;
  }

/*
  var size=size.toLowerCase();

  var currentUrl = location.href;
  var redactieUrlRegExp = new RegExp("int.www.autotekoop.nl");

  if( currentUrl.match(redactieUrlRegExp) )
  {
    var dimension = size.split("x");
    if(dimension[0]==728 && dimension[1]==90)
    {
      dimension[1]=0; // just write one pixel for menu
      document.write("<div height=1px;></div>");
      return;
    }
  document.write("<div style=\"width: "+dimension[0]+"px; height: "+dimension[1]+"px; border: 1px solid black; background-color: #cccccc; color: #777777; font-family:Arial; font-size: 7pt; text-align: center;\">(banner)</div>");
  return;
  }
  */
}

// ---------------------------------------------------------------------------------------------------------

var tilecounter = 0;

function showDartBanner(size) {

  var prefix = "http://ad.nl.doubleclick.net/";

  if (typeof usezone == 'undefined')
  {
    var zone = getZoneFromPath(location.pathname);
  } else  {
    var zone=usezone;
  }

  if (size=='245x245')
  {
    //count the banners on one page for all 245x245 commercial positions (o.a. reiskrant)
    BANNERCOUNT245++;
  }
  
  
  if (typeof segQS == 'undefined') { segQS = ''; }
  
  if (typeof nvurl != "undefined") { custom = nvurl } else { custom = "" } // add custom targetting values from global var set by /wireframe/customtarget.jsp

  if (typeof ttvar != "undefined") { custom += "kw="+ttvar+";" } // add custom targetting values from global var set by /wireframe/customtarget.jsp

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

  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>");

    // Firebug logging if installed in client
    if ( console.log ) {
      console.log( "BannerPos => width: " + width + "px. height: " + height + "px. zone:" + zone + " call:" + prefix + 'adj/' + domain + specific );
    }
  }
}

// ---------------------------------------------------------------------------------------------------------

function getZoneFromPath(path) {

  var zone = 'other';
  var originalPath = path;
  
  if(path == ""){
      path = "/";
  }
  
  if(path != "/" && path.lastIndexOf("/") != -1 && path.lastIndexOf("/") == path.length -1){
    path = path.substring(0, path.length-1);
  }

  zone = matchZoneWithPath(path);

  while (path!= "" && path!="/" && zone=="other") {
    xIndex = path.substring(1, path.length).lastIndexOf("/");
    path = path.substring(0, xIndex+1);

    zone = matchZoneWithPath(path);
  }

  return zone;
}

// ---------------------------------------------------------------------------------------------------------

function matchZoneWithPath(newPath) {
  var zone = 'other';

  if ((document.location.href.indexOf("www.autotekoop.") >-1) || (document.location.href.indexOf("autotelegraaf.nl") >-1) || (document.location.href.indexOf("autotekoop.nl:8080") >-1))
  {
    switch (newPath) {
      case '/':                                 zone = 'home';                      break;
      case '/occasion':                         zone = 'advertentie';               break;
      case '/reviews':                          zone = 'review';                    break;
      case '/testverslagen':                    zone = 'testverslagen';             break;
      case '/zoeken':                           zone = 'zoekresultaat';             break;
      case '/zoeken-uitgebreid':     		zone = 'uitgebreid-zoeken';         break;
      case '/search.htm':  			zone = 'zoekresultaat';             break;
      case '/ssearch.htm':  			zone = 'zoekresultaat';             break;
      case '/auto-verkopen':           		zone = 'auto-verkopen';             break;
      case '/specials':       			zone = 'specials';                  break;
      case '/loginForm.htm':       	        zone = 'inloggen';                  break;
      case '/forgotPassword.htm':       	zone = 'wachtwoord-vergeten';       break;
      case '/register.htm':     		zone = 'registreren';               break;
      case '/contact.htm':     			zone = 'contact';                   break;
      case '/disclaimer.htm':     		zone = 'disclaimer';                break;
      case '/advertising_conditions.htm':     	zone = 'advertentievoorwaarden';    break;
    }
  }
  return zone;
}
// ---------------------------------------------------------------------------------------------------------

