slateUrl = document.location.href;
allowSurvey = true;

var debugAdCode = false ;
if (document.location.search.indexOf("debugAdCode")+1)
  debugAdCode = true ;
var show_doubleclick_ad = true ;


// constants
var KEEP_NODE = false ;
var CHANGE_NODE = true ;
 
// changed on first call to placeAd or when assertive is true
var adNoda = new String() ;
var adSite = new String() ;
var adZone = new String() ;
var adSiteZone = new String() ;
var adDir = new String() ;
var adArgs = 0 ;
var inter_value = '';



function placeAd(layer,node,kw,pos,dir,w,h,tile)
{

if (typeof msn_cobrand == "undefined" || msn_cobrand == 0)
	var msn_refer = 'n';
else
	var msn_refer = 'y';

if (typeof PStax == "undefined")
	var dept = 'unknown';
else
	var dept = PStax;	
	
if (show_doubleclick_ad)
{
  
	if(typeof ord == "undefined")
{
    var axel = Math.random()+"";
	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');
	var inter_value='';
	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);
	if (tile == 1)	
	{
		//inter_value='';
		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
		{
		  if (docUrl.indexOf("sg") != -1) {
			var inter_value = "";
			}
		  
		}
	// END GOOGLE LOGIC
}

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

    kw = mkKeyword(kw,node) ;
//    dir = mkDir(dir) ;


if (tile == 3) {
switch(slateUrl) {
case "http://www.slate.com/":
case "http://www.slate.com":
case "http://slate.msn.com/":
case "http://slate.msn.com/?debugAdCode":
case "http://www.slate.com/?debugAdCode":
node = 'slate.homepage/slate';
break;

default:null;break;
}
}

switch(slateUrl) {
case "http://www.slate.com/":
case "http://www.slate.com":
case "http://slate.msn.com/":
case "http://slate.msn.com/?debugAdCode":
case "http://www.slate.com/?debugAdCode":
slate_homepage = true;
break;
default:slate_homepage = false;break;
}

	if (msn_refer == 'y') inter_value += ';!category=nopops';

	var keyvalues = node+";"+inter_value+";msn_refer="+msn_refer+";dept="+dept+";kw="+kw+";pos="+pos+";sz="+w+"x"+h+";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); }

	if (tile == 4 && dept == 30830) document.write('');
	else document.write(adCode);



} // 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 ) { wi = "728"; }	// leaderboard
  else if ( tile == 2 ) { wi = "300"; } // showcase
  else if ( tile == 3 ) { wi = "120"; } // 120x240 tile
  else if ( tile == 4 ) { wi = "160"; } // 160x600 skyscraper
  else if ( tile == 5 ) { wi = "446"; } // feature bar

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

function setHeight(tile)
{
  var he ;
  if      ( tile == 1 ) { he="90"; }
  else if ( tile == 2 ) { he="250"; }
  else if ( tile == 3 ) { he="240"; }
  else if ( tile == 4 ) { he="600"; } //160x600 skyscraper
  else if ( tile == 5 ) { he="33"; } //feature bar

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



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


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>';
}