﻿

var totalPage;
var curpage=1;

var bigclass;
var middleclass;
var littleclass;


function goclick(){
	
	var needPage=document.getElementById("gotopage").value;
	document.getElementById("gotopage").value="";
	check1=/^[0-9]*$/.test(needPage);
	var currentPageOnDisplay=$("#curpage").html();
	var totalPageOnDisplay=$("#totalpages").html();
	if(currentPageOnDisplay==""||totalPageOnDisplay==""){
		ShowMsg(SUCCESS,"温馨提示","输入页数有误！","当前并没有查询结果！请先查询！");
		return false;
	}
	if( needPage==""||!check1){ShowMsg(SUCCESS,"温馨提示","输入页数有误！","跳转页数必须为正整数。");}
	else { 
		temppage=curpage;
		curpage=needPage;
		if(curpage>totalPage){ShowMsg(SUCCESS,"温馨提示","输入页数有误！","超出页面范围，请重新输入。");curpage=temppage;}
		else{
	$.ajax( {
		url : "findPosJobDesc.action",
		type : "post",
		dataType : "json",
			data: "bigclass="+bigclass+"&middleclass="+middleclass+"&curpage="+curpage+"&littleclass="+littleclass,
		success : function(result) {if(/requireLogin:true/.test(result)){var loginUrl = result.split(/loginUrl:/)[1];if(loginUrl){loginUrl = loginUrl.replace(/\}/,"");window.location.href = loginUrl;}return;}
		var json = eval("("
				+ result + ")");
		totalPage=json.totalPage;
		curpage=json.currentPage;
		var jsonList=json.content;
		$("#totalpages").empty();
		$("#curpage").empty();
		$("#searchResult").empty();
		for(var i=0;i<jsonList.length;i++){
			str = "<tr align='center'>";
			str = str+"<td>"+jsonList[i].bigCode+"&nbsp;</td>";
			str = str+"<td>"+jsonList[i].bigclass+"&nbsp;</td>";
			str = str+"<td>"+jsonList[i].middleCode+"&nbsp;</td>";
			str = str+"<td>"+jsonList[i].middleclass+"&nbsp;</td>";
			str = str+"<td>"+jsonList[i].littleCode+"&nbsp;</td>";
			str = str+"<td>"+jsonList[i].littleclass+"&nbsp;</td>";
			str = str+"<td>"+jsonList[i].poltypegrade+"&nbsp;</td>";
			str = str+"<td>"+jsonList[i].claimrate+"&nbsp;</td>";
			str = str+"</tr>";
		$("#searchResult").append(str);
			}
		$("#pageCtrl").css("display","block");
		$("#totalpages").html(totalPage);
		$("#curpage").html(curpage);}
	}

	);
		}
	}

}


function first(){
	curpage=1;
}

function per(){
	if(curpage>1)
	{
		curpage=curpage-1;
	}
	else
	{
		curpage=1;
	}
	
}

function next(){
	if((curpage)>=totalPage)
	{
		curpage=totalPage;
	}
	else
	{
		curpage=curpage+1;
	}
}

function last(){
	curpage=totalPage;
}

function isEmpty(str) {
    if(str == "null" || str.length == 0) {
        return true;
    }
    else {
        return false;
    }
}


function selectMidClass(obj,midBranch) {

	
	var bigCode = obj.value;
	if(obj.value==''){
		$('#middleclass').empty().append("<option value=\"\">--请选择--</option>");
		return;
	}
	
	$.ajax( {
		url : "selectMidClass.action",
		type : "post",
		dataType : "json",
		data : "bigCode="+bigCode,
		success : function(result) {if(/requireLogin:true/.test(result)){var loginUrl = result.split(/loginUrl:/)[1];if(loginUrl){loginUrl = loginUrl.replace(/\}/,"");window.location.href = loginUrl;}return;}
		var json = eval("(" + result + ")");
		var str = "<option value=\"\">--请选择--</option>";
		for(var i=0; i<json.length; i++){
			str += "<option value='"+json[i][0]+"'>"+json[i][1]+"</option>";
		}
		$('#middleclass').empty().append(str);
	},
	error : function() {
		alert("failed...");
	}
	});
}

function isEmpty(str) {
    if(str == "null" || str.length == 0) {
        return true;
    }
    else {
        return false;
    }

}


