  //ffx_swap unaltered. Will add the html to the innerHTML of the defined div
  //http://fdimages.fairfax.com.au/crtvs/code/mywestnet/ffxutils.js
  //090206 - updated to add AREA= in var pageString = line 80
  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;
  }

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]));
	try{
	if(rootDomain != currDom)
	document.domain = rootDomain;
	}
	catch(e){}
}

var ad, x = 0;
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://"+currDom+"/ffxd/intermediatory.html?w="+wid+"&h="+hei+"&ad=http://direct.fairfax.com.au/jserver/acc_random="+ran+"/";
  if(ad.adtype == null || (ad.adtype.toLowerCase()!="panorama" && ad.adtype.toLowerCase()!="doubleisland"))
   call = "http://direct.fairfax.com.au/hserver/acc_random="+ran+"/";

   cat = "";
   if(typeof(ffxpageVars.cat) == "undefined" || ffxpageVars.cat.length<=0)
    cat = "OTHER";
    else{
    cat = ffxpageVars.cat;
   if(typeof(ffxpageVars.subcat) != "undefined" && ffxpageVars.subcat.length>0)
 	cat += "."+ffxpageVars.subcat;
 }

  var pageString = "SITE=ONL.CH.MYWESTNET.NEWS/AREA=NEWS.MYWESTNET."+fixStr(cat)+"/";
  var adString = "";
  for(i in ad){
  if(i!="height"&&i!="width"&&i.toLowerCase().indexOf("site")==-1)
    adString += fixStr(i).toUpperCase()+"="+fixStr(ad[i]).toUpperCase()+"/";
}
adString = adString.replace(/LOC=/gi,"POS=");
//  if(adString.indexOf("adspace")==-1)
  	adString += "AAMSZ="+wid+"X"+hei+"/";
  var adspace = wid+"x"+hei;

  for(i in ffxpageVars){
  if(i.toLowerCase().indexOf("site")==-1)
	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(wid!="468" && (ad.adtype == null || (ad.adtype.toLowerCase()!="panorama" && ad.adtype.toLowerCase()!="doubleisland")))
      targetString=unescape(targetString);

  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);
  ffx_swap(holderDivId, iFrame);
  x++;
}
