  //ffx_swap unaltered. Will add the html to the innerHTML of the defined div
  //http://fdimages.fairfax.com.au/crtvs/code/thevine/ffxutils.js
  // 091119 change 290x50 to use iframe height 0 - dfinnecy
  
  
  function fixStr(str){
  return str.toUpperCase().replace(/[/\-\&]/gi,"").replace(/[ +]/,"_");
}
  function ffx_swap(elName, html) {
      var d = document;
      if (!d.getElementById) {
          return;
      }
      var el = d.getElementById(elName);
      if (!el) {
          return;
      }
      var remove = false;
      if (typeof ffxAdExclusionList != "undefined") {
        var thisPage = window.location.pathname;
        for (var i=0; i<ffxAdExclusionList.length; i++) {
          var current = ffxAdExclusionList[i];
          if (current == 'remove_all_ads'){
            return;
          }
          else if (current == 'remove_article_ads'){
            if (thisPage.match(/\/news\/[a-zA-Z0-9-]+\/[a-zA-Z0-9-]+\/[0-9]{4}\/[0-9]{2}\/[0-9]{2}\/[0-9]+.html/) || thisPage.match(/\/articles\/.*?/)){
              remove = true;
            }
          }
          else if (current == 'remove_index_ads'){
            if  (thisPage.match(/\/index.html$/) || !thisPage.match(/.html$/)){
              remove = true;
            }
          }
          else if (current == thisPage) {
            return;
          }
        }
      }
      if (remove == true) {return;}
      el.innerHTML = html;
  }
  
  function getVal(zMSmyStr,zMStagline)
  {
  	zMSmyStr = zMSmyStr+"=";
  	var zMSind = zMStagline.indexOf(zMSmyStr)+zMSmyStr.length;
  	if(zMSind==(zMSmyStr.length-1)) //test for myStr not found
  		return "";
  	zMStagline += "&";
  	return zMStagline.substring(zMSind,zMStagline.indexOf("&",zMSind));
  }
  
  // Testmodule - takes query string values for ad testing
  function testMods(testTarg,testKey,testSize){
  	testSizeMatch = 0;
  	testSizeList = 0;
  	if(testSize){
  		testSize = testSize.split("_");
  		testSizeList=1;
  		}
  	for(i=0;i<testSize.length;i++){
  		if(testTarg.match("AAMSZ="+testSize[i])) testSizeMatch=1;
  		}
  	if(!testSizeList || testSizeMatch){
  		testTarg = testTarg.replace(/SITE=[A-Z\.]+\//gi, "SITE=ZZ.ADTEST/");
  		if(testTarg.indexOf("/KEYWORD=")!=-1) testTarg = testTarg.replace(/\/KEYWORD=[A-Z\.]*\//gi, "/KEYWORD="+testKey+"/");
  		else testTarg = testTarg.replace(/SITE=ZZ.ADTEST\//gi, "SITE=ZZ.ADTEST/KEYWORD="+testKey+"/");
  		}
  	return(testTarg);
  }


var currDom = document.domain, match, rootDomain;
if(match = currDom.match(/([a-z0-9\-\_]+)\.(com|org|net|info|id|asn|biz|name)/i)) {
  rootDomain = currDom.substr(currDom.indexOf(match[1]));
  document.domain = rootDomain;
}

pageid = Math.floor(Math.random()*100000000000000000);

function runAds(){
var ad, x = 0;



if(document.location.toString().indexOf("specialtest")==-1)
{
while(ad = ffxAds[x]) {

ran = Math.floor(Math.random()*100000000000000000);
if(typeof(ad.height) == "undefined")
	hei = "1";
else
   hei=ad.height;
if(typeof(ad.width) == "undefined")
	wid = "1";
else
   wid=ad.width;

  var call = "http://www.thevine.com.au/adredirect.html?ad=http://direct.fairfax.com.au/jserver/acc_random="+ran+"/pageid="+pageid+"/";
  if(ad.adtype == null || (ad.adtype!="panorama"&&ad.adtype!="doubleisland"))
   call = "http://direct.fairfax.com.au/hserver/acc_random="+ran+"/";

     cat = "";
   if(typeof(ad.cat) == "undefined" || ad.cat.length<=0)
    cat = "OTHER";
   else
    cat = ad.cat.toUpperCase();

  var pageString = "SITE=ONL.MH.THEVINE.YOUTH/";
  var adString = "";
  for(i in ad)
  if(i!="height"&&i!="width")
    adString += fixStr(i).toUpperCase()+"="+fixStr(ad[i]).toUpperCase()+"/";

//  if(adString.indexOf("ADSPACE")==-1)
if(ad.adspace=="networkad")
    adString += "AAMSZ=1X4/";
  else   
  if(adString.indexOf("adspace")==-1)
  {
    if(ad.adtype == "panorama" && ad.width == "940" && ad.height == "0")
  	    adString += "AAMSZ=940x20/";
  	else 
  	    adString += "AAMSZ="+wid+"x"+hei+"/";
  }



  var adspace = wid+"x"+hei;

 if(document.location.toString().toLowerCase().indexOf("widget")!=-1)
 {ffxpageVars.cat = "WIDGET";
 ffxpageVars.area = "YOUTH.THEVINE.WIDGET";
 }
  for(i in ffxpageVars){
  if(fixStr(i).toUpperCase()!="SITE")
	pageString+= fixStr(i).toUpperCase()+"="+fixStr(ffxpageVars[i]).toUpperCase()+"/";
	}
  if(adString.length>0)
  	adString = adString.substring(0,adString.length-1);
  var targetString = escape(pageString+adString);
 // if(ad.adtype == null || (ad.adtype!="panorama"&&ad.adtype!="doubleisland"))
      targetString=unescape(targetString);
//To allow the 290x50 to have 0 height iframe. - to be resized.
	  if(wid == 290 && hei == 50){
		  hei = 0;
	  }


var urlStr = window.location.search.toUpperCase();
targetString = targetString.toUpperCase(); //to fixe testSize not working
if(urlStr.indexOf("ADTEST=TRUE")!=-1 && urlStr.indexOf("ADTESTKEYWORD=")!=-1){
	testKeyword = getVal("ADTESTKEYWORD",urlStr);
	testSizes = getVal("ADTESTSIZE", urlStr);
	targetString = testMods(targetString,testKeyword,testSizes);
	}

  var iFrame = "<iframe id='ffxadiframe"+x+"' name='ffxadiframe"+x+"' allowtransparency='true' width="+wid+" height="+hei+" marginwidth=0 marginheight=0 hspace=0 VSPACE=0 frameborder=0 scrolling=no bordercolor='#000000' src='"+call+targetString+"'></iframe>";
  var holderDivId = "ffxad"+(x + 1);
  area = "";
  if(typeof(ffxpageVars.area) != "undefined")
    area = ffxpageVars.area;
  ffx_swap(holderDivId, iFrame);
  x++;
}
}
else
{

x=0;
while(ad = ffxAds[x]) {

try{
var code = eval('AAMB'+(x+1));
//put eyeblaster size fix here
}
catch(e){}

var divName = "ffxad"+(x + 1);
var invObj = 'INV' + divName;

//document.getElementById(divName).style.display = 'none';

if(navigator.userAgent.indexOf('MSIE') > -1) {
/*if(code.indexOf("serving-sys")>-1){ // if eyeblaster tags resize iframe
document.getElementById(divName).innerHTML +=
'<div id="TMP' + divName + '" style="display:none">' +
escape('<body style="margin:0"><div id="adDiv">'  + code + '</div>') +
'</div><iframe name="' + invObj + '" frameborder="0" height="'+ adsizes[1] +'" width="'+ adsizes[0] +'"></iframe>';
}else{*/
document.getElementById(divName).innerHTML +=
'<div id="TMP' + divName + '" style="display:none">' +
escape('<body><div id="adDiv">' + code + '</div>') +
'</div><iframe name="' + invObj + '" width="0" height="0" frameborder="0" ' +
'onload="javascript:try { document.getElementById(\'' + divName + '\').' +
'insertAdjacentElement(\'beforeEnd\', window.frames[\'' + invObj + '\'].' +
'document.getElementById(\'adDiv\')) } catch(aamErr) { }"></iframe>';
//}
window.frames[invObj].document.location = 'javascript:unescape(parent.document.getElementById(\'TMP' + divName + '\').innerHTML)';
} else {

document.writeln('<div id="' + invObj + '" style="display:none">' + code +  '<script type="text/javascript" defer="true">' +
'document.getElementById(\'' + divName + '\').innerHTML = ' +
'document.getElementById(\'' + invObj + '\').innerHTML;' +
'document.getElementById(\'' + invObj +
'\').innerHTML = \'\';</scr' + 'ipt></div>');
}


x++
}


}

}

if(document.location.toString().indexOf("specialtest")!=-1){

allAds = "http://direct.fairfax.com.au/bserver/AAMALL/acc_random="+pageid+"/pageid="+pageid+"/SITE=ONL.MH.THEVINE.YOUTH";

for(i in ffxpageVars){
  if(fixStr(i).toUpperCase()!="SITE")
	allAds+= "/"+fixStr(i).toUpperCase()+"="+fixStr(ffxpageVars[i]).toUpperCase();
}

x=0;
while(ad = ffxAds[x]) {

allAds+="/AAMB"+(x+1);

 for(i in ad)
  if(i!="height"&&i!="width")
    allAds += "/"+fixStr(i).toUpperCase()+"="+fixStr(ad[i]).toUpperCase();

if(typeof(ad.height) == "undefined")
	hei = "1";
else
   hei=ad.height;
if(typeof(ad.width) == "undefined")
	wid = "1";
else
   wid=ad.width;

if(ad.adspace=="networkad")
    allAds += "/AAMSZ=1X4";
  else
  	allAds += "/AAMSZ="+wid+"x"+hei;


x++

}

document.write('<SCR' + 'IPT SRC="' + allAds  +  '?"  type="text/JavaScript" onLoad="runAds();" defer="defer" language="JavaScript">');
document.write('</SCR' + 'IPT>');

document.write('<div id="adWriter"></div>');

}
if(document.location.toString().indexOf("specialtest")==-1){
var alreadyrunflag=0 //flag to indicate whether target function has already been run

if (document.addEventListener)
  document.addEventListener("DOMContentLoaded", function(){alreadyrunflag=1; runAds()}, false)
else if (document.all && !window.opera){
  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
  var contentloadtag=document.getElementById("contentloadtag")
  contentloadtag.onreadystatechange=function(){
    if (this.readyState=="complete"){
      alreadyrunflag=1
      runAds()
    }
  }
}

try{
var backupOnload = window.onload;
window.onload=function(){
if((typeof(backupOnload) != "undefined") &&(backupOnload != null)){backupOnload();}
setTimeout("if (!alreadyrunflag) runAds()", 0)
}
}catch(e){}
}