﻿$(function(){
    var locat = location.pathname;
    var   regu   =   "^(/news/)"     
    var   re   =   new   RegExp(regu);     
    if(locat.search(re) == -1){
        $(".top_nav2 ul").eq(0).show();
        $(".top_nav div").eq(0).addClass("MeunSelect");
    } else {
        $(".top_nav2 ul").eq(1).show();
        $(".top_nav div").eq(1).addClass("MeunSelect");
    }
    
    //读取会员信息
     $.ajax({ 
        type: "POST", 
        dataType:"json",
        url: "/ServiceManager/Personal.ashx", 
        data:"Command=MemberInfo&email=&pwd=",
        success: function(res) { 
            if(res.ID !=0){
                $("#Login").show();
                $("#nuLogin").hide();
                $("#Login span").html(res.Name+"光临");
            } else {
                $("#Login").hide();
                $("#nuLogin").show();
            }
        }
    });
    
	

	
	
    //显示分店列表
     $.getJSON("/ServiceManager/DataActions.ashx",{dateItem:"ShopList",PageSize:10,Page:1},
        function(res) {
            var tobody = "<li><!--[if lte IE 6]><a href=\"#nogo\"><table><tr><td><![endif]--><dl class=\"one\"><dt><a href=\"/ListShop.aspx\"><img src=\"/images/top_b2.png\" /></a></dt>";
            $.each(res.ShopList,function(i,n){
                if(i=1)
                {
                tobody +="<dd><a href=\"http://"+ n.F5_T097 +"\">"+ n.F1_T019 +"</a></dd>";
                }
            });
            tobody += "<dd class=\"last\"><a href=\"/ListShop.aspx\"  ><< 全部分店 >></a></dd></dl><!--[if lte IE 6]></td></tr></table></a><![endif]--></li>";
            $("#menu").html(tobody);   
        }
    );

    //商品搜搜
    $("[name='buttonViewProduct']:input").click(function(){
        var keys = $("[name='key']:input").val();
        if(keys.length == 0){
            alert('请输入商品名称');$("[name='key']:input").focus();
        } else {
            location.href = "/ListProduct.aspx?key=" + escape(keys);
        }
    });
        //资讯搜搜
    $("[name='buttonViewNews']:input").click(function(){
        var keys = $("[name='key']:input").val();
        if(keys.length == 0){
            alert('请输入搜索内容');$("[name='key']:input").focus();
        } else {
            location.href = "/news/news_list.aspx?key=" + escape(keys);
        }
    });
    //推荐店铺
    $.ajax({ 
        ContentType: "text/xml;UTF-8",
        type: 'GET',     
        url: "/webimg/xml/homepage/store.xml",   
        dataType: 'xml',   
        timeout: 1000,   
        success: function(xml){
            var tobody = "";
            $(xml).find("data item").each(function(){
                tobody += "<li><a href=\""+ $(this).children("Link").text() +"\">"+ $(this).children("Name").text() +"</a></li>";
            });
            tobody += "";
            $(".top_nav2 ul").eq(0).html(tobody);
        }
    });
    
    //友情连接
    $.ajax({ 
        ContentType: "text/xml;UTF-8",
        type: 'GET',     
        url: "/webimg/xml/homepage/frendlinks.xml",   
        dataType: 'xml',   
        timeout: 1000,   
        success: function(xml){
            var tobody = "";
            $(xml).find("data item").each(function(){
               tobody += "<li><a href=\""+ $(this).children("Link").text() +"\" target='_blank'>"+ $(this).children("Name").text() +"</a></li>";
            });
            $(".friendlink_txt ul").html(tobody);
        }
     });
    
   //底部连接
     $.ajax({ 
        ContentType: "text/xml;UTF-8",
        type: 'GET',     
        url: "/webimg/xml/baseinfo.xml",   
        dataType: 'xml',   
        timeout: 1000,   
        success: function(xml){
            var tobody = "";
            $(xml).find("data Item").each(function(){
               tobody += "<li><a href=\"/showInfo.aspx?id="+ $(this).children("Field_Id").text() +"\">"+ $(this).children("Field_Text").text() +"</a></li><li>|</li>";
            });
            $(".bottom ul").html(tobody+"<li><a href=\"http://console.dajiankang.com/substoreConsole/View/login.aspx\">商家入口</a></li><li>|</li><li><a href=\"http://console.dajiankang.com/console/media/login.aspx\">媒体入口</a></li><li>|</li><li><a href=\"http://console.dajiankang.com/console/agent/login.aspx\">媒体代理</a></li>");
        }
     });
});

function unLogin()
{
    $.ajax({ 
        type: "POST", 
        dataType:"json",
        url: "/ServiceManager/Personal.ashx", 
        data:"Command=unLogin&email=&pwd=",
        error:function(){alert('Member is null...');}, 
        success: function(res) { 
            $("#Login").hide();
            $("#nuLogin").show();
        }
    });
}

function showMeun(item)
{
    $(".top_nav2 ul").hide();
    $(".top_nav2 ul").eq(item).show();
}

