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

/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : set variables
- create an error string for testing
*/
var strErrors = "oasStringMJX.js:" ;


/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : function [ cookie ]
- some pages need this function, as they do not contain standard [cookies.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));
}


/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : set variables
- OAS_HOST
*/
/*** This will go away when migration is complete ***/
var OAS_HOST = "http://oascentral.discovery.com/RealMedia/ads/";


/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : special cases
- OAS_HOST / pathForAOS
*/
/* special instance for NationBodyChallenge */
if ( theLocalPath.indexOf("nationalbodychallenge2005") != -1 || location.host.indexOf("ediets") != -1 ) {
	OAS_HOST = "http://oascentral-bc.discovery.com/RealMedia/ads/";
}

if (location.host.indexOf("ediets") != -1 ) {
	pathForOAS = "bodychallenge.health.discovery.com/ediets"; 
}


/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : function [ convert tags ]
- some pages need this function, as they do not contain standard [cookies.js] include
*/
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" ];
		oas_tag_list[20] = [ "promotile", "Frame1" ];

	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); 
	}
}

/*** this variable needs to persist across all calls
 *** in order for frequency capping, companion placement, etc. to work
 *** some pages generate the oasRand using ESI, in order to sync video ads 
 *** this, we need to test for it first, before we create one locally
***/
try {
	var strDebug = "TryCatch: \n";
	if ( !oasRand || oasRand == undefined ) { 
		var oasRand = "1" + new String(Math.random()).substring(2, 11);
	}

} catch (e) { var errMsg = "Error: " + e; }

function OAS_RICH(position) {

	var plist = new Array();
	var oas_position = getNewTag(position);

	//no ads for DiscoveryHospital
	var dhosp = "discoveryhospital.com"; 
	var dref = document.referrer;
	if ( dref.indexOf(dhosp) != -1 || top.location.hostname.indexOf(dhosp) != -1 ) {
		var umcImage = false;
		var strSRC = dref
		if ( oas_position == "TopLeft" ) {
			umcImage = true;
			strSRC += "/includes/js_banner.asp";
		} else if ( oas_position == "x29" || oas_position == "x10" ) {
			umcImage = true;
			strSRC += "/includes/js_tower.asp";
		}

		if ( umcImage ) {

			var strJS = "<scr" + "ipt type=\"text/javascript\" language=\"JavaScript1.1\" src=\"" + strSRC + "\"><\/scr" + "ipt>";

			document.write( strJS );
		}
		return false;
	}

	try { if (postionList) { plist = postionList.split(","); } }
	catch (e) { strErrors += "<br/>" + e; }
	
	try { if (oasPositionArray) { plist = oasPositionArray.split(","); } }
	catch (e) { strErrors += "<br/>" + e; }
	
	var tlist = new Array();
	for (var p=0; p<plist.length; p++) {
		tlist.push( getNewTag( plist[p] ) );
	}
	
	var tag_list = tlist.join(",");
	var positions = tag_list;
	
	var strJS = "<scr" + "ipt type=\"text/javascript\" language=\"JavaScript1.1\" src=\"" + OAS_HOST + "adstream_jx.cgi/" + pathForOAS + "/" + oasRand + "@" + positions + "!" + oas_position + "\"><\/scr" + "ipt>";

	document.write(strJS);
}


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


/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : function [ refresh ]
- 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(); }
}

/* END OAS */

