﻿// JScript 文件
window.IncludeFile={"header":"head.html","tailer":"tail.html"}; 
window.JsModule=["system/jqframe.js","plugins/grid/js/jqModal.js","plugins/grid/js/jqDnR.js"];
window.EhaiGrid={curPage:1,curRowNum:1,totalRecord:-1,curFun:null,bDiv:null,sc:null,sc3:null};
function WebMain()
{
    $.SetFormat("zh","settypesmall","<a class='qiyeli' style='width:70px;color:#17367E;' href=\"productlist.html?{'Sort':'#1#'}\">#0#</a>","","");
    $.SetFormat("zh","jpgysformat","<li style='height:auto;color:#17367E;text-indent:0;padding:0 7px 2px 10px;margin-left:0;width:233px'><p><a style='font-weight:bold;color:#17367E;' href=\"shop.html?{'id':'#0#'}\" target=\"_blank\">#1#</a></p><p style=\"height:60px;overflow: hidden;\">#2#</p><p><a style=\"width:200px;\" href=\"#3#\">#3#</a></p></li>","");
    
    /*产品分类列表*/$.SendMessage({callback:setbigtype,bLoading:false,type:"DBSelect",id:"getproducttypebig",pm :"<@ehai_typetable%16Id%16eName,Class,Id%16%16%16Class asc%160%16Sort=2 and LENGTH(Class)=2%16@>"});
    /*金牌供应商*/$("#com_jpgys").SendMessage({bLoading:false,type:"DBSelect",id:"jpgysinfo",pm :"<@ehai_user%16Id%16Id,Company,Permission,WebSite%16%16%16altertime desc,GoldRank desc%160%16IsGold=1 and IsShow=1 and IsCheck=1@>%16",format:"jpgysformat",start:0,total:5});
     getCategoryRightData($.PageParam.cptj,$.PageParam.qytj);
    if($.PageParam.Sort)
        {
            getCategoryData($.PageParam.Sort); 
        }
        EhaiGrid.grid = jQuery("#list").jqGrid({
            url:'Default.aspx',
            datatype: 'json',
            colNames:['企业信息'],
            colModel :[ 
            {name:'id',index:'id', width:498,sortable:false}
            ],
            pager: jQuery('#pager'),
            rowNum:4,
            rowList:[4,16,24],
            sortname: 'id',
            sortorder: "desc",
            viewrecords: true,
            imgpath: 'Controls/grid/themes/ehai_front1/images',
            caption: "",
            width:480,
            height:600,
            jsonReader : {
                root: "rows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems: true,
                cell: "cell",
                id: "id",
                userdata: "userdata"
            }
        });
        $(".selbox:last").before("<span>&nbsp;显示&nbsp;</span>"); 
        $(".selbox:last").after("<span>&nbsp;条&nbsp;</span>"); 
        getAdsInfo(19);
    }
