  //ffx_swap unaltered. Will add the html to the innerHTML of the defined div
  //081118 - added if for 1x8 sponsored links - dfinnecy
  //081230 - AREA scrubbing for multiple sector search results - ln 90-94
  // 2009/09/14 AL Added AdTest Module - authored by dfinnecy
  
//***START  This is the Adtest Module that helps test ads via parameters passed via URLs***
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);
}
//***END This is the Adtest Module that helps test ads via parameters passed via URLs***

  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 ad, x = 0;
var BatchAds = [];
var BatchPage = "";

thedomain = document.domain+"";
rightdomain = false;

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){}
}



while(ad = ffxAds[x]) {

if(typeof(ad.height) == "undefined")
	hei = "1";
else
   hei=ad.height;
if(typeof(ad.width) == "undefined")
	wid = "1";
else
   wid=ad.width;
   if(hei=="0"&&wid=="0"){
   hei = "68";
   wid="638";
   }

testcheck = "";
if(document.location.toString().indexOf("ffxdtest")!=-1)
 testcheck = "test=true&";
  var call = "http://content.mycareer.com.au/ffxd/intermediatoryV2.html?"+testcheck+"ad=http://direct.fairfax.com.au/jserver/";
  if(wid!="638" && (ad.adtype == null || (ad.adtype!="panorama"&&ad.adtype!="doubleisland")))
    call = "http://direct.fairfax.com.au/hserver/";
  var pageString = "SITE=ONL.CL.MYCAREER.JOBS/";
  if(typeof(ffxpageVars.section)!="undefined" && ffxpageVars.section=="homepage")
  {
  if(wid=="468"&&hei=="60")
  pageString += "EXCLUSIVE=JOBS.MYCAREER.HOMEPAGE/";
  else
  pageString += "AREA=JOBS.MYCAREER.HOMEPAGE/";
  }else
  {
  add = "";
  if(typeof(ffxpageVars.sector)!="undefined"){
    pvSector = ffxpageVars.sector.split(",",10);
    pvRand = Math.floor((pvSector.length)*Math.random());
    add = "."+pvSector[pvRand].toUpperCase();
    }
    
  if(typeof(ffxpageVars.section)!="undefined")
    add += "."+ffxpageVars.section.toUpperCase();
  if(add.length==0)
    add = ".OTHER";
  pageString += "AREA=JOBS.MYCAREER"+add+"/";
  }
  var adString = "";
  if(ad.adtype=="panorama")
  	adString = "domain=mycareer.com.au/";
  for(i in ad)
  if(i!="height"&&i!="width")
    adString += i.toUpperCase()+"="+ad[i].toUpperCase()+"/";


if(ad.adspace=="networkad")
    adString += "AAMSZ=1X4/";
  else   if(adString.indexOf("adspace")==-1)
  	adString += "AAMSZ="+wid+"x"+hei+"/";


  var adspace = wid+"x"+hei;
  for(i in ffxpageVars){
  if(i!="site")
	pageString+= i.toUpperCase()+"="+ffxpageVars[i].toUpperCase()+"/";
	}
	pageString = pageString.replace(/SECTION=/g,"SECT=").replace(/LOCATION=/,"LOCAREA=");



  /*state targeting*/
  if(pageString.indexOf("LOCAREA=NSWCOUNTRY")!=-1||pageString.indexOf("LOCAREA=SYDNEYMETRO")!=-1)
    pageString += "LOCSTATE=NSW/";
  if(pageString.indexOf("LOCAREA=QLDCOUNTRY")!=-1||pageString.indexOf("LOCAREA=BRISBANEMETRO")!=-1)
    pageString += "LOCSTATE=QLD/";
  if(pageString.indexOf("LOCAREA=VICCOUNTRY")!=-1||pageString.indexOf("LOCAREA=MELBOURNEMETRO")!=-1)
    pageString += "LOCSTATE=VIC/";
  if(pageString.indexOf("LOCAREA=WACOUNTRY")!=-1||pageString.indexOf("LOCAREA=PERTHMETRO")!=-1)
    pageString += "LOCSTATE=WA/";
  if(pageString.indexOf("LOCAREA=SACOUNTRY")!=-1||pageString.indexOf("LOCAREA=ADELAIDEMETRO")!=-1)
    pageString += "LOCSTATE=SA/";
  if(pageString.indexOf("LOCAREA=TASCOUNTRY")!=-1||pageString.indexOf("LOCAREA=HOBARTMETRO")!=-1)
    pageString += "LOCSTATE=TAS/";
  if(pageString.indexOf("LOCAREA=NTCOUNTRY")!=-1||pageString.indexOf("LOCAREA=DARWINMETRO")!=-1)
    pageString += "LOCSTATE=NT/";
  if(pageString.indexOf("LOCAREA=ACTCOUNTRY")!=-1||pageString.indexOf("LOCAREA=CANBERRAMETRO")!=-1)
    pageString += "LOCSTATE=ACT/";

pageString = pageString.replace(/#|@|!|\||\$|\*/g,"");
adString = adString.replace(/#|@|!|\||\$|\*/g,"");
  if(adString.length>0)
  	adString = adString.substring(0,adString.length-1);
  var targetString = escape(pageString+adString+"/acc_random="+Math.floor(Math.random()*100000000000000000));
  if(wid!="638" && (ad.adtype == null || (ad.adtype!="panorama"&&ad.adtype!="doubleisland")))
      targetString=unescape(targetString);
   if(hei=="68")
    hei = "90";
    
  if (wid == "1" && hei == "8"){ //sponsored links
     wid="298";
     hei="200";
     }
     
	//***START  This is the Adtest Module that helps test ads via parameters passed via URLs***
	//test for adtest and modify target if neccessary
	targetString = unescape(targetString.toUpperCase());
	var urlStr = window.location.search.toUpperCase();
	if(urlStr.indexOf("ADTEST=TRUE")!=-1 && urlStr.indexOf("ADTESTKEYWORD=")!=-1){
		testKeyword = getVal("ADTESTKEYWORD",urlStr);
		testSizes = getVal("ADTESTSIZE", urlStr);
		targetString = escape(testMods(targetString,testKeyword,testSizes));
	}
	//***END  This is the Adtest Module that helps test ads via parameters passed via URLs***	
	 
  var iFrame = "<iframe id='ffxadiframe"+x+"' name='ffxadiframe"+x+"' style='width:"+wid+"px;' 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);
  if(typeof(ad.batch)!="undefined"&&ad.batch.toLowerCase()=="true"){
  	iFrame = "<div id='batch"+BatchAds.length+"'></div>";
  	BatchAds.push(adString);
  	BatchPage = pageString;
  }
  ffx_swap(holderDivId, iFrame);
  document.writeln("<!-- "+document.domain+" -->");
  x++;

}

function placeBatchAds()
{
	for(p=0;p<BatchAds.length;p++)
		eval("ffx_swap('batch"+p+"', AAMB"+(p+1)+");");
}

if(BatchAds.length!=0){
	batchScript = "<scr"+"ipt src='http://direct.fairfax.com.au/bserver/AAMALL/acc_random="+Math.floor(Math.random()*100000000000000000)+"/"+BatchPage+"/";
x=0
while(ad = BatchAds[x]) {
	batchScript += "AAMB"+(x+1)+"/"+ad+"/";
	x++
}
batchScript += "'>\n</scr"+"ipt>";
document.write(batchScript);

var alreadyrunflag=0 //flag to indicate whether target function has already been run

if (document.addEventListener)
  document.addEventListener("DOMContentLoaded", function(){alreadyrunflag=1; placeBatchAds()}, 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
      placeBatchAds()
    }
  }
}

try{
var backupOnload = window.onload;
window.onload=function(){
if((typeof(backupOnload) != "undefined") &&(backupOnload != null)){backupOnload();}
setTimeout("if (!alreadyrunflag) placeBatchAds()", 0)
}
}catch(e){}


}

