// Ad Display Globals
var zzzadslot = Math.random() * 10000000000000000;
var adurl = "http://ad.doubleclick.net/adj/nym.nymag";
var pageads=new Array();
var ns4webtv=(((!document.images && navigator.userAgent.indexOf('Mozilla/2.') >= 0)||navigator.userAgent.indexOf("WebTV")>= 0))?true:false;
var gAdSubSection='';
var adid='';

// Define pre-sold ad sub-sections here
// Format: [ pattern_to_match , section_name , subsection_name ],
// Using a // comments out a line.  Be sure to put a comma at the end of each line
// The last item should not have a comma at the end of the line
var adsection = [
['restaurants/index.htm','restaurant','index'],
['restaurants/$','restaurant','index'],
['restaurants$','restaurant','index'],
['nightlife/index.htm','nightlife','index'],
['nightlife/$','nightlife','index'],
['nightlife$','nightlife','index'],
['arts/index.html','arts','index'],
['arts/$','arts','index'],
['arts$','arts','index'],
['movies/index.html','movies','index'],
['movies/$','movies','index'],
['movies$','movies','index'],
['bestofny/shopping/index.htm', 'bestofny', ''],
['bestofny/shopping/index.html', 'bestofny', ''],
['bestofny/shopping/$', 'bestofny', ''],
['bestofny/shopping$', 'bestofny', ''],
['shopping/index.htm', 'shopping', 'index'],
['shopping/index.html', 'shopping', 'index'],
['shopping/$', 'shopping', 'index'],
['shopping$', 'shopping', 'index'],
['fashion/index.html', 'fashion', 'index'],
['fashion/$', 'fashion', 'index'],
['fashion$', 'fashion', 'index'],
['bestofny/index.html', 'bestofny', 'index'],
['bestofny/$', 'bestofny', 'index'],
['bestofny$', 'bestofny', 'index'],
['travel/index.html', 'travel', 'index'],
['travel/$', 'travel', 'index'],
['travel$', 'travel', 'index'],
['news/index.html', 'news', 'index'],
['news/$', 'news', 'index'],
['news$', 'news', 'index'],
['beauty/index.html', 'fashion', 'beautyspas'],
['beauty/$', 'fashion', 'beautyspas'],
['beauty$', 'fashion', 'beautyspas'],
['bestdoctors/index.htm', 'stress', 'bestdoctors'],
['bestdoctors/$', 'stress', 'bestdoctors'],
['bestdoctors$', 'stress', 'bestdoctors'],
['doctors/results.cfm', 'stress', 'bestdoctors'],
['bestlawyers/index.htm', 'bestlawyers', 'index'],
['bestlawyers/$', 'bestlawyers', 'index'],
['bestlawyers$', 'bestlawyers', 'index'],
['realestate/index.html','realestate','index'],
['realestate/$','realestate','index'],
['realestate$','realestate','index'],
['realestate','realestate',''],
['homedesign/index.html','homedesign','index'],
['homedesign/$','homedesign','index'],
['homedesign$','homedesign','index'], 
['fashion/fashionshows/index.html','fashionshows','index'],
['fashion/fashionshows/$','fashionshows','index'],
['fashion/fashionshows$','fashionshows','index'],
['fashion/fashionshows/designers','fashionshows','designers'],
['bestofny/shopping/2006/sportsfashion','bestofny','sportsfashion'],
['weather','weather','weather'],
['restaurants/recipes','restaurants','recipes'],
['shopping/columns/body','shopping','body'],
['shopping/columns/bestbets','shopping','bestbets'],
['nightlife/articles/partylist','nightlife','party'],
['urban/strategist/everything/11855','everything','pearls'],
['urban/strategist/everything/pearls','everything','pearls'],
['urban/strategist/everything/14926','everything','caribbean'],
['urban/strategist/everything/caribbean','everything','caribbean'],
['guides/summer','guides','summer'],
['guides/holidays','guides','holiday'],
['guides/cheap','guides','cheap'],
['sydney','travel','sydney'],
['travel/features/winter','travel','winter'],
['travel/guides/winter','travel','winter'],
['nymag/marketplace/travel/archive','travel','travelcolumns'],
['sex/columns/mating','nightlife','mating'],
['nymag/advertorial/fathersday','advertorial','fathersday'],
['bestdoctors','stress','bestdoctors'],
['stress','stress',''],
['fashion','fashion',''],
['fashion/05/fall/valleyofthedolls','shopping','valleyofthedolls'],
['guides/usopen','guides','usopen'],
['guides/weddings','weddings',''],
['urban/guides/family/','guides','family'],
['/shopping/guides/weddings/brides/features/2005/gowns','weddings','gowns'],
['fashion/blog','fashionshows','runwaytalkblog'],
['fashion/blog/2006/02/06/sunday-diary-roopal-patel','restaurants',''],
['shopping/lookbook','fashion','thelookbook'],
['fashion/lookbook','fashion','thelookbook'],
['shopping/fashion/columns/look','fashion','thelookbook'],
['shopping/bestbets','shopping','bestbets'],
['/menrunway/','fashionshows','men'],
['/menrunway/$','fashionshows','men'],
['/menrunway$','fashionshows','men'],
['/men/','fashionshows','men'],
['/men/$','fashionshows','men'],
['/men$','fashionshows','men'],
['/kids/','culture','kids'],
['/kids/$','culture','kids'],
['/kids$','culture','kids'],
['/kids/','bestofny','kids'],
['/kids/$','bestofny','kids'],
['/kids$','bestofny','kids'],
['/kids/','family','kids'],
['/kids/$','family','kids'],
['/kids$','family','kids'],
['nymag/','restaurants','index'],
['/stpatricksday/','guides','stpats'],
['/stpatricksday/$','guides','stpats'],
['/stpatricksday$','guides','stpats']
// ['fashion/index.html', 'fashion', 'splash']
// ['fashion/blog/2006/02/04/friday-diary-diane-von-furstenberg','restaurants',''],
// ['shopping/guides/weddings/bridalparty','weddings','bridalparty'],
// ['shopping/guides/weddings$', 'weddings', 'splash'],
// ['shopping/guides/weddings/$', 'weddings', 'splash'],
// ['shopping/guides/weddings/index.htm', 'weddings', 'splash'],
// ['fashion/fashionshows/men','fashionshows','index'],
// ['shopping/lookbook','shopping','bestbets'],
// ['fashion/lookbook','shopping','bestbets'],
// ['shopping/fashion/columns/look','shopping','look'],
];

