﻿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';

}


/****** (START) Social Media Marketing Control ************/

 var addthis_config = {
                data_track_clickback: true,
                services_exclude: 'twitter'
            };

function fb_comments(sender, url) {
    var FBGraphURL = "https://graph.facebook.com/?ids=" + escape(url) + "&callback=?";
    $.getJSON(FBGraphURL, function (data) {
        var commentsCount = 0;
        if (data[url].comments) {
            commentsCount = data[url].comments;
        }
        $("#" + sender).innerHTML = commentsCount;
    });
}

/****** (END) Social Media Marketing Control ************/


/***** (START) FancyBox  **************/

$(document).ready(function () {

    $(".hiddenPopupClicker").each(
        function () {
            var fancybox_iframe = $('.hiddenPopupClicker');
            if (fancybox_iframe.length > 0) {
                fancybox_iframe.each(function (index) {
                    // Inline frame width param
                    if ($(this).attr('href').match(/width=[0-9]+/i)) {
                        var fWidth = parseInt($(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=', ''));
                    } else {
                        var fWidth = '70%';
                    }
                    // Inline frame height param
                    if ($(this).attr('href').match(/height=[0-9]+/i)) {
                        var fHeight = parseInt($(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=', ''));
                    } else {
                        var fHeight = '70%';
                    }
                    if (window.console && window.console.log) {
                        console.log('fWidth #' + index + ': ' + fWidth);
                        console.log('fHeight #' + index + ': ' + fHeight);
                    }


                    $(this).fancybox({
                        'padding': 0,
                        'zoomOpacity': true,
                        'zoomSpeedIn': 500,
                        'zoomSpeedOut': 500,
                        'overlayOpacity': 0.75,
                        'hideOnContentClick': false,
                        'hideOnOverlayClick': true,
                        'overlayShow': true,
                        'modal': false,
                        'titlePosition': 'outside',
                        'titleShow': false,
                        'speedIn': 500,
                        'speedOut': 500,
                        'transitionIn': 'elastic',
                        'transitionOut': 'elastic',
                        'autoScale': false,
                        'autoDimensions': false,
                        'width': fWidth,
                        'height': fHeight,
                        'enableEscapeButton': true,
                        'orig': this
                    });
                });
            }
        });
});

/***** (END) FancyBox  **************/

/***** (START) blink ********/
String.prototype.format = function() {
    var s = this,
        i = arguments.length;

    while (i--) {
        s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
    }
    return s;
};

function startBlink(ctrlId, class1, class2) {
               setInterval("doBlink('{0}', '{1}', '{2}')".format(ctrlId, class1, class2) , 1000);
     }
     
function doBlink(ctrlId, class1, class2) {
        var lblPaymentInstruction = document.getElementById(ctrlId);
        if (lblPaymentInstruction.className) lblPaymentInstruction.className   = (lblPaymentInstruction.className == class1) ? class2 : class1;
}

/***** (END) blink ********/










