if (window['getWrapperAd']) getWrapperAd();

var dfpHost='http://ad.doubleclick.net/';
var dfpHostCountryCode='http://ad.doubleclick.net/';
var dfpNetworkId='N1600/';
var dfpJump='jump/';
var dfpAd='ad/';
var dfpAdj='adj/';
var dfpAdi='adi/';
var dfpAdf='adf/';
var dfpAdl='adl/';
var dfpAdx='adx/';
var dfpSitename='trb.zap2it/';
var dfpDefaultZone='stage/ntl/zc/listings;';
var dfpProgramZone='stage/ntl/zc/program;';
var dfpSearchZone='stage/ntl/zc/search;';
var dfpInCellZone='stage/ntl/zc/listings/incell;';
var dfpInterstitial='';
var dfpZone = dfpDefaultZone;
var dfpRandNum;
var moreDfpKeyValues='';
/* Affiliate handling */
var dfpAffINPath='afl-in/';
var dfpAffOUTPath='afl-out/';
var dfpAffDefaultPath='tv/listings;';
var dfpAffProgramPath='tv/programs;';
var dfpAffSearchPath='tv/search;';
var dfpAffEditorialPath='editorial;';
var dfpAffInCellZone='afl-out/zc/listings/incell;';
var dfpBuddyTVInCellZone='afl-out/buddytv/zc/listings/incell;';

/* Affiliates with non-standard DFP zones */
var arrayRF=new Array();
arrayRF['buddytv'] = 'buddytv/';
arrayRF['dish'] = 'dish/';
arrayRF['coxoneoff'] = 'coxoneoff/';
arrayRF['twop'] = 'twop/';

arrayRF['acceller'] = 'mso/';
arrayRF['acclinks'] = 'mso/';
arrayRF['aci'] = 'mso/';
arrayRF['amb'] = 'mso/';
// arrayRF['aru'] = 'mso/';
arrayRF['bristol'] = 'mso/';
arrayRF['ctcvid'] = 'mso/';
arrayRF['greenlight'] = 'mso/';
arrayRF['hitech'] = 'mso/';
arrayRF['indpho'] = 'mso/';
arrayRF['lafa466'] = 'mso/';
arrayRF['murphy'] = 'mso/';
arrayRF['newsdaytv'] = 'mso/';
arrayRF['spknob4ad'] = 'mso/';
arrayRF['srt'] = 'mso/';
arrayRF['surewest'] = 'mso/';
arrayRF['tmsmil'] = 'mso/';
arrayRF['tvmax'] = 'mso/';

arrayRF['amb'] = 'nm/';
arrayRF['coaxcab'] = 'nm/';
arrayRF['hightel'] = 'nm/';
arrayRF['mcn'] = 'nm/';
arrayRF['mdeaeu'] = 'nm/';
arrayRF['shentel'] = 'nm/';

function getRandNum(){ return Math.round(Math.random()*10000000000); } var dfpTileRandNum = getRandNum(); /*var dfpTileCount = 0;*/

var abcStationAccessed;
var abcStationList;

function getAd(dfpPos, dfpTile, dfpSize, dfpZoneReff, dfpAffType) {
	if ( abcStationList != null && abcStationAccessed == null ) {
		if (document.getElementById('zc-shell')) {
			var zcGrid = document.getElementById('zc-shell');
			abcStationAccessed = true;
			if ( zcGrid.getAttribute('class') == 'zc-grid' || zcGrid.getAttribute('className') == 'zc-grid' ) {
				tableList = zcGrid.getElementsByTagName('table');
				for ( var i = 0; i < tableList.length; i++ ) {
					if ( abcStationList.match(tableList[i].getElementsByTagName('td')[0].getAttribute('id')) ) {
						tableList[i].setAttribute('class', tableList[i].getAttribute('class') + ' zc-abcStation');
						tableList[i].setAttribute('className', tableList[i].getAttribute('className') + ' zc-abcStation');
					}
				}
			}
		}
	}

    /*alert('dfpAffType= '+dfpAffType+' !=zap2it');*/
    /* comment to disable 120x50 ad */
    /*
    if(dfpPos=='1' && arrayRF[dfp_aid]==null) {
        return;
    } else
    */
    if(dfpAffType!='' && dfpAffType=='noAds') {
        return;
    } else if(dfpAffType!='' && dfpAffType!='zap2it' && dfp_aid!='google') {


      if(dfpAffType=='in') {
      	dfpZone = dfpAffINPath;
      } else {
      	dfpZone = dfpAffOUTPath;
      }


      /* Separate Zones */
      if(window.dfp_aid) {
	if(arrayRF[dfp_aid]!=null) {
		dfpZone += arrayRF[dfp_aid];
	}
      }


      if(dfpZoneReff=='incell') {
        if(dfp_aid=='buddytv') {
          dfpZone = dfpBuddyTVInCellZone;
        } else {
          dfpZone = dfpAffInCellZone;
        }
      } else if(dfpZoneReff=='program') {
          dfpZone += dfpAffProgramPath;
      } else if(dfpZoneReff=='search') {
          dfpZone += dfpAffSearchPath;
      } else if(dfpZoneReff=='editorial') {
          dfpZone += dfpAffEditorialPath;
      } else {
          dfpZone += dfpAffDefaultPath;
      }


      //alert(dfpZone);
    } else {
      if(dfpZoneReff=='incell') {
          dfpZone = dfpInCellZone;
      } else if(dfpZoneReff=='program'){
          dfpZone = dfpProgramZone;
      } else if(dfpZoneReff=='search') {
          dfpZone = dfpSearchZone;
      } else {
          dfpZone = dfpDefaultZone;
      }
    }


    /* interstial ad */
    if(dfpPos!='T') {
        dfpInterstitial='';
    } else {
        dfpInterstitial='dcopt=ist;';
    }


    if(dfpPos!='0000'){
        dfpPos='pos=' + dfpPos + ';';
    } else {
        dfpPos='';
    }


    if(dfpTile!='0000'){
        //dfpRandNum = dfpTileRandNum;
        dfpTile= 'tile=' + dfpTile + ';';
    } else {
        dfpTile='';
    }


    if(dfpSize=='0000' || dfpSize==''){
        dfpSize = 'sz=728x90';
    } else {
        dfpSize = 'sz='+dfpSize+';';
    }


    if(dfpKeyValues==undefined || dfpKeyValues==null) {
        dfpKeyValues='';
    }


    if(moreDfpKeyValues==undefined || moreDfpKeyValues==null) {
        moreDfpKeyValues='';
    }


    dfpRandNum = getRandNum();
    //alert('getAd() == '+ dfpHost + dfpAdj + dfpSitename + dfpZone + dfpKeyValues + moreDfpKeyValues + dfpInterstitial + dfpSize + dfpPos + dfpTile + 'ord=' + dfpRandNum);
    buildAd(dfpPos, dfpTile, dfpSize);


}


function buildAd(dfpPos, dfpTile, dfpSize) {


    var dfpURL = dfpHost + dfpAdj + dfpSitename + dfpZone + dfpKeyValues + moreDfpKeyValues;
    //alert('ad ==============>  '+dfpURL + dfpInterstitial + dfpSize + dfpPos + dfpTile + 'ord=' + dfpRandNum);
    document.write('<script language="JavaScript" src="'+ dfpURL + dfpInterstitial + dfpSize + dfpPos + dfpTile + 'ord=' + dfpRandNum + '?" type="text/javascript"></scr' + 'ipt>');


}
