//Updated 20/03/08, PH, fix for news targeting

zMSislandCount = 1;

function writeIt(a){
    document.write(a);
}

function writeItln(a){
    document.writeln(a);
}

function zMSRand(){
    return Math.round(Math.abs(Math.sin((new Date()).getTime())) * 1000000000) % 10000000;
}

var zMSdomain = "http://media.sensis.com.au";
var zMSsecureDomain = "https://media.sensis.com.au";
var zMSlocation = document.location + "";
if (zMSlocation.indexOf("https://") != -1) 
    var zMSHome = zMSsecureDomain;
else 
    var zMSHome = zMSdomain;
var zMSpagenum = zMSRand();

var zMSACCsite = "TEL.TELSTRA.SEARCH_DIRECTORIES";
var zMSACCarea = "SEARCH_DIRECTORIES.TELSTRA.OTHER";
var zMSposition = "1";
// p9 declaration to switch on/off all P9 activation code.

var zMSp9switch = true; // default on
function zMSsecureMe(){
}

function zMSgetValue(zMSmyStr, zMStagline){
    zMSmyStr = zMSmyStr + "=";
    var zMSind = zMStagline.indexOf(zMSmyStr) + zMSmyStr.length;
    if (zMSind == (zMSmyStr.length - 1)) //test for myStr not found
        return "";
    zMStagline += "&";
    var output = zMStagline.substring(zMSind, zMStagline.indexOf("&", zMSind));
	
	if(output == "island"){
		output = zMSislandCount;
		zMSislandCount++;
	}
	if(output == "head") {
		output = 1;
	}
	return output;
}

function zMSconvertSize(zMSsize){
    if (zMSsize == "hariable") 
        return "728x90";
    if (zMSsize == "variable") 
        return "120x240";
    if (/\d+x\d+/.test(zMSsize)) 
        return zMSsize;
    return "ERROR";
}

function zMSgetJS(zMSmyStr){
	if(zMSaffiliate == "ausgamers" && zMSsection == "home"){
		zMSp9switch = false;
	}
	zMSposMod = "";
    //BigPond Promotions code
    zmsSiteTemp = "";
    if (zMSmyStr.indexOf("position=bppromo") != -1) {
        zmsSiteTemp = zMSACCsite;
        zMSACCsite = zMSACCsite.replace(/V8/i, "BPPROMO.V8");
        zms_temp_pos = zMSmyStr.indexOf("position=bppromo");
        zMSposMod = "/POSITION=" + zMSmyStr.charAt(zms_temp_pos + 16);
    }
	if (zMSmyStr.indexOf("position=island") != -1) {
        zMSposMod = "/POSITION=" + zMSislandCount;
		zMSislandCount++;
    }
	//Telstra Promotions code
    if(zMSmyStr.indexOf("position=telstrapromo") != -1) {
        zmsSiteTemp = zMSACCsite;
        zMSACCsite = zMSACCsite.replace(/TELSTRA/i, "TELSTRAPROMOTIONS");
        zms_temp_pos = zMSmyStr.indexOf("position=telstrapromo");
        zMSposMod = "/POSITION=" + zMSmyStr.charAt(zms_temp_pos + 21);
    }
	
	
    if (zMSaffiliate == "v8" && zMSACCarea == "SPORT.V8.HOMEPAGE" && zMSposition == "1") {
        document.write("<scr" + "ipt src=\"" + zMSHome + "/jserver/acc_random=" + zMSRand() + "/SITE=" + zMSACCsite + "/AREA=" + zMSACCarea + "/AAMSZ=" + zMSconvertSize(zMSgetValue("adsize", zMSmyStr)) + zMSposMod +"/pageid=" + zMSpagenum + "\">\n");
        document.write("</scr" + "ipt>");
        zMSposition = "2";
    }
    
    else 
        if (zMSaffiliate == "v8" && zMSACCarea == "SPORT.V8.HOMEPAGE" && zMSposition == "2") {
            document.write("<scr" + "ipt src=\"" + zMSHome + "/jserver/acc_random=" + zMSRand() + "/SITE=" + zMSACCsite + "/AREA=" + zMSACCarea + "/AAMSZ=" + zMSconvertSize(zMSgetValue("adsize", zMSmyStr)) + "/POSITION="+ zMSgetValue("position",zMSmyStr) +"/pageid=" + zMSpagenum + "\">\n");
            document.write("</scr" + "ipt>");
        }
        else {
            if (zMSmyStr.indexOf("104946_Ausgamers_adverotial_64940") != -1) 
                zMSmyStr = "adsize=2x1";
            var zMSpagenuma = zMSpagenum;
            if (zMSmyStr.indexOf("2x") != -1) 
                zMSpagenuma = zMSRand();
            if (zMSmyStr.indexOf("104831_aus_hp_adv_13840") != -1) 
                document.write("<scr" + "ipt src=\"" + zMSHome + "/jserver/acc_random=" + zMSRand() + "/SITE=" + zMSACCsite + "/AREA=" + zMSACCarea + zMSposMod + "/AAMSZ=2x4/KEYWORD=104831_aus_hp_adv_13840/pageid=" + zMSpagenum + "\">\n");
            else 
                document.write("<scr" + "ipt src=\"" + zMSHome + "/jserver/acc_random=" + zMSRand() + "/SITE=" + zMSACCsite + "/AREA=" + zMSACCarea + "/AAMSZ=" + zMSconvertSize(zMSgetValue("adsize", zMSmyStr)) + "/pageid=" + zMSpagenum + "\">\n");
            document.write("</scr" + "ipt>");
        }
    if (zmsSiteTemp != "") {
        zMSACCsite = zmsSiteTemp;
    }
}

