﻿var menuImgRoot = "/App_Themes/Default/Images/icon/";
var timeout = null;
function ImgRestore() { $("a[id*='top']").removeClass().addClass("default") };
function setImg() {
    var rootId = $("#hidRootId").val() == undefined ? "" : $("#hidRootId").val();
    switch (rootId) {
        case "31": ImgRestore(); $("#top01").removeClass().addClass("selected");
            break;
        case "36": ImgRestore(); $("#top03").removeClass().addClass("selected");
            break;
        case "39": ImgRestore(); $("#top04").removeClass().addClass("selected");
            break;
        case "40": ImgRestore(); $("#top05").removeClass().addClass("selected");
            break;
        case "41": ImgRestore(); $("#top06").removeClass().addClass("selected");
            break;
        case "42": ImgRestore(); $("#top07").removeClass().addClass("selected");
            break;
        case "46": ImgRestore(); $("#top08").removeClass().addClass("selected");
            break;
        case "sale": ImgRestore(); $('#top09').removeClass().addClass("selected");
            break;
        default: ImgRestore();
    }
}
$(document).ready(function() {
    getCartAmount();
    var rootId = $("#hidRootId").val() == undefined ? "0" : $("#hidRootId").val();
    setImg();

    //$$$$$$$$$$$$导航菜单的切换$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    $("#top01,#catlayer1").hover(function() {//家具餐具
        setImg();
        $("#top01").removeClass().addClass("selected");
        if (timeout != null) { window.clearTimeout(timeout); }
        $(".tnDropDowns").hide();
        $("#catlayer1").show();
    },
         function() {
             timeout = setTimeout("$('#catlayer1').hide();if('" + rootId + "'!='31')document.getElementById('top01').className = 'default'", 500);
         });
    //-----------------------------------------------------------------------
    $("#top03,#catlayer3").hover(function() {//系列床品
        setImg();
        $("#top03").removeClass().addClass("selected");
        if (timeout != null) { window.clearTimeout(timeout); }
        $(".tnDropDowns").hide();
        $("#catlayer3").show();
    },
     function() {
         //setTimeout("ImgRestore();setImg()", 500);
         timeout = setTimeout("$('#catlayer3').hide();if('" + rootId + "'!='36')document.getElementById('top03').className = 'default'", 500);
     });
    //-----------------------------------------------------------------------
    $("#top04,#catlayer4").hover(function() {//卫浴用品
        setImg();
        $("#top04").removeClass().addClass("selected");
        if (timeout != null) { window.clearTimeout(timeout); }
        $(".tnDropDowns").hide();
        $("#catlayer4").show();
    },
     function() {
         timeout = setTimeout("$('#catlayer4').hide();if('" + rootId + "'!='39')document.getElementById('top04').className = 'default'", 500);
     });
    //-----------------------------------------------------------------------
    $("#top05,#catlayer5").hover(function() {//地板/地毯/靠垫
        setImg();
        $("#top05").removeClass().addClass("selected");
        if (timeout != null) { window.clearTimeout(timeout); }
        $(".tnDropDowns").hide();
        $("#catlayer5").show();
    },
     function() {
         timeout = setTimeout("$('#catlayer5').hide();if('" + rootId + "'!='40')document.getElementById('top05').className = 'default'", 500);
     });
    //-----------------------------------------------------------------------
    $("#top06,#catlayer6").hover(function() {//灯饰
        setImg();
        $("#top06").removeClass().addClass("selected");
        if (timeout != null) { window.clearTimeout(timeout); }
        $(".tnDropDowns").hide();
        $("#catlayer6").show();
    },
     function() {
         timeout = setTimeout("$('#catlayer6').hide();if('" + rootId + "'!='41')document.getElementById('top06').className = 'default'", 500);
     });
    //-----------------------------------------------------------------------
    $("#top07,#catlayer7").hover(function() {//窗帘
        setImg();
        $("#top07").removeClass().addClass("selected");
        if (timeout != null) { window.clearTimeout(timeout); }
        $(".tnDropDowns").hide();
        $("#catlayer7").show();
    },
     function() {
         timeout = setTimeout("$('#catlayer7').hide();if('" + rootId + "'!='42')document.getElementById('top07').className = 'default'", 500);
     });
    //-----------------------------------------------------------------------
    $("#top08,#catlayer8").hover(function() {//家用配饰
        setImg();
        $("#top08").removeClass().addClass("selected");
        if (timeout != null) { window.clearTimeout(timeout); }
        $(".tnDropDowns").hide();
        $("#catlayer8").show();
    },
     function() {
         timeout = setTimeout("$('#catlayer8').hide();if('" + rootId + "'!='46')document.getElementById('top08').className = 'default'", 500);
     });
    //-----------------------------------------------------------------------
    $("#top09,#catlayer9").hover(function() {//促销
        setImg();
        $("#top09").removeClass().addClass("selected");
        if (timeout != null) { window.clearTimeout(timeout); }
        $(".tnDropDowns").hide();
        $("#catlayer9").show();
    },
     function() {
         timeout = setTimeout("$('#catlayer9').hide();if('" + rootId + "'!='sale')document.getElementById('top09').className = 'default'", 500);
     });
     //---------------------搜索用js-----------------------------------------------------
     if (document.getElementById("search_txt")) { $("#search_txt").autocomplete("/Ajax/AjaxSearch.aspx") };
    $("#search_txt").focus(function() {
        if ($.trim($("#search_txt").val()) == "关键字或编号查询") {
            $(this).val("");
        }
    }).keypress(function(event) {
        if (event.keyCode == 13) {
            if (!doValidate($(this).val())) {
                return false;
            }
            else {
                location.href = "/search/1--" + encodeURIComponent($.trim($("#search_txt").val().replace("<", "").replace("%", ""))) + ".html";
                return false;
            }
        }
    }).blur(function() {
        if ($.trim($("#search_txt").val()) == "") {
            $(this).val("关键字或编号查询");
        }
    });
    $("#search_btn").click(function() {
        if (!doValidate($("#search_txt").val())) {
            //location.href = "/search/";
        }
        else {
            location.href = "/search/1--" + encodeURIComponent($.trim($("#search_txt").val().replace("<", "").replace("%", ""))) + ".html";
        }
    });
});

