
adOpsLocalFlag = (typeof adOpsLocalFlag == 'undefined')?false:adOpsLocalFlag;

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;
}

var estNow = new Date();
var estNowInMillis = estNow.getTime();
var millisFromEST = (estNow.getTimezoneOffset() - 240) * 60000;
var estNow = new Date( estNowInMillis + millisFromEST )

var estNow = dateToString(estNow);


var doTiffany = false;
var tiffWidth = '300';
var tiffHeight = '45';
var tiffOnTheFly = '';
var ord=Math.floor(Math.random()*10000000000);
var tiffDelivery = 'adi';
var broadNode = new Array('politics','business','opinion');
var classifieds = new Array('weather','cars','cityguide','jobs','cars','shopping');
var jrsArray = new Array('jobs','rentals','shopping');


function tiffContCategories(_commercialNode,_targCat)
{
	if(_commercialNode.charAt(_commercialNode.length-1) != '/')
	{
		_commercialNode += '/';
	}
	tiffCatArray = [];
	//tiffCatArray['metro'] = ['metro'];
	//tiffCatArray['sports'] = ['sports'];
	tiffCatArray['health'] = ['health','education'];
	tiffCatArray['classifieds'] = ['jobs','cars','realestate','rentals'];
	tiffCatArray['entertainment'] = ['artsandliving/movies','artsandliving/television','artsandliving/entertainmentnews','artsandliving/dvdhomevideo'];
	tiffCatArray['artsandliving'] = ['artsandliving/adviceandrelationships','artsandliving/books','artsandliving/comics','artsandliving/crosswords','artsandliving/fashionandbeauty','artsandliving/foodanddining','artsandliving/homeandgarden','artsandliving/museums','artsandliving/music','artsandliving/pets','artsandliving/style','artsandliving/theater','artsandliving/horoscopes','travel'];
	tiffCatArray['execnews'] = ['opinion','nation','politics','world','print','business','liveonline','technology'];
	tiffCatArray['local'] = ['cityguide','weather','cars','shopping','shoppingNEW','shoppingOLD','jobs'];

	var tiffCatLength = tiffCatArray[_targCat.toLowerCase()].length;
	if(!tiffCatArray[_targCat])
	{
		return false;
	}
	for(var a=0;a<tiffCatLength;a++)
	{
		var re = RegExp('^'+tiffCatArray[_targCat][a]+'/','gi');
		if (_commercialNode.match(re))
		{
			return true;
		}
	}
	return false;
}

var doTiffCheck = false;

//commented out by TM 5:35 6/17/08--why is this here?
if(!doTiffany && typeof commercialNode != 'undefined' && commercialNode)
{
	doTiffCheck = true;
}

function cnm(a)
{
	var nodes = a.split(';');
	for (var b = 0; b < nodes.length; b++)
	{
		
if(commercialNode.match(nodes[b])) return true;
	}
	return false;
}


//4313-HS-185127576
if(doTiffCheck && commercialNode.match(/^realestate/gi))
{
	tiffWidth = "300";
	tiffHeight = "45";
	doTiffany = true;
	tiffDelivery = "adi";
}


//4294-MW-196774514
if(doTiffCheck && ( typeof contentCategories != 'undefined' && contentCategories(commercialNode,'style') || commercialNode == 'artsandliving/style' ) && estNowWithYear <= '200902282359' )
{
	tiffWidth = "300";
	tiffHeight = "45";
	doTiffany = true;
	tiffDelivery = "adi";
}


//8678-ST-210761510 
if(doTiffCheck && estNowWithYear >= '200901120000' && estNowWithYear <= '200901312359')
for(var j=0;j<jrsArray.length;j++)
{
	if(commercialNode.match(jrsArray[j]))
	{
		tiffWidth = "300";
		tiffHeight = "45";
		doTiffany = true;
		tiffDelivery = "adi";
	}
}


//8564-AR-210084744
if(doTiffCheck && commercialNode.match('metro') && (estNowWithYear >= '200901010000' && estNowWithYear <= '200901312359'))
{
	tiffWidth = "300";
	tiffHeight = "45";
	doTiffany = true;
	tiffDelivery = "adi";
}

//8650-ST-210711176
if(doTiffCheck && tiffContCategories(commercialNode,'entertainment') && estNowWithYear <= '200901112359')
{
	tiffWidth = "300";
	tiffHeight = "45";
	doTiffany = true;
	tiffDelivery = "adi";
}

//8755-ST-211065734
if(doTiffCheck && (tiffContCategories(commercialNode,'classifieds') || commercialNode.match('shopping')) && estNowWithYear <= '200902082359')
{
	tiffWidth = "300";
	tiffHeight = "45";
	doTiffany = true;
	tiffDelivery = "adi";
}

