﻿var jobListPageObject = {
    XMLHttpObject:null,
    inProcessing:false,
    init:function(){
        if(jobListPageObject.XMLHttpObject==null){
            jobListPageObject.XMLHttpObject = corefunc.getXMLHttpObject();
        }
        if(jobListPageObject.XMLHttpObject==null){
            alert("创建XMLHttp对象失败!");
            return false;
        }
        if(jobListPageObject.inProcessing){
            alert("请求正在处理中,请稍侯再试!");
            return false;
        }
        return true;
    },
    checkAll:function(obj){
        var val = obj.checked;
        corefunc.$("chkAll1").checked = corefunc.$("chkAll2").checked = val;
        var objs = corefunc.$$("chkJob");
        for(var idx=0;idx<objs.length;idx++){
            objs[idx].checked = val;
        }
    },
    getJobList:function(){
        var joblist = "";
        var objs = corefunc.$$("chkJob");
        for(var idx1=0,idx2=0;idx1<objs.length;idx1++){
            if(objs[idx1].checked){
                if(idx2>0)joblist+=",";
                joblist+=objs[idx1].value;
                idx2++;
            }
        }
        return joblist;
    },
    handle_ReturnProc:function(){
	    with(jobListPageObject.XMLHttpObject){
		    if(readyState==4){
			    if(status == 200 ){
			        var rtnObj = eval('('+responseText+')');
			        alert(rtnObj.MESSAGE);
			        if(rtnObj.LOGIN==false){
			            location.assign("Login.aspx?url="+escape(document.location));
			        }
			    }else{
			        alert("系统错误，请和管理员联系！");
			    }
			    jobListPageObject.inProcessing = false;
		    }
	    }
    },
    addJobToFav:function(){
        if(jobListPageObject.init()==false) return;
        var jobid = jobListPageObject.getJobList();
        if(jobid.length<1){
            alert("请选择要收藏的职位！");
            return;
        }
        jobListPageObject.inProcessing=true;
        jobListPageObject.XMLHttpObject.open("POST","Tools/AddJobToFavBatch.aspx",true);
	    jobListPageObject.XMLHttpObject.onreadystatechange = jobListPageObject.handle_ReturnProc;
	    jobListPageObject.XMLHttpObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	    jobListPageObject.XMLHttpObject.send("jobid="+jobid);
    },
    jobCandidate:function(){
        if(jobListPageObject.init()==false) return;
        var jobid = jobListPageObject.getJobList();
        if(jobid.length<1){
            alert("请选择要应聘的职位！");
            return;
        }
        jobListPageObject.inProcessing=true;
        jobListPageObject.XMLHttpObject.open("POST","Tools/JobCandidateBatch.aspx",true);
	    jobListPageObject.XMLHttpObject.onreadystatechange = jobListPageObject.handle_ReturnProc;
	    jobListPageObject.XMLHttpObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	    jobListPageObject.XMLHttpObject.send("jobid="+jobid);
    },
    checkSearch:function(){
        if(corefunc.isIdSeries(corefunc.$("hidRegion1").value)==false && corefunc.isIdSeries(corefunc.$("hidRegion2").value)==false){
            alert("工作地点不能为空！");
            return false;
        }
        return true;
    }
}
