allowSurvey = true;

if (typeof point == 'undefined') point = '';
if (typeof tile == 'undefined') tile = '';

/*function jobsSearchString() {
jString = '';
(joblocation == "")?null:jString+=joblocation + ";";
(jobfe == "")?null:jString+=jobfe + ";";
(jobindustry == "")?null:jString+=jobindustry + ";";
(jobfunction == "")?null:jString+=jobfunction + ";";
(jobedlevel == "")?null:jString+=jobedlevel + ";";
(jobstatus == "")?null:jString+=jobstatus + ";";
(jobkw == "")?null:jString+=jobkw + ";";
}
*/

var debugAdCode = false ;
if (document.location.search.indexOf("debugAdCodeStatic")+1)
  debugAdCode = true ;
else if (document.location.search.indexOf("debugAdCodeJsp")+1)
  debugAdCode = false ;
else if (document.location.search.indexOf("debugAdCode")+1)
  debugAdCode = true ;
var show_doubleclick_ad = true ;
var static_wpatc = getWPATCookie() ;

// constants
var KEEP_NODE = false ;
var CHANGE_NODE = true ;
 
// changed on first call to placeAd
var firstTimeCalled = true ;
var firstTimeCalledNew = true ;
var adUniqueNumber = '' ;
var newsAncestorAsString = new String("") ;
// var newsAncestorAsString = new String(",metro,nation,style,opinion,food,outlook,magazine,books,digest,archive,print,") ;

// changed on first call to placeAd or when assertive is true
var adAncestor = new String() ;
var adNoda = new String() ;
var adSite = new String() ;
var adZone = new String() ;
var adSiteZone = new String() ;
var adDir = new String() ;
var adArgs = 0 ;

