﻿function moveScroller(anchor, scroller) {
    var a = function() {
        var b = $(window).scrollTop();
        var d = $(anchor).offset({ scroll: false }).top;
        var c = $(scroller);

        if (c.height() >= $(window).height()) {
            return; //If the div is greater than the height of the window, then dont scroll
        }

        if (b > d) {
            c.css({ position: "fixed", top: "0px" })
        } else {
            if (b <= d) {
                c.css({ position: "relative", top: "" })
            }
        }
    };
    $(window).scroll(a); a()
}



function bindUpdatePanelEndRequest() {
    if (typeof (Sys) != "undefined") {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(OnUpdatePanelEndRequest);
    }
}

function OnUpdatePanelEndRequest() {
    if (typeof (_wr_i) != "undefined") {
        _wr_i(_wr_d.body);
    }
    if (typeof (_wr_re) != "undefined") {
        _wr_re(_wr_d.body);
    }
}

function SingleClickButton(sender, validationGroup) {
    if (typeof (validationGroup) == 'boolean' && validationGroup === false) //Does not require validation on client-side
    {
        sender.onclick = function () { alert('Request is being processed... Please wait...'); return false; }
    }
    else { //client side validation may be required
        var validated = true;
        if (typeof (Page_ClientValidate) == 'function') {
            validated = Page_ClientValidate(validationGroup);
        }
        if (validated) {
            sender.onclick = function () { alert('Request is being processed... Please wait...'); return false; }
        }
        else {
            return false;
        }
    }

}

function getQuerystring(urlWithQueryString, key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(urlWithQueryString);
    if (qs == null)
        return default_;
    else
        return qs[1];
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

function checkCookie() {
    username = getCookie('username');
    if (username != null && username != "") {
        alert('Welcome again ' + username + '!');
    }
    else {
        username = prompt('Please enter your name:', "");
        if (username != null && username != "") {
            setCookie('username', username, 365);
        }
    }
}



function closeHomePageSplashGeneric(val, storeCode) {
    //var storeCode = '<%=CurrentStore.RWStore.StoreCode%>';
    var id = 'divHomePageSplashContainer';
    var cookieName = "HomePageSplash-" + storeCode; //not a good idea to create cookie for each store, but for faster delivery have to do this
    var promo = val;
    var toCookieValue = '';
    var embHomePageFlash = document.getElementById("divHomePageSplashContainer").getElementsByTagName("embed");
    if (embHomePageFlash) {
        var src = embHomePageFlash[0].getAttribute("src");
        if (src) {
            promo = getQuerystring(src, "promo");
        }
    }
    if (typeof (promo) !== "undefined" && promo != '') {
        toCookieValue = promo;
        var existingCookie = getCookie(cookieName);
        if (existingCookie != null && existingCookie != "") {
            if (existingCookie.indexOf(promo) >= 0) {
                toCookieValue == ''; //No need to set the cookie because it already exists
            }
            else {
                //If value doesn't exist in the list, then add it
                toCookieValue = existingCookie + " " + promo;
            }
        }
    }

    if (toCookieValue != null && toCookieValue != '') {
        setCookie(cookieName, toCookieValue, null);
    }

    document.getElementById(id).style.display = 'none';

}