//-------------------------------common function--------------------
function QueryString(qs) { var s = location.href; s = s.replace("?", "?&").split("&"); var re = ""; for (i = 1; i < s.length; i++) if (s[i].indexOf(qs + "=") == 0) re = s[i].replace(qs + "=", ""); return re; }
function getCartAmount() { $.ajax({ type: "GET", url: "/ajax/shoppingCartHandle.aspx", data: "action=getCount", success: function(data) { $("#spanCartCount,.cartCount").text(data); }, error: function(msg) { } }); }

//失去焦点
function OnBlurSet(txtname, txtvalue) { var objTxt = document.getElementById(txtname); if (objTxt.value == "") { objTxt.value = txtvalue; return; } }
//获取焦点
function OnFocusSet(txtname, txtvalue) { var objTxt = document.getElementById(txtname); if (objTxt.value == txtvalue) { objTxt.value = ""; return; } }


function contactUS() {
    window.open('/dialog_1.htm', null, 'height=433,width=698,top=' + (screen.height - 500) / 2 + ',left=' + (screen.width - 800) / 2 + ',toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');
}
function doValidate(value)
  {
   vkeyWords=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/;
   if(value==null || value=="")
   {
    alert("请输入正确的查询参数");
    return false
   }
   if(!vkeyWords.test(value))
   {
    alert("您输入的查询参数不正确,请重新输入!");
    return false;
   }   
   return true;
  } 
//---------------电子杂志订阅和退订------------------------
function subscribeCatalog(obj, action) {
    var patrn = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    var strEmail = obj.val().replace(/(^\s*)|(\s*$)/g, "");
    if (!patrn.test(strEmail)) {
        alert("Email格式不正确,请输入正确的Email");
    }
    else {
        if (action == "add") {
            $("#imgSubscribCatalog").show();
        } else {
        $("#imgCancelCatalog").show();
        }
        $.ajax({
            type: "GET",
            url: "/ajax/CatalogSubscrib.aspx",
            data: "email=" + strEmail + "&action=" + action,
            success: function(msg) {
            $("#imgSubscribCatalog,#imgCancelCatalog").hide();
                alert(msg);
                obj.val(""); 
            },
            error: function(msg) {
            $("#imgSubscribCatalog,#imgCancelCatalog").hide();
                alert(msg);
                obj.val(""); 
            }
        });
    }

}
$(document).ready(function() {
    $("#btnSubscribe").click(function() {
        subscribeCatalog($("#txtEmail"), "add");
    });
    $("#btnCancelCatalog").click(function() {
        subscribeCatalog($("#txtTDEmail"), "cancel");
    });
    $("input#txtEmail,input#txtTDEmail").focus(function() {
        if ($.trim($(this).val()) == "请输入E-mail地址") {
            $(this).val("");
        }
    });
});
