// Tiffany Manager 0.5A

tiffArray = new Array('10050000','10052359','sports;wpid=metro_metro','tifftest','08170000','12312359','artsandliving','shermans')	

// wpid TEST!
var url = document.location.href;
url = url.toLowerCase()
var urlarray = url.split('/');
var tail = urlarray[urlarray.length -1];
if (tail.indexOf('nav=') != -1){
	tail = tail.substring(0,tail.indexOf('nav='));
}
var illegals = ['?test_ads','?debugadcode','wpidtest','?','=','/','\\',':',';',',','*','(',')','&','$','%','@','!','^','+',' ','[',']','{','}','.html','.htm','.',];
for (i=0;i<illegals.length;i++){
	sRE = new RegExp('(\\' + illegals[i] + ')', 'g');
	tail = tail.replace(sRE,"");
}
if (tail == 'index' || tail == ''){
	tail = urlarray[urlarray.length -2];
}
var nodedump = thisNode.split('/');
var wpidnode = '';
for (i=0;i < nodedump.length;i++){
	wpidnode += nodedump[i];
}
var wpid = 'wpid='+wpidnode+'_'+tail;
if (wpid.length > 55){
	wpid = wpid.substring(0,55);
}
if(typeof(wpidTestCheck) == 'undefined'){
	wpidTestCheck = 0;
}
if (url.indexOf('?wpidtest') != -1 && wpidTestCheck != 1){
	prompt('wpid',wpid);
	wpidTestCheck = 1;
}
//end wpid TEST!

function dateToString(date) {
		var yyyy = date.getYear();
		var mm = date.getMonth() + 1;
		var dd = date.getDate();
		var hour = date.getHours();
		var min = date.getMinutes();
		if (mm < 10) mm = "0"+mm;
		if (dd < 10) dd = "0"+dd;
		if (hour < 10) hour = "0"+hour;
		if (min < 10) min = "0"+min;
		return ''+mm+dd+hour+min;
		}
		function getDay(today) {return today.getDay()}
		var today = new Date();
		var now = dateToString(today);
		
		if(typeof(doLocal) == 'undefined'){
			doLocal = false;
		}
		
		var tiff_ran = Math.floor(Math.random() * 1000000);
		var tiff_placed = false;
		


thisTiffNode = ''	
if (typeof thisNode != 'undefined')	{tiffNode = thisNode};
if (typeof commercialNode == 'undefined')	{commercialTiffNode=tiffNode}
else
{commercialTiffNode = commercialNode};

//runs through each ad entry, which consists of four elements: start, end, location string, and keyword.
for (x=0;x<tiffArray.length;x+=4)
//if this ad is current we commit to examing the location string.
{	if (now > tiffArray[x+0] && now < tiffArray[x+1])
	//we create an array called tiffLocations, which all the nodes and/or wpids this bugger is running on.
	{	tiffLocations=tiffArray[x+2].split(';');
		//now we iterate through each of the nodes and wpids.
		for (y=0;y<tiffLocations.length && tiff_placed == false;y++)
		//keyWpid has three states: no, and then two positive ones: blank (if this is node driven) or wpid=...
		{	keyWpid='no';
			//is this location the same as our current WPID? then make keyWpid a wpid.
			if (tiffLocations[y] == wpid)
			{	keyWpid=wpid
			};
			//if it's a node, then make the keyWpid blank.
			if (tiffLocations[y] == tiffNode || tiffNode.indexOf(tiffLocations[y]) >= 0)
			{	keyWpid=''
			}
		
			//if keyWpid isn't NO, then we got a fever and the only prescription is MORE TIFFANYTILE.
			if (keyWpid != 'no')
			//one more thing--homepage isn't actually a site name.
			{	if (tiffNode == 'homepage')
				{	tiffNode = 'washingtonpost.com'
				};
				//NOW more tiffanytile!!!!
		
				document.write('<div style="width:348px;position:absolute;top:-3px;left:656px;padding:0px;margin:0px;"><div style="padding-bottom:15px;float:left;"><img src="http://www.washingtonpost.com/wp-srv/hp/img/advertical.gif" ></div><iframe src="http://ad.doubleclick.net/adi/wpni.'+commercialTiffNode.split("/")[0]+';ad=tif;kw='+tiffArray[x+3]+';'+keyWpid+';ord='+tiff_ran+'?" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" allowtransparency="true" width="320" height="60"></iframe></div>');
				tiff_placed = true;
			}
		}
	}
}