function zMSgetIframe(zMSmyStr){
    if (typeof(zMSmyStr) == 'undefined') 
        var zMSmyStr = '';
    zMSmySize = zMSconvertSize(zMSgetValue("adsize", zMSmyStr)); //get adsize
    if (zMSmyStr.length > 0) 
        zMSmyStr += '&';
    zMSmySize = zMSmySize.toLowerCase();
    var zMSwidth = zMSmySize.substring(0, zMSmySize.indexOf("x") ? zMSmySize.indexOf("x") : 0); //get width
    var zMSheight = zMSmySize.substring(zMSmySize.indexOf("x") + 1, zMSmySize.length); //get height
    var zMSdim = "";
    if (zMSwidth != "" && (zMSwidth * 1) > 0) //test that adsize is in correct format
        zMSdim = "width=" + zMSwidth + " height=" + zMSheight;
    document.write('<IFRAME src="' + zMSHome + "/hserver/acc_random=" + zMSRand() + "/SITE=" + zMSACCsite + "/AREA=" + zMSACCarea + "/AAMSZ=" + zMSconvertSize(zMSgetValue("adsize", zMSmyStr)) + "/pageid=" + zMSpagenum + '" ' + zMSdim + ' frameborder="no" border=0 marginwidth=0 marginheight=0 scrolling="no">\n');
    document.write('</IFRAME>\n');
}

function zMSgetTower(){
    var zMSmyColour;
    
    if (arguments.length < 1)//no arguments entered i.e. use existing bgcolour of page.
        zMSmyColour = 'bgcolor="' + document.bgColor + '"';
    else 
        zMSmyColour = 'bgcolor="' + arguments[0] + '"';
    //var zMSsubDir = zMSgetValue("site",zMSvals)+'/'; //site name in tagline is used as zMSsubdir
    document.write('<iframe src="http://medrx.sensis.com.au/images/sensis/' + zMSsite + '/genericTower2.html?' + escape(zMSmyColour + '&' + escape('&SITE=' + zMSACCsite + '&AREA=' + zMSACCarea + '&pageid=' + zMSpagenum)) + '" width="160" height="600" frameborder="no" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no" id="towerFrame">\n');
    document.write("</iframe>\n");
}

function zMScallGeneric(){
    //hack for v8 homepage
    if (typeof(zMSaffiliate) != "undefined") {
        if (zMSlocation == "http://www.v8supercar.com.au" || zMSlocation == "http://www.v8supercar.com.au/") 
            zMSsection = "homepage";
        if (zMSlocation.toLowerCase().indexOf("/news/") != -1) 
            zMSsection = "news";
        if (zMSaffiliate == "ausgamers") {
            zMSACCsite = "TEL.AUSGAMER.GAMING";
            zMSACCarea = "GAMING.AUSGAMERS.OTHER";
            if (document.location.toString().length == 25) 
                zMSACCarea = "GAMING.AUSGAMERS.HOME";
            else if(zMSlocation.toLowerCase().indexOf("/forums") != -1)
            	zMSACCarea = "GAMING.AUSGAMERS.FORUMS"; 
            // if(zMSsection=="home")
            // 	zMSACCarea = "GAMING.AUSGAMERS.HOME";
        }
        if (zMSaffiliate == "v8") {
			if (document.location.toString() == "http://www.v8supercars.com.au" || document.location.toString() == "http://www.v8supercars.com.au/" || document.location.toString() == "http://www.v8supercars.com.au/default.asp?ind=M" || document.location.toString() == "http://www.v8supercars.com.au/default.asp?ind=M&p=6415" || document.location.toString() == "http://www.v8supercars.com.au/default.asp"){ 
				zMSACCarea = "SPORT.V8.HOMEPAGE";
			}
            
            zMSACCsite = "TEL.V8.SPORT";
            if (zMSsection == "tipping") {
                zMSACCarea = "SPORT.V8.TIPPING";
            }
            if (zMSlocation.toLowerCase().indexOf("/v8_competitions/") != -1) {
                zMSACCarea = "SPORT.V8.COMP";
            }
            
            if (zMSlocation.toLowerCase().indexOf("valvoline") != -1) {
                zMSACCarea = "SPORT.V8.VALVOLINE";
            }
            if(zMSsection == "home"){
            	zMSACCarea = "SPORT.V8.HOMEPAGE";
            }
            //else
            //zMSACCarea = "SPORT.V8.OTHER";
        }
        
        
        if (zMSlocation.toLowerCase().indexOf("/latest_news/") != -1) 
            zMSACCarea = "SPORT.V8.NEWS";
        
        //fix for v8 hidden commented out 2 may as it has been implemented directly on site 30 April 2007
        //if(zMSaffiliate=="v8")
        //	zMSgetJS("position=hidden&adsize=1x1");
    }
    if (zMSlocation.indexOf("telstra.com") != -1) 
        zMSACCarea = "SEARCH_DIRECTORIES.TELSTRA." + zMSsection.toUpperCase();
    
	//tmp fix for V8 News
	
	if(zMSlocation.indexOf("news") != -1 && zMSlocation.indexOf("v8supercars.com") != -1){
		zMSACCarea = "SPORT.V8.NEWS";
	}
	
	
    if (zMSlocation.indexOf("zmstestingenvironment375") != -1) {
        zMSACCarea = "MOB.TEST.DEMO";
        zMSACCsite = "Z_ZORRO";
    }
}




