var SiteDomain = ''; //需要进行跳转的网站主域名
var SiteDomain1 = ''; //需要进行跳转的网站主域名
var LipinceDomain = ''; //需要进行跳转的礼品兑换册网站
var SiteJS = ''; //JS链接信息
var SiteImageDomain = "http://img.li63.com"//网站图片地址
 
function GetLoad(n) {
    $("#c" + n).find("ul").each(function() {
        $(this).mouseover(function() {
            $("#c" + n + " ul").find(".m").css("display", "");
            $("#c" + n + " ul").find(".tselect").css("display", "none");
            $(this).find(".m").css("display", "none");
            $(this).find(".tselect").css("display", "block");
            $(this).stop(true, true);
        });
    });
}

function SetHome(obj, vrl) {
    try {
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
    }
    catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', vrl);
        }
    }
}

 
function addfavoriteli() 
{ 
    try {
        window.external.addFavorite('http://www.li63.com', '礼仪之邦送礼网');
    }
    catch (e) {
        try {
            window.sidebar.addPanel('礼仪之邦送礼网', 'http://www.li63.com', "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
} 
 $(function () {
 
    $("#topSreach").keydown(function(event) {
        if (event.which == 13) {
            $("#t_search").click();
        }
    });

    /*搜索框得到焦点*/
    $("#topSreach").focus(function () {
        $(this).css("color", "#4a4a4a");
        if ($(this).val() == "请输入简短关键字,如:项链") {
            $(this).val("");
        }
    });
    /*搜索框失去焦点*/
    $("#topSreach").blur(function () {
        if ($(this).val() == "" || $(this).val() == null) {
            $(this).css("color", "#b7b7b7");
            $(this).val("请输入简短关键字,如:项链");
        }
    });
    $("#siteNavContent").mouseover(function() {
        $(this).css("display", "block");
        $("#siteNav").attr("class", "select right1");
    }).mouseout(function() {
    $("#siteNav").attr("class", "right1");
        $(this).css("display", "none");
    });
    //顶部样式分类JS
    $(".menu ul li[name='menu']").mouseover(function() {
        var s = this.id;
        s = s.replace("menu", "");
        $("#mc" + s).css("display", "block");
        $(".menu ul li[name='menu']").attr("class", "bg");
        $(this).attr("class", "select bg");
    }).mouseout(function() {
        var s = this.id;
        s = s.replace("menu", "");
        $("#mc" + s).css("display", "none");
        $(this).attr("class", "bg");
        $(".menu ul li[name='menu']").attr("class", "bg");
    });
    $(".menu div[name='mc']").mouseover(function() {
        $(this).css("display", "block");
        var str = this.id;
        str = str.replace("mc", "");
        $(".menu li[name='menu']").attr("class", "bg");
        $("#menu" + str).attr("class", "select bg");
    }).mouseout(function() {
        $(this).css("display", "none");
        $(".menu li[name='menu']").attr("class", "bg");
    });
 
    $(".menu ul[name='menu1']").mouseover(function () {
        var s = this.id;
        s = s.replace("menu", "");
        $("#mc" + s).css("display", "block");
    }).mouseout(function() {
        var s = this.id;
        s = s.replace("menu", "");
        $("#mc" + s).css("display", "none");
       
    });

    $(".menu div[name='mc1']").mouseover(function () {
        $(this).css("display", "block");
    }).mouseout(function() {
        $(this).css("display", "none");
        
    });
    if ($("#disID").html() == 1) {
        $("#columnList").show();
    }
    else {
        $("#columnMenu em").addClass("tb");
    }
    
    $("#columnMenu,#columnList").hover(function () {
        $("#columnList").show();        
    }, function() {
        if ($("#disID").html() == "0") {
            $("#columnList").hide(); 
        } else {
            $("#columnList").show();
            
        }
    })
    $("#columnList ul").last().css({"border-bottom": "0px" });

   
    //$("#columnList ul").hover(function () {
    //    //得到id值
    //    var ids = $(this).attr("id");
    //    var $target = $(this);
    //    var area = $target.children("li").eq(0);
    //    var contli = $target.children("li").eq(1);

    //    //显示listdiv
    //    contli.show();
    //    area.css("border-top", "solid 1px #CB1007").css("border-bottom", "solid 1px #CB1007");
       

    //}, function () {
    //    var ids = $(this).attr("id");
    //    var $target = $(this);
    //    var areali = $target.children("li").eq(0);
    //    var contli = $target.children("li").eq(1);
    //    //contli.hide();

    //    areali.css("border", "solid 1px #ffffff").css("border-bottom", "solid 1px #E3E0D1");
     // });
    var Thread = null;
    $(".area span").hover(function () {
        //清空timeout
        window.clearTimeout(Thread);
        //每次hover的时候隐藏所有显示的列表
        $('.listDIv').each(function (index, element) {
            element = $(element);
            var elem_span = element.prev().find('span.addCss');
            element.hide();
            elem_span.css("padding", "1px 0px").removeClass("addCss");
        });
        //重新显示当前hover的项
        $(this).css("padding","0px").addClass("addCss");
        $(this).parent(".area").siblings(".listDIv").css("display", "block");

    }, function () {
        var $span = $(this);
        $span.parent().next('.listDIv').unbind('mouseover').mouseover(function () {
            //清空timeout
            window.clearTimeout(Thread);
            var $this = $(this);
            $this.show();
            var span = $this.prev().find('>span');
            span.css("padding", "0px").addClass("addCss");
            $this.unbind('mouseout').mouseout(function () {
                //清空timeout
                window.clearTimeout(Thread);
                Thread = window.setTimeout(function(){
                    span.css("padding", "1px 0px").removeClass("addCss");
                    $this.hide();
                }, 100);
            });
        });
        Thread = window.setTimeout(function () {
            $span.css("padding", "1px 0px").removeClass("addCss");
            $span.parent(".area").siblings(".listDIv").css("display", "none");
        }, 100);
    });

    $(".allDiv td").last().css("border", "0px");
});

function _deletecart(id){
    LI.Common.DeleteCart(id, function (html, count) {
        $("#ShoppingCartCount").html(count);
        $("#ShoppingCartCountredText").html(count);
        $("#mc_1").html(html);
    });
}
function GetSiteMove() {
    $("#siteNav").attr("class", "select right1");
    $("#siteNavContent").css("display", "block");
}
function GetSiteOut() {
    $("#siteNav").attr("class", "right1");
    $("#siteNavContent").css("display", "none");
}
function _ProSearch() {
    var _val = $("#topSreach").val();
    if (_val == "" || _val.indexOf("请输入") != -1) {
        $("#topSreach").css("color", "#b7b7b7");
        $("#topSreach").val("请输入你要搜索的内容");
    }
    else {
        location.href = encodeURI("/lipin/?k=" + escape(_val));
        $("#topSreach").css("color", "#4a4a4a");
        $("#topSreach").val(_val);
    }
}
/*表示用户注销=======================================*/
function login_out() {
    var urls = SiteDomain1 + "/javascript/Ajax/LoginAjax.ashx?Action=LoginOut";
    htmlobj = $.ajax({ url: urls, async: true, cache: false, success: function(req) {
        window.location.href = "";
    }
    });
}
//当前用户的登录状态=======================================*/
function GetLogin() {
    var urls = SiteDomain1 + "/javascript/ajax/LoginAjax.ashx?Action=GetLoginDetail";
    $.ajax({ url: urls, async: true, cache: false, dataType: "jsonp", jsonp: "callbackparam", jsonpCallback: "json_callbackparam", success: function(req) {
        $("#H_lBar").html(req);
    }
    });
}
//判断是否登录
function IsUserLogin() {
    var _return = false;
    $.ajax({ url: SiteDomain1 + "/javascript/Ajax/LoginAjax.ashx", data: { Action: "IsUserLogin" }, cache: false, async: false, success: function(html) {
        if (html == "1") {
            _return = true;
        }
    }
    });
    return _return;
}
function AddToUserLogin() {//跳转到登录页面
    window.location.href = 'http://member.li63.com/login/index.aspx';
}
//跳转到用户注册页面
function RegLoginUrl() {
    window.location.href = 'http://member.li63.com/login/registpersonal.aspx';
}
/*获取零售商城购物车列表以及购物车数量
=================================*/
/*===========ProductIntegral===========*/
/*1为零售礼品，2为积分礼品*/
function GetShoppingCount() {
    $.ajax({ url: SiteDomain1 + "/javascript/ajax/ShoppingCard.aspx", dataType: "jsonp", jsonp: "callbackparam", jsonpCallback: "jsoncallbackparam", async: true, cache: true, data: { Action: "GetShoppingCartListDataSource", ProductType: 1, IsFlag: 2 }, success: function(html) {
        var DataSource = eval("(" + html + ")");
        var indexcount = 0;
        var string = "";
        var allshopprice = 0;
        var count = 0;
        if (DataSource.length > 0) {
            for (var i = 0; i < DataSource.length; i++) {
                if (indexcount <= 3) {
                    var Pro_ShopPrice = parseFloat(DataSource[i].Price);
                    var Pro_Quantity = parseFloat(DataSource[i].Quantity);
                    var Pro_NickName = (DataSource[i].ProductName.length > 10) ? DataSource[i].ProductName.substring(0, 10) + "..." : DataSource[i].ProductName;

                    string += "<ul>";
                    string += " <li class=\"img\"><a  target=\"_blank\"  href=\"/lipin" + DataSource[i].ProductId + ".html\"><img src=\"" + DataSource[i].ProductImage + "\" title=\"" + DataSource[i].ProductName + "\" alt=\"" + DataSource[i].ProductName + "\" /></a></li>";
                    string += "<li class=\"text\"><a  target=\"_blank\"  href=\"/lipin" + DataSource[i].ProductId + ".html\">" + DataSource[i].ProductName.length>12? +DataSource[i].ProductName.substring(0,12):DataSource[i].ProductName+ "</a><br />" + DataSource[i].ProductNickName + "</li>";
                    string += "<li class=\"p\"><font color=red>￥" + Pro_ShopPrice.toFixed(2) + "</font> X " + Pro_Quantity + "<br /><a href=\"javascript:_ShoppintCartDel('" + DataSource[i].UniqueID + "')\">删除</a></span></li>";
                    string += "</ul>";
                }
                count = count + DataSource[i].Quantity;
                allshopprice += Pro_ShopPrice * Pro_Quantity;
                indexcount++;
            }
            string += "<div style=\"float:left; width:100%; font-size:12px;padding-bottom:5px;padding-top:10px; text-align:right;\">";
            var setAll = indexcount > 3 ? "<a href=\"http://member.li63.com/cart/cart.aspx\">查看全部>></a>" : "";
            string += "共<font color=red size=3><b>" + count + "</b></font>件礼物，共计<font size=3 color=red><b>￥" + allshopprice + "</b></font>元 " + setAll;
            string += "</div>";
        }
        else {
            string += '<div style="width:100%; height:60px;line-height:60px; text-align:center; color:#989896; float:left" class=\"H_sf_div\" id=\"H_sf_div\">';
            string += '<a href=\"/lipin/\" title=\"零售列表页面\">您还没有选购礼品,赶快来选礼吧！</a>';
            string += '</div>';
        }
        $("#mc_1").html(string); //更新购物车区域
        $("#ShoppingCartCount").html(count); //更新网站头部购物车区域购物车数量
    }
    });
}
 
function AddShoppingCart(ProID) {
    var shoppingcount = $("#iStock");
    var _count = (shoppingcount.length > 0) ? Number(shoppingcount.val()) : 1; //需要进行添加的购物车数量
    //创建一个提示框
    var item = "<ul id=\"DalogFavoritesContent\"><li><span style=\"font-size:12px;\">正在加入购物车...</span></li></ul>";
    dialog("<font color=\"#c01818\">添加礼品袋</font>", "text:" + item, "353px", "140px", "CardDiv", true);
    LI.Common.AddCart(ProID, _count, function (b) {
        if (b == true) {
            item = "<li class=\"liimg\">礼物已经成功添加到礼品袋<br /><a href=\"javascript:GetClose();\" title=\"继续选礼\" style=\"color:#c01818;\" ><<继续选礼</a>&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"button\" value=\"去礼品袋结算\" style=\" font-weight:bold;background:url(/LI63Image/btn.gif) -152px -240px;border:none; width:91px; height:30px; text-align:center; line-height:30px; color:#fff; cursor:pointer;\" onclick=\"javascript:location.href='http://member.li63.com/cart/cart.aspx'\" /></li>";
            LI.Common.GetCart(function (html, count) {
                $("#ShoppingCartCount").html(count);
                $("#ShoppingCartCountredText").html(count);
                $("#mc_1").html(html);
            });
        }
        else {
            item = "<li>加入礼品袋失败</li>";
        }
        $("#DalogFavoritesContent").html(item);
    });
}
 
/*===================================*/
/*添加收藏夹信息2011415*/
function AddProFavorite(ProID) {
     LI.Common.GetLoginState(function (islogin) {
         if (islogin) {
             var item = "<ul id=\"DalogFavoritesContent\"><li><img src=\"/web_images/body/productshow/loading.gif\" /></li></ul>";
             dialog("<font color=\"#c01818\">添加收藏夹</font>", "text:" + item, "353px", "140px", "CardDiv", true);
             LI.Common.AddCollec(ProID, function (b) {
                 if (b == true) {
                     item = "<li class=\"liimg\">礼品成功添加到您的收藏夹<br /><a href=\"javascript:GetClose();\" title=\"继续选礼\" style=\"color:#c01818;\" ><<继续选礼</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"http://member.li63.com/home/collec.aspx\" title=\"查看我的收藏夹\" target=\"_blank\" >查看我的收藏夹>></a></li>"
                     $("#DalogFavoritesContent").html(item);
                 }
             });
         }
         else {
             IntegralLoginRewrite(ProID);
         }
    });
}
 

/*=====================================================================================
登录-注册提示框通用接口(CallbackFunction:登录成功执行函数 Params[]:参数数组)===========*/
function IntegralLoginRewrite(ProID) {

    var str = "<div id=\"mai\"><iframe width=\"600px\" height=\"270px\" src=\"/web/LoginRewrite/MemberLogin.aspx?ID=" + ProID + "\" scrolling=\"no\" frameborder=\"0\"></iframe></div>";
    var height = "auto";
    var width = "600px";
    dialog("用户登录", "text:" + str, width, height, "IntegralLoginRewrite", true);
    oncodeclick('/mincode.aspx', $(".IntegralLoginRewrite #vcodeimg")[0]); //重置验证码
    $("#floatBox .title span").html("").attr("title", "关闭");
    //判断是否选中
    $(".chk").click(function() {
        var clas = $(this).attr("class");
        if (clas == "chk") {
            $(this).addClass("chks");
        } else if (clas == "chk chks") {
            $(this).removeClass("chks");
        }

    });
}
/*===================================*/
/*jquery弹出框效果*/
var dialogFirst = true;
var dialogidFirst = true;
function dialog(title, content, width, height, cssName, isshowtitle) {
    if (dialogFirst == true) {
        var temp_float = new String;
        temp_float += "<div id=\"floatBox\" class=\"floatBox\">";
        temp_float += "<div class=\"title\"><h3></h3><span>关闭</span></div>";
        temp_float += "<div class=\"content\"></div>";
        temp_float += "</div>";
        $("body").append(temp_float);
        dialogFirst = false;
    }
    if (isshowtitle == false) { $("#floatBox .title").remove(); }
    $("#floatBox .title span").click(function() {
        $("#floatBoxBg").hide(100);
        $("#floatBox").hide(100, function() { $("#Box-if").hide(); });
    });

    $("#floatBox .title h3").html(title);
    contentType = content.substring(0, content.indexOf(":"));
    content = content.substring(content.indexOf(":") + 1, content.length);
    switch (contentType) {
        case "url":
            var content_array = content.split("?");
            $("#floatBox .content").ajaxStart(function() {
                $(this).html("loading...");
            });
            $.ajax({
                type: content_array[0],
                url: content_array[1],
                data: content_array[2],
                error: function() {
                    $("#floatBox .content").html("error...");
                },
                success: function(html) {
                    $("#floatBox .content").html(html);
                }
            });
            break;
        case "text":
            $("#floatBox .content").html(content);
            break;
        case "id":
            if (dialogidFirst == true) { var htmlcontent = $("#" + content + "").html(); $("#" + content + "").remove(); $("#floatBox .content").html(htmlcontent); dialogidFirst = false; }
            break;
        case "iframe":
            $("#floatBox .content").html("<iframe src=\"" + content + "\" width=\"100%\" height=\"" + (parseInt(height) - 30) + "px" + "\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" allowtransparency=\"true\"></iframe>");
    }

    $("#floatBoxBg").show();
    $("#Box-if").show();
    $("#floatBoxBg").css("opacity", "0.5");
    $("#floatBox").attr("class", (cssName == "") ? "floatBox" : cssName);
    $("#floatBox").css({ display: "block", width: width, height: height });
    //用于解决谷歌下获取滚动条高低
    var top = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
    $("#floatBox").css("top", top + (document.documentElement.clientHeight - $("#floatBox").height()) / 2);
    $("#floatBox").css("left", document.documentElement.scrollLeft + (document.documentElement.clientWidth - $("#floatBox").width()) / 2);
}
/*刷新验证码方法*/
function oncodeclick(page, theobject, parameter) {
    var url = page + "?" + (parameter == null ? "" : parameter + "&") + "date=" + new Date().getTime();
    $("#" + theobject).attr("src", url);
}
/*显示注册的界面*/
function registers() {
    $("#floatBox .title h3").html("用户注册");
}
/*显示登录的界面*/
function logins() {
    $("#floatBox .title h3").html("用户登录");
}

/*关闭*/
function GetClose() {
 
    $("#floatBox").css("display", "none");
}



function GetLoginString() {
 
    if (str == "")
        $("#iframeContent").html(GetLoginStr());
    else
        $("#iframeContent").html(str);
}

function GetLoginStr() {
    var str = '';
    str += '<ul>';
    str += '<li class="lititle">账&nbsp;号：</li>';
    str += '<li style=" width:130px"><input type="text" value="" id="name" class="UserTxt" /></li>';
    str += '</ul>';
    str += '<ul>';
    str += '<li class="lititle">密&nbsp;码：</li>';
    str += '<li style=" width:130px"><input type="password" value="" id="pwd" class="UserTxt" /></li>';
    str += '</ul>';

    str += '<ul>';
    str += '<li class="lititle">验证码：</li>';
    str += '<li style=" width:80px"><input type="text" value="" id="code" class="UserTxt" style="width:70px;" /></li>';
    str += '<li style=" width:50px"><img src="/mincode.aspx"  onclick="javascript:oncodeclick(\'mincode.aspx\',this,\'\');" height=23 /></li>';
    str += '</ul>';
    str += '<ul style=" padding:0px;">';
    str += '<li class="lititle">&nbsp;</li>';
    str += '<li style="width:100px"><input type="button" hidefocus="hidefocus"class="UserSubmit" value="" onclick="TitleLogin();" /></li>';
    str += '</ul>';
    return str;
}


var titleSpan = "User";
$(function () {
    //网站底部的荣誉证hover事件
    $(".Honor li").hover(function () {
        var cls = $(this).attr("id");
        if (cls == "Honor_li1") {
            $(this).siblings("li").children(".img_Y1").css("display", "block");
        } else if (cls == "Honor_li2") {
            $(this).siblings("li").children(".img_Y2").css("display", "block");
        } else if (cls == "Honor_li3") {
            $(this).siblings("li").children(".img_Y3").css("display", "block");
        } else if (cls == "Honor_li4") {
            $(this).siblings("li").children(".img_Y4").css("display", "block");
        }
    }, function () {

        var cls = $(this).attr("id");
        if (cls == "Honor_li1") {
            $(this).siblings("li").children(".img_Y1").css("display", "none");
        } else if (cls == "Honor_li2") {
            $(this).siblings("li").children(".img_Y2").css("display", "none");
        } else if (cls == "Honor_li3") {
            $(this).siblings("li").children(".img_Y3").css("display", "none");
        } else if (cls == "Honor_li4") {
            $(this).siblings("li").children(".img_Y4").css("display", "none");
        }

    });
$("#titleUserLogin,#titleLpcLogin").mouseover(function() {

        if ($(this).attr("id") == "titleUserLogin") {

            $("#titleUserLogin").attr("class", "select");
            $("#titleLpcLogin").attr("class", "none");
            $("#iframeContent").show();
            $("#iframeBooklet").hide();
        } else {
            $("#titleUserLogin").attr("class", "");
            $("#titleLpcLogin").attr("class", "select none");
            $("#iframeContent").show();
            $("#iframeContent").hide();
            $("#iframeBooklet").show();
        }
    });
    
})


function TitleLogin() {
    var name = $("#name");
    var pass = $("#pwd");
    var code = $("#code");
    if (name.val().trim() == "") {
        alert("请输入用户名！");
        name.focus();
        return;
    }
    else if (pass.val() == "") {
        alert("请输入密码！");
        pass.focus();
        return;
    }
    else if (code.val().trim() == "") {
        alert("请输入验证码！");
        code.focus();
        return;
    }
    else {
        LI.Common.UserLogin(name.val().trim(), pass.val(), code.val().trim(), function (s) {
            if (s == true) {
                window.location.reload();
            }
        })
    }

    }



function Cookies() {
    this.getCookie = function (key) {
        var cookie = document.cookie;
        var cookieArray = cookie.split(';');
        var val = "";
        for (var i = 0; i < cookieArray.length; i++) {
            if (cookieArray[i].Trim().substr(0, key.length) == key) {
                val = cookieArray[i].Trim().substr(key.length + 1);
                break;
            }
        }
        return unescape(val);
    };
    this.getChild = function (key, childKey) {
        var child = this.get(key);
        var childs = child.split('&');
        var val = "";
        for (var i = 0; i < childs.length; i++) {
            if (childs[i].Trim().substr(0, childKey.length) == childKey) {
                val = childs[i].Trim().substr(childKey.length + 1);
                break;
            }
        }
        return val;
    };
    this.setCookie = function (key, value) {
        var cookie = "";
        if (!!key && !!value)
            cookie += key + "=" + escape(value) + ";";
        if (!!arguments[2])
            cookie += "expires=" + arguments[2].toGMTString() + ";";
        if (!!arguments[3])
            cookie += "domain=" + arguments[3] + ";";
        if (!!arguments[4])
            cookie += "path=" + arguments[4] + ";";
        document.cookie = cookie;
    };
    this.remove = function (key) {
        var date = new Date();
        date.setFullYear(date.getFullYear() - 1);
        var cookie = " " + key + "=;expires=" + date + ";"
        document.cookie = cookie;
    }
}

function setCookies(name, value) {
    var Days = 30;//此 cookie 将被保存 30 天
    var exp = new Date();　　　　 //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expire=" + exp.toGMTString();
}
function getCookies(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;
}
function isIE7() {
    var browser = navigator.appName
    var b_version = navigator.appVersion
    var version = b_version.split(";");
    var trim_Version = version[1].replace(/[ ]/g, "");
    var rs = false;
    if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE7.0") {
        rs = true;
    }
    return rs;
}