/* layer = 0 ==> no layer */
/* layer = [1-6] ==> use layer, layer should match tile */
/* w = width, h = height */
function placeAd(layer,node,kw,pos,dir,w,h,tile)
{


if (show_doubleclick_ad)
{
  
  // if ((tile == 1||layer == 1||kw == 1) || (layer ==0) || (node.substring(5,15) == "liveonline") || (node.substring(5,13) == "washtech"))
  if ( firstTimeCalled )
  {
    var axel = Math.random()+"";
    var ord = axel * 1000000000000000000;
    adUniqueNumber = ord+'?' ;
  }
  
  if (node.indexOf("/") == -1) node += "/" ;

  // only pass in abbreviated argument list: layer [0,1,2] and node (tile and pos are set based on layer)
  // usage: placeAd(layer,node); example: placeAd(1,'wpni.entertain/music');
  if ( arguments.length == 2 )
  {
	adArgs = 2 ;
    platform = 'STATIC' ;
    layer = arguments[0] ;
    if (layer == 0) { tile = 1 } else { tile = layer }
    node = arguments[1] ;
    pos = setPosition(tile); w = setWidth(tile); h = setHeight(tile); f = setFlexvalue(tile);
    kw = '';dir='';
	dir=getDir(node);
	node=mkNode(node);
  }
  
  // only pass in abbreviated argument list: layer, node, and tile (pos is set based on tile)
  // this is to be used when layer is 0, but you still need to set tile=1 and tile=2
  // usage: placeAd(layer,node,tile); example: placeAd(0,'wpni.entertain/music',1);
  else if ( arguments.length == 3 )
  {
  	jobsUrl = document.location.href;
	platform = 'STATIC' ;
    layer = arguments[0] ;
    node = arguments[1] ;
    tile = arguments [2] ;
    pos = setPosition(tile); w = setWidth(tile); h = setHeight(tile); f = setFlexvalue(tile);
	
    // sja 3/10/04
	// need to override kw on jobs page.
	// campaign ends 12/31/04
	/*topjob = (jobsUrl.indexOf("topjob") != -1)?true:false;
	if (jobsUrl.indexOf("jobs/JS_JobSearchResult") != -1) {
	if (!topjob) {
	jobsSearchString();
	kw = "searchresults;" +jString ;
	}
	}*/
	
	//else
	kw = '';

		
	dir=getDir(node);
	node=mkNode(node);
	
    layer = new String(layer) ;
    // sneaking in call to new place ad
    if (! layer.match(/[0-9]+/) )
    {
      placeAd(layer,node,tile,'',true) ;
	  return '' ;
    }
  }

  else if ( arguments.length == 4 )
  {
    placeAd(arguments[0],arguments[1],arguments[2],arguments[3],'') ;
    return '' ;
  }

/**
 * crk added 17 Jul 2002
 * methods for 5 parameter placeAd call
 * placeAd(platform,node,tile,kw,assertive)
 * @param platform: STATIC, FT, or JSP: not usef for anything yet
 * @param node: should have the form of a spud node, e.g. "metro/dc/schools"
 * @param tile: integer value from 1 to 14 (as of 17 Jul 2002)
 * @param kw: this text will just be thrown into the ad tag, unmanipulated, whatever it is
 * @param assertive: if assertive is true, adSite, adZone, and adDir are calculated anew, otherwise the previous values are used
 **/
  else if ( arguments.length == 5 )
  {
    jobsUrl = document.location.href;
	var na = [arguments[0],arguments[1],arguments[2],arguments[3],arguments[4]] ;
    adArgs = 5 ;
    platform = na[0] ;
    node = cleanNode(na[1]) ;
    tile = na[2] ;
	
	// sja 4/25/04
	// Add job search criteria to key values on job pages.
	/*topjob = (jobsUrl.indexOf("topjob") != -1)?true:false;
	if (jobsUrl.indexOf("jobs/JS_JobSearchResult") != -1) {
	if (!topjob) {
	jobsSearchString();
	kw = "searchresults;" +jString ;
	}
	}*/
	
	//else
	kw = na[3];

	assertive = na[4] ;
	pos = setPosition(tile); w = setWidth(tile); h = setHeight(tile); f = setFlexvalue(tile);
	
    if ( firstTimeCalledNew || assertive )
	{
	  adAncestor = getAdAncestor(node) ;
	  adSite = getAdSite(adAncestor) ;
	  adNoda = getAdNode(node,adAncestor) ;
	  adZone = getAdZone(adNoda) ;
	  adDir = getAdDir(node) ;
	  firstTimeCalledNew = false ;

    if (adZone)
	  adSiteZone = adSite + "/" + adZone ;
	else
	  adSiteZone = adSite ;

	}

	var alerts = false ;
	if (assertive)
    {
      if (alerts) alert("adAncestor: "+adAncestor) ;
      if (alerts) alert("adSite: "+adSite) ;
      if (alerts) alert("adNoda: "+adNoda) ;
      if (alerts) alert("adZone: "+adZone) ;
      if (alerts) alert("adDir: "+adDir) ;
    }

  }

  // for full parameter list, modernize the positions
  else if ( arguments.length == 8 )
  {
	adArgs = 8 ;
    platform = 'STATIC' ;
    // added logic specifically for liveonline templates
    // the new 468 tags are 8 arguments... so there's logic for !468
    if ( node.substring(5,15) == "liveonline" && w != 468)
    //if (node.substring(5,15) == "liveonline")
    {
      pos = "ad" + pos;
      tile = 11;
    }
    else
    {
      pos = setPosition(tile) ;
    }

  }

  //insert interstitial value in the top banner
  if ( firstTimeCalled )
  {
    inter_value="dcopt=ist;";  
    
    // TO DETERMINE IF USER CAME FROM GOOGLE:
    var docUrl = document.location.href;
    var key = docUrl.indexOf('?');
    
    if (key != -1) // make sure there are parameters
    {
      // get the parameter
      var temp = docUrl.substring(key + 1, docUrl.length);
      
      // if just "g" was passed in, set the interstitial to false
      if (temp.length == 1 && (temp == "g" || temp == "G") )
      {
        inter_value = "";
      } 
    }
    // END GOOGLE LOGIC
    
	// TO DETERMINE IF THE AD IS BEING CALLED FROM A POPUP //added by mw & pk- April 7, 2003
	if ( window.opener )
    {
	inter_value = "";
    }
	
  	if ( document.cookie.indexOf ("dcSessionLimit=") != -1 )
    {
	 inter_value = "";
    }
    else if ( document.cookie.indexOf ("dcCount=") != -1 )
    {
      var startAt = document.cookie.indexOf( "dcCount=" ) + 8;
      var endAt = document.cookie.indexOf( ";", startAt );
      if ( endAt == -1 ) endAt = document.cookie.length;
      dcCount = parseInt ( document.cookie.substring ( startAt, endAt ) );
      if ( dcCount >= 5 ) inter_value = "";
    }
    if ( location.href.indexOf ( ".washingtonpost.com" ) == -1 )
    {
      inter_value = "";
    }
  }
  else
    inter_value="";

  if ( adArgs != 5 )
  {
    kw = mkKeyword(kw,node) ;
    dir = mkDir(dir) ;
    var keyvalues = node+dir+static_wpatc+inter_value+"kw="+kw+";pos="+pos+";sz="+w+"x"+h+";"+f+point+"tile="+tile+";ord="+adUniqueNumber ;
  }
  else if ( adArgs == 5 )
  {
    var keyvalues = adSiteZone+";"+static_wpatc+inter_value+adDir+kw+"pos="+pos+";sz="+w+"x"+h+";"+f+point+"tile="+tile+";ord="+adUniqueNumber ;
  }
  
  var adCode = "" ;
  adCode += ('<script language="JavaScript1.1" src="http://ad.doubleclick.net/adj/'+keyvalues+'">');
  adCode += ('</script>');

  if ( (typeof ceTag != 'undefined') && (ceTag) ) adCode = '';
  
  if (debugAdCode) {  adCode += debugTextArea(adCode); }

    
	document.write(adCode);


  firstTimeCalled = false ;
  
} // end if (show_doubleclick_ad)

} // end placeAd



