

if (!window.XMLHttpRequest)
{
    window.XMLHttpRequest = function()
    {
        try { return new ActiveXObject("MSXML3.XMLHTTP") } catch(ex) { }
        try { return new ActiveXObject("MSXML2.XMLHTTP.3.0") } catch(ex) { }
        try { return new ActiveXObject("MSXML2.XMLHTTP") } catch(ex) { }
        try { return new ActiveXObject("Microsoft.XMLHTTP") } catch(ex) { }
    }
}

if (!window.Delegate)
{
    window.Delegate = function(instance, method)
    {
        return function()
        {
            return method.apply(instance, arguments);
        }
    }
}

if (!window.CallAjax)
{
    window.CallAjax = function(address, callback, synchronous)
    {
        var request = new XMLHttpRequest();
        var random = "";
        
        for (var i = 0; i < 10; i++) random += new String(parseInt(Math.random() * 9));
        
        if (synchronous)
        {
            request.open("GET", address + (address.indexOf("?") == -1 ? "?" : "&") + "_r!=" + random, false);
            request.send(null);
            
            callback(request.responseText);
        }
        else
        {
            request.onreadystatechange = function()
            {
                if (request.readyState == 4)
			    {
				    if (request.status == 200)
					    callback(request.responseText);
				    else
					    callback("\r\n~SPLIT~\r\n");
			    }
            }
            
            request.open("GET", address + (address.indexOf("?") == -1 ? "?" : "&") + "_r!=" + random, true);
            request.send(null);
        }
    }
}

if (!window.Kook)
{
    window.Kook = function()
    {
    }
}

if (!window.Kook.AdCentre)
{
    window.Kook.AdCentre = function()
    {
    }
}

if (!window.Kook.AdCentre.Campaign)
{
    window.Kook.AdCentre.Campaign = function(campaignId)
    {
        this.__campaignId = campaignId;
        
        this.Render = new Delegate(this, function(width, height)
        {
            document.write("<div id=\"Campaign_" + this.__campaignId + "\" style=\"height: " + (height - parseInt((height - 32) / 2)) + "px; overflow: hidden; padding-top: " + parseInt((height - 32) / 2) + "px; width: " + width + "px;\"><img alt=\"\" src=\"http://adcentre.coastemedia.com.au/Media/Wait.gif\" /></div>");

            var address = "/Ajax.aspx?Address=http%3a%2f%2fadcentre.coastemedia.com.au%2fAdServe.aspx%3fCampaign_ID%3d" + this.__campaignId + "%26Referrer%3d" + escape(window.location);
                        
            CallAjax(address, new Delegate(this, function(response)
            {
                var split = response.indexOf("~SPLIT~");
                
                var javascript = response.substring(0, split);
                var html = response.substring(split + "~SPLIT~".length);
                
                var campaign = document.getElementById("Campaign_" + this.__campaignId);
                
                campaign.style.height = height + "px";
                campaign.style.paddingTop = "0px";
                
                campaign.innerHTML = html;
                
                eval(javascript);
            }));
        });
        
        this.RegisterClick = new Delegate(this, function(advertisementId)
        {
            var address = "/Ajax.aspx?Address=http%3a%2f%2fadcentre.coastemedia.com.au%2fAnalytics.aspx%3fAdvertisement_ID%3d" + advertisementId + "%26Referrer%3d" + escape(window.location);
        
            CallAjax(address, new Delegate(this, function(response)
            {
                window.open(response, null, "left=100, top=100, width=" + parseInt(screen.availWidth - 200) + ", height=" + parseInt(screen.availHeight - 200) + ", location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes");
            }), true);
        });
    }
}