﻿window.IncludeFile={};
window.IncludeFile={"head":"head.html","tail":"tail.html"};
window.JsModule=["system/jqframe.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,searchCondition:""};
function WebMain()
{
    $.SendMessage({type:"Session",callback:getsessionadmin,pm :"<@@>"},true);
    $("#logindiv").login({type:0,callback:loginback,arrID:['txtUserName','txtPwd','','','','btlogin'],strField:'<@euser%16username%16password%16permission@>',isReqval:0});
    setGrid();
    getValueByUsername();
    sendMsgForCollege();
    sendMsgForjobtitle();
}
function getsessionadmin(re)
{
    if(re!="")
    {
        if(re[0][0])
        {
            $.SendMessage({type:"Date",callback:getDate,id:"date",pm :"<@@>"},true); 
            var username=re[0][0];
            $("#logindiv").html("<div style=\"text-align:center;\" >登录用户："+username+"</div><div style=\"text-align:center;margin:5px 0 10px;\"><a href=\"resume.html\">返回简历管理页面</a></div><div style=\"text-align:center;\"><input type=\"button\" onclick=\"logout();\" value=\"退出\"</div>");
        }
    }    
};

function logout()
{
    $.SendMessage({callback:function(){window.location.href='zpindex.html';},type:"LoginOut",pm :"<@@>"},true);
};

function loginback(re)
{
    if(re[0][0]=="0") window.location.href="resume.html";
    else  
    {
        alert("用户名密码错误");
        logout();
    }
}  
//begin ************* grid *******************************************

function setGrid()
{
	EhaiGrid.grid = jQuery("#list").jqGrid({
        url:'Default.aspx',
        datatype: 'json',
        colNames:['招聘单位','二级学科/专业','职位类别','学 历','操作'],
        colModel :[ 
        {name:'time',index:'time', width:100,sortable:false}, 
        {name:'researchname',index:'researchname', width:100,align:'left',sortable:false},
        {name:'researchname',index:'researchname', width:80,align:'left',sortable:false},
		{name:'role',index:'role', width:80,align:'left',sortable:false},
		{name:'role',index:'role', width:80,align:'left',sortable:false}
        ],
        pager: jQuery('#pager'),rowNum:15,rowList:[15,30,40],sortname: 'id',sortorder: "desc",viewrecords: true,
		multiselect:false,
        imgpath: 'plugins/grid/themes/ehai_front1/images',caption: "",
        width:510,height:160,
        jsonReader : {
            root: "rows",
            page: "page",
            total: "total",
            records: "records",
            repeatitems: true,
            cell: "cell",
            id: "id",
            userdata: "userdata"
            }
    });
	jQuery("#list").navGrid('#pager',
            {edit:false,add:false,del:false,search:false},{url:"Default.aspx",top: 0,left:0, pm :"<@mjgetmessagebox@>%16messageid in(###)"},{},{},{});
    $(".selbox:last").before("<span>&nbsp;显示&nbsp;</span>").after("<span>&nbsp;条&nbsp;</span>");
   
}

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({bDefCall:false,callback:sendMsg,type:"DBSelect",pm :"<@recruitment,college,college2,jobtitle%16recruitment.id%16Count(*)%16%16%16%160%16recruitment.college2_id=college2.id and recruitment.college_id=college.id and recruitment.jobtitle_id=jobtitle.id and enddate>now()@>"+EhaiGrid.searchCondition+"%16"},true);
};
function sendMsg(re,msg)
{
	var t={type:"DBSelect",callback:newsCallback,bDefCall:false,id:"gridList",pm :"<@recruitment,college,college2,jobtitle%16recruitment.id%16recruitment.id,collegename,college2name,jobtitlename,diploma%16%16%16%160%16recruitment.college2_id=college2.id and recruitment.college_id=college.id and recruitment.jobtitle_id=jobtitle.id and enddate>now()@>"+EhaiGrid.searchCondition+"%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:['"+re[i][1] +"','"+re[i][2] +"','"+re[i][3] +"','"+re[i][4] +"','<input onclick=\"zhaopintable(\\\'"+re[i][0]+"\\\')\" type=\"button\" value=\"查看\" /> ']},";
     }
    if(rows.lastIndexOf(',')==rows.length-1)
        rows=rows.substring(0,rows.length-1);
        rows+="]";
        records.rows=eval("("+rows+")");
        EhaiGrid.curFun(records,EhaiGrid.bDiv);
  };

 //end ************* grid *******************************************
 function getValueByUsername()
{
    $.SendMessage({type:"DBSelect",callback:addFormValue, pm :"<@school%16id%16id,schoolinf%16%16%16%160%16%16@>"},true);  
}   
function addFormValue(re)
{
	$("#schoolinf").html(re[0][1]);
}
 //查看招聘信息
function zhaopintable(id)
{
    window.open("../table/zhaopintable.html?{id:"+id+"}");
}
//拼接搜索条件，搜索应聘学院以及应聘状态
function simpleSearch()
{
	var collegeId = $('#college').val(),jobtitleId = $('#jobtitle').val();
	EhaiGrid.searchCondition = "";
	EhaiGrid.searchCondition += collegeId == 0 ? "" : " and recruitment.college_id=" + collegeId;
	EhaiGrid.searchCondition += jobtitleId == 0 ? "" : " and recruitment.jobtitle_id=" + jobtitleId;
	jQuery("#list").trigger("reloadGrid");
}
// select框，从数据库中读取职位类别
function sendMsgForjobtitle()
{
	$.SendMessage({bDefCall:false,callback:getSelectjobtitle,type:"DBSelect",pm :"<@jobtitle%16id%16id,jobtitlename%16%16%16%160%16%16@>"},true);
}
function getSelectjobtitle(re)
{
	if(re && !re.error)
	{
		setOptionsForSelect(re,"jobtitle");
	}
}