var rotate_ads_flag = true;		// set to false to disable ads rotating
var refresh_timeout = 5;		// time for ad js to load, seconds

// configuration for site sections, ad formats and reload timeouts
var rotate_config = new Array;
rotate_config = {
	"arts": {
		formats: ["728x90", "336x280", "336x600", "336x800"],	// 336x280 = 300x250
		reload_interval: 60		// seconds
	},

//	"arts-left": {
//		formats: ["160x60_left"], reload_interval: 10
//	},

//	"arts-right": {
//		formats: ["160x60_right"], reload_interval: 10
//	}
	"travel": {
		formats: ["728x90", "336x280", "336x600", "336x800"],
		reload_interval: 60
	},

	"restaurants": {
		formats: ["728x90", "336x280", "336x600", "336x800"],
		reload_interval: 60
	},

	"shopping": {
		formats: ["728x90", "336x280", "336x600", "336x800"],
		reload_interval: 60
	},

	"news": {
		formats: ["728x90", "336x280", "336x600", "336x800"],
		reload_interval: 60
	}
};

// internal stuff, don't change
var rotate_timer_id;
var rotate_timer_interval = 1;  // seconds
var rotate_timer_counter = 0;
var old_write;
var old_writeln;
var reloading_ad_id = null;
var reloading_ad_code = "";
var rotate_ads = new Array;
var rotate_ads_index = 0;

addOnload(rotateOnload);

function addOnload(new_function) {
	var old_onload = window.onload; 

	if (typeof window.onload != "function") { 
		window.onload = new_function; 
	} else { 
		window.onload = function() {
			old_onload();
			new_function();
		}
	} 
}

function getHashLength(h) {
	var ctr = 0;
	for (i in h) ctr++;
	return ctr;
}

function logmsg(s) {
	var logger = document.getElementById("logger");
	if (logger) {
		logger.innerHTML = s + "<br>" + logger.innerHTML;
	}
}

function logmsgEscaped(msg) {
	logmsg(escapeHtml(msg));
}

function updateOrd() {
	zzzadslot = Math.random() * 10000000000000000;
}