function setPosition(tile)
{
  var p = "ad"+tile ;
  // document.write(p) ;
  return p ;
}

function setWidth(tile)
{
  var wi ;
  if      ( tile >= 1 && tile <= 2 ) { wi = "468"; }
  else if ( tile >= 3 && tile <= 5 ) { wi = "120"; }
  else if ( tile >= 6 && tile <= 6 ) { wi = "105"; }
  else if ( tile >= 8 && tile <= 9 ) { wi = "300"; }
  else if ( tile >= 10 && tile <= 10 ) { wi = "125"; }
  else if ( tile >= 11 && tile <= 11 ) { wi = "120"; }
  else if ( tile >= 12 && tile <= 12 ) { wi = "130"; }
  else if ( tile >= 13 && tile <= 13 ) { wi = "728"; }
  else if ( tile >= 14 && tile <= 14 ) { wi = "120"; }
  else if ( tile >= 15 && tile <= 15 ) { wi = "446"; }
  else if ( tile >= 16 && tile <= 16 ) { wi = "300"; }
  else if ( tile >= 17 && tile <= 17 ) { wi = "720"; }
  else if ( tile >= 18 && tile <= 18 ) { wi = "120"; }
  else if ( tile >= 19 && tile <= 19 ) { wi = "760"; }
  else if ( tile >= 20 && tile <= 20 ) { wi = "120"; } // tower left
  else if ( tile >= 21 && tile <= 21 ) { wi = "160"; }
  else if ( tile >= 22 && tile <= 22 ) { wi = "110"; }
  else if ( tile >= 23 && tile <= 23 ) { wi = "234"; }
  else if ( tile >= 24 && tile <= 24 ) { wi = "336"; } // half page left
  else if ( tile >= 25 && tile <= 25 ) { wi = "728"; } // super banner bottom
  else if ( tile >= 26 && tile <= 26 ) { wi = "300"; } // big box left
  else if ( tile >= 27 && tile <= 27 ) { wi = "160"; } // tower left 160
  else if ( tile >= 28 && tile <= 28 ) { wi = "1"; } // 1x1 filler pos.
  else if ( tile >= 29 && tile <= 29 ) { wi = "120"; } // 120x60 VM.

  // document.write(wi) ;
  return wi ;
}

