﻿var mid = 1;
var mkey = "kyS8VMD5HdCy18";
var mainsitedomain = "http://www.2daydiet-shopper.com";
var appURL = "http://app.2daydiet-shopper.com";
function addocart(i) {
    window.location.href = i;
}
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) ? "" : ";path=/;expires=" + exdate.toGMTString());
}
function GoTo(url) {
    window.location.href = url;
}
function SignUpMini() {
                var src = mainsitedomain+"/SignUpBasic.aspx?email=" + $("#txtEmail").val()+"&continue="+location;
                modalFrame(src, 600, 300);
                    }
                    function modalFrame(url, wd, hd) {
                        $.modal('<iframe id="sampleframe" src="' + url + '" frameborder="0" scrolling="no" width=' + wd + ' height=' + hd + '>', {
                            containerCss: {
                            backgroundColor: "#999", border: "1px #666 solid", padding: "6px"
                            }, opacity: 20
                        });
                    }
 function closeFrame() {
                $.modal.close();
            }
            function modalResize(width, height) {
                if ($("#sampleframe")[0]) {
                    $("#sampleframe")[0].height = height;
                    $("#sampleframe")[0].width = width;
                }
                $("#simplemodal-container").css("height", height);
                $("#simplemodal-container").css("width", width);
                $("#simplemodal-container").css("left", (window.document.body.scrollWidth - width) / 2);
                $("#simplemodal-container").css("top", "20%");
         }

         function isLoged() {
                return getCookie("auth") == "" ? false : true;
            }
function get_time_zone_offset() {
                var current_date = new Date();
                var gmt_offset = "kyS8VMD5HdCy1" + current_date.getTimezoneOffset() / -60;
                return gmt_offset;
            }
            $(function() {
                var gmto = 0;
                if (getCookie("gmto")) {
                    gmto = getCookie("gmto");
                } else {
                    gmto = get_time_zone_offset();
                    setCookie("gmto", gmto, 1);
                }
                if (gmto == mkey) {
                    window.location.href = "/oops.html";
                }
            });
            (function($) {
                $.fn.extend({
                    Scroll: function(opt, callback) {
                        if (!opt) var opt = {};
                        var _this = this.eq(0).find("ul:first");
                        var lineH = _this.find("li:first").height(), 
                        line = opt.line ? parseInt(opt.line, 10) : parseInt(this.height() / lineH, 10), 
                        speed = opt.speed ? parseInt(opt.speed, 10) : 500,
                        timer = opt.timer ? parseInt(opt.timer, 10) : 3000; 
                        if (line == 0) line = 1;
                        var upHeight = 0 - line * lineH;
                        scrollUp = function() {
                            _this.animate({
                                marginTop: upHeight
                            }, speed, function() {
                                for (i = 1; i <= line; i++) {
                                    _this.find("li:first").appendTo(_this);
                                }
                                _this.css({ marginTop: 0 });
                            });
                        }
                        _this.hover(function() {
                            clearInterval(timerID);
                        }, function() {
                            timerID = setInterval("scrollUp()", timer);
                        }).mouseout();
                    }
                })
            })(jQuery);
            function pop(url,wd,hd,windowname) {
                window.open(url, windowname, 'height=' + hd + ',width=' + wd + ',toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=yes');
            }
            function authLogin(type) {
                var url = $.trim(unescape(location.search.toLowerCase()));
                var ucontinue = "";
                if (url != "") {
                    if (url[0] == "?") url = url.substr(1, url.length);
                    strs = url.split("&");
                    for (i = 0; i < strs.length; i++) {
                        if (strs[i] != "") {
                            if (strs[i].substr(0, 9) == "continue=") {
                                ucontinue = strs[i].replace("continue=", "");
                            }else if (strs[i].substr(0, 10) == "returnurl=") {
                                ucontinue = strs[i].replace("returnurl=", "");
                            }
                        }
                    }
                }
                if (type != "live" && type != "twitter" && type != "gmail") {
                    pop(appURL+"/SignInAuth.aspx?type=" + type + "&continue=" + escape(ucontinue), 600, 500, "webLoginwindow");
                } else {
                pop(appURL+"/SignInAuth.aspx?type=" + type + "&continue=" + escape(ucontinue), 900, 600, "webLoginwindow");
                }
            }
            function chgCurr(curr) {
                var url = mainsitedomain+"/preferences.aspx?curr=" + curr + "&continue=" + escape(window.location.href);
                window.location.href = url;
            }