function getRandomNum() {
	return Math.random() * 10000000000000000;
}

function myWrite(s) {
	reloading_ad_code += fixAdCode(s);
}

function rotateOnload() {
	//alert("onload");
	logmsg("onload");

	if (!rotate_ads_flag) {
		logmsg("ad reloading disabled");
		return;
	}

    if (rotate_timer_id) {
        logmsg("rotate timer has already been set");
        return;
    }

	document.write = myWrite;
	document.writeln = myWrite;

	rotate_timer_id = window.setInterval("rotateAds()", rotate_timer_interval * 1000);
}

function rotateStop() {
    window.clearInterval(rotate_timer_id);
}

function rotateAds() {
	rotate_timer_counter++;
    //logmsg("timer counter: " + rotate_timer_counter);

    if (reloading_ad_id != null) {
        logmsg("skipping reload: still working on " + reloading_ad_id);
        return;
    }

	for (ad_id in rotate_ads) {
		if ((rotate_timer_counter - rotate_ads[ad_id].display_time) >= rotate_ads[ad_id].reload_interval) {
			if (rotate_ads_index >= getHashLength(rotate_ads)) {
				rotate_ads_index = 0;
				updateOrd();
			}
			reloadAd(ad_id);
			window.setTimeout("refreshAd('"+ad_id+"')", refresh_timeout * 1000);
			rotate_ads_index++;
			break;
		}
	}
}

function reloadAd(ad_id) {
    reloading_ad_id = ad_id;
	var jssrc = rotate_ads[ad_id].js_uri + "ord=" + zzzadslot + ";random=" + getRandomNum();
	logmsg("loading "+ ad_id + ": " + jssrc);

	var jsdiv = document.getElementById("jsdiv");
	if (jsdiv) {
		jsdiv.parentNode.removeChild(jsdiv);
	}

	jsdiv = document.createElement("div");
	jsdiv.id = "jsdiv";
	jsdiv.style.display = "none";

	var adjs = document.createElement("script");
	adjs.src = jssrc;

	jsdiv.appendChild(adjs);
	document.body.appendChild(jsdiv);
}

function refreshAd(ad_id) {
	if (reloading_ad_code) {
		var target_id = getAdTargetId(ad_id);

		var adtarget = document.getElementById(target_id);
		if (adtarget) {
			adtarget.innerHTML = reloading_ad_code;
            var cid = Math.floor(Math.random() * 10000);
            var show_hide_code_js = "javascript: showHideAdCode(); function showHideAdCode() { var d=document.getElementById('" + cid + "'); d.style.display = (d.style.display == 'none') ? 'block' : 'none'; }";
			logmsg("<a href=\"" + show_hide_code_js + "\">show ad code</a><div id='" + 
				cid + "' style='display: none'>" + formatForHtml(escapeHtml(reloading_ad_code)) + "</div>");
			logmsg("refreshed " + ad_id + ": " + reloading_ad_code.length + " bytes)");
            logmsg("========================================================================");
		} else {
			logmsg("refreshAd(" + ad_id + "): missing target ad container");
		}
	} else {
		logmsg("refreshAd(" + ad_id + "): no ad code loaded");
	}

	rotate_ads[ad_id].display_time = rotate_timer_counter;
	reloading_ad_code = "";
	reloading_ad_id = null;
}

function getAdTargetId(ad_id) {
	//if (ad_id == "728x90") return "column col-1";
	//if (ad_id == "300x250") return "336x280";
	//if (ad_id == "300x600") return "336x600";

    return ad_id;
}

function fixAdCode(s) {
	return s.replace(/&amp;/gi, "&");
}

