function selectUserFunction(userCode){
	$("#userCode").val(userCode);
	var empRoleId = $("#" + userCode + "_empRoleId").val();
	var highEmpRoleId = $("#" + userCode + "_highEmpRoleId").val();
	$("#empRoleId").val(empRoleId);
	$("#highEmpRoleId").val(highEmpRoleId);
	$("#empRoleSelect").html("选择");
	$("#highEmpRoleSelect").html("选择");
	if (empRoleId != null && empRoleId != "") {
		$("#empRoleSelect").html($("#" + empRoleId).html());
	}
	if (highEmpRoleId != null && highEmpRoleId != "") {
		$("#highEmpRoleSelect").html($("#" + highEmpRoleId).html());
	}
}

function selectEmpRole(roleId, roleType){
  var userCode = $("#userCode").val();
  if (roleType == '01') {
		$("#empRoleId").val(roleId);
		$("#" + userCode + "_empRoleId").val(roleId);
  } else if (roleType == '02') {
		$("#highEmpRoleId").val(roleId);
		$("#" + userCode + "_highEmpRoleId").val(roleId);
  }
}

function saveEmpRoleInfo(){
	jsonStr = '{"userCode":"' + $("#userCode").val() + '","empRoleId":"' + $("#empRoleId").val() + '","highEmpRoleId":"' + $("#highEmpRoleId").val() + '"}';
	$.ajax({
		 type: "POST", 
		 contentType:"application/json; charset=UTF-8",
	     url: "saveUserRoleInfo.do",
	     data:jsonStr,
	     dataType:"json",
	     success:function(data){
	    	 if (data.errorFlag == 'Y') {
	    		 alert("保存成功！");
	    	 } else {
	    		 alert(data.errorMsg + "！");
	    	 }
	     },
	     error:function(data){
	    	alert("保存失败！") ;
	     }
	});
}

function saveEmpRole(){
	changeStr = "["+changeStr.substring(0,changeStr.length-1)+"]";
	jsonStr = '{"ids":"","empRoleList":' + changeStr+'}';
	$.ajax({
		 type: "POST", 
		 contentType:"application/json; charset=UTF-8",
	     url: "saveRoleSet.do",
	     data:jsonStr,
	     dataType:"json",
	     success:function(data){
	    	 alert("保存成功");
	    	 SkipByPost("showRoleSet.do","");
	     },
	     error:function(data){
	    	alert(data) ;
	     }
	});
}

function compareRepeat(input){
	if( $(input).attr("code") != $(input).val()){
		var roleName = $("#roleList tr:eq("+index+") input:eq(0)").val();
		var roleLevel = $("#roleList tr:eq("+index+") input:eq(1)").val();
		$("#roleList").find("tr").each(function(i,n){
			if( i != index){
				if(roleName == $(this).find("input:eq(0)").val() && roleLevel == $(this).find("input:eq(1)").val()){
					alert("已存在相同的角色信息,请确认");
					$("#roleList tr:eq("+index+") input:eq(1)").attr("value","");
					$("#roleList tr:eq("+index+") input:eq(1)").focus();
					return false;
				}
			}
		});
	}
	
	
}

function selected(){
	$(".select").hover( function () {
		$(this).addClass("sel_over");
	},function () {
		$(this).removeClass("sel_over");
	}).on('click',function(){
		var _this = $(this),
			_bthis = $(this).find(".sel_list");
		if ( _this.attr('isopen') ) {
			_bthis.slideUp(0 , function(){
				_this.removeAttr('isopen');
			});			
		} else {
			_bthis.slideDown(0,function(){
				_this.attr('isopen',"1");
			});	
		}
	}).on('mouseleave',function(){
		var _thisa = $(this).find(".sel_list"),
			_this = $(this);
		_thisa.hide();
		_this.removeAttr('isopen');
	}),
	$(".select").find(".sel_list li").hover( function (){
		$(this).addClass("sel_hov");		
	},function (){
		$(this).removeClass("sel_hov");	
	}).on('click',function(){
		var _this = $(this).html();
		var _thisText = $(this).closest(".select").find(".sel_text");
		_thisText.html(_this);
	});
	
}