//gets revsci info
if (document.domain != '') {
document.write('<s\cript src="http://js.revsci.net/gateway/gw.js?csid=J05531"></s\cript>');
}


wpniAds = new Object();
wpniAds.keyvalues = new Object();
wpniAds.adTypes = new Object();
wpniAds.utils = new Object();

wpniAds.templates = new Object();
wpniAds.templates.rules = new Object();
wpniAds.templates.initRule = function (ruleName)
{
	this.rules[ruleName] = new Object();
	this.rules[ruleName].where = new Array('');
	this.rules[ruleName].when = new Array('');
	this.rules[ruleName].what = new Array('');
}

function maxDim(_obj)
{
	var lcSize = _obj.size.toLowerCase();
	var dimArray = lcSize.split(',');
	var maxWidth = 0;
	var maxHeight = 0;
	for(var a = 0; a< dimArray.length; a++)
	{
		maxWidth = Math.max(dimArray[a].split('x')[0],maxWidth)
		maxHeight = Math.max(dimArray[a].split('x')[1],maxHeight)
	}
	return [maxWidth,maxHeight]
}


function getQSValue( name )
{
	  var locString=(arguments[1])?arguments[1]:window.location.href;
//first test to see if the qs variable at all. if not, return null.
  var regex = new RegExp( "[\\?&;]"+name );
  var results = regex.exec( locString );
  if(!results) return null;
//ok, it's there. get the value.

  var regex = new RegExp( "[\\?&;]"+name+"=([^&#]*)" );
  var results = regex.exec( locString );
  return (results==null)?"":results[1]
}

//generates random number (but not ord string) once for entire page
function randomInt(top)
{
	return Math.floor(Math.random()*top)
}

//generates ord string once for entire page
function ordMaker()
{	
	//if this.AJAX is passed as true as an argument overload then it just throws back a new ord value
	/*if(arguments[0])
	{
		return "ord=" + randomInt(1000000000000000000);
	}*/
	
	if (typeof this.ordReturnValue == 'undefined')
	{	
		this.ordReturnValue = "ord=" + randomInt(1000000000000000000);
    } 
	return this.ordReturnValue
}

//checks for dfpcomp variable. if it exists, return dfpcomp as a keyvalue.
function dfpCompFunc()
{
	if(typeof this.dfpReturnValue == 'undefined' || this.dfpReturnValue == '')
	{	
		if(typeof dfpcomp != 'undefined')
		{	
			this.dfpReturnValue = 'dfpcomp=' + dfpcomp + ";";
		}
		else
		{
			this.dfpReturnValue = '';
		}
	}
	return this.dfpReturnValue;
}