function escapeHtml(s) {
    return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

function formatForHtml(s) {
	return s.replace(/\n/g, "<br>");
}


var refreshSeconds = 540;

// Run the refresh after refreshSeconds
function refreshIframe () {
	window.setInterval("refresher()", refreshSeconds*1000);
} 

function norefreshIframe () {
	// Do nothing
}

// Refresh a location
function refresher () {
	location.reload(true);
}

// DART section targeting
function convertSect(SectionName,SubSectionName) {
	cvtSect = new Object;

	// Convert DART section identifiers to Falk IDs (baseline)
	if (SectionName == 'gHome')		cvtSect.SectionName='homepage'
	else if (SectionName == 'gNews')	cvtSect.SectionName='news'
	else if (SectionName == 'gArts')	cvtSect.SectionName='culture'
	else if (SectionName == 'gShops')	cvtSect.SectionName='shopping'
	else if (SectionName == 'gFFF') 	cvtSect.SectionName='fashion'
	else if (SectionName == 'gFFF') 	cvtSect.SectionName='fashionshows'
	else if (SectionName == 'gTravel') 	cvtSect.SectionName='travel'
	else if (SectionName == 'gTest')	cvtSect.SectionName='test'
	else if (SectionName == 'arts')	 	cvtSect.SectionName='culture'
	else if (SectionName == 'bony') 	cvtSect.SectionName='bestofny'
	else if (SectionName == 'doctors') 	cvtSect.SectionName='bestdoctors'
	else if (SectionName == 'lawyers') 	cvtSect.SectionName='lawyers'
	else if (SectionName == 'homepage') 	cvtSect.SectionName='homepage'
	else if (SectionName == 'news') 	cvtSect.SectionName='news'
	else if (SectionName == 'personals') 	cvtSect.SectionName='springstreet'
	else if (SectionName == 'realestate') 	cvtSect.SectionName='realestate'
	else if (SectionName == 'propdetail') 	cvtSect.SectionName='propdetail'
	else if (SectionName == 'restaurants') 	cvtSect.SectionName='restaurants'
	else if (SectionName == 'shopping') 	cvtSect.SectionName='shopping'
	else if (SectionName == 'travel') 	cvtSect.SectionName='travel'
		else if (SectionName == 'family') 	cvtSect.SectionName='family'
		else if (SectionName == 'beauty') 	cvtSect.SectionName='beauty'
	else if (SectionName == 'test')		cvtSect.SectionName='test'
	else if (SectionName == 'everything')		cvtSect.SectionName='everything'
	else 								cvtSect.SectionName='ros';

	// Regex the DART based on URL criteria
	// This overrides page-based rules, so use conservatively
	// Note: hierarchical ranking, highest depth items must go first!
	var currenturl = parent.location.href;

	if (currenturl.match("bestofny"))		cvtSect.SectionName='bestofny';
	else if (currenturl.match("bestdoctors"))	cvtSect.SectionName='bestdoctors';
	else if (currenturl.match("lawyers"))		cvtSect.SectionName='lawyers';
	else if (currenturl.match("urban")) 		cvtSect.SectionName='guides';
	else if (currenturl.match("guides"))		cvtSect.SectionName='guides';
	else if (currenturl.match("visitorsguide"))	{ cvtSect.SectionName='travel'; cvtSect.SubSectionName='visitorsguide'; }
	else if (currenturl.match("nymetro/arts"))	cvtSect.SectionName='culture';
	else if (currenturl.match("news"))		cvtSect.SectionName='news';
	else if (currenturl.match("fashion/fashionshows")) cvtSect.SectionName='fashionshows';
	else if (currenturl.match("fashion"))		cvtSect.SectionName='fashion';
	else if (currenturl.match("homedesign"))	cvtSect.SectionName='homedesign';
	else if (currenturl.match("movies"))		cvtSect.SectionName='movies';
	else if (currenturl.match("nightlife"))		cvtSect.SectionName='nightlife';
	else if (currenturl.match("restaurants"))	cvtSect.SectionName='restaurants';
	else if (currenturl.match("food"))			cvtSect.SectionName='restaurants';
	else if (currenturl.match("marketplace"))	cvtSect.SectionName='shopping';
	else if (currenturl.match("storeopenings"))	cvtSect.SectionName='shopping';
	else if (currenturl.match("weddings"))		cvtSect.SectionName='weddings';
	else if (currenturl.match("everything"))	cvtSect.SectionName='everything';
	else if (currenturl.match("travel"))		cvtSect.SectionName='travel';
	else if (currenturl.match("family"))		cvtSect.SectionName='family';
	else if (currenturl.match("beauty"))		cvtSect.SectionName='beauty';


	// Populate Falk sub-section based on destination URL
	// This overrides all previous rules defined
	var adflag = 0;
	for (var i=0; i < adsection.length; i++) {
		var pattern = adsection[i][0];
		if (!adflag && currenturl.match(pattern)) {
			cvtSect.SectionName=adsection[i][1];
			cvtSect.SubSectionName=adsection[i][2];	
			adflag = 1;
		}
	}

	if (!adflag) cvtSect.SubSectionName='';

	return cvtSect;
}

function cDARTAd(AdId, Ord,hRefName, SectionName, sSlot, sSlotLayer, iTile, iWidth, iHeight, sSubSect){
	this.base = __cDARTAd;
	this.base(Ord, hRefName, SectionName, sSlot, sSlotLayer, iTile, iWidth, iHeight, sSubSect);

	if (AdId) {
		if (AdId == "160x60") {
			AdId += (sSubSect == "left") ? "_left" : "_right";
		}

		var section = SectionName + (sSubSect ? "-" + sSubSect : "");
		if (!rotate_config[section]) {
			section = SectionName;
		}
		//alert("section: " + section + ", ad_id: " + AdId + ", SectionName: " + SectionName + ", sSubSect: " + sSubSect);

		if (rotate_config[section] && rotate_config[section]["formats"]) { 
			for (var i=0; i < rotate_config[section]["formats"].length; i++) {
				if (rotate_config[section]["formats"][i] == AdId) {
					rotate_ads[AdId] = {
						reload_interval: rotate_config[section].reload_interval,
						display_time: 0,
						js_uri: this.getJsUri()
					};
				}
			}
		}
    }
}

function __cDARTAd(Ord, hRefName, SectionName, sSlot, sSlotLayer, iTile, iWidth, iHeight, sSubSect){
	this.ord=Ord;
	this.hrefname=hRefName;
	this.sectionname=SectionName;
	this.slot=sSlot;
	this.layer=sSlotLayer;
	this.tile=iTile;
	this.w=iWidth;
	this.h=iHeight;
	this.sW=iWidth+"x"+iHeight;
	this.subsection=sSubSect;

	cvtSect=convertSect(this.sectionname,this.subsection);
	this.sectionname=cvtSect.SectionName;
	if (this.subsection.length == 0) {
		this.subsection=cvtSect.SubSectionName;
	} else if ((this.subsection == "left") || (this.subsection == "right")) {
		this.position=this.subsection;
		if (cvtSect.SubSectionName.length > 0) {
			// this.position=this.subsection;
			this.subsection=cvtSect.SubSectionName;
		}
	} else {
	 	this.subsection=sSubSect;
	}

	// DART specific tuning here
	var position = '';
	if (this.position == 'left') {
		position='pos=left;';
		if (this.subsection == 'left')
			this.subsection='';
	} else if (this.position == 'right') {
		position='pos=right;';
		if (this.subsection == 'right')
			this.subsection='';
	}

	var multimedia = '';
	if ((this.w == 160) && (this.h == 60) && (position == 'pos=left;')) 
		multimedia = 'dcopt=ist;';

	// DART Initiate
	if (this.subsection.length > 0)
		this.dartsubsect = this.subsection;

        if ((this.w == 300) && (this.h == 250)) {
		this.w = ''; this.h = '';
		this.dartres='300x250';
	} else if ((this.w > 0) && (this.w != 336))
		this.dartres=this.w+'x'+this.h;
	else if ((this.w == 336) && (this.h == 280)) {
		this.w = ''; this.h = '';
		this.dartres='300x250';
	} else if (this.w == 336) {
		this.w = '300'; this.h = '600';
		this.dartres='300x600';
	} 

	if (this.dartres == '3x3')
		this.sectionname = 'ros';


	// Show target placement (useful for testing)
	// document.writeln('<font color=\"#DD0000\" size=1>Ad tag: sect='+this.sectionname+((this.subsection.length>0)?';subs='+this.dartsubsect:'')+';comp='+adid+((position.length>0)?';'+position:'')+'</font><br>');


	// DART Build Tag
	this.dartjsuri = adurl + '/' + this.sectionname + ';sect=' + this.sectionname +
		((this.subsection.length > 0) ? ';subs=' + this.dartsubsect : '') + ';comp=' + adid +
		';tile=' + this.tile + ';' + multimedia + 'sz=' + this.dartres + ';' + position;

	this.dartjssrc='<script type="text/javascript" language="JavaScript" src="'+this.dartjsuri +
		'ord=' + this.ord + '?"><\/script>';

	this.core=this.dartjssrc;

        // document.writeln('<font color=\"#DD0000\" size=1>Ad url: '+adurl+'/'+this.sectionname+';sect='+this.sectionname+((this.subsection.length>0)?';subs='+this.dartsubsect:'')+';tile='+this.tile+';'+multimedia+'sz='+this.dartres+';'+position+'ord='+this.ord+'</font><p>');

	pageads[pageads.length]=this; // Ad to Collection for CloseAds

	this.write=function() { // write out Ad
		document.writeln(this.getAdCode());
	}

	this.getAdCodeBody = function() {
		return this.dartjsbody;
	}
	
	this.getAdCode = function() {
		return this.core;
	}

	this.getJsUri = function() {
		return this.dartjsuri;
	}

	this.close=function() { }

}

function DisplayAd(AdId, ord, hRefName, SectionName, sSlot, sSlotLayer, iTile, iWidth, iHeight, SubSection) {
	var oFalkAd=new cDARTAd(AdId, ord, hRefName, SectionName, sSlot, sSlotLayer, iTile, iWidth, iHeight, SubSection);
	oFalkAd.write();
}

function GetAdCode( AdId, ord, hRefName, SectionName, sSlot, sSlotLayer, iTile, iWidth, iHeight, SubSection ) {
	var oFalkAd=new cDARTAd(AdId, ord, hRefName, SectionName, sSlot, sSlotLayer, iTile, iWidth, iHeight, SubSection);
	return oFalkAd.getAdCode();
}

function GetAdCodeBody( AdId, ord, hRefName, SectionName, sSlot, sSlotLayer, iTile, iWidth, iHeight, SubSection ) {
	var oFalkAd=new cDARTAd(AdId, ord, hRefName, SectionName, sSlot, sSlotLayer, iTile, iWidth, iHeight, SubSection);
	return oFalkAd.getAdCodeBody();
}

function EndAds() {	if (pageads.length>0)pageads[0].close(); }

function InsertAd(AdId, SectionName, sSlot, sSlotLayer, iTile, iWidth, iHeight) {
	DisplayAd(AdId, zzzadslot, SectionName, SectionName, sSlot, sSlotLayer, iTile, iWidth, iHeight);
}

function InsertRichMedia() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:1;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd('', zzzadslot, sSect, sSect, '', '', iTile,'','', sSub);
}