function setHeight(tile)
{
  var he ;
  if      ( tile >= 1 && tile <= 2 ) { he="60"; }
  else if ( tile >= 3 && tile <= 5 ) { he="90"; }
  else if ( tile >= 6 && tile <= 6 ) { he="60"; }
  else if ( tile >= 8 && tile <= 8 ) { he = "360"; }
  else if ( tile >= 9 && tile <= 9 ) { he = "250"; }
  else if ( tile >= 10 && tile <= 10 ) { he = "125"; }
  else if ( tile >= 11 && tile <= 11 ) { he = "600"; }
  else if ( tile >= 12 && tile <= 12 ) { he = "31"; }
  else if ( tile >= 13 && tile <= 13 ) { he = "90"; }
  else if ( tile >= 14 && tile <= 14 ) { he = "240"; }
  else if ( tile >= 15 && tile <= 15 ) { he = "33"; }
  else if ( tile >= 16 && tile <= 16 ) { he = "250"; }
  else if ( tile >= 17 && tile <= 17 ) { he = "60"; }
  else if ( tile >= 18 && tile <= 18 ) { he = "600"; }
  else if ( tile >= 19 && tile <= 19 ) { he = "90"; }
  else if ( tile >= 20 && tile <= 20 ) { he = "600"; } // tower left 120
  else if ( tile >= 21 && tile <= 21 ) { he = "600"; }
  else if ( tile >= 22 && tile <= 22 ) { he = "90"; }
  else if ( tile >= 23 && tile <= 23 ) { he = "60"; }
  else if ( tile >= 24 && tile <= 24 ) { he = "850"; } // half page left
  else if ( tile >= 25 && tile <= 25 ) { he = "90"; } // super banner bottom
  else if ( tile >= 26 && tile <= 26 ) { he = "250"; } // big box left
  else if ( tile >= 27 && tile <= 27 ) { he = "600"; } // tower left 160
  else if ( tile >= 28 && tile <= 28 ) { he = "1"; } // 1x1 filler position
  else if ( tile >= 29 && tile <= 29 ) { he = "60"; } // 120x60
  // document.write(he) ;
  return he ;
}

function setFlexvalue(tile) {
var fv
switch(tile) {
case 1:
case 2:
fv = "ad=bn;";
break;

case 9:
case 16:
case 26:
fv = "ad=bb;"
break;

case 11:
case 18:
case 20:
fv = "ad=ss120;";
break;

case 13:
case 25:
fv = "ad=lb;ad=bn;";
break;

case 21:
case 27:
fv = "ad=ss;";
break;

case 24:
fv = "ad=bb;ad=hp;";
break;

default:fv="";break;
}
return fv ;

}


function mkDir(myDir)
{
  var dirAry = myDir.split("/") ;
  var dirBreakUp = 0 ;
  if ( dirAry.length > dirBreakUp )
  {
    var myDir = "" ;
    for(var i=0;i<dirBreakUp;i++)
    {
      myDir += dirAry[i] ;
      if (i < dirBreakUp-1)
        myDir += "/" ;
    }
    myDir += ";" ;
    for(var i=0;i<dirAry.length;i++)
    {
      myDir += "dir="+dirAry[i]+";" ;
    }
  }
  else
  {
    myDir += ";" ;
  }
  return myDir ;
}

function mkKeyword(myKeyword,myNode)
{
  if (myKeyword == "" )
  {
    if (myNode.indexOf("/") != -1 )
    {
      nodeAry = myNode.split("/") ;
      myKeyword = nodeAry[1] ;
    }
  }
  return myKeyword ;
}

function getDir(node)
{
  var dirAry = node.split("/") ;
  var newDir = "" ;
  if (dirAry.length > 1)
  {
    for (i=1;i<dirAry.length;i++)
	{
	  newDir += dirAry[i] ;
	  if (i!=dirAry.length-1)
	    newDir += "/" ;
	}
  }
  return newDir ;
}

