function AdTechServer(ats_placementid, ats_sizeid, ats_alias, ats_target) {
	var ats_url = 'http://adserver.adtechus.com/addyn';
    
	// Pace campaigns by user?s time and not just network time
	var curDateTime = new Date();
	var offset = -(curDateTime.getTimezoneOffset());
	if (offset > 0)
		offset = "+" + offset;

	if (ats_target == undefined)
		ats_target == '';
	if (window.adgroupid == undefined) {
		window.adgroupid = Math.round(Math.random() * 1000);
	}
    
	var ats_aliasid = 0;
	if (ats_alias.indexOf("2210") > 0)
		ats_aliasid = 2210; //Leaderboard ATF
	if (ats_alias.indexOf("285") > 0)
		ats_aliasid = 285; //Leaderboard BTF
	if (ats_alias.indexOf("2211") > 0)
		ats_aliasid = 2211; //300x250 ATF
	if (ats_alias.indexOf("4541") > 0)
		ats_aliasid = 4541; //300x80
	if (ats_alias.indexOf("328") > 0)
		ats_aliasid = 328; //300x250 BTF
	if (ats_alias.indexOf("714") > 0)
	    ats_aliasid = 714; //Interstitial

	document.write('<scr'+'ipt id="AdTechScr' + ats_aliasid + '" src="' + ats_url +
	'|3.0|5259.1|' + ats_placementid + '|0|' + ats_sizeid + '|alias=' + ats_alias +
	';ADTECH;loc=300;target=_blank;key=' + ats_target + ';grp=' +
	window.adgroupid + ';misc=' + new Date().getTime() + ';aduho='+ offset +
	'"></scri'+'pt>'); 
 
	ats_adsArray.push(ats_aliasid);
}

function AdTechMoveEndPageDivs(ats_aliasid) {
    jQuery(ats_adsArray).each(function(i, ats_aliasid) {
        try {
            var scr = document.getElementById('AdTechScr'+ats_aliasid);
            scr.parentNode.removeChild(scr);
            var secureDiv = document.getElementById('AdTechEndPage'+ats_aliasid);
            switch (ats_aliasid) {
                case 2210:
                    document.getElementById('aleader-child').innerHTML = '';
                    document.getElementById('aleader-child').appendChild(secureDiv);
                    jQuery('#content-ad-header').show();
                    break;
                case 285:
                    document.getElementById('aleader-2').innerHTML = '';
                    document.getElementById('aleader-2').appendChild(secureDiv);
                    jQuery('#aleader-2').show();
                    break;
                case 2211:
                    document.getElementById('amedium').innerHTML = '';
                    document.getElementById('amedium').appendChild(secureDiv);
                    jQuery('#amedium').show();
                    break;
                case 4541:
                    document.getElementById('amediumchild').innerHTML = '';
                    document.getElementById('amediumchild').appendChild(secureDiv);
                    jQuery('#amediumchild').show();
                    break;
                case 328:
                    document.getElementById('amedium-2').innerHTML = '';
                    document.getElementById('amedium-2').appendChild(secureDiv);
                    jQuery('#amedium-2').show();
                    break;
                default:
                // do nothing
            }
        } catch(e) {
            // alert(e);
        }
    });
}
ats_adsArray = [];
jQuery(function() {
	AdTechMoveEndPageDivs();
});

function bodyClick(url, toggleHeaderOn) {
    jQuery('body').css({ 'min-height':'100%', 'height':'auto', 'cursor':'pointer' });
    jQuery('#ipbwrapper').css({ 'min-height':'100%', 'height':'auto', 'cursor':'default' });
    jQuery('#header').css('cursor','pointer');
    jQuery('#header div.hdbox').css('cursor','default');
    jQuery('body').click(function(e) {
        var obj = (e.target ? e.target : e.srcElement);
        if (obj.tagName != 'BODY') return true;
        window.open(url);
        //alert('body click recorded')
        return false;
    });
    if (toggleHeaderOn == "1") {
        jQuery('#header').click(function(e) {
            var obj = (e.target ? e.target : e.srcElement);
            if (obj.id != 'header') return true;
            window.open(url);
            return false;
        });
    }
}
