
$(function() {
    // This check is used by the demo to allow you to remove the cookie. Do not use in production code.

    CreatePopup("/portal/popup/solidrules_popup.html", 200, 1500, "new_solidrules_portal_popup", 5);
});

function CreatePopup(url, height, duration, description, lifetime) {
    // Exit if the current browser has already received the popup, or 
    // the browser is not supported (IE6).
    if (HasAlreadyReceivedPopup(description))
        return;

    $.get(url, function(data) {
        var popup = $("<div>" + data + "</div>")
			.attr({ "id": "sliding_popup" })
			.css({ "bottom": -1 * height })
			.css({ "position": "fixed" })
			.css({ "width": "100%" })
			.css({ "left": "0px" })
	    	.height(height)
			.hide()
			.appendTo("body");

        ShowPopup(description, lifetime, popup, duration);
    });
}

function ShowPopup(description, lifetime, popup, duration) {
    popup.show().animate({ bottom: 0 }, duration);
    ReceivedPopup(description, lifetime);
}

function HasAlreadyReceivedPopup(description) {
    return document.cookie.indexOf(description) > -1;
}

function ReceivedPopup(description, lifetime) {
    var date = new Date();
    date.setDate(date.getDate() + lifetime);
    document.cookie = description + "=true;expires=" + date.toUTCString() + ";path=/";
}

function IsUnsupportedUserAgent() {
    return (!window.XMLHttpRequest);
}

function DestroyPopup(duration) {
    $("#sliding_popup").animate({ bottom: $("#sliding_popup").height() * -1 }, duration, function() { $("#sliding_popup").remove(); })
}