﻿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);
}