﻿var recordNum;        //记录总数
var pageNo=0;           //当前页码
var recPerPage;      //每页记录数
var pageNum;          //总页数
var jobtype=0;          //0求职1招聘

function searchrec(page)
{
    if(pageNum==0){//无数据
        $("searchResult").innerHTML="<table cellspacing='0' cellpadding='4' rules='all' class='list_table' border='0' style='border-collapse:collapse;'><tr><td>暂时没有相关数据！</td></tr></table>";
    }
    else{
        if(!/^\d*$/.test(page))
        {
            alert("请输入数字");
            return;
        }
        else if(page<1)
        {
            alert("请输入大于1的数字");
            return;
        }
        else if(page>pageNum)
        {
            alert("请输入小于"+pageNum+"的数字");
            return;
        }
        else if((page==pageNo)&&(page!=1))
            return;
        
        $("searchResult").innerHTML="<img src='images/divloading.gif'/>";
        AjaxPro.timeoutPeriod = 121000;
        
        CanLian.DAL.AjaxTransfer.JobList(jobtype,recPerPage,page,_callbackSearch);
        pageNo=eval(page);
    }
}
function _callbackSearch(res){
    var restable=res.value.Tables[0];
    var tt="";
    var bcolor;
    if(jobtype==1)
    {
        tt+="<table cellspacing='0' cellpadding='4' rules='all' class='list_table' border='0' style='border-collapse:collapse;'>"+
            "<tr><th style='font-size:14px;width:35%;'>招聘单位</th><th style='font-size:14px;width:20%;'>招聘岗位</th><th style='font-size:14px;width:10%;'>招聘人数</th><th style='font-size:14px;width:35%;'>岗位描述</th></tr>";
    }
    for(var i=0;i<restable.Rows.length;i++){
        var r=restable.Rows[i];
        if(jobtype==0){//求职信息
            tt+="<table cellspacing='0' cellpadding='4' rules='all' class='list_table' border='0' style='border-collapse:collapse;'>";
            tt+="<tr><td class='tbltitle'>姓名</td><td>"+r.DisName+"</td><td class='tbltitle'>性别</td><td>"+(r.DisSex?"女":"男")+"</td><td class='tbltitle'>年龄</td class='tbltitle'><td>"+r.DisAge+"</td><td class='tbltitle'>户口所在地</td><td>"+r.DisRes+"</td></tr>";
            tt+="<tr><td class='tbltitle'>残疾类别</td><td>"+r.DisType+"</td><td colspan='2' class='tbltitle'>残疾级别</td><td colspan='2'>"+r.DisLevel+"</td><td class='tbltitle'>文化程度</td><td>"+r.DisEdu+"</td></tr>";
            tt+="<tr><td class='tbltitle'>联系人</td><td>"+r.ContactName+"</td><td colspan='2' class='tbltitle'>联系电话</td><td colspan='2'>"+r.ContactTel+"</td><td class='tbltitle'>电子邮件</td><td>"+r.ContactEmail+"</td></tr>"
            tt+="<tr><td class='tbltitle'>职业技能</td><td colspan='7'>"+r.WorkSkill+"</td></tr>";
            tt+="<tr><td class='tbltitle'>其它要求</td><td colspan='7'>"+r.DisMemo+"</td></tr>";
            tt+="</table><br/>"
        }
        else{//招聘信息
            if(i%2==0) {bcolor="#FFFFFF";} else {bcolor="#EFF3FB";}
            tt+="<tr onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ccffcc',this.style.fontWeight='bolder';\" onmouseout=\"this.style.backgroundColor=currentcolor,this.style.fontWeight='';\" style=\"background-color:"+bcolor+";\">"
            tt+="<td><a href='javascript:getcominfo("+r.ComID+")'>"+r.ComName+"</a></td><td>"+r.PostName+"</td><td>"+r.PostRequest+"</td><td>"+r.PostDesc+"</td></tr>"
        }
    }
    if(jobtype==1) tt+="</table><br/>"
    //alert(restable.Rows.length);
//    var tt="<table cellspacing='0' cellpadding='4' rules='all' class='list_table' border='0' style='border-collapse:collapse;'>";
//    if(listType>0)tt+="<tr>";
//    var bcolor;
//    for(var i=0;i<restable.Rows.length;i++){
//        if(i%2==0) {bcolor="#FFFFFF";} else {bcolor="#EFF3FB";}
//        if(listType==1){    //图片列表
//            if(i%5==0) tt+="</tr><tr>";
//            tt+="<td onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ccffcc';\" "+
//                "onmouseout=\"this.style.backgroundColor=currentcolor;\" style='text-align:center;vertical-align:top;font-size:10px;background-color:#"+
//                bcolor+";'><a href='Show.aspx?ID="+restable.Rows[i].ID+
//                "' target='_blank'><img src='"+restable.Rows[i].Picture+"' style='border:solid 1px gray;width:100px;' class='linkimg'/><br/>"+
//                restable.Rows[i].ATitle+"</a></td>"
//        }else if(listType==0){       //文章列表
//            tt+="<tr onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ccffcc',this.style.fontWeight='bolder';\" onmouseout=\"this.style.backgroundColor=currentcolor,this.style.fontWeight='';\" style=\"background-color:#"+bcolor+";\">"
//            tt+="<td><div class='tabcon' style='width:42em;'><div class='text_con'><a href='Show.aspx?ID="+restable.Rows[i].ID+"' title='"+restable.Rows[i].ATitle+"' class='list_con' target='_blank'>"+restable.Rows[i].ATitle;
//            if(restable.Rows[i].APicture) tt+="<img src='Images/picnews.gif' title='此信息包含上传图片' style='border:0'/>";
//            tt+="</a></div><div class='text_dotted' style='font-family:宋体'>...</div></div></td>"
//            tt+="<td class='list_date'>"+restable.Rows[i].ADate.format("yyyy-MM-dd")+"</td></tr>"
//        }else{  //视频或期刊
//            if(i%5==0) tt+="</tr><tr>";
//            tt+="<td onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ccffcc';\" "+
//                "onmouseout=\"this.style.backgroundColor=currentcolor;\" style='text-align:center;vertical-align:top;font-size:10px;background-color:#"+
//                bcolor+";''><a href='Show.aspx?TYPE="+escape("视频")+"&ID="+restable.Rows[i].ID+
//                "' target='_blank'><img src='"+restable.Rows[i].Location.substr(0,restable.Rows[i].Location.length-3)+
//                "jpg' style='border:solid 1px gray;width:100px;' class='linkimg'/><br/>"+
//                restable.Rows[i].Title+"</a></td>"
//        }
//    }
//    if(listType==1)tt+="</tr>";
//    tt += "</table>";
//    
    var tv="<div class='list_bottom'>共<font color='#ff0000'>"+pageNum+"</font>页<font color='#ff0000'>"+recordNum+"</font>条记录,每页最多显示<font color='#ff0000'>"+recPerPage+"</font>条记录,当前显示第<font color='#ff0000'>"+pageNo+"</font>页&nbsp;&nbsp;";
    if(pageNo==1) tv+="&nbsp;&nbsp;首页&nbsp;&nbsp;上一页";
    else tv+="&nbsp;&nbsp;<a href='#' onclick='searchrec(1)'>首页</a>&nbsp;&nbsp;<a href='#' onclick='searchrec("+(pageNo-1)+")'>上一页</a>"
    
    if(pageNo==pageNum) tv+="&nbsp;&nbsp;下一页&nbsp;&nbsp;尾页";
    else tv+="&nbsp;&nbsp;<a href='#' onclick='searchrec("+(pageNo+1)+")'>下一页</a>&nbsp;&nbsp;<a href='#' onclick='searchrec("+pageNum+")'>尾页</a>";
    
    tv+="&nbsp;&nbsp;&nbsp;&nbsp;<input id='gotopageno' type='text' style='width:15px;height:15px;line-height:15px;border:solid 1px #689902;'/>&nbsp;"+
    "<input id='Button1' class='btn3_mouseout' type='button' onclick='this.blur();searchrec($(\"gotopageno\").value)' value='转到' style='width:35px;' "+
    "onmouseover=\"this.className='btn3_mouseover'\" onmouseout=\"this.className='btn3_mouseout'\" onmousedown =\"this.className='btn3_mousedown'\" onmouseup=\"this.className='btn3_mouseup'\"/>"
    
    tv+="</div>";
    $("searchResult").innerHTML=tt+tv;
}

