//ajax方法封装
var req;
function getRequest() {	
	req = getXMLHttpRequestFromIE();	
	if (req == null) {
		req = new XMLHttpRequest();
	}	
}
function getXMLHttpRequestFromIE() {
	var namePrefixes = [ "Msxml3", "Msxml2", "Msxml", "Microsoft" ];
	for ( var i = 0; i < namePrefixes.length; i++) {
		try {
			var name = namePrefixes[i] + ".XMLHTTP";
			return new ActiveXObject(name);
		} catch (e) {
		}
	}
	return null;
}
function sendPostRequest(url,param,processFunc){	
    getRequest();   
    if (req) {
        req.onreadystatechange = processFunc;
        req.open("post", url, true);
        req.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        req.send(param);
    }
}
//重复申请【七天内】---------单个人----------------------------------------------------------------------------
//是否登录，以什么省份登录
function isOrnotLongin(id){
   
   var userLogin = $('#userflag').val();
   if(userLogin=='one'){//没登陆
        alert('Sorry,请先登录',location.href='personLogin.jsp');   
	    return false;    
   }
   if(userLogin=='two'){//个人登录【验证是否是七天内登录】
   	       var url = "./position.do?operate=isRonotSevenDay";
		   var query_string ="positionid="+id;
		   sendPostRequest(url, query_string, checkDayResponse);
   }
   if(userLogin=='three'){//企业省份登录
          alert('对不起,企业不能申请职位');   
	      return false; 
   }
   if(userLogin=='four'){
          alert('你还没有公开的简历');
          return false;
   }
}
//七天验证的回调函数
function checkDayResponse(){
  if (req.readyState == 4 && req.status == 200){	
       var isOrnot = req.responseText;
       if(isOrnot=='falie'){//七天内重复申请
           alert("你在七天内已近申请过该职位，请不要如此高频率的申请");
           return false; 
       }
       if(isOrnot=='success'){//申请成功
           alert('申请成功');  
       }
    }
}
//重复申请【七天内】---------批量申请----------------------------------------------------------------
//1是否选择了申请的条目
function isOrnotSelectItem(){
   var userLogin = $('#userflag').val();
   if(userLogin=='one'){//没登陆
        alert('Sorry,请先登录',location.href='personLogin.jsp');   
	    return false;    
   }
   if(userLogin=='two'){//个人登录【验证是否是七天内登录】
   	     var flag = false;
           $(":checkbox[name=positionId]").each(function(){
		    if($(this).attr("checked")==true)
		           flag = true;
				})
				if(!flag){
				alert("请选择你要申请的职位");
				return false;
				}
				var ids="";
				$(":checkbox[name=positionId]").each(function(){
				    if($(this).attr("checked")==true)
				        ids = ids+$(this).val()+":";
				})
				//发送IDS
				var url = "./position.do?operate=doBathApply";
				var query_string ="ids="+ids;
				sendPostRequest(url, query_string, getNullTwo);	
	   }
	   if(userLogin=='three'){//企业省份登录
	          alert('对不起,企业不能申请职位');   
		      return false; 
	   }
	  if(userLogin=='four'){
          alert('你还没有公开的简历');
          return false;
   }
}
function getNullTwo(){
if (req.readyState == 4 && req.status == 200){	
    var test = req.responseText;
    if(test=='one'){
        alert("申请成功");
        return false;
      }else{
          window.open('./position.do?operate=againapplyremind&ids='+test+'','newwindow','height=400,width=700,top=150,left=150,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');         
      }
   }
} 
