﻿var HomePageTagMapping = {
    // Media    
//    ALC08L001 : { name: 'Door Drop (Mosaic)', tagType: 'doubleClick', tagValue: 'doord812' }
//    ,ALC08D002 : { name: 'Direct Mail (PacMicro)', tagType: 'doubleClick', tagValue: 'direc048' }
//    ,ALC08D003 : { name: 'Direct Mail (Aust. Post)', tagType: 'doubleClick', tagValue: 'direc068' }
//    ,ALC08I001 : { name: 'Infomercial (Red Hammer)', tagType: 'doubleClick', tagValue: 'infom805' }
//    ,ALC08I002 : { name: 'Infomercial (9am D&K)', tagType: 'doubleClick', tagValue: 'infom072' }
//    ,ALC08I003 : { name: 'Infomercial (KAK)', tagType: 'doubleClick', tagValue: 'infom202' } 
	
	 ALC08B003 : { name: 'MSDR Banners', tagType: 'doubleClick', tagValue: 'msdrb003' }
	,ALC08B004 : { name: 'DrivePM Banners', tagType: 'doubleClick', tagValue: 'msdrb004' }
	,ALC08E003 : { name: 'eDM (3DI 1) - Test A', tagType: 'doubleClick', tagValue: 'edmta003' }
	,ALC08E004 : { name: 'eDM (3DI 2)- Test B', tagType: 'doubleClick', tagValue: 'edmtb004' }
	,ALC08B006 : { name: 'Sensis Banner - Test A', tagType: 'doubleClick', tagValue: 'sensa006' }
	,ALC08B007 : { name: 'Sensis Banner - Test B', tagType: 'doubleClick', tagValue: 'sensb007' }
	,ALC08B008 : { name: 'Realestate Banner', tagType: 'doubleClick', tagValue: 'realb008' }
	
}

var genericDoubleClickTag = {
    tagValue: 'homep944'
}

var tagFormat = {
doubleClick: '<img src="https://ad.au.doubleclick.net/activity;src=1763141;type=onceo975;cat={0};ord={1}?" border="0" style="display:none;width:1px;height:1px;">'
        
}

function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	this.get=Querystring_get;
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length);

	if (qs.length == 0) 
		return;

    // Turn <plus> back to <space>
    // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
    // split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var pair = args[i].split('=');
		var name = unescape(pair[0]);
		
		var value = (pair.length==2)
			? unescape(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

function Querystring_get(key, default_) {
	var value=this.params[key];
	return (value!=null) ? value : default_;
}

function TagHomePage()
{
    var queryString;
    var campaignCode;
    var pageTagInfo;
    var pageTag;
    
    // double click tag variables
    var axel = Math.random() + '';
    var a = axel * 10000000000000;  
    
    // build the query string key value collection
    queryString = new Querystring();
    // retrieve the campaign code from the current id
    campaignCode = queryString.get('CurrentId') || '';
    campaignCode = campaignCode.toUpperCase();

    // valid campaign code
    if (campaignCode != null && campaignCode != '')
    {        
        pageTagInfo = HomePageTagMapping[campaignCode];
        // if there a specific tag has been found for the campaign code then use it
        // otherwise just the default home page tag
        if (pageTagInfo != null && pageTagInfo.tagType == 'doubleClick')
        {            
            pageTag = tagFormat.doubleClick.replace('{0}', pageTagInfo.tagValue).replace('{1}', a);                                        
        }
        else
        {
            pageTag = tagFormat.doubleClick.replace('{0}', genericDoubleClickTag.tagValue).replace('{1}', a);
        }
    }    
    else // serve the generic spotlight tag
    {
        pageTag = tagFormat.doubleClick.replace('{0}', genericDoubleClickTag.tagValue).replace('{1}', a);
    }   
    // server the spotlight tag
    document.write(pageTag); 
}
