



function saveGroup(){
	var groupList =[];
	$("#context").find("tr").each(function(){
		var GroupInfo = {};
		GroupInfo.groupNo= $(this).find("td:eq(0)").html().trim();
		GroupInfo.groupName = $(this).find("input:eq(0)").val();
		GroupInfo.groupMemo = $(this).find("input:eq(1)").val();
		groupList.push(GroupInfo);
	});

	$.ajax({
		type:"POST",
		url:"saveGroup.do",
		contentType:"application/json; charset=UTF-8",
		data:JSON.stringify(groupList),
		error:function(){
			alert("保存失败");
		},
		success:function(data){
				if(data.message=="success"){
					alert("保存成功");
					location.reload(true); 
				}else if(data.message=="exist"){
					alert("已存在");
				}
		}
	});
}

function deleteGroup(){
	if(confirm("请确定是否删除此条信息")==true){

	$.ajax({
		type:"POST",
		url:"deleteGroup.do",
		data:{"groupNo":$("#no").val()},
		error:function(){
			alert("删除失败");
		},
		success:function(data){
			if(data.status=="success"){
				alert("删除成功");
				location.reload(true);
			}
		}
	});
	}
}


function addRow(){
		$("#context").prepend("<tr><td></td><td><input type=\"text\" class=\" input i_s_240 input_bot_line\" value=\"\" /></td><td><input type=\"text\" class=\" input i_s_240 input_bot_line\" value=\"\" /></td></tr>");
}

//选择某行
function selRow(flag){
	$("#hiddenGroupNo").val($(flag).attr("id"));
	$("#no").val($(flag).attr("id"));
	$(flag).css("background-color", "#e5e5e5").siblings().css("background-color", "#FFFFFF");
	
	$("#row-no").val($(flag).index());
}


//翻页
function cur_skip(e){
	var pn = $(e).find("span").html();
	SkipByPost("group.do",{"groupName":$("#group-name-keyword").val(),pageNumber:pn});
	$(".turn_cur").removeAttr("class");
	$(e).find("span").attr("class","turn_cur");
}

//前一页
function pre(e){
	var maxPage = $("#max").val();
	var cur = $("#nav").find(".turn_cur").html();
	if(cur>1){
	var pre = Number(cur)-Number(1);
	SkipByPost("group.do",{"groupName":$("#group-name-keyword").val(),pageNumber:pre});
	}else{
		SkipByPost("group.do",{pageNumber:maxPage});
	}
}
//下一页
function next(e){
	var cur = $("#nav").find(".turn_cur").html();
	var next = Number(cur)+Number(1);
	var maxPage = $("#max").val();
	if(parseInt(cur)<parseInt(maxPage)){
		SkipByPost("group.do",{"groupName":$("#group-name-keyword").val(),pageNumber:next});
	}else{
		SkipByPost("group.do",{pageNumber:1});
	}
}
//跳转至
function custom(){
	var pn = $.trim($("#turn_inp").val());
	if(pn == "") return;
	SkipByPost("group.do",{"groupName":$("#group-name-keyword").val(),pageNumber:Number(pn)});
}


//根据组别名称搜索组别
function searchGroup(){
	var currentPageNumber = $("#nav").find(".turn_cur").html();
	
	SkipByPost("group.do",{"groupName":$("#group-name-keyword").val(),"pageNumber":currentPageNumber});
	
	/*$.ajax({
		type:"POST",
		url:"searchGroupInfo.do",
		data:{"groupName":$("#group-name-keyword").val(),"pageNumber":currentPageNumber},
		error:function(){
			alert("查询出错");
		},
		success:function(data){
			$("#context").empty();
			for ( var i = 0; i < data.length; i++) {
				var groupInfo = data[i];
				$("#context").append("<tr id="+groupInfo.groupNo+">" +
						                "<td>"+groupInfo.groupNo+"</td>" +
							            "<td>"+groupInfo.groupName+"</td>" +
							            "<td>"+groupInfo.groupMemo+"</td>" +
						             "</tr>");
			}
			
		}
	});*/
}


