var AdDomain = "http://a.interweave.com/"
var FloaterZoneID = 23;
var InlineZoneID = 24;

function ShowInlineAd(showDiv, source) {
    var show = document.getElementById(showDiv);
    if (show)
    {
        var tags = show.getElementsByTagName('iframe');
        if (tags.length > 0)
            tags[0].src = source;

        //Small delay so frame can load before displaying
        setTimeout("Show('" + show.id + "')", 300);
    }
}

function Hide(hideDiv) {
    var hide = document.getElementById(hideDiv);

    if (hide) {
        hide.style.visibility = 'hidden';
        hide.style.height = 0;
        hide.style.left = '-1000px';
    }
}

function Show(showDiv) {
    var show = document.getElementById(showDiv);
    if (show) {
        show.style.visibility = 'visible';
        show.style.height = null; //back to original CSS value
        show.style.left = null;
    }
}

function SetAdContent(fixedPanel, fixedSrc, floatingSrc, minutes) {
    if (!readCookie(fixedPanel)) {
        createCookie(fixedPanel, 'true', minutes);

        ShowFloater(floatingSrc);
        Hide(fixedPanel);
    }
    else {
        ShowInlineAd(fixedPanel, fixedSrc);
    }
}

function createCookie(name, value, minutes) {
    var expires;
    if (minutes)
    {
        var date = new Date();
        date.setTime(date.getTime() + (minutes * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    }
    else
        expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }

    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}


function ShowFloater(floatingSrc)
{
    var Mask = document.getElementById("AdMask");
    if (Mask) {
        Mask.style.display = "block";
    }
    var Content = document.getElementById("AdContent");
    if (Content) {
        Content.style.display = "block";

        var tags = Content.getElementsByTagName('iframe');
        if (tags.length > 0)
            tags[0].src = GetAdCall(FloaterZoneID);
    }    
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function LoadAds()
{
	SetAdContent('AdInline', GetAdCall(InlineZoneID), GetAdCall(FloaterZoneID), 30);
}

function CloseFloater(floaterID, maskID) {
	HideAndRemoveElement(document.getElementById(floaterID));
	HideAndRemoveElement(document.getElementById(maskID));
	ShowInlineAd("AdInline", GetAdCall(InlineZoneID));
}

function HideAndRemoveElement(Element) {
	if (Element) {
		Element.style.display = "none";
		try {
			document.body.removeChild(Element);
		}
		catch (err) {}
	}
}

function GetAdCall(ZoneID) {
	return AdDomain + "afr.php?zoneid=" + ZoneID + "&cb=" + Math.floor(Math.random() * 99999999999);
}