function InsertBanner() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:1;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd("468x60", zzzadslot, sSect, sSect, '', '', 7, 468, 60, sSub);
}

function InsertBanner2() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:1;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd("728x90", zzzadslot, sSect, sSect, '', '', 2, 728, 90, sSub);
}

function InsertSquare() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:9;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd("180x150", zzzadslot, sSect, sSect, '', '', iTile, 180, 150, sSub);
}

function InsertSmallSquare1() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:5;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd("120x60", zzzadslot, sSect, sSect, '', '', iTile, 120, 60, sSub);
}

function InsertSmallSquare2() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:6;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	dISplayAd("120x60", zzzadslot, sSect, sSect, '', '', iTile, 120, 60, sSub);
}

function InsertSmallSquare3() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:3;
	// var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	var sSub = "right";
	DisplayAd("160x60_right", zzzadslot, sSect, sSect, '', '', 3, 160, 60, sSub);
}

function InsertSmallSquare3_2() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:2;
	// var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	var sSub = "left";
	DisplayAd("160x60_left", zzzadslot, sSect, sSect, '', '', 1, 160, 60, sSub);
}

function InsertSmallSquare3_3() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:4;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd("160x60", zzzadslot, sSect, sSect, '', '', 3, 160, 60, sSub);
}

function InsertSmallSquare4() {
        // var bNum=(arguments.length>0)?arguments[0]:1;
        var sSect=(arguments.length>1)?arguments[1]:gAdTag;
        var iTile=(arguments.length>2)?arguments[2]:3;
        var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
        var sSub = "left";
        DisplayAd("160x60_left", zzzadslot, sSect, sSect, '', '', 1, 160, 60, sSub);
}

