 var CokeFamily = window.CokeFamily = new Object();
CokeFamily.TopLayer = new Object();
CokeFamily.TopLayer.openTopLayer = function (url) {
            TOPLAYER_checkTopLayer();
    var temp_url = url;
    var w = 354;
    var h = 310;
    if (url.match(/layerType=products/)) {
        var w = 460;
        var h = 360;
    }
    temp_url = temp_url.replace(/\height=(\d\d\d)/,'height='+h);
    temp_url = temp_url.replace(/\width=(\d\d\d)/,'width='+w);
    url = temp_url;
    $(document).ready(function (){tb_show(null,url,null);});
}
CokeFamily.TopLayer.closeAndRedirect = function () {
    self.parent.tb_remove();                 
    self.parent.location.replace("Pomoc.aspx");
}
CokeFamily.TopLayer.ifr = null;
CokeFamily.TopLayer.interval = null;
CokeFamily.TopLayer.updateIFrameDimension = function () {
    if (this.ifr == null) return
    var frame = this.ifr;
     var frameDoc = frame.contentWindow.document;
     if (frameDoc.documentElement) { 
      var frameBody = frameDoc.documentElement;
     } else if (frameDoc.body) {
      var frameBody = frameDoc.body;
     } else {
      var frameBody = null;
     }
     if (frameBody != null)
     {
      if (frameBody.clientHeight < frameBody.scrollHeight) frame.style.height = frameBody.scrollHeight+'px';
     }
}

CokeFamily.TopLayer.initIFrameResizing = function () {
    this.ifr = self.parent.window.document.getElementById('TB_iframeContent');
    $(document).ready(function () {
        CokeFamily.TopLayer.updateIFrameDimension();
        CokeFamily.TopLayer.interval = window.setInterval("CokeFamily.TopLayer.updateIFrameDimension()",500);
        $(window).unload(function () {
            var w = window.clearInterval(CokeFamily.TopLayer.interval);
        })
    }) ;
}





CokeFamily.UserAccountHistory = new Object()
CokeFamily.UserAccountHistory.ini = function () {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_endRequest(CokeFamily.UserAccountHistory.updateView)
    CokeFamily.UserAccountHistory.updateView();
}
CokeFamily.UserAccountHistory.updateView = function (sender, args) {
    CokeFamily.UserAccountHistory.setActiveTab();
    CokeFamily.UserAccountHistory.colorifyTable();
    CokeFamily.UserAccountHistory.setTooltip();
}
CokeFamily.UserAccountHistory.setActiveTab = function () {
    var active = String($('#updatePanelLoaded').attr('class')).split('_')[1];
    $('#historyTabs li').removeClass('active').siblings('#'+active).addClass('active');
}
CokeFamily.UserAccountHistory.colorifyTable = function () {
    $('#tabContent table tbody tr:odd').addClass('odd');
}
CokeFamily.UserAccountHistory.setTooltip = function () {
    $('#historyPanel table tr').tooltip({
        track:true,
	    delay: 0,
	    showURL: false,
	    fade: 250,
	    top: -115,
	    left: -27,
	    extraClass: 'white'
    });
}

CokeFamily.AddNewCode = new Object();
CokeFamily.AddNewCode.config = null;
CokeFamily.AddNewCode.ini = function (options) {
    this.config = options;
    
    this.config['code1'].keyup(function () {
        if (this.value.length == 6) CokeFamily.AddNewCode.config['code2'].focus();
    });
    this.config['code2'].keyup(function () {
        if (this.value.length == 6) CokeFamily.AddNewCode.config['code3'].focus();
    });
    
    if (typeof this.config.clear != "undefined") {
        if (this.config.clear == true) {
            this.config['code1'].val('');
            this.config['code2'].val('');
            this.config['code3'].val('');
        }
    }
    
    if (typeof this.config.focus != "undefined") {
        if (this.config.focus == true) {
            window.setTimeout("CokeFamily.AddNewCode.config['code1'].focus()",500);
        }
    }
}


CokeFamily.NavigationMain = new Object();
CokeFamily.NavigationMain.selectedTab = null;
CokeFamily.NavigationMain.activate = function () {
    $('#navigationMain li' + this.selectedTab + ' a').addClass('active');
}
CokeFamily.NavigationMain.ini = function () {
    if (this.selectedTab != null) this.activate()
}







