﻿// JScript 文件
window.IncludeFile={"header":"head.html","zj_right":"zj_right.html","tailer":"tail.html"};
window.JsModule=["system/jqframe.js","js/zj_right.js","plugins/grid/js/jqModal.js","plugins/grid/js/jqDnR.js","plugins/n2menu/js/n2menu.js"]; 
window.EhaiGrid={curPage:1,curRowNum:1,totalRecord:-1,curFun:null,bDiv:null,sc:null,sc2:null};
var isFirstCallBack=true;
function WebMain()
{
    if($.PageParam.Sort)
    {
        getCategoryClassData($.PageParam.Sort); 
    }
    getCategoryWtData($.PageParam.wttj,$.PageParam.lbtj);
    EhaiGrid.grid = jQuery("#list").jqGrid({
    url:'Default.aspx',
    datatype: 'json',
    colNames:['咨询问题','咨询者','状态','时间','点击'],
    colModel :[ 
    {name:'JobName',index:'JobName', width:150,sortable:false}, 
    {name:'JobName',index:'JobName', width:60,sortable:false}, 
    {name:'CompanyName',index:'CompanyName', width:40,sortable:false},
    {name:'WorkPlace',index:'WorkPlace', width:60,sortable:false}, 
    {name:'PubDate',index:'PubDate', width:40,sortable:false,align:"center"}
    ],
    pager: jQuery('#pager'),
    rowNum:30,
    rowList:[30,60,80],
    sortname: 'id',
    sortorder: "desc",
    viewrecords: true,
    imgpath: 'Controls/grid/themes/ehai_front1/images',
    caption: "",
    width:475,
    height:435,
    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;&nbsp;&nbsp;共</span>"); 
    answerbut(0);
     $.SetFormat("zh","settypesmall","<p style=\"float:left;width:70px;padding-left:30px;\"><a style=\" font-weight:normal;color:#1A679D;\" href=\"javascript:getCategoryData('#1#')\">#0#</a></p>","","");

    $.SendMessage({callback:setbigtype,bLoading:false,type:"DBSelect",id:"getwentibig",pm :"<@ehai_typetable%16Id%16eName,Class,Id%16%16%16Class asc%160%16Sort=6 and LENGTH(Class)=2%16@>"});
    $.SendMessage({bLoading:false,type:"DBSelect",pm :"<@ehai_typetable%16id%16LENGTH(Class)/2,eName%16%16%16Class asc%160%16Sort=6%16@>",callback:getwttypetree},true);
}

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_askonline%16ehai_askonline.Id%16Count(*)%16%16%16%160%16IsCheck=1 and IsShow=1@>"+(EhaiGrid.sc?EhaiGrid.sc:"")+(EhaiGrid.sc2?EhaiGrid.sc2:"")+"%16"},true);

    //与招聘信息类似的grid加上
    $("table.scroll thead th").css("backgroundImage","none");
    
};
function sendMsg(re,msg)
{
    var t={type:"DBSelect",callback:newsCallback,bDefCall:false,id:"zhaopinnews",pm :"<@ehai_askonline%16ehai_askonline.Id%16Id,QuestionContent,AskUserName,AnswerContent,DATE_FORMAT(AskTime,'%y-%m-%d'),Counts%16%16%16AskTime desc%160%16IsCheck=1 and IsShow=1@>"+(EhaiGrid.sc?EhaiGrid.sc:"")+(EhaiGrid.sc2?EhaiGrid.sc2:"")+"%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++)
    {
         rows+="{id:'"+re[i][0]+"',cell:['<a href=\"specialdetail.html?{id:"+re[i][0]+"}\" target=\"_blank\">"+htmlreplace(re[i][1])+"</a>','"+re[i][2]+"','"+((re[i][3]=='')?"未回复":"已回复")+"','"+re[i][4]+"','"+re[i][5]+"']},";
    }
    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"); 
}; 

/*
功能：html处理函数
*/
function htmlreplace(text)
{
    if ( !text ) return '' ;
	var Summary = HTMLDecode(text);
	Summary = Summary.replace(/<\/?[^>]*>/g,''); //去除HTML tag
	Summary = Summary.replace(/[ | ]*\n/g,'\n'); //去除行尾空白
	Summary = Summary.replace(/\s/ig,""); 
    Summary = Summary.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
	Summary = Summary.replace(/<(.*?)>/g,''); //去除<>
    Summary = Summary.replace(/&nbsp;/g,''); //去除&nbsp;
    Summary=Summary.substring(0,60) + "...";
	return Summary ;
};
function HTMLDecode ( text )
{
	if ( !text ) return '' ;
	text = text.replace( /&gt;/g, '>' ) ;
	text = text.replace( /&lt;/g, '<' ) ;
	text = text.replace( /&amp;/g, '&' ) ;
	return text ;
}

function answerbut(b)
{
   document.getElementById("a"+b).className="answer1";
    for(var i=0;i<3;i++)
    {
        if(b!=i)
            document.getElementById("a"+i).className="";
    }
    if(b==0)
    {
        getbanswer("");
    }
    else if(b==1)
    {
        getbanswer(" and (AnswerContent='' or AnswerContent is null) ");
    }
    else if(b==2)
    {
        getbanswer(" and AnswerContent<>''");
    }
};
 function getbanswer(classid)  
{
    EhaiGrid.sc=classid;
    EhaiGrid.totalRecord=-1;
    jQuery("#list").trigger("reloadGrid");
    
}; 
function setbigtype(re)
{
    if(re)
    {
        var h=""
        for(i=0;i<re.length;i++)
        {
            h+="<ul><li class=\"sort\"><a href=\"javascript:getCategoryData('"+re[i][1]+"')\">"+decodeURIComponent(re[i][0])+"</a></li><li id=\"bigtypeli"+re[i][1]+"\"></li></ul>";
        }
         $("#wentileibie").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=6 and LENGTH(Class)=4 and left(Class,2)='@>"+re[i][1]+"'%16",format:"settypesmall"});
        }
    }
};
function getCategoryData(classid)  
{
    EhaiGrid.sc=" and Sort like '"+classid+"%'";
    EhaiGrid.totalRecord=-1;
    jQuery("#list").trigger("reloadGrid");
    
};
function getallwt(){
    window.location="special_online.html";
};
function gettypesort()
{
    var key=$("#wtkey").val();
    var type=$("#wttype").val();
    if(type=="")
    {
        getCategoryWtData(key,type);
    }else if(type!="")
    {
     $.SendMessage({bLoading:false,type:"DBSelect",pm :"<@ehai_typetable%16id%16Class%16%16%16%160%16Sort=6 and eName='@>"+type+"'%16",callback:getwttype},true);
    }
};
function getwttype(re)
{
    if(re&&re[0])
    {
    getCategoryWtData($("#wtkey").val(),re[0][0]);
    }else{
        alert("类别不存在，请重新选择!");
    }
};
function getCategoryWtData(key,type)
{
    //debugger;
     EhaiGrid.sc2="";
    if(key)
    {
        EhaiGrid.sc2+=" and QuestionContent like '%"+key+"%'";
    }
    if(type)
    {
        EhaiGrid.sc2+=" and Sort like '"+type+"%'";
    }
    EhaiGrid.totalRecord=-1;
    jQuery("#list").trigger("reloadGrid");
    
};
function getwttypetree(re)
{
    var h=classify(re,"<li><a href=\"#\">","</a>","</li>","<ul>","</ul></li>");
    $("input#wttype").popup("<ul class=\"treeview-popup\">"+h+"</ul>");
    $(".treeview-popup").treeview({	         
    persist: "location",
    cookieId: "treeview-popup"
    });
    $(".popupPanel").bgiframe();
};
function classify(re,fl,fr,sr,cs,ce)
{
    var html="";
    for(var i=0;i<re.length;i++)
    {
        html+=fl+re[i][1]+fr;
        if(re[i+1]&&re[i+1][0]>re[i][0])
            html+=cs;
        else if(re[i+1]&&re[i+1][0]==re[i][0])
            html+=sr;
        if(re[i][0]!=1)
        {
           if(re[i+1]&&re[i+1][0]<re[i][0])
                html+=sr+ce;
        }
    }
    return html;
};