function pageId()
{
	var pageIdStringRoot = (typeof pageIdRoot != 'undefined')?pageIdRoot:wpniSite;
	if(typeof this.returnValue=='undefined')
	{
		
		this.pIdReturnValue = location.href.split('?')[0]
		if(this.pIdReturnValue.lastIndexOf('.') > this.pIdReturnValue.lastIndexOf('/'))
		{
			this.pIdReturnValue = this.pIdReturnValue.substring(0,this.pIdReturnValue.lastIndexOf('.'))
		}
				if(this.pIdReturnValue.lastIndexOf('index') > this.pIdReturnValue.lastIndexOf('/') || this.pIdReturnValue.lastIndexOf('default') > this.pIdReturnValue.lastIndexOf('/'))
		{
			this.pIdReturnValue = this.pIdReturnValue.substring(0,this.pIdReturnValue.lastIndexOf('/'))
		}
		//take off domain name and protocol declaration
		this.pIdReturnValue = this.pIdReturnValue.split(document.domain)[1]
		//trim slashes from start and end
		this.pIdReturnValue=trimAll(this.pIdReturnValue,'/')
		this.pIdReturnValue=this.pIdReturnValue.replace(/[\/\.]/gi,'-')
		
		if(this.pIdReturnValue=='')
		{
			this.pIdReturnValue = pageIdStringRoot
		}
	}
	return 'pageId=' + pageIdStringRoot + '-' + this.pIdReturnValue.replace(/[\#]/gi,'') + ';'
}
function trimAll(sString,toTrim) 
{
	if(typeof sString == 'undefined' || !sString) return '';
	
	while (sString.substring(0,1) == toTrim)
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == toTrim)
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

//if revsci array exists, creates revsci keyvalues
function revsci()
{	
	if (typeof rsinetsegs != 'undefined' && (typeof this.revsciReturnValue == 'undefined' || this.revsciReturnValue == '') )
	{
		this.revsciReturnValue='';
		for(i=0;i<rsinetsegs.length;i++)
		{
			this.revsciReturnValue += "rs="+rsinetsegs[i].replace("J05531_","j")+";"
		}
	}
	else if (typeof this.revsciReturnValue=='undefined')
	{
		this.revsciReturnValue='';
	}
	
	return this.revsciReturnValue
}

//creates debugAdCode box for each ad spot
function debugTextArea(ac,adAddress)
{ 
	if(!location.href.match('debugAdCode') && !location.href.match('allAds')) return;
  document.write('<div style="position:relative;float:left;z-index:1000000000">');
  document.write('<div style="text-align:left;text-transform:none;letter-spacing:normal;line-spacing:normal;padding:8px;position:absolute:top:0px;left:0px;width:300px;background-color:#FFAA00;color:#770000;font-family:verdana;font-size:9px;word-wrap:break-word;text-wrap:unrestricted;overflow:scroll">');
  document.write(ac+'<br/>');
  var re = new RegExp("/adj/","g")
  var adAddress = adAddress.replace(re,"/adi/")
  document.write('<a style="color:#111177;font-weight:bold;text-decoration:none" target="_blank" href="' + adAddress + '">Click Here To See The Ad Call In Its Own Window</a>')
  document.write('</div></div>')
  
}

//getCookie function
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

//returns size if it isn't a flex

function wpFlex(flexBoolean,size)	
{	
	this.flexAndSizeReturnValue = '';
	if (flexBoolean==true || flexBoolean==false)
	{
	this.flexAndSizeReturnValue = 'sz='+size+';'
	}
	return this.flexAndSizeReturnValue
}

//setcookie function
function setCookie (name, value, expires, path, domain, secure) {
	
	
      cookieString = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
		if(location.href.match('test_cookie'))
		{
			adOpsDebug('<b>domain passed to setCookie:</b> ' +domain + '<br/>');
		}
		document.cookie = cookieString;
}

//sets Point of Entry value--once for entire page
function poe()
{
	if(typeof this.poeReturnValue == 'undefined')
	{
		poeString = wpniSite + "_poe";
		this.poeReturnValue = 'poe=no;';
		if (getCookie(poeString) == null || getCookie(poeString) == "false")
		{
			this.poeReturnValue = 'poe=yes;';
			setCookie(poeString,"true","","/","",'')
		}
	}
	return this.poeReturnValue
}

//sets rss-user values--once for entire page
function rss()
{ 
 if(typeof rssString == 'undefined') return '';
 if (typeof this.rssReturnValue == 'undefined')
 {
  if (location.href.indexOf(rssString) != -1)
  {
   this.rssReturnValue="fromrss=y;";
   setCookie('rss_now','true','','/',wpniDomain,'');
   setCookie('rss','true',''+cookieExpStringMaker((28 * 24 * 60 * 60 * 1000),thisDate())+'','/',wpniDomain,'');
  }
  else
  {
   this.rssReturnValue="fromrss=n;";
   setCookie('rss_now','false',''+cookieExpStringMaker((28 * 24 * 60 * 60 * 1000),thisDate())+'','/',wpniDomain,'');
  }
  if (getCookie('rss') != null) 
  {
   this.rssReturnValue+='rss=y;'
  }
  else 
  {
   this.rssReturnValue += 'rss=n;'
  }
 }
 
 return this.rssReturnValue
}

//figures out if this user came from a link (not heavy) or opened a window with this (heavy)
function heavy()
{
	if (typeof this.heavyReturnValue == 'undefined')
	{
		this.heavyReturnValue = "heavy=n;"
		if (typeof document.referrer != "undefined")
		{
			if (document.referrer == '') this.heavyReturnValue = "heavy=y;"
		}
	}
	return this.heavyReturnValue
}

//writes a doubleclick tile keyvalue
function tile(tileBoolean,varDcCount,what,AJAX)
{
	this.tileReturnValue = varDcCount;
	if (tileBoolean == true)
	{
		if(AJAX)
		{
			if(typeof AJAXTileArray == 'undefined')
			{
				this.AJAXTileArray = new Array();
			}
			if(!this.AJAXTileArray[what + AJAX])
			{
				this.AJAXTileArray[what + AJAX] = varDcCount;
			}
			else
			{
				this.tileReturnValue = this.AJAXTileArray[what + AJAX]
			}
		}
		return "tile=" + this.tileReturnValue + ";"
	}
}

//returns a string that is the current date plus an amount of milliseconds, passed in the argument
function cookieExpStringMaker() {
 var today = new Date()
 var todayPlusDay = today.getTime() + arguments[0]
 today.setTime(todayPlusDay)
 return '' + today + ''
}
//returns true if the user...
function timeScope()
{
 numPop=(typeof numPop == 'undefined')?5:numPop;
 hourScope=(typeof hourScope == 'undefined')?24:hourScope;
 
 var finalNumOfPops = (numPop-1)*2;
 
 var returnValue24 = true;
 if(getCookie('popUpClockCookie'))
 {
  if (parseInt(getCookie('popUpClockCookie')) > finalNumOfPops )
  {
   var returnValue24 = false
  }
  else
  {
   setCookie('popUpClockCookie','' + (parseInt(getCookie('popUpClockCookie')) + 1) + '', cookieExpStringMaker((hourScope * 60 * 60 * 1000),thisDate()), '/', wpniDomain,'')
 
  }
 }
 else
 {
  setCookie('popUpClockCookie','1','' + cookieExpStringMaker((hourScope * 60 * 60 * 1000),thisDate()) + '','/', wpniDomain,'')
 }
 return returnValue24
}
//returns true if the user...
function didntSeePopUpOnPreviousPage()
{
 var returnValuePrev = true;
 if(getCookie('popUpOnPreviousPageCookie')!=null)
 {
   if(getCookie('popUpOnPreviousPageCookie') == 'true')
   {
         var returnValuePrev = false
         setCookie('popUpOnPreviousPageCookie','false','', '/', wpniDomain,'')
        }
      else
        {
         setCookie('popUpOnPreviousPageCookie','true','', '/', wpniDomain,'')
        }
 }
 else
 { 
      setCookie('popUpOnPreviousPageCookie','true','', '/',wpniDomain,'')
 }
 return returnValuePrev
}
//is passed one or more strings and then asks the question...
function isAnyOfTheseInTheUrl()
{
 var returnValue = false;
  for(var x=0;x<arguments.length;x++)
  {
   if(location.href.match(arguments[x]))
   {
    returnValue = true;
   }
  }
 return returnValue
}
//interstitial and popup manager
function interstitial()
{
 if(typeof tileThatGetsDcopt != 'undefined' && !tileThatGetsDcopt)
 {
	return '';
 }
 if(typeof tileThatGetsDcopt == 'undefined')
 {
	tileThatGetsDcopt = 1; 
 }
//interstitial is processed if the returnValue doesn't exist, if we're on the home domain, if no_interstitials isn't in the URL, and this is the right tile number
 if(typeof this.intReturnValue == 'undefined' && !isAnyOfTheseInTheUrl('no_interstitials') && arguments[1] == tileThatGetsDcopt)
 {
  //default is that dcopt=ist should be passed
  this.intReturnValue = "dcopt=ist;";
  //if this is a refresh page or from a google search page, or there are no cookies, skip pops
  if(!isAnyOfTheseInTheUrl('g=1','o=','sid=','reload=true') && document.domain.match(wpniDomain))
  { 
   var a = timeScope();
   var b = didntSeePopUpOnPreviousPage();
   adopsDebug("Interstitial Time Scope: " + a + "<br>" + "Didn't See Pops On Previous Page: " + b + "<br>")
   if(a && b)
   {
    this.intReturnValue += 'ad=pop;';
   }
  }
  return this.intReturnValue;
 } 
 return ''
}

function thisDate()
{
	if (typeof this.dateReturnValue == 'undefined')
	{
		this.dateReturnValue = new Date()
	}
	return this.dateReturnValue
}

function dateToString()
{
	if (typeof this.dtsReturnValue == 'undefined')
	{
		var thisDateObj = thisDate()
		var yyyy = thisDateObj.getYear();
		yyyy += (yyyy < 1900 )?1900:0;
		var mm = thisDateObj.getMonth() + 1;
		var dd = thisDateObj.getDate();
		var hour = thisDateObj.getHours();
		var min = thisDateObj.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;
		this.dtsReturnValue = ''+yyyy+mm+dd+hour+min;
	}
	return this.dtsReturnValue
}

function dayOfWeekCheck(now,dosString)
{
 //if day of week string is undefined, return true
 if(typeof dosString == 'undefined') return true;
 dosDate = thisDate()
 thisDos = dosDate.getDay()
 return (dosString.match(thisDos))?true:false
}

function dateCheck(when,now)
{
 
 this.dateCheckReturnValue=false;
 if (typeof when == "undefined" || when == '')
 {
  this.dateCheckReturnValue = true;
 }
 else
 {
  dateSets = when.split(';')
  for (x=0;x<dateSets.length;x++)
  {
   if (now >= dateSets[x].split('/')[0] && now <= dateSets[x].split('/')[1] && dayOfWeekCheck(now,dateSets[x].split('/')[2]))
   {
    this.dateCheckReturnValue=true
   }
  }
 }
 return this.dateCheckReturnValue 
}

function locationCheck(where,currentLoc)
{
 	//if empty string is passed for where, it's ROS, so true
 	if (typeof where == 'undefined' || where == '')
 	{
		return true
	}

	var nodes = where.split(';');
	
	//default value is true unless one or more checks is for an positive match--then default is false
	this.locCheckReturnValue = true;
 	for (var x=0;x<nodes.length;x++)
	{
		if(nodes[x].charAt(0)!='!')
		{
			this.locCheckReturnValue = false;
		}
	}

	for (var x=0;x<nodes.length;x++)
	{

		//checking for positive or negative match?
		var posTest = (nodes[x].charAt(0)=='!')?false:true;
		//strips negative flag from start of string, if there is one
		nodes[x] = (nodes[x].charAt(0)=='!')?nodes[x].split('!')[1]:nodes[x];
		//makes this into a Reg Exp
		var posRegExp = RegExp(nodes[x],'gi');
		//checks pageId and currentLoc for a match
		
		var thisLocCheck = (currentLoc.match(posRegExp) || pageId().match(posRegExp))
		
		//if we have a match...
		if(thisLocCheck)
		{
			
			//if we have a match, and it is positive, make it true but continue checking the rest
			if(posTest)
			{
				this.locCheckReturnValue = true;
			}
			//if we have a match, but it is negative, make the return value negative and consider it done
			else
			{
				this.locCheckReturnValue = false;
				break;
			}
		}
	}
	
 	return this.locCheckReturnValue
}
 

function getHighestValue()
{
	var longest = 0;
	var loop;
	for (loop=0;loop<arguments.length;loop++)
	{
		if (arguments[loop] > longest)
		{
			longest = arguments[loop];
		}
	}
return longest;
}


function posMaker(what,AJAXflag,posOverride)
{
	if(AJAXflag)
	{
		return 'pos='+what+'AJAX'+posOverride+';'
	}
	if(posOverride)
	{
		return 'pos='+what+'_'+posOverride+';'
	}
	if (typeof this.usedSpots == 'undefined')
	{
		this.usedSpots = new Array();
	}
	if (this.usedSpots[what] == null)
	{
		this.usedSpots[what] = 1;
		return 'pos='+what+';';
	}
	else
	{
		this.usedSpots[what]++;
		return 'pos='+what+"_"+this.usedSpots[what]+';';
	}
}



function siteZoneDir(currentLoc)
{
		var currentLocArray = currentLoc.split('/');
		this.szdReturnValue = wpniSite + "." + currentLoc + ";";
		for(var x=0;x<currentLocArray.length;x++)
		{
			this.szdReturnValue += 'dir=' + currentLocArray[x] + ";"
		}
	return this.szdReturnValue
}

function doubleClickTestCode(testFlagArray)
{
	if(typeof this.dctCodeValue == 'undefined')
	{
		this.dctCodeValue = '';
		var queryResult = getQSValue('test_ads');
	
		if(queryResult != null)
		{
			this.dctCodeValue = 'kw=test_' + ((queryResult!='')?queryResult:'ads') + ';';	
		}
	}
	return this.dctCodeValue
}

function AdInstance()
{	
	this.when = new Array()
	this.where = new Array()
	this.isTest = false;
	this.managerListLength = 0
	this.AJAX = false;
	this.debugAction = function (output) { return debugTextArea(output) }
	this.adSlugDisplayStyle = 'block';
	
	this.dateObject = new Date()
	this.now = dateToString(this.dateObject)
	
	this.tile = true
	this.flex = false
	
	this.interstitial = "dcopt=ist;"
	
	this.doubleClickFlag = true;
	this.doubleClickAdType = "adj";
	this.dcCode =  heavy() + pageId() + poe() + revsci() + dfpCompFunc() + rss(this.dateObject) + front();
	
	this.templateCheck = function(currentLoc,thisPos)
	{
		var templateTest = true;
		
		for(a in wpniAds.templates.rules)
		{
			
			var totalFlights = Math.max(wpniAds.templates.rules[a].where.length,wpniAds.templates.rules[a].when.length);
			
			for(var b = 0; b < totalFlights; b++)
			{	
				if(locationCheck(wpniAds.templates.rules[a].where[b],currentLoc) && dateCheck(wpniAds.templates.rules[a].when[b], dateToString()))
				{
					
					for(var c = 0; c < wpniAds.templates.rules[a].what.length; c++)
					{
						
						var posTestFlag = (wpniAds.templates.rules[a].what[c].charAt(0) != '!')?true:false;
						var testNoExclam = wpniAds.templates.rules[a].what[c];
						var testNoExclam = (testNoExclam.charAt(0) != '!')?testNoExclam:testNoExclam.substring(1,wpniAds.templates.rules[a].what[c].length);
						var testRE = RegExp(testNoExclam.toLowerCase(),'gi')
						if(thisPos.match(testRE) && testNoExclam != '')
						{				  
							templateTest = posTestFlag;
							adopsDebug('<b>Template Match [' + a + ']:</b> <i>' + posTestFlag + '</i> for <i>' + testRE + '</i><br>');
							
						}
					}
				}
			}
		}
		if(!templateTest)
		{
			adopsDebug('<i style="color:#910004;font-weight:bold">Failed template test</i><br>');
		}
		return templateTest;
	}
	
	this.testAction = function (testFlagArray)
	{	
		return doubleClickTestCode(testFlagArray)
	}
	
	this.code = '';
	
	
	//START OF 
	this.adExecute = function (currentLoc,what,flexBoolean,onTheFly,thisPos,AJAXflag)
	{
	
		adopsDebug('currentLoc='+currentLoc+'&nbsp;&nbsp; what='+what+'&nbsp;&nbsp; onTheFly='+onTheFly+'&nbsp;&nbsp; thisPos='+thisPos + '&nbsp;&nbsp;AJAXFlag=' + AJAXflag)
		
		var divId = thisPos.split('=')[1].split(';')[0];
		var targetDivId = 'wpni_adi_' + divId;
		var slugDivId = 'slug_' + divId;
		var thisPos = thisPos.toLowerCase();
		var deliveryType = (AJAXflag || this.adType == 'inline' || this.adType == 'iframe')?'iframe':'js';
		var dcMediaServer = (AJAXflag || this.adType == 'inline' || this.adType == 'iframe')?'adi':'adj';
		
		adopsDebug('&nbsp;&nbsp; AJAXflag='+AJAXflag+'&nbsp;&nbsp;thisPos='+thisPos+'&nbsp;&nbsp;slugId='+slugDivId+'&nbsp;&nbsp;targetDivId='+targetDivId + '&nbsp;&nbsp;deliveryType = ' + deliveryType + '&nbsp;&nbsp;dcMediaServer =' + dcMediaServer + '<br>')
	
		
	
		if(this.adType == 'inline')
   		{	
			var inlineAdGraf = getInlineAdGraf(this)
			if(!inlineAdGraf)
			{
				adopsDebug('<i style="color:#910004;font-weight:bold">It is an inline ad but we couldn\'t find a good space for the inline ad in the container DIV ' + this.parentId + '.</i><br/>' )
				return;
			}
			else
			{
				var inlineDiv = document.createElement('div');
				inlineDiv.style.width = maxDim(this)[0] + 'px';
				inlineDiv.style.height = maxDim(this)[1] + 'px';
				inlineDiv.style.margin = "8px 0px";
				inlineDiv.id = targetDivId;
				document.getElementById(this.parentId).insertBefore(inlineDiv, inlineAdGraf )
				
				if(this.slugURL)
				{
					inlineAdSlugDiv = document.createElement('div');
					inlineAdSlugDiv.id = slugDivId;
					inlineAdSlugDiv.style.marginTop = "8px";
					inlineAdSlugImg = document.createElement('img');
					inlineAdSlugImg.src = this.slugURL;
					inlineAdSlugDiv.appendChild(inlineAdSlugImg);
					document.getElementById(this.parentId).insertBefore(inlineAdSlugDiv,inlineDiv )
				}
		 	}
		}

		if(AJAXflag && !document.getElementById(targetDivId) )
		{
			adopsDebug('<i style="color:#910004;font-weight:bold">It is an AJAX call but we could not find the target DIV.</i><br/>' )
			return;
		}

		//if this is a doubleclick thing, iterate (or initialize) the tile number. 
		
		if(this.adSlugDisplayStyle)
		{
					
			if(document.getElementById(slugDivId))
			{
				document.getElementById(slugDivId).style.display = this.adSlugDisplayStyle;
			}
			else
			{
				adopsDebug('<i style="color:#910004;font-weight:bold">Could not find a DIV with the ID of ' + slugDivId + '</i><br/>' )
			}
		}
		else
		{
			adopsDebug('<i>This ad type has its slug type intentionally omitted.' )
		}
		
		if (this.doubleClickFlag == true)
		{ 
			if (typeof varDcCount == 'undefined')
			{
			 	varDcCount = 1
			}
			else
			{
				varDcCount++
			}
				
			var adAddress = "http://ad.doubleclick.net/" + dcMediaServer + "/" + siteZoneDir(currentLoc) + this.code + this.testAction(this.testFlagArray) + wpFlex(flexBoolean,this.size) + kvAjax(AJAXflag) + tile(this.tile,varDcCount,what,AJAXflag) + interstitial(this.interstitial,varDcCount) + this.dcCode + thisPos + onTheFly +  ordMaker(AJAXflag) +  "?"
		}
			
		if (deliveryType == 'iframe')
		{
			iframeObj = document.createElement('iframe');
			iframeObj.setAttribute('src',adAddress);
			iframeObj.style.width = maxDim(this)[0] + 'px';
			iframeObj.style.height = maxDim(this)[1] + 'px'
			iframeObj.setAttribute('marginWidth','0');
			iframeObj.setAttribute('marginHeight','0');
			iframeObj.setAttribute('frameBorder','0');
			iframeObj.setAttribute('scrolling','no');
			iframeObj.style.border = "none"
			
			
			adDivRef = document.getElementById(targetDivId)
					
			if(adDivRef.hasChildNodes())
			{
    			while ( adDivRef.childNodes.length >= 1 )
    			{
       				adDivRef.removeChild(adDivRef.firstChild );
    			} 
			}
			adDivRef.appendChild(iframeObj);
			
			adopsDebug('<b>'+targetDivId+' Appended Iframe Ad Call:</b> '+ textifyCode(adDivRef.innerHTML) + '<br/>')
		}
		else
		{
			var output="<s\cript language='JavaScript1.1' src='" + adAddress + "'></s\cript>";
			document.write(output);
			adopsDebug('<b>document-written call:</b> ' + textifyCode(output) + '<br>');
			debugTextArea(textifyCode(output),adAddress);
		}
	}
}



function placeAd2(currentLoc,what,flex,onTheFly)
{	
	
	
	if (location.href.match('no_ads'))
	{
		return
	}
	
	adopsDebug('<div style="margin-top:10px;font-size:14px;font-weight:bold">placeAd2("'+currentLoc+'","'+what+'",'+flex+',"'+onTheFly+'")</div>')
	if(typeof onTheFly == 'undefined')
	{
		onTheFly = ''
	}
	
	//pipe is delimiter for pos iterator override, //AJAX is delimiter for AJAX
	
	var currentLoc = hackBin('currentLoc',currentLoc,what,flex,onTheFly);
	var what = hackBin('what',currentLoc,what,flex,onTheFly);
	var flex = hackBin('flex',currentLoc,what,flex,onTheFly);
	var onTheFly= hackBin('onTheFly',currentLoc,what,flex,onTheFly);
	var AJAXflag = what.split('AJAX')[1]
	var posOverride = what.split('|')[1] || AJAXflag;
	var what = (AJAXflag)?what.split('AJAX')[0]:what.split('|')[0];
	var thisPos = posMaker(what,AJAXflag,posOverride);
	//if array adClasses doesn't exist, initializes it.
	if (typeof adClasses == "undefined")
	{
		var adClasses = new Array()
	}

	//if the specified ad type (what) doesn't exist in the array adClasses, define it with initAdType
	
	if (typeof adClasses[what] == "undefined")
	{
		adClasses[what] = initAdType(what)
	}
	
	
	
	//run this adtype's  method, which actually does what has to be done.
	
	if(adClasses[what].isTest && location.href.match('testAdSpots'))
	{
		adopsDebug('<b style="color:#009900">This is a test spot.</b></br>');
	}
	else if (adClasses[what].isTest)
	{
		adopsDebug('<b style="color:#990000">This is a test spot and there is no "testAdSpots" in the query string, so it did not get rendered.</b>');
	}
	
	var testCheck = !adClasses[what].isTest || location.href.match('testAdSpots');
	
	if( (adClasses[what].templateCheck( currentLoc,thisPos ) && testCheck) || location.href.match('allAds') )
	{	
		adClasses[what].adExecute(currentLoc,what,flex,onTheFly,thisPos,AJAXflag)
	}
}

function adopsDebugToggle()
{
	var toggleButton = document.getElementById('adopsDebugToggle');
	var adopsDebugDiv = document.getElementById('adopsDebugDiv');
	adopsDebugDiv.style.display = (toggleButton.innerHTML == 'Show Data')?'block':'none';
	toggleButton.innerHTML = (toggleButton.innerHTML == 'Show Data')?'Hide Data':'Show Data';
	
}

function adopsDebug(_str)
{
	if(!location.href.match('debugAdCode') && !location.href.match('adopsDebug') && !location.href.match('allAds')) return;
						   
	if(!document.getElementById('adopsDebugDiv'))
	{
		debugDiv = document.createElement('DIV');
		debugDiv.style.fontSize = '9px';
		debugDiv.style.textAlign = 'left';
		debugDiv.style.fontFamily = 'verdana,arial,helvetica';
		debugDiv.style.padding = "10px";
		debugDiv.style.marginBottom = "10px";
		debugDiv.style.borderBottom = "1px solid #a8a1a1";
		debugDiv.style.backgroundColor= "#e1e1e8";
		debugDiv.innerHTML = "<p style='margin:0px 0px 5px 0px;padding:0px;font-size:14px;color:#272127'>WPNI AdOps Debug Info&nbsp;<a href='javascript:adopsDebugToggle()' style='font-weight:bold;font-size:10px' id='adopsDebugToggle'>Show Data</a></p>"
		debugDivContent = document.createElement('DIV');
		debugDivContent.setAttribute('id','adopsDebugDiv');
		debugDivContent.style.display = "none";
		debugDiv.appendChild(debugDivContent);
		document.body.insertBefore(debugDiv, document.body.firstChild);
	}
	document.getElementById('adopsDebugDiv').innerHTML += _str;
}

function textifyCode(_code)
{
	_code = _code.replace(/</gi,'&lt;');
	_code = _code.replace(/>/gi,'&gt;');
	return _code;
}


function getInlineAdGraf(thisAdType) {

	var bottom_of_obstacle = 0;
	if(document.getElementById(thisAdType.obstacleId))
		{
			var obstacle = document.getElementById(thisAdType.obstacleId);
			var bottom_of_obstacle = obstacle.offsetTop+obstacle.offsetHeight;
		}
		
	var grafs = document.getElementById(thisAdType.parentId).getElementsByTagName(thisAdType.childElement);
		
	if(bottom_of_obstacle == 0 && grafs.length > 4)
	{
		var targetGrafNum = Math.min(Math.ceil(grafs.length/3),4);
			adopsDebug('<span style="font-style:bold;font-color:#009900">Found No Obstacle! Putting inline ad after Graf #' + targetGrafNum + '</span><br/>');
		return grafs[targetGrafNum]
	}
	else
	{
		for( var i=0; i<grafs.length; i++ )
		{
			if ( grafs[i].offsetTop > bottom_of_obstacle + thisAdType.obstacleMargin && i < grafs.length - 2)
			{
				adopsDebug('<span style="font-style:bold;font-color:#009900">Cleared an Obstacle! Putting inline ad after Graf #' + i + '</span><br/>');
				return grafs[i] ;
			}
		}
	}

	return false;
}


function kvAjax(AJAXflag)
{
	return 'ajax=' + (  ( AJAXflag  )?'y':'n' ) + ';';	
}

//this function varies from site to site, so this is just a shell
function front()
{
	return '';
}