//8969-ST-211541456
if(doTiffCheck && (tiffContCategories(commercialNode,'classifieds') || commercialNode.match('shopping')) && estNowWithYear >= '200902090000' && estNowWithYear <= '200902282359')
{
	tiffWidth = "300";
	tiffHeight = "45";
	doTiffany = true;
	tiffDelivery = "adi";
}

//8795-ST
if(doTiffCheck && commercialNode.match('washingtonpost.com') &&  estNowWithYear <= '200902282359')
{
	tiffDelivery = 'hc';
	//rev 8726#4 ST--time offset 1 hour--dst iss in estNowWithYear
	tiffSrc = (estNowWithYear <= '200901191600')?'http://www.washingtonpost.com/wp-adv/advertisers/wwh/wwh_290x60_a.gif':'http://www.washingtonpost.com/wp-adv/advertisers/store/InaugStore_Tiffany02_rev5.jpg';
	tiffRef = (estNowWithYear <= '200901191600')?'http://ad.doubleclick.net/clk;210762028;26407044;u?http://www.washingtonpost.com/wp-srv/welcome_to_the_white_house/index.html':'http://ad.doubleclick.net/clk;211118065;30461737;v?http://www.cafepress.com/washingtonpost/6336611/';
	//end of rev
	tiffWidth = '290';
	tiffHeight = '60';
	doTiffany = true;
}

//8780-MB-210961134
if(doTiffCheck && commercialNode.match('washingtonpost.com') && (estNowWithYear >= '200901200000' && estNowWithYear <= '200901202359'))
{
	tiffWidth = "290";
	tiffHeight = "60";
	doTiffany = true;
	tiffDelivery = "adi";
}

//8869-MM
if(doTiffCheck && tiffContCategories(commercialNode,'local') && (estNowWithYear >= '200902100000' && estNowWithYear <= '200902162359'))
{
	tiffWidth = "300";
	tiffHeight = "45";
	doTiffany = true;
	tiffDelivery = "adi";
}

//8956-AR-210084748
if(doTiffCheck && commercialNode.match('metro') && (estNowWithYear >= '200902010000' && estNowWithYear <= '200902282359'))
{
	tiffWidth = "300";
	tiffHeight = "45";
	doTiffany = true;
	tiffDelivery = "adi";
}

if(location.href.match("test_ads"))
{
	tiffOnTheFly = "kw=test_ads;";
}

//end of logic for flights

if(doTiffany && !location.href.match('no_ads'))
{
	
	 tiffDiv = document.getElementById('adTiff')
	 tiffDiv.style.display = 'block';
	 tiffDiv.style.position = 'absolute';
	 tiffDiv.style.left = '';
	 tiffDiv.style.top = '';
	 tiffDiv.style.right = '0px';
	 tiffDiv.style.bottom = '0px';
	 tiffDiv.style.marginBottom = '2px';
	 tiffDiv.parentNode.style.position = 'relative';
	 
	 if(tiffDelivery == 'adi')
	 {
	  tiffIframe = document.createElement('iframe')
	  tiffIframe.src= 'http://ad.doubleclick.net/' + tiffDelivery + '/wpni.' + commercialNode + ';ad=tiff;sz=234x60,300x45,290x60;' + tiffOnTheFly + 'ord=' + ord + '?';
	  tiffIframe.width = tiffWidth;
	  tiffIframe.height = tiffHeight;
	  tiffIframe.frameBorder = 0;
	  tiffIframe.marginHeight = 0;
	  tiffIframe.marginWidth = 0;
	  tiffIframe.scrolling = "no";
	  if(!document.getElementById('tiffTD'))
	   {
		document.write('<div id="tiffTD"></div>')
	   }
	  document.getElementById('tiffTD').appendChild(tiffIframe);
	 }
	 else if(tiffDelivery == 'hc' && typeof tiffRef != 'undefined' && typeof tiffSrc != 'undefined')
	 {
		tiffAnchor = document.createElement('a');
		tiffImg = document.createElement('img');
		tiffAnchor.href = tiffRef;
		tiffAnchor.target = '_blank';
		tiffImg.src = tiffSrc;
		tiffImg.width = tiffWidth;
	  	tiffImg.height = tiffHeight;
		tiffImg.alt = '';
		tiffImg.border = '0';
		if(!document.getElementById('tiffTD'))
		{
			document.write('<div id="tiffTD"></div>')
		}
		tiffAnchor.appendChild(tiffImg);
		document.getElementById('tiffTD').appendChild(tiffAnchor);
	 }
	 else
	 {
	 	 placeAd('SECTION',commercialNode,14,'',true)
	 }
// We had to remove the placeAd and use an iframe so that the ad will function properly in channelNav.js
	
}
