//Last edited by PH, 03/06/08, Added keyword functionality
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();

//Try to get the parent page number in case it is in an iFrame
try {
    if (typeof(parent.zMSpagenum) != 'undefined') {
        zMSpagenum = parent.zMSpagenum;
    }
} 
catch (e) {
}

//default site area tags to create target string
var zMSACCsite = "3RD.VIRTUALMEDICALCENTRE.HEALTH";
var zMSACCtarget = "HEALTH.VIRTUALMEDICALCENTRE.OTHER"; // default Acc Area string
var zMSACCusertype = "OTHER"

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 += "&";
    return zMStagline.substring(zMSind, zMStagline.indexOf("&", zMSind));
}

function zMSconvertSize(zMSsize, zMSposition){
    // convert size string
    if (zMSsize == "hariable") 
        return "728x90";
    
    if (/\d+x\d+/.test(zMSsize)) //zMSsize test if adsize string format is digitsxdigits output true false
        return zMSsize;
    return "ERROR";
}

function zMSgetJS(zMSmyStr){
	if(zMSmyStr.indexOf("728x90") !=-1 || zMSmyStr.indexOf("300x250") !=-1)
	zMSgetIframe(zMSmyStr);
	else{
    //Network Promotions
    zmsSiteTemp = "";
    if (zMSmyStr.indexOf("position=bppromo") != -1) {
        zmsSiteTemp = zMSACCsite;
        zMSACCsite = "3RD.BPPROMO.VIRTUALMEDICALCENTRE.HEALTH";
        zms_temp_pos = zMSmyStr.indexOf("position=bppromo");
		
		zMSmyStr = zMSmyStr.replace(/bppromo/i, "");
       // zMSposMod = "/POSITION=" + zMSmyStr.charAt(zms_temp_pos + 16);
    }
    

    if (zMSlocation.indexOf("zmstestingenvironment375") != -1) {
        zMSACCtarget = "MOB.TEST.DEMO";
        zMSACCsite = "Z_ZORRO";
        zMSkey = "/KEYWORD=EXPANDABLE";
    }
    zMSmyStr = zMSmyStr.replace(/55x25/, "55x30");
    document.write("<scr" + "ipt src=\"" + zMSHome + "/jserver/acc_random=" + zMSRand() + "/SITE=" + zMSACCsite + "/AREA=" + zMSACCtarget + "/POSITION=" + zMSgetValue("position", zMSmyStr) + zMSkey + "/AAMSZ=" + zMSconvertSize(zMSgetValue("adsize", zMSmyStr), zMSgetValue("position", zMSmyStr)) + "/pageid=" + zMSpagenum + "\">\n");
    document.write("</scr" + "ipt>");
    
	
    if (zmsSiteTemp != "") {
        zMSACCsite = zmsSiteTemp;
    }
	}
}

function zMSgetIframe(zMSmyStr) // not used for swellnet ; intiate an adsever ad call from an Iframe similar.
{	
	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=" + zMSACCtarget + "/POSITION=" + zMSgetValue("position", zMSmyStr) + zMSkey + "/AAMSZ=" + zMSconvertSize(zMSgetValue("adsize", zMSmyStr)) + "/pageid=" + zMSpagenum + '" ' + zMSdim + ' frameborder="no" border=0 marginwidth=0 marginheight=0 scrolling="no">\n');
    document.write('</IFRAME>\n');
}

function zMSgetSkyTower(){
    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=' + zMSACCtarget + '&pageid=' + zMSpagenum)) + '" width="160" height="600" frameborder="no" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no" id="towerFrame" ALLOWTRANSPARENCY=TRUE>\n');
    document.write("</iframe>\n");
}


function zMScallGeneric(){ // generate Acc Area targeting string zMSACCtarget
    if (typeof(zMSusertype) != "undefined" && zMSusertype.length > 0) {
    
        zMSACCusertype = zMSusertype.toUpperCase();
        
    }// else default zMSACCusertype string used.
    if (typeof(zMSsection) != "undefined" && zMSsection.length > 0) {
    
        zMSACCtarget = 'HEALTH.VIRTUALMEDICALCENTRE.' + zMSsection.toUpperCase() + '/SITE_REG_USER=' + zMSACCusertype;
        
    }// else default zMSACCtarget string used.
    zMSkey = "";
    
    //Manual smoking targeting
    zMSsmokingURL = new Array("featuredpages.asp?artid=16&title=Smoking#C5", "calc.asp?calc=smo&", "videopage.asp?vidid=504", "humanatlas1/vmc_white.asp?anim=0243", "healthandlifestyle.asp?sid=3", "healthandlifestyle.asp?sid=199", "healthandlifestyle.asp?sid=199", "healthandlifestyle.asp?sid=205", "healthandlifestyle.asp?sid=206", "/featuredpages.asp?artid=16");
    
    var smoking_length = zMSsmokingURL.length;
    
    for (i = 0; i < smoking_length; i++) {
        var url = zMSsmokingURL[i];
        if (zMSlocation.indexOf(url) != -1) {
            zMSACCtarget = 'HEALTH.VIRTUALMEDICALCENTRE.SMOKING' + '/SITE_REG_USER=' + zMSACCusertype;
            break;
        }
    }
    
    //Manual weight loss targeting
    zMSweightLossURLs = new Array("/featuredpages.asp?artid=10", "calc.asp?calc=bmi&sid=2", "caloriecounter.asp");
    var zmsURL = zMSlocation.toUpperCase();
    for (i = 0; i < zMSweightLossURLs.length; i++) {
        if (zmsURL.indexOf(zMSweightLossURLs[i].toUpperCase()) != -1) {
            zMSACCtarget = 'HEALTH.VIRTUALMEDICALCENTRE.WEIGHTLOSS' + '/SITE_REG_USER=' + zMSACCusertype;
            break;
        }
    }
    
    if (typeof(zMSarticle) != "undefined" && zMSarticle.length > 0) {
        zMSkey = "/KEYWORD=" + zMSarticle;
    }
}


