var xList = new Array(0, 728, 468, 160, 120, 120, 336, 300, 250, 120, 160, 203, 200, 150);
var yList = new Array(0,  90,  60, 600, 600, 240, 280, 250, 250,  60,  30, 249, 150,  45);
var AdCounter = 0;
adid = '';
random   = Math.floor(Math.random()*1000000000);

/*
// use for debugging in firefox using firebug
function printfire()
{
    if (document.createEvent)
    {
        printfire.args = arguments;
        var ev = document.createEvent("Events");
        ev.initEvent("printfire", false, true);
        dispatchEvent(ev);
    }
}
*/

function DISPLAY_AD(instance, sizeIndex, position)
{
	// Uncomment this line to debug line by line.
	// debugger;
	site     = AD_SITE;
	zone     = 'generalhealth';
	topic    = 'none';
	category = 'none';
	width    = 0;
	height   = 0;

	// Check that the user has passed in a valid size key.
	if (sizeIndex <= 13)
	{
		width  = xList[sizeIndex];
		height = yList[sizeIndex];
	}

	// Map the ad categories to zone, topic, and category here.
	if (this.AD_CATEGORIES && AD_CATEGORIES.length > 0)
	{
		zone = AD_CATEGORIES[0];
		
		if (AD_CATEGORIES.length > 1)
		{
			topic = AD_CATEGORIES[1];
		
			if (AD_CATEGORIES.length > 2)
			{
				category = AD_CATEGORIES[2];
			}
		}
	}
	
	// Make sure the horizontal value is only stored in the cateogory var.
	if (isHorizontal(topic))
	{
		temp = category;
		category = topic;
		topic = temp;
	}
	
	// Perform SCC operations.
	if (this.SCC_ZONE && SCC_ZONE.length > 0)
	{
		zone = SCC_ZONE;
	}
	
	// Build the ad tag here.
	adTag    = '';
	adTag = adTag + '<script language="javascript" src="http://ad.doubleclick.net/adj/';
	adTag = adTag + site + '/' + zone + ';';
	adTag = adTag + 't=' + topic + ';';
	adTag = adTag + 'h=' + category + ';';
	if (this.SCC_NAME && SCC_NAME.length > 0)
	{
		adTag = adTag + 's=' + SCC_NAME + ';';
	}
	
	// Check for position here.
	if (position && position > 0)
	{
		adTag = adTag + 'pos=' + position + ';';
	}
	
	// Check for exclusion here.
	if (this.EXCLUSION_CAT && EXCLUSION_CAT.length > 0)
	{
		adTag = adTag + '!category=' + EXCLUSION_CAT + ';';
	}
	
	// Check for search terms here.
	if (this.SEARCH_TERM && SEARCH_TERM.length > 0)
	{
		adTag = adTag + 'kw=' + encodeURI(SEARCH_TERM) + ';';
	}
	
	// Finish the ad tag.
	adTag = adTag + 'comp=' + adid + ';';
	adTag = adTag + 'tile=' + instance + ';';
	adTag = adTag + 'sz=' + width + 'x' + height + ';';
	adTag = adTag + 'ord=' + random + '?"></script>';

	// printfire(adTag);	
	// Write the ad tag to the page.
	document.write(adTag);
}

function isHorizontal(category)
{
	result =  
	     (category == 'caregiver'
		|| category == 'childrenshealth'
		|| category == 'infanthealth'
		|| category == 'menshealth'
		|| category == 'seniorhealth'
		|| category == 'teenhealth'
		|| category == 'womenshealth');
		
	return result;
}

function IncrementCounter()
{
    AdCounter ++;
    return AdCounter;
}