CokeFamily.ViewPort = new Object();
CokeFamily.ViewPort.ini = function () {
    if (typeof Sys == "undefined") return
    if (typeof Sys.WebForms == "undefined") return
    if (typeof Sys.WebForms.PageRequestManager == "undefined") return
    var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_endRequest(CokeFamily.ViewPort.update)
}
CokeFamily.ViewPort.update = function () {

    $('html,body,.pageWrapper').css({
        height: $('#page').get(0).offsetHeight + 'px'
    });
}



// banner na stronie glownej zapunktowani.pl
CokeFamily.AdRotator = new Object();
CokeFamily.AdRotator.cookieName = 'zpkt_cookie_banner';
CokeFamily.AdRotator.ini = function() {

    var cookie_name = 'zpkt_cookie_banner';
    var cookie = getCookie(cookie_name);
    var max_banner = $('ul#adRotator li').length - 1;
    if (typeof cookie != "undefined" && cookie != null && cookie != "") {
        if (parseInt(cookie) < max_banner) {
            var banner = parseInt(cookie) + 1;
        } else {
            var banner = 0;
        }
        $('ul#adRotator li:eq(' + banner + ')').show();
        setCookie(cookie_name, banner, '30');
    } else {
        $('ul#adRotator li:eq(0)').show();
        setCookie(cookie_name, '1', '30');
    }
}

// banner na stronie zapunktowani.pl/nagrodyzapunkty
CokeFamily.AdRotator_ = new Object();
CokeFamily.AdRotator_.cookieName = 'zpkt_cookie_banner_';
CokeFamily.AdRotator_.ini = function() {


    var cookie_name = 'zpkt_cookie_banner_';
    var cookie = getCookie(cookie_name);
    var max_banner = $('ul#adRotator li').length - 1;
    if (typeof cookie != "undefined" && cookie != null && cookie != "") {
        if (parseInt(cookie) < max_banner) {
            var banner = parseInt(cookie) + 1;
        } else {
            var banner = 0;
        }
        $('ul#adRotator li:eq(' + banner + ')').show();
        setCookie(cookie_name, banner, '30');
    } else {
        $('ul#adRotator li:eq(1)').show();
        setCookie(cookie_name, '1', '30');
    }
}

function IfKeyEnter(e) {
    if (!e) var e = window.event;
    return (e.keyCode == 13)
}

function StopPropogationEvent(e) {
    if (!e) var e = window.event;

    e.returnValue = false;
    
    //IE
    e.cancelBubble = true;

    //Firefox
    if (e.stopPropagation) {
        e.stopPropagation();
        e.preventDefault();
    }
    
    return false;
}

function IfKeyEnterToClickElement(btnClientID, e) {
    if (e.keyCode == 13) {

        var btnHref = $("#" + btnClientID).attr('href')
        if (btnHref != undefined) {
            document.location.href = btnHref;
        }

        var btnName = $("#" + btnClientID).attr('name')
        if (btnName != undefined) {
            document.location.href = "javascript:__doPostBack('" + btnName + "','')"
        }

        // cancel the default submit
        //e.cancelBubble is supported by IE - this will kill the bubbling process.
        e.cancelBubble = true;
        e.returnValue = false;

        //e.stopPropagation works only in Firefox.
        if (e.stopPropagation) {
            e.stopPropagation();
            e.preventDefault();
        }
        return false;
    }
}

function getCookie(name){
var cookies = document.cookie.split(/; /g);
var cookie;

for(var i=0; i<cookies.length; i++){
    cookie=cookies[i].split("=");
    if(cookie[0] == name){
        var value = cookie[1];
    }
}
return value;
}

function setCookie(cookieName,cookieValue,nDays) {
  var today = new Date();
  var expire = new Date();
  if (nDays!=null || nDays!=0){
  expire.setTime(today.getTime() + 3600000*24*nDays);
  document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
  }
} 



// przelotki z wywolan .net
var tb_open_new = CokeFamily.TopLayer.openTopLayer;
var closeAndRedirect = CokeFamily.TopLayer.closeAndRedirect;







$(document).ready(function () {
    CokeFamily.ViewPort.ini();
    
        // cross domain trick for toplayer with ssl page in iframe 
        $("a.thickbox").bind("click", function () {
            TOPLAYER_checkTopLayer();
        })
});


$(document).ready(function(){
    
    $('#popupNew img').pngfix();
    if(getCookie("popupNew") != "jest"){
    
    $('#popupNew').removeClass('hide');
    
    setCookie("popupNew", "jest");
    }
$('#popupNew p').click(function(event){ 
 $(this).parent('#popupNew').addClass('hide');
 

  
});  


    
});