/* OAS MJX */

var strErrors = "oasStringMJX.js:" ;

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 */
var OAS_HOST = "http://oascentral.discovery.com/RealMedia/ads/";


/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : special cases
- OAS_HOST / pathForAOS
*/
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 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; }

var oasPosList = "";
try { if (postionList) { oasPosList = postionList; } }
catch (e) { strErrors += "<br/>" + e; }

try { if (oasPositionArray) { oasPosList = oasPositionArray; } }
catch (e) { strErrors += "<br/>" + e; }


var strJS = "<scr" + "ipt type=\"text/javascript\" language=\"JavaScript1.1\" src=\"" + OAS_HOST + "adstream_mjx.ads/" + pathForOAS + "/" + oasRand + "@" + oasPosList + "\"><\/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 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 */