function InsertMedSquare() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:1;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd("250x90", zzzadslot, sSect, sSect, '', '', 8, 250, 90, sSub);
}

function InsertBigSquare() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:1;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd("250x250", zzzadslot, sSect, sSect, '', '', iTile, 250, 250, sSub);
}

function InsertBigSquare2() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:5;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd("336x280", zzzadslot, sSect, sSect, '', '', 5, 300, 250, sSub);
}

function InsertTower() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:2;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd("120x600", zzzadslot, sSect, sSect, '', '', iTile, 120, 600, sSub);
}

// Start right tower units -------------------------------------------------
function InsertRightAd(ad_id) {
	if (show_ad_format_flags && show_ad_format_flags[ad_id]) {
		try {
			eval("InsertRight_" + ad_id + "()");
		} catch(er) {
		}
	}
}

function InsertRight_336x280() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:2;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
//	return GetAdCode(zzzadslot, sSect, sSect, '', '', iTile, 300, 250, sSub);
	// DisplayAd( zzzadslot, sSect, sSect, '', '', iTile, 336, 280, sSub );
	DisplayAd("336x280", zzzadslot, sSect, sSect, '', '', 5, 300, 250, sSub);
}
function InsertRight_336x600() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:2;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
//	return GetAdCode(zzzadslot, sSect, sSect, '', '', iTile, 336, 600, sSub);
	//// DisplayAd( zzzadslot, sSect, sSect, '', '', iTile, 300, 250, sSub );
	DisplayAd("336x600", zzzadslot, sSect, sSect, '', '', 9, 336, 600, sSub);
}
function InsertRight_336x800() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:2;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
//	return GetAdCode(zzzadslot, sSect, sSect, '', '', iTile, 336, 800, sSub);
	//// DisplayAd( zzzadslot, sSect, sSect, '', '', iTile, 300, 250, sSub );
	DisplayAd("336x800", zzzadslot, sSect, sSect, '', '', 9, 336, 800, sSub);
}
function InsertRight_160x600() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:2;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
//	return GetAdCode(zzzadslot, sSect, sSect, '', '', iTile, 160, 600, sSub);
	DisplayAd("160x600", zzzadslot, sSect, sSect, '', '', 4, 160, 600, sSub);
}
// End right tower units ---------------------------------------------------


