function queryDeceit(){
	var parameters = {};
	
//	chooseCondValue="class";
	
   if(chooseCondValue=="class"){
	   parameters["deceitReason"]= $("#input").val();
	   parameters['deceitType'] ='1';
	   
   }else if(chooseCondValue=="desc"){
	   parameters["deceitReason"] = $("#input").val();
	   parameters['deceitType'] ='2';
   }
	

	
	$.ajax({
	
		type:"POST",
		url:"getDeceitReason.do",
		data:parameters,
		error:function(){
			alert("查询失败！");
			return;
		},
		success:function(data){
			if(data==""||data==null){
				$("#context").html("");
				$("#context").append("<tr><td>没有相关内容，请检查输入是否正确</td></tr>");
				return;
			}
			
			$("#context").html("");
			for(var i=0;i<data.length;i++){
				var deceitReason = data[i];
				$("#context").append("<tr style=\"cursor:pointer\" id=\""+deceitReason.objId+"\" onclick=\"choosEd(this)\"><td ondblclick=\"edit(this)\">"+deceitReason.deceitTypeDesc+"</td><td ondblclick=\"edit(this)\">"+deceitReason.deceitReasonDesc+"</td><td>"+deceitReason.createUser+"</td><td>"+deceitReason.showUpdateDate+"</td><td>"+deceitReason.showCreateDate+"</td></tr>");
			}
			
		}
		
	});
	

	
	
}

//获取选择条件
var chooseCondValue = "class";
function chooseCond(obj){
	$("#context").html("");
	chooseCondValue = obj.id;
}

//添加
function addDeceit(){
	
	//增加一行输入框
	var addInput=document.getElementById("addInput");
	
	$("#context").html("");
	if(addInput==null||addInput==undefined){
		$("#context").prepend("<tr id=\"addInput\"><td><input type=\"text\" class=\"input i_s_100\" id=\"deceitTypeDesc\" /></td><td><input type=\"text\"  class=\"input i_s_240\" id=\"deceitReasonDesc\" /></td><td></td><td></td><td></td></tr>");
	}else{
		$("#deceitTypeDesc").focus();
	}
	
	
}

//保存
function saveDeceit(){
	
	var deceitTypeDesc = $("#deceitTypeDesc").val();
    var deceitReasonDesc = $("#deceitReasonDesc").val();
    
	if(deceitTypeDesc==""||deceitTypeDesc==null||deceitReasonDesc==""||deceitReasonDesc==null){
		alert("请先输入,再保存!");
		return;
	}
 
	
	
	//提交数据至服务器
	$.ajax({
		
		type:"POST",
		url:"addDeceitReason.do",
		data:{"deceitTypeDesc":deceitTypeDesc,"deceitReasonDesc":deceitReasonDesc},
		error:function(){
			alert("提交新增失败");
			return;
		},
		success:function(data){
			
			var message = data.message;
			if(message=="success"){
				querySave(deceitReasonDesc);
				alert("保存成功！");
			}else if(message=="isExist"){
				alert("已存在！");
			}else{
				alert("保存失败！");
			}
		}
	
	});
	
	
	
}



//添加成功之后,再查询一次添加的数据
function querySave(deceitReasonDesc){

$.ajax({
	
	type:"POST",
	url:"getDeceitReason.do",
	data:{"deceitReason":deceitReasonDesc,"deceitType":"2"},
	error:function(){
		alert("查询失败！");
		return;
	},
	success:function(data){
		$("#context").html("");
		for(var i=0;i<data.length;i++){
			var deceitReason = data[i];
			$("#context").append("<tr style=\"cursor:pointer\" id=\""+deceitReason.objId+"\" onclick=\"choosEd(this)\"><td ondblclick=\"edit(this)\">"+deceitReason.deceitTypeDesc+"</td><td ondblclick=\"edit(this)\">"+deceitReason.deceitReasonDesc+"</td><td>"+deceitReason.createUser+"</td><td>"+deceitReason.showUpdateDate+"</td><td>"+deceitReason.showCreateDate+"</td></tr>");
		}
		
	}
	
});


}


//删除操作

var index=null;
function removeRows(){
	
	if(objId==null){
		alert("请选择要删除的行");
		return;
	}
	
	if(confirm("请确定是否删除此条信息")){
        deleteRequest();
		$("#"+objId).remove();
		objId=null;
		
	}
}
	





//删除AJAX请求

function deleteRequest(){
	
	$.ajax({
		
		type:"POST",
		url:"deleteDeceitReason.do",
		data:{"objId":objId},
		error:function(){
			alert("删除失败");
			return;
		},
		success:function(data){
			alert("删除成功");
			queryDeceit();
			$("#changed").removeAttr("id");
		},
		
	});
	
}




//选中某行

var objId=null;
function choosEd(flag){
	
	objId=$(flag).attr("id");
	$(flag).css("background-color", "#e5e5e5").siblings().css("background-color", "#FFFFFF");
	index=$(flag).index();
	
}


//双击编辑

function edit(td){
	
		var tdText=$(td).html();
		var tds=tdText.split('<');
		if(tds.length>1){
			return;
	
	}
	$(td).html("<input onblur='blurSave(this)' class='input i_s_240' type='text' value='"+$(td).html()+"'></input>");
	$(td).find("input")[0].focus();
}
//失焦恢复td
function blurSave(obj){
	var objTxt=$(obj).val();
	$(obj).parent().attr("id","changed");
	$(obj).parent().html(objTxt);
	saveEdit();
}

//保存编辑后的内容
function saveEdit(){
	var id = $("#changed").parent().attr("id");
	var deceitTypeDesc = $("#"+id).find("td").eq(0).html();
	var deceitReasonDesc = $("#"+id).find("td").eq(1).html();
	
	//提交数据至服务器
	$.ajax({
		
		type:"POST",
		url:"updateDeceitReason.do",
		data:{"objId":id,"deceitTypeDesc":deceitTypeDesc,"deceitReasonDesc":deceitReasonDesc},
		error:function(){
			alert("提交新增失败");
			return;
		},
		success:function(data){
			
			if(data.message=="success"){
				alert("保存成功!");
			}else{
				alert("保存失败!");
			}
			
			queryDeceit();
			$("#changed").removeAttr("id");
		}
	
	});
}

//回车查询
function enterQuery(){
	 var event = window.event||arguments.callee.caller.arguments[0];
	 if(event.keyCode==13){
		 queryDeceit();
	 }
}