﻿function BannerManager() {
    var obj = this;
    var BannerObj;
    var ButtonObj;
    this.BannerId = null;
    this.IsActive = '0';


    this.init = function() {

	BannerObj = document.getElementById(obj.BannerId);
	BannerObj.style.display = "none";

        if (obj.IsActive == '0')
            return;

        ButtonObj = document.getElementById("BannerCloseButton");
        var cookie = new CookieHandler;

        var ctrl = BannerControl();
	
        if (ctrl && cookie.getCookie("DeikBanner") != "True") {	    

       	    setStyleDivElement(BannerObj);
	
            ButtonObj.onclick = function() {
               	BannerObj.style.display = "none";
		document.body.parentNode.style.overflow = "auto";
	    };

            addLoadEvent(resize);

	    cookie.setCookie("DeikBanner", "True", "5000");
        }

        cookie.deleteCookie("DeikBanner");
    };

    var setStyleDivElement = function(elem) {
	elem.style.display = "block";
        elem.style.width = document.body.parentNode.clientWidth + 15;
        elem.style.height = document.body.parentNode.clientHeight;
        document.body.parentNode.style.overflow = "hidden";
    };

    var resize = function() {
        var htmlheight = document.body.parentNode.clientHeight;
        var windowheight = window.innerHeight;
        if (htmlheight < windowheight) {
            document.body.style.height = windowheight + "px";
            BannerObj.style.height = windowheight + "px";
        }
        else {
            document.body.style.height = htmlheight + "px";
            BannerObj.style.height = htmlheight + "px";
        }
    };

    var BannerControl = function() {
        if (BannerObj != null || BannerObj != undefined) {
            return true
        } else {
            return false
        }
    };
}

function resize(obj) {
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function CookieHandler() {

    this.setCookie = function(name, value, seconds) {
        if (typeof (seconds) != 'undefined') {
            var date = new Date();
            date.setTime(date.getTime() + (seconds * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else {
            var expires = "";
        }
        document.cookie = name + "=" + value + expires + "; path=/";
    }

    this.getCookie = function(name) {

        name = name + "=";
        var carray = document.cookie.split(';');

        for (var i = 0; i < carray.length; i++) {
            var c = carray[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
        }

        return null;
    }

    this.deleteCookie = function(name) {
        this.setCookie(name, "", -1);
    }

}