//产品分类
function setbigtype(re)
{
    if(re)
    {
        var h=""
        for(i=0;i<re.length;i++)
        {
            h+="<ul style='width:260px'><li class=\"sort\"><a style='color:#17367E;font-weight:bold;' href=\"productlist.html?{'Sort':'"+re[i][1]+"'}\">"+decodeURIComponent(re[i][0])+"</a></li><li id=\"bigtypeli"+re[i][1]+"\"></li></ul>";
        }
         $("#gq_left").html(h);
        for(i=0;i<re.length;i++)
        {
            /*产品小类*/$("#bigtypeli"+re[i][1]).SendMessage({bLoading:false,type:"DBSelect",pm :"<@ehai_typetable%16Id%16eName,Class,Id%16%16%16Class asc%160%16Sort=2 and LENGTH(Class)=4 and left(Class,2)='@>"+re[i][1]+"'%16",format:"settypesmall"});
        }
    }
};
var curSid;
var curPage,curRowNum,totalRecord,curFun,bDiv;
function getNews(page,rowNum,sortname,sortorder,fun,bd)
{            
    EhaiGrid.curPage=page;
    EhaiGrid.curRowNum=rowNum;
    EhaiGrid.curFun=fun;
    EhaiGrid.bDiv=bd;
    if(EhaiGrid.curPage==1)
    $("div.r_slider").css("left","0px");
    if(EhaiGrid.totalRecord==-1)
        getTotalRecord();
    else
        sendMsg();
};
function getTotalRecord()
{
    $.SendMessage({type:"DBSelect",bDefCall:false,callback:sendMsg,pm :"<@ehai_product left join ehai_user on ehai_product.UserName=ehai_user.UserName%16ehai_product.Id%16Count(*)%16%16%16%160%16ehai_product.IsShow=1 and ehai_product.IsCheck=1 and ehai_product.ProductName<>''@>"+(EhaiGrid.sc?EhaiGrid.sc:"")+(EhaiGrid.sc3?EhaiGrid.sc3:"")+"%16"},true);
};
function sendMsg(re,msg)
{
    var t={type:"DBSelect",callback:newsCallback,bDefCall:false,id:"chanpinList",pm :"<@ehai_product left join ehai_user on ehai_product.UserName=ehai_user.UserName%16ehai_product.Id%16ehai_product.Id,ehai_product.Pic,ehai_product.ProductName,ehai_product.Description,ehai_user.Company,ehai_user.Website,DATE_FORMAT(PubTime,'%y-%m-%d')%16%16%16PubTime desc%160%16ehai_product.IsShow=1 and ehai_product.IsCheck=1 and ehai_product.ProductName<>'' and ehai_product.ProductName<>''@>"+(EhaiGrid.sc?EhaiGrid.sc:"")+(EhaiGrid.sc3?EhaiGrid.sc3:"")+"%16",start:EhaiGrid.curRowNum*(EhaiGrid.curPage-1),total:EhaiGrid.curRowNum};
    if(re)
    {
        EhaiGrid.totalRecord=re[0][0];
        t.bRefresh=true;
    }
    $.SendMessage(t,true);
};
function newsCallback(re,msg)
{
    var records={total:Math.ceil(EhaiGrid.totalRecord/EhaiGrid.curRowNum),page:EhaiGrid.curPage,records:EhaiGrid.totalRecord};
    var rows="[";
    for(var i=msg.start,j=msg.start+msg.total;i<j;i++)
    {
        if(re[i][1]=="" || re[i][1]== "undefinedundefined" || re[i][1]=="ProductImg/")
        picimg="images/nophoto.gif";
        else
        picimg=re[i][1];
        rows+="{id:'"+re[i][0]+"',cell:['<div style=\"width:520px;margin:10px auto;height:115px;\" class=\"enterprise_unit\"><a href=\"productdetaile.html?{\\\'id\\\':\\\'"+re[i][0]+"\\\'}\"><img class=\"enterprise_image\" alt=\"图片\" src=\""+picimg+"\" /></a><ul class=\"enterprise_intro\"><li><span>产品名称：</span><label><a target=\"_blank\" href=\"productdetaile.html?{\\\'id\\\':\\\'"+re[i][0]+"\\\'}\">"+re[i][2]+"</a></label></li><li><span>产品介绍：</span><label class=\"enterprise_intro_label\">"+jQuery.htmlencode(re[i][3].replace(/\n/g,'').replace(/\r/g,''))+"</label></li><li><span>公司名称：</span><label>"+re[i][4]+"</label></li><li><span>企业网站：</span><label><a target=\"_blank\" href=\""+re[i][5]+"\">"+re[i][5]+"</a></label></li></ul></div>']},";
    }
    if(rows.lastIndexOf(',')==rows.length-1)
        rows=rows.substring(0,rows.length-1);
    rows+="]";
    records.rows=eval("("+rows+")");
    EhaiGrid.curFun(records,EhaiGrid.bDiv);
    $("table.scroll tr.over td").css("backgroundColor","#FFF"); 
};  
 function getCategoryData(classid)  
{
    EhaiGrid.sc=" and ehai_product.eType like '"+classid+"%'";
    EhaiGrid.totalRecord=-1;
    jQuery("#list").trigger("reloadGrid");
    
} ; 
 function getCategoryRightData(cp,qy)
{
    //debugger;
    EhaiGrid.sc3="";
    if(cp)
    {
        EhaiGrid.sc3+=" and ProductName like '%"+cp+"%'";
    }
    if(qy)
    {
        EhaiGrid.sc3+=" and ehai_user.Company like '%"+qy+"%'";
    }
  
    EhaiGrid.totalRecord=-1;
    jQuery("#list").trigger("reloadGrid");
}; 
function cprightsearch()
{
    var aimUrl;
    var cptj=$("#sproductname").val();
    var qytj=$("#scomname").val();
    aimUrl="productlist.html?{'cptj':'"+cptj+"','qytj':'"+qytj+"'}";
    window.location=aimUrl;
};