function InsertGoogle() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:8;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd( '', zzzadslot, sSect, sSect, '', '', iTile, 3, 3, sSub );
}

function InsertTower2() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:6;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd( '', zzzadslot, sSect, sSect, '', '', 4, 160, 600, sSub );
}

function InsertButton() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:3;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd( '', zzzadslot, sSect, sSect, '', '', iTile, 125, 125, sSub);
}
function InsertPopup() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:5;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd( '', zzzadslot, sSect, sSect, '', '', iTile, 1, 1, sSub );
}

function InsertHalfB() {
	// var bNum=(arguments.length>0)?arguments[0]:1;
	var sSect=(arguments.length>1)?arguments[1]:gAdTag;
	var iTile=(arguments.length>2)?arguments[2]:2;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd( '', zzzadslot, sSect, sSect, '', '', iTile, 234, 60, sSub );
}

function InsertFashionAd() {
	// var bNum=(arguments.length>0)?arguments[0]:'';
	var sSect=(arguments.length>1)?arguments[1]:'fashion';
	var iTile=(arguments.length>2)?arguments[2]:5;
	var sSub=(arguments.length>3)?arguments[3]:gAdSubSection;
	DisplayAd( '', zzzadslot, sSect, sSect, '', '', iTile, 100, 60, sSub);
}

// Soon to be obsolete
function DisplayBanner( hRefName, SectionName ) {
	DisplayAd( '', zzzadslot, hRefName, SectionName, "slot1", "adslot1", 7, 468, 60, gAdSubSection );
}

function DisplayTower( hRefName, SectionName ) {
	DisplayAd( '', zzzadslot, hRefName, SectionName, "vmslot1", "vmslot1", 2, 120, 600, gAdSubSection );

}

function DisplayTower2( hRefName, SectionName ) {
	DisplayAd( '', zzzadslot, hRefName, SectionName, "vmslot1", "vmslot1", 2, 160, 600, gAdSubSection );

}


function DisplayButton( hRefName, SectionName ) {
	DisplayAd( '', zzzadslot, hRefName, SectionName, "sqslot1", "sqslot1", 3, 125, 125, gAdSubSection );
}

// CloseAds function is obsolete. Use EndAds.
var CloseAds=EndAds;

// Below is from DoubleClick to avoid disappearance of dropdowns when Polo Ad is served.