//分页初始化开始
$(document).ready(function() {
	$('#search')
	.click(
			function() {

				bigclass=document.getElementById("bigclass").value;
				middleclass=document.getElementById("middleclass").value;
				littleclass=encodeURIComponent(encodeURIComponent(document.getElementById("littleclass").value));
				if(isEmpty(bigclass)==1&&isEmpty(middleclass)==1&&isEmpty(littleclass)==1){
					ShowMsg(SUCCESS,"温馨提示","请选择查询条件！","请您确认查询条件选择是否完整。");
					return false;
				}
				$("#first").unbind(); 
				$("#per").unbind(); 
				$("#next").unbind(); 
				$("#last").unbind();
				$("#totalPages").empty();
				$("#curpage").empty();
				curpage = 1;
				$.ajax( {
							url : "findPosJobDesc.action",
							type : "post",
							dataType : "json",
							data: "bigclass="+bigclass+"&middleclass="+middleclass+"&curpage="+curpage+"&littleclass="+littleclass,
							success : function(result) {if(/requireLogin:true/.test(result)){var loginUrl = result.split(/loginUrl:/)[1];if(loginUrl){loginUrl = loginUrl.replace(/\}/,"");window.location.href = loginUrl;}return;}
								var json = eval("("+ result+ ")");
								if (json.errorObject==null){									
									totalPage=json.totalPage;
									curpage=json.currentPage;
									var jsonList=json.content;
									$("#totalPages").empty();
									$("#curpage").empty();
									$("#searchResult").empty();
									if (jsonList.length==0){
										ShowMsg(SUCCESS,"温馨提示","信息不存在！","您查询的信息不存在。");
									}else {
										for(var i=0;i<jsonList.length;i++){		  
											str = "<tr align='center'>";
											str = str+"<td nowrap>"+jsonList[i].bigCode+"&nbsp;</td>";
											str = str+"<td nowrap>"+jsonList[i].bigclass+"&nbsp;</td>";
											str = str+"<td nowrap>"+jsonList[i].middleCode+"&nbsp;</td>";
											str = str+"<td nowrap>"+jsonList[i].middleclass+"&nbsp;</td>";
											str = str+"<td nowrap>"+jsonList[i].littleCode+"&nbsp;</td>";
											str = str+"<td nowrap>"+jsonList[i].littleclass+"&nbsp;</td>";
											str = str+"<td nowrap>"+jsonList[i].poltypegrade+"&nbsp;</td>";
											str = str+"<td nowrap>"+jsonList[i].claimrate+"&nbsp;</td>";
											str = str+"</tr>";
										$("#searchResult").append(str);
										}
									$("#pageCtrl").css("display","block");
									$("#totalpages").html(totalPage);
									$("#curpage").html(curpage);
									
									$("#first").click(function(){
										first();
										$.ajax( {
											url : "findPosJobDesc.action",
											type : "post",
											dataType : "json",
											data: "bigclass="+bigclass+"&middleclass="+middleclass+"&curpage="+curpage+"&littleclass="+littleclass,
											success : function(result) {if(/requireLogin:true/.test(result)){var loginUrl = result.split(/loginUrl:/)[1];if(loginUrl){loginUrl = loginUrl.replace(/\}/,"");window.location.href = loginUrl;}return;}
											var json = eval("("
													+ result + ")");
											totalPage=json.totalPage;
											curpage=json.currentPage;
											var jsonList=json.content;
											$("#totalPages").empty();
											$("#curpage").empty();
											$("#searchResult").empty();
											for(var i=0;i<jsonList.length;i++){
												str = "<tr align='center'>";
												str = str+"<td>"+jsonList[i].bigCode+"&nbsp;</td>";
												str = str+"<td>"+jsonList[i].bigclass+"&nbsp;</td>";
												str = str+"<td>"+jsonList[i].middleCode+"&nbsp;</td>";
												str = str+"<td>"+jsonList[i].middleclass+"&nbsp;</td>";
												str = str+"<td>"+jsonList[i].littleCode+"&nbsp;</td>";
												str = str+"<td>"+jsonList[i].littleclass+"&nbsp;</td>";
												str = str+"<td>"+jsonList[i].poltypegrade+"&nbsp;</td>";
												str = str+"<td>"+jsonList[i].claimrate+"&nbsp;</td>";
												str = str+"</tr>";
											$("#searchResult").append(str);
												}
											$("#pageCtrl").css("display","block");
											$("#totalpages").html(totalPage);
											$("#curpage").html(curpage);
											
												}}
											);
									});
									
										$("#per").click(function(){
											per();
											$.ajax( {
												url : "findPosJobDesc.action",
												type : "post",
												dataType : "json",
												data: "bigclass="+bigclass+"&middleclass="+middleclass+"&curpage="+curpage+"&littleclass="+littleclass,
												success : function(result) {if(/requireLogin:true/.test(result)){var loginUrl = result.split(/loginUrl:/)[1];if(loginUrl){loginUrl = loginUrl.replace(/\}/,"");window.location.href = loginUrl;}return;}
												var json = eval("("
														+ result + ")");
												totalPage=json.totalPage;
												curpage=json.currentPage;
												var jsonList=json.content;
												$("#totalPages").empty();
												$("#curpage").empty();
												$("#searchResult").empty();
												for(var i=0;i<jsonList.length;i++){
													str = "<tr align='center'>";
													str = str+"<td>"+jsonList[i].bigCode+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].bigclass+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].middleCode+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].middleclass+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].littleCode+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].littleclass+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].poltypegrade+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].claimrate+"&nbsp;</td>";
													str = str+"</tr>";
												$("#searchResult").append(str);
													}
												$("#pageCtrl").css("display","block");
												$("#totalpages").html(totalPage);
												$("#curpage").html(curpage);
												
													}}
												);
										});
										$("#next").click(function(){
											next();
											$.ajax( {
												url : "findPosJobDesc.action",
												type : "post",
												dataType : "json",
													data: "bigclass="+bigclass+"&middleclass="+middleclass+"&curpage="+curpage+"&littleclass="+littleclass,
												success : function(result) {if(/requireLogin:true/.test(result)){var loginUrl = result.split(/loginUrl:/)[1];if(loginUrl){loginUrl = loginUrl.replace(/\}/,"");window.location.href = loginUrl;}return;}
												var json = eval("("
														+ result + ")");
												totalPage=json.totalPage;
												curpage=json.currentPage;
												var jsonList=json.content;
												$("#totalpages").empty();
												$("#curpage").empty();
												$("#searchResult").empty();
												for(var i=0;i<jsonList.length;i++){
													str = "<tr align='center'>";
													str = str+"<td>"+jsonList[i].bigCode+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].bigclass+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].middleCode+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].middleclass+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].littleCode+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].littleclass+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].poltypegrade+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].claimrate+"&nbsp;</td>";
													str = str+"</tr>";
												$("#searchResult").append(str);
													}
												$("#pageCtrl").css("display","block");
												$("#totalpages").html(totalPage);
												$("#curpage").html(curpage);
												
													}}
												);
										});
										$("#last").click(function(){
											last();
											$.ajax( {
												url : "findPosJobDesc.action",
												type : "post",
												dataType : "json",
													data: "bigclass="+bigclass+"&middleclass="+middleclass+"&curpage="+curpage+"&littleclass="+littleclass,
												success : function(result) {if(/requireLogin:true/.test(result)){var loginUrl = result.split(/loginUrl:/)[1];if(loginUrl){loginUrl = loginUrl.replace(/\}/,"");window.location.href = loginUrl;}return;}
												var json = eval("("
														+ result + ")");
												totalPage=json.totalPage;
												curpage=json.currentPage;
//												alert("totalPage--"+totalPage);
//												alert("curpage--"+curpage);
												var jsonList=json.content;
												$("#totalpages").empty();
												$("#curpage").empty();
												$("#searchResult").empty();
												for(var i=0;i<jsonList.length;i++){
													str = "<tr align='center'>";
													str = str+"<td>"+jsonList[i].bigCode+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].bigclass+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].middleCode+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].middleclass+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].littleCode+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].littleclass+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].poltypegrade+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].claimrate+"&nbsp;</td>";
													str = str+"</tr>";
												$("#searchResult").append(str);
													}
												$("#pageCtrl").css("display","block");
												$("#totalpages").html(totalPage);
												$("#curpage").html(curpage);}
											});
										});
										
										//跳转
							/*			$("#pagego").click(function(){
											var needPage=document.getElementById("gotopage").value;
											check1=/^[0-9]*$/.test(needPage);
											if( needPage==""||!check1){alert("请正确输入数字"); return;}
											else { 
												temppage=curpage;
												curpage=needPage;
												if(curpage>totalPage){alert("超过最大页数");curpage=temppage;}
												else{
											$.ajax( {
												url : "findPosJobDesc.action",
												type : "post",
												dataType : "json",
													data: "bigclass="+bigclass+"&middleclass="+middleclass+"&curpage="+curpage+"&littleclass="+littleclass,
												success : function(result) {if(/requireLogin:true/.test(result)){var loginUrl = result.split(/loginUrl:/)[1];if(loginUrl){loginUrl = loginUrl.replace(/\}/,"");window.location.href = loginUrl;}return;}
												var json = eval("("
														+ result + ")");
												totalPage=json.totalPage;
												curpage=json.currentPage;
												var jsonList=json.content;
												$("#totalpages").empty();
												$("#curpage").empty();
												$("#searchResult").empty();
												for(var i=0;i<jsonList.length;i++){
													str = "<tr align='center'>";
													str = str+"<td>"+jsonList[i].bigCode+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].bigclass+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].middleCode+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].middleclass+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].littleCode+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].littleclass+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].poltypegrade+"&nbsp;</td>";
													str = str+"<td>"+jsonList[i].claimrate+"&nbsp;</td>";
													str = str+"</tr>";
												$("#searchResult").append(str);
													}
												$("#pageCtrl").css("display","block");
												$("#totalpages").html(totalPage);
												$("#curpage").html(curpage);}
											}

											);
												}
											}
										});*/
										}
								}else {
									ShowMsg(SUCCESS,"温馨提示","系统繁忙！","请您稍后再试。");
//									alert(json.errorObject.errorMessage);
								}	
							},
							error : function() {
							}
						});
				
				
			});
});


