/*var address = "不限";
var tp = "不限";
var tp0 = "不限";
var isAll = true;
var name = null;
var typeName = "花木介绍";
var pages = 0;
var storage = window.sessionStorage;
/!**
 * 由encyclopedia.js中getContent(str)方法跳至此并获取此参数
 * contentNewsId参数用于获取新闻内容
 * @type {any}
 *!/
var contentNewsId = storage["contentNewsId"];
var addressActive = storage["addressActive"];
console.log("contentNewsId:="+contentNewsId+"----"+"addressActive:="+addressActive);*/
$(function () {
    UrlSearch();
    $(".logo button").click(function () {
        var content = $("#Sou").val();
        var type = $("#selectType").val();
        if(content.trim().length<2){
            layer.tips("请至少输入两个字符","#Sou");
        }else{
            if(type=="供应"){
                window.location.href="/spzs/?search="+content;
            }else if(type=="采购"){
                window.location.href="/syjh/qiugou.htm?search="+content;
            }else if(type=="企业"){
                window.location.href="/qyml/?search="+content;
            }else if(type=="资讯"){
                window.location.href="/hyxx/informationSearch.html?search="+content;
            }else if(type=="百科"){
                window.location.href="/qyfw/encyclopediaSearch.html?search="+content;
            }
        }
    });
    $(".address").click(function(){
        window.location.href="/qyfw/encyclopediaThreePage.html?type="+$(this).html();
    });
    var newsid = parseInt(window.newsid);
    if(!newsid){
        var weburl = window.location.href;
        newsid = weburl.substring(weburl.lastIndexOf('/')+1).split(".")[0];
    }
    newsid = parseInt(newsid);
    if(newsid){
        addSeeTime();
        var info = getInfo(newsid);
        if(info!=null){
            console.log(info);
            document.title=info.title;
            if(info.kwd){
                $("meta[name='keywords']").attr('content',info.kwd);
            }
            if(info.des){
                $("meta[name='description']").attr('content',info.des);
            }
            $("#content_title").html(info.title);
            if(info.path){
                $(".title_img").attr("src",formatImgUrl(info.path))
            }else {
                $(".title_img").hide();
            }
            if(info.content==null||info.content==""){
                $("#content_content").html("无详细内容");
            }else{
                $("#content_content").html(info.content.replace(/{{/g,'<').replace(/}}/g,'>').replace(/amp;/g,''));
            }
            $("#content_title").css({"text-align":"center","font-size":".36rem"});
            $("#content_content").css({"font-size":".16rem","line-height":"30px"});
            $(".list_01").show();
            var typename = info.typename;
            if(typename == "法律咨询"||typename =="规章制度"){
                typename = "法律法规";
            } else if (typename == "合同样本"){
                typename = "合同范文";
            }
            $("#source").html(info.source?'来源:'+info.source:'来源:网络');
            $("#date").html(info.dateandtime?'日期:'+info.dateandtime.slice(0,10):'未知');
            $("#type").html('分类:'+typename);
            $("a[class='address']").each(function(index, result){
                if($(this).html() == typename){
                    $(this).attr("class", "address active");
                }
            });
        }else{
            window.location.href="/qyfw/";
        }
    }else{
        window.location.href="/qyfw/";
    }
/*    // //修改分类标题颜色
    if(addressActive != null && addressActive != undefined && addressActive != ""){
        $("a[class='address']").each(function(index, result){
            if($(this).html() == addressActive){
                $(this).attr("class", "address active");
                return;
            }
        })
    }
    // //获取详细内容
    if(contentNewsId != null && contentNewsId != undefined && contentNewsId != ""){
        getContent(contentNewsId)
    }
    // /!**
    //  * 设置本地缓存
    //  *!/
    $(".address").click(function(){
        typeName = $(this).html();
        storage["url"] = $(this).html();
        // 修改颜色
        $(this).parent().siblings().children().css("color", "#333333");
        $(this).css("color", "#ff774d");
        //获取数据
        console.log(typeName);
        getInfo(typeName,0);
        getTotal(typeName);
    })*/
});
/*
/!**
 * 获取详细内容
 *!/
function getContent(str){
    if(str != ''){
        $.ajax({
            url: url+"/qyfw/commerce/commercechaxunid",
            data: {
                newsid: str
            },
            type: "get",
            dateType: "json",
            async: false,
            success: function success(response, status, xhr) {
                console.log(response);
                if(response.length > 0){
                    $(".list").attr("style","display: none");
                    $(".page").attr("style","display: none");
                    $(".list_01").attr("style","display: block");
                    var title = "<h1>"+response[0].title+"</h1>";
                    $("#content_title").html(title);
                    $(".title_img").attr("src",response[0].picurl);
                    $("#content_content").html(response[0].content);
                } else {
                    layer.msg("数据为空")
                }
            },
            error: function error() {
                layer.msg('未知错误,请联系客服!', { icon: 5 });
            }
        });
    } else {
        layer.msg("无详细内容")
    }
}*/

function UrlSearch(){
    var str=window.location.href; //取得整个地址栏
    var num=str.indexOf("?");
    str=str.substr(num+1); //取得所有参数   stringvar.substr(start [, length ]

    var arr=str.split("&"); //各个参数放到数组里
    for(var i=0;i < arr.length;i++){
        num=arr[i].indexOf("=");
        if(num>0){
            name=arr[i].substring(0,num);
            value=decodeURI(arr[i].substr(num+1));
            this[name]=value;
        }
    }
}

function getInfo(newsid) {
    var result = null;
    $.ajax({
        url: url+"/qyfw/commerce/commercechaxunid",
        data: {
            newsid: newsid
        },
        type: "get",
        dateType: "json",
        async: false,
        success: function (response, status, xhr) {
            console.log(response);
            if(response.length == 1){
                result = response[0];
            }
        },
        error: function () {
            layer.msg('未知错误,请联系客服!', { icon: 5 });
        }
    });
    return result;
}

function addSeeTime() {
    $.ajax({
        url:url+"/news/zxbk/addBkSee",
        data: {"id":window.newsid},
        type: "get",
        dateType: "json",
        async: true
    });
}