//显示招聘公司信息
function getcominfo(id){
        CanLian.DAL.AjaxTransfer.JobBase(1,
            function(res){
                if(res.value) 
                    ymPrompt.win({title:"公司信息",message:res.value,width:500,height:300,btn:[["确定","ok"]]})
            }
        )
}

////读取Cookie值

//function GetCookie (name) { 
//    var arg = name + "="; 
//    var alen = arg.length; 
//    var clen = window.document.cookie.length; 
//    var i = 0; 
//    while (i < clen){ 
//        var j = i + alen; 
//        if (window.document.cookie.substring(i, j) == arg) return getCookieVal (j); 
//        i = window.document.cookie.indexOf(" ", i) + 1; 
//        if (i == 0) break; 
//    } 
//    return null;
//}

//function getCookieVal (offset){ 
//    var endstr = window.document.cookie.indexOf (";", offset); 
//    if (endstr == -1) endstr = window.document.cookie.length; 
//    return unescape(window.document.cookie.substring(offset, endstr));
//}
////设置Cookie值
//function SetCookie (name, value){ 
//    var exp = new Date(); 
//    exp.setTime(exp.getTime() + (30*24*60*60*1000));
//    window.document.cookie = name + "=" + escape (value) + "; expire*=" + **p.toGMTString()+";path=/";
//}

////删除Cookie
//function DeleteCookie (name){ 
//    var exp = new Date(); 
//    exp.setTime (exp.getTime() - 1); 
//    var cval = GetCookie (name); 
//    window.document.cookie = name + "=" + cval + "; expire*=" + **p.toGMTString()+";path=/";
//}

    var Alert=ymPrompt.alert;
    var ltype=0;
    var oldvalue;//=$('logininfo').innerHTML;
//                var coo = new HttpCookie("gxyg_user");;
//            coo.setExpires(0); 
//            coo.save();

    function checklogin(){  //提交登录信息
        CanLian.DAL.AjaxTransfer.JobLogin(getRegType(),$('TextBoxUser').value,$('TextBoxPass').value,$('TextBoxAdd').value,_callbackLogin);
    }
    function _callbackLogin(res){   //登录返回
        //oldvalue=$('logininfo').innerHTML;
            $('vcodeimg').src='../Handlers/GetValidateCode.ashx?r='+Math.random();
        if(res.value){
            var coo = new HttpCookie("gxyg_user");//设置cookie
            if(coo.isExisted() == false){
                coo.values.set("type",getRegType());
                coo.values.set("name", $('TextBoxUser').value); 
                coo.values.set("pass", $('TextBoxPass').value);
            } 
            coo.setExpires(1000*60*60*24); 
            coo.save();
            //SetCookie("gxyg_user",$('TextBoxUser').value);//设置cookie
            //SetCookie("gxyg_pass",$('TextBoxPass').value);
            $('logininfo').innerHTML=res.value;
        }
        else{
            alert('登录失败');
        }
    }
    
    function logout(){  //提交退出登录
        CanLian.DAL.AjaxTransfer.JobLogout(_callbackLogout);
        
    }
    function _callbackLogout(res){  //退出登录返回
        if(res.value){
//            DeleteCookie("gxyg_user");//删除cookie
//            DeleteCookie("gxyg_pass");
            var coo = new HttpCookie("gxyg_user");;
            coo.setExpires(0); 
            coo.save();
            $('logininfo').innerHTML=oldvalue;
            $('vcodeimg').src='../Handlers/GetValidateCode.ashx?r='+Math.random();
        }
        else alert('退出失败');
        
    }
    function reg(){ //注册窗口
        var str="<table border='0' cellspacing='0' id='infotable' rules='all' style='border-collapse: collapse;font-size: 12px; width: 100%'>"+
                "<tr><td style='text-align:right;'>注册类型:</td><td colspan='3'><input id='regPer' name='regType' type='radio' value='0' checked /><label for='regPer'>个人用户</label><input id='regCom' name='regType' type='radio' value='1'/><label for='regCom'>单位用户</label></td></tr>"+
                "<tr><td style='text-align:right;'>用户名:</td><td><input type='text' id='reguser' class='inputUser' onblur='CanLian.DAL.AjaxTransfer.JobUserName(getRegType(),this.value,_callbackCheckUserName);'/></td><td style='width:16px;' id='icon0'></td><td id='userdesc'>请输入登录用的名字</td></tr>"+
                "<tr><td style='text-align:right;'>密码:</td><td><input type='password' id='regpass' class='inputPass' onblur='checkpass(this)'/></td><td style='width:16px;' id='icon1''></td><td>请输入密码</td></tr>"+
                "<tr><td style='text-align:right;'>重输密码:</td><td><input type='password' id='regpass2' class='inputPass' onblur='checkpass(this)'/></td><td style='width:16px;' id='icon2'></td><td>再输一次密码</td></tr>"+
                "<tr><td style='text-align:right;'>验证码:</td><td><input type='text' id='regcode' class='inputKey' onblur='CanLian.DAL.AjaxTransfer.JobCheckCode(this.value,_callbackCheckCode);'/></td><td style='width:16px;' id='icon3'></td><td>请在输入框中输入<img src='Handlers/GetValidateCode.ashx?r='+Math.random() "+
                "id='Img1' alt='验证码,看不清楚?请点击刷新验证码!' style='vertical-align: middle;' onclick=\"this.src='../Handlers/GetValidateCode.ashx?r='+Math.random()\"/></td></tr>"+
                "</table>"

        ymPrompt.win({title:'用户注册',message:str,width:400,height:190,handler:reguser,btn:[['注册','ok'],['取消','cancel']]})
    }
    function _callbackCheckUserName(res){   //验证用户名
        if(res.value||(!$('reguser').value)){
            $('icon0').innerHTML="<img src='Images/cancel.png'/>";
            $('userdesc').innerHTML="<span style='red'>此用户名已经存在或包含非法字符</span>";
        }else{
            $('icon0').innerHTML="<img src='Images/accept.png'/>";
            $('userdesc').innerHTML="<span style='balck'>请输入登录用的名字</span>";
        }
    }
    function _callbackCheckCode(res){   //验证验证码
        if(res.value) $('icon3').innerHTML="<img src='Images/accept.png'/>";
        else $('icon3').innerHTML="<img src='Images/cancel.png'/>";
    }
    function checkpass(ob){ //验证密码
        if((ob.id=='regpass') && ($('regpass2').value.length==0)) return;
            if(($('regpass').value==$('regpass2').value) && (ob.value.length>0)){
                $('icon1').innerHTML=$('icon2').innerHTML="<img src='Images/accept.png'/>";
            }
            else{
                $('icon1').innerHTML=$('icon2').innerHTML="<img src='Images/cancel.png'/>";
            }
    }
    function reguser(tp){   //提交注册新用户
    
        //Alert('你点击的按钮的标志为：'+tp);
        if(tp=='ok'){
            var testok=true;
            for(i=0;i<4;i++){
                //alert($('icon'+i).innerHTML);
                if($('icon'+i).innerHTML.indexOf('Images/accept.png')<0){
                    testok=false;
                    break;
                }
            }
            if(testok){
//                var regtype;
//                var rdo=document.getElementsByName("regType");
//                for(i=0;i<rdo.length;i++){
//    　　             if(rdo[i].checked)
//       　　            regtype=rdo[i].value;
//　　            }
//　　            alert(getRegType());
                CanLian.DAL.AjaxTransfer.JobNewUser(getRegType(),$('reguser').value,$('regpass').value,$('regcode').value,_callbackNewUser);
            }else{
                Alert('您输入的用户信息不正确，\n无法完成注册');
            }
        }
    }
    function getRegType(){  //注册类型
        var regtype=0;
        var rdo=document.getElementsByName("regType");
        for(i=0;i<rdo.length;i++){
             if(rdo[i].checked)
　            regtype=rdo[i].value;
        }
        return regtype;
    }
    
    function _callbackNewUser(res){ //新用户注册返回
        if(res.value){
            $('logininfo').innerHTML=res.value;
            Alert('用户已经建立，请尽快修改个人资料以便我们审核');
                editbase(res.value.indexOf("(0)")>=0?0:1);
        }
        else{
            Alert('用户信息输入错误，未能建立用户');
        }
        $('vcodeimg').src='../Handlers/GetValidateCode.ashx?r='+Math.random();
    }
    function editbase(type){    //用户基本信息
        ltype=type;
        var w,h,t;
        if(type==0){w=670;h=330;t="用户基本信息";}
        else{w=500;h=300;t="招聘单位基本信息";}
        CanLian.DAL.AjaxTransfer.JobBase(ltype,
            function(res){
                if(res.value) 
                    ymPrompt.win({title:t,message:res.value,width:w,height:h,handler:editinfo,btn:[["确定","ok"],["取消","cancel"]]})
            }
        )
    }
    function editinfo(tp){    //基本信息修改
        if(tp=='ok'){
            //var re=/([a-zA-Z]+\=)([#a-zA-Z0-9\u4e00-\u9fa5\-@\.]+)/ig;    //补上缺失的引号
            var str= $('infotable').innerHTML; 
            //str=str.replace(re, '$1 "$2"').replace(/checked/ig,'checked="checked"').replace(/selected/ig,'selected="selected"'); 

//            alert(str);
//            var ex=new RegExp('<SELECT[^>]*\\s+id=[\'"]?(.+?)[\'">]+(<option selected>)+([^\'"<>\\s]*).+?</SELECT>','ig');
//            var cr=str.match(ex);
//            var result = ''; 
// 
// 
// 
//if ( cr != null && typeof(cr) == 'object' && cr.length != null ) // 如果计算结果是一个数组, 则取出所有数组的值 
// 
//{ 
// 
//for ( i = 0; i < cr.length; i++ ) 
// 
//{ 
// 
//result += "array[" + i + "] = '" + cr[i] + "'\n"; 
// 
//} 
// 
//} 

//alert(result);
            CanLian.DAL.AjaxTransfer.JobBaseEdit(ltype,str,
                                                            function(res){
                                                                if(res.value){
                                                                    Alert('修改成功');
                                                                }
                                                                else{
                                                                    Alert('修改失败');
                                                                }
                                                            }
            );
        }
    }
