/* OAS MJX [ map old tags to new ] */

/* some pages need this function, as they do not contain standard .js include */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";

    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) { begin = dc.indexOf(prefix); if (begin != 0) return null; }
    else { begin += 2; }

    var end = document.cookie.indexOf(";", begin);
    if (end == -1) { end = dc.length; }

    return unescape(dc.substring(begin + prefix.length, end));
}

//var OAS_HOST = "http://ads.discovery.com/RealMedia/ads/";
var OAS_HOST = "http://oascentral.discovery.com/RealMedia/ads/";

var strDebug = "";

function getNewTag(old_tag)
{
	var oas_tag_list = new Array();
		oas_tag_list[0] = [ "oldtag", "newtag" ];
		
		oas_tag_list[1] = [ "compscreen", "x21" ];
		oas_tag_list[2] = [ "interstitial", "x24" ];
		oas_tag_list[3] = [ "nuiad", "x12" ];
		oas_tag_list[4] = [ "popupad", "x08" ];
		oas_tag_list[5] = [ "admedia", "TopLeft" ];
		oas_tag_list[6] = [ "admediab", "Top" ];
		oas_tag_list[7] = [ "hedthick", "Top3" ];
		oas_tag_list[8] = [ "promohome", "x02" ];
		oas_tag_list[9] = [ "hp150x255", "x19" ];
		oas_tag_list[10] = [ "edit120x60", "x20" ];
		oas_tag_list[11] = [ "roadblock", "x16" ];
		oas_tag_list[12] = [ "tower", "x29" ];
		oas_tag_list[13] = [ "tower120x600", "x10" ];
		oas_tag_list[14] = [ "tile300x250", "x25" ];
		oas_tag_list[15] = [ "evt", "x30" ];
		oas_tag_list[16] = [ "evtexp", "x31" ];
		oas_tag_list[17] = [ "videoad", "x26" ];
		oas_tag_list[18] = [ "videoadend", "x27" ];
		oas_tag_list[19] = [ "browsertag", "x28" ];

	var new_tag = "";

	//loop through the list of tags defined on this page
	var arrylen = oas_tag_list.length;
	var tagfound = false;
	for (i=0; i<arrylen; i++)
	{
		if (old_tag == oas_tag_list[i][0])
		{
			//we have a match = grab new tag
			new_tag = oas_tag_list[i][1];
			tagfound = true;
			break;
		}
	}
	if (!tagfound) new_tag = old_tag;

	return new_tag;

}

function deBug() { 
	if ( getCookie("oastags") ) { 
		document.getElementById("debugDIV").innerHTML = strDebug; 
		//document.write(strDebug); 
	}
}

function OAS_RICH(position)
{
	//for debugging -- once testing is complete, following should be removed
	var hasCookie = getCookie("oastags");
	var oldtag = position;

	var newtag = getNewTag(position);

	//delete following line when testing is complete
	//var oas_position = (hasCookie) ? newtag : oldtag;

	// uncomment following line when testing is complete and new tags are being served
	var oas_position = newtag;

	//var all_positions = "compscreen,hedthick,interstitial,admedia,edit120x60,roadblock,tower,tile300x250,nuiad";
	var plist = postionList.split(",");
	var tlist = new Array();
	for (var p=0; p<plist.length; p++)
	{
		tlist.push( getNewTag( plist[p] ) );
	}
	
	var tag_list = tlist.join(",");
	//var positions = (hasCookie) ? tag_list : postionList;
	var positions = tag_list;

	var strJS = "<scr" + "ipt type=\"text/javascript\" language=\"JavaScript1.1\" src=\"" + OAS_HOST + "adstream_jx.cgi/" + pathForOAS + "/1" + Math.random() + "@" + positions + "!" + oas_position + "\"><\/scr" + "ipt>";

	document.write(strJS);

	strDebug += "<br/><br/><b>tag:</b> " + oldtag + " --> " + newtag;
	strDebug += "<br/><b>path@position</b> -->" + pathForOAS + "@" + oas_position;
}

/* AD REFRESH [adrefresh] JS */

/* ------------------------------------------------------------------------ refresh [function] */
// upon triggering of below function ... the ad banner and tower will be reloaded
function interactiveReload () {
	if (window.adbanner) { window.adbanner.location.reload(); }
	if (window.adtower) { window.adtower.location.reload(); }
}


//dummy function -- currently in dev/testing phase, 
//but being called from various swfs in production, so function needs to at least exist
function oasAdCap() { }

/* END OAS */