function mkNode(node)
{
  var dirAry = node.split("/") ;
  var newNode = node ;
  if (dirAry.length >3)
  {
    newNode = "" ;
    for (i=0;i<3;i++)
    {
      newNode += dirAry[i] ;
      if (i!=2)
        newNode += "/" ;
    }
  }
  return newNode ;
}


function debugTextArea(ac)
{
  var re = new RegExp("\"","g") ;
  ac = ac.replace(re,"\\\"") ;
  return '<form><textarea wrap=physical cols=\"+55+\" rows=\"+10+\">'+ac+'</textarea></form>';
}

function getWPATCookie()
{
  if (document.cookie.indexOf("WPATC") != -1)
  {
    var start = (document.cookie.indexOf("WPATC") + 6);
    var end = (document.cookie.indexOf(";",start)) == -1 ? document.cookie.length : document.cookie.indexOf(";",start);
    var cookie = document.cookie.substring(start,end) + ";";
    while (cookie.indexOf(":") != -1)
      cookie = cookie.substring(0,cookie.indexOf(":"))+";"+cookie.substring(cookie.indexOf(":")+1,cookie.length);
    if (cookie.lastIndexOf(";") != cookie.length - 1) cookie += ';';
    if (cookie.indexOf("=") == 0) cookie = cookie.substring(cookie.indexOf(";")+1,cookie.length);
  }
  else var cookie = "" ;
  return cookie ;
}

/**
 * crk added 17 July 2002
 * methods for 5 parameter placeAd call
 * placeAd(platform,node,tile,kw,assertive)
 **/

  // get ancestor from node
  function getAdAncestor(node)
  {
	var end = node.indexOf("/") ;
	if ( end == -1 )
	  return node ;
    else
	{
	  var adAncestor = node.substring(0,end) ;	
      return adAncestor ;
	}
  }

  // get adSite
  function getAdSite(ancestor)
  {
    if ( isNewsAncestor(ancestor) )
      return "wpni.news" ;
    else
      return "wpni."+ancestor ;
  }
  
  // get ad node
  function getAdNode(node,ancestor)
  {
    if ( isNewsAncestor(ancestor) )
	  return node ;
	else
	{
	  var start = node.indexOf("/")+1 ;
	  if (start)
        return node.substring(start) ;
	  else
	    return "" ;
	}
  }

  // get ad node
  function getAdZone(node)
  {
    var ary = new Array() ;
	if ( node.indexOf("/") != -1 )
	  ary = node.split("/") ;
	else
	  ary[0] = node ;

	if ( ary.length <= 2 )
	  return node ;
	else
	{
	  var zone = '' ;
	  for(var i=0; i<2; i++)
	  {
	    zone += ary[i] ;
		if (i==0) zone += "/" ;
	  }
	  return zone ;
	}
  }
  
  function getAdDir(node)
  {
    var page = "" ;
    var ary = new Array() ;
	if ( node.indexOf("/") != -1 )
	  ary = node.split("/") ;
	else
	  ary[0] = node ;

	var dir = '' ;
	for(var i=0; i<ary.length; i++)
	{
	  // parse out article string if present in ancestor
	  if ( i == 0 &&
	       ary[i].indexOf("article") != -1 &&
		   ary[i].indexOf("article") == ary[i].length - "article".length &&
		   ary[i] != "article" )
	  {
	    ary[i] = ary[i].substring(0,ary[i].indexOf("article")) ;
		page = "page=article;" ;
	  }
	  dir += "dir="+ary[i]+";" ;
	}
	return "dir="+ary[ary.length-1]+"node;"+dir+page ;
  }

  // check if adSite should be wpni.news
  function isNewsAncestor(ancestor)
  {
    if ( newsAncestorAsString != null &&
	     newsAncestorAsString != ""   &&
		 newsAncestorAsString.indexOf(","+ancestor+",") != -1
	   )
      return true  ;
    else
	  return false ;
  }
  
  function cleanNode(node)
  {
    if ( node.charAt(node.length-1) == "/" )
	  return node.substring(0,node.length-1) ;
	else
	  return node ;
  }

// end crk added 17 July 2002

