var cnnad_tileID = cnnad_getID();
var cnnad_enabled = true;
var cnnad_adIframes = new Array();
// flag for geo targetting image
alreadySwappedDETargetImage = false;
var cnnDEadDEonCookie = false;
// document domain security issues
var cnnDocDomain = cnnad_getTld(location.hostname);
if(cnnDocDomain) {document.domain = cnnDocDomain;}
function reverseString (input)
{
// convert everything to a string
input = "" + input;
var output = '';
if (input.length)
{
var i;
for (i = input.length; i > 0; i--)
{
output += input.charAt(i-1);
}
}
return(output);
}
function cnnad_getID() {
return (reverseString(new Date().getTime()));
}
function cnnad_renderAd(cnnad_url) {
if(cnnad_enabled == true) {
document.write("<script type=\"text/javascript\"");
document.write(" src=\""+cnnad_url+"&tile="+cnnad_tileID+"\"></scr");
document.write("ipt>");
}
}
function cnnad_preview(cnnad_adstring) {
if ( location.host.indexOf("turner.com") > -1) {
// we are on preview (or on local subnet, so we have to use internal names)
cnnad_adstring = cnnad_adstring.replace(new RegExp("ads\..*?\.com","gi"),"ads.turner.com");
cnnad_adstring = cnnad_adstring.replace(new RegExp("ads\..*?\.tv","gi"),"ads.turner.com");
}
return cnnad_adstring;
}
function cnnad_createAdNoTileId(adId,cnnad_url,cnnad_height,cnnad_width) {
cnnad_url = cnnad_preview(cnnad_url);
document.write('<iframe ALLOWTRANSPARENCY="true" hspace="0" vspace="0" marginHeight="0" marginWidth="0" src="' + cnnad_url + '&page.allowcompete=yes&domId=' + adId + '" border="0" frameBorder="0" height="0" width="0" scrolling="no" id="'+adId+'" style="position: absolute; visibility: hidden;" ></iframe>');
}
function cnnad_createAd(adId,cnnad_url,cnnad_height,cnnad_width) {
cnnad_url = cnnad_preview(cnnad_url);
document.write('<iframe ALLOWTRANSPARENCY="true" hspace="0" vspace="0" marginHeight="0" marginWidth="0" src="' + cnnad_url + '&tile=' + cnnad_tileID + '&page.allowcompete=yes&domId=' + adId + '" border="0" frameBorder="0" height="0" width="0" scrolling="no" id="'+adId+'" style="position: absolute; visibility: hidden;" ></iframe>');
}
function cnnad_writeAd(cnnad_callid,cnnad_url) {
if(cnnad_enabled == true) {
document.write("<script id=\"" + cnnad_callid + "\" type=\"text/javascript\" onload=\"cnnSendData();\"");
document.write(" src=\""+cnnad_url+"&tile="+cnnad_tileID+"\"></scr");
document.write("ipt>");
}
}
function cnnad_showAd(cnnad_id) {
if (document.getElementById(cnnad_id))
{
document.getElementById(cnnad_id).style.position = 'relative';
document.getElementById(cnnad_id).style.visibility = 'visible';
} else
{
//alert("Error displaying ad component: " + cnnad_id);
// just do not display the ad. -sg
}
}
function cnnad_setAdSize(docId,height,width) {
if (document.getElementById(docId)) {
document.getElementById(docId).height = height;
document.getElementById(docId).width = width;
}
}
function cnnad_readCookie( name ) {
if ( document.cookie == '' ) { // there is no cookie, so go no further
return false;
} else { // there is a cookie
var firstChar, lastChar;
var theBigCookie = document.cookie;
firstChar = theBigCookie.indexOf(name); // find the start of 'name'
var NN2Hack = firstChar + name.length;
if ( (firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=') ) { // if you found the cookie
firstChar += name.length + 1; // skip 'name' and '='
lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
if (lastChar == -1) lastChar = theBigCookie.length;
return unescape( theBigCookie.substring(firstChar, lastChar) );
} else { // If there was no cookie of that name, return false.
return false;
}
}
}
function cnnad_getTld (hostname)
{
var data = hostname.split(".");
if (data.length >= 2)
{
return (data[data.length-2] + "." + data[data.length-1]);
}
return(null);
}
function cnnad_getDEAdHeadCookie( imageRef ) {
if (typeof(cnnad_readCookie) != "undefined") {
cnnDEadDEonCookie = cnnad_readCookie( 'adDEon' );
}
var newSrc = "http://gdyn." + cnnad_getTld(location.hostname) + "/1.1/1.gif?" + new Date().getTime();
if ( !alreadySwappedDETargetImage && !cnnDEadDEonCookie) {
imageRef.src = newSrc;
alreadySwappedDETargetImage = true;
}
}