//    function _callbackEdit(res){    //基本信息修改的返回结果
//        if(res.value){
//            Alert('修改成功');
//        }
//        else{
//            Alert('修改失败');
//        }
//    }
    function modipass(type){    //修改密码
        ltype=type;
        var str="<table border='0' cellspacing='0' id='itable' rules='all' style='border-collapse: collapse;font-size: 12px; width: 100%'>"+
                "<tr><td style='text-align:right;'>旧密码:</td><td><input type='password' id='reguser' class='inputPass'/></td><td style='width:16px;' id='icon0'></td><td id='userdesc'>请输入旧密码</td></tr>"+
                "<tr><td style='text-align:right;'>新密码:</td><td><input type='password' id='regpass' class='inputPass' onblur='checkpass(this)'/></td><td style='width:16px;' id='icon1''></td><td>请输入密码</td></tr>"+
                "<tr><td style='text-align:right;'>重输新密码:</td><td><input type='password' id='regpass2' class='inputPass' onblur='checkpass(this)'/></td><td style='width:16px;' id='icon2'></td><td>再输一次密码</td></tr>"+
                "<tr><td style='text-align:right;'>验证码:</td><td><input type='text' id='regcode' class='inputKey' onblur='CanLian.DAL.AjaxTransfer.JobCheckCode(this.value,_callbackCheckCode);'/></td><td style='width:16px;' id='icon3'></td><td>请在输入框中输入<img src='Handlers/GetValidateCode.ashx?r=12'+Math.random() "+
                "id='Img111' alt='验证码,看不清楚?请点击刷新验证码!' style='vertical-align: middle;' onclick=\"this.src='../Handlers/GetValidateCode.ashx?r='+Math.random()\"/></td></tr>"+
                "</table>"

        ymPrompt.win({title:'密码修改',message:str,width:400,height:190,handler:pass,btn:[['修改','ok'],['取消','cancel']]})
    }
    function pass(tp){    //密码提交
        if(tp=='ok'){
            var testok=true;
            for(i=1;i<4;i++){
                //alert($('icon'+i).id);
                if($('icon'+i).innerHTML.indexOf('Images/accept.png')<0){
                    testok=false;
                    break;
                }
            }
            if(testok){
                CanLian.DAL.AjaxTransfer.ModiPass(ltype,$('reguser').value,$('regpass').value,$('regcode').value,_callbackEdit);
            }else{
                Alert('您输入的用户信息不正确，\n无法完成修改');
            }
        }
    }
    function modiPost(){    //接收岗位信息
        CanLian.DAL.AjaxTransfer.JobPost(
            function(res){
                if(res.value){
                    var str="<table border='0' cellspacing='0' id='postable' rules='all' style='border-collapse: collapse;font-size: 12px; width: 100%'>"+
                        "<tr><th>序号</th><th>岗位名称</th><th>招聘人数</th><th>岗位描述</th></tr>";
                    for(var i=0;i<5;i++){
                        var r=res.value.Tables[0].Rows[i];
                        str+="<tr><td>"+(i+1)+"</td><td><input id='obPostName' value='"+ (r?(r.PostName?r.PostName:""):"")+"' style='width:150px'></input></td>"+
                            "<td><input id='obPostRequest' value='"+(r?(r.PostRequest?r.PostRequest:""):"")+"' style='width:50px'></input></td>"+
                            "<td><input id='obPostDesc' value='"+(r?(r.PostDesc?r.PostDesc:""):"")+"' style='width:200px'></input></td></tr>";
                    }
                    str+="</table>";
                    ymPrompt.win({title:"岗位信息修改",message:str,width:500,height:220,handler:postinfo,btn:[["确定","ok"],["取消","cancel"]]})
                }
            }
        )
    }
    function postinfo(tp){  //发送岗位信息
        if(tp=='ok'){
            var str= $('postable').innerHTML; 
            
            CanLian.DAL.AjaxTransfer.JobPostEdit(str,
                                                    function(res){
                                                        if(res.value){
                                                            Alert('修改成功');
                                                        }
                                                        else{
                                                            Alert('修改失败');
                                                        }
                                                    }
            );
        }
    }
    
    
