jQuery(function($){
	
	$('#activoSn003').rup_combo({
		source : [
				   {label: $.rup.i18n.app.mantenimientos.todas, value:"0"},
				   {label: $.rup.i18n.app.mantenimientos.activos, value:"S"},
				   {label: $.rup.i18n.app.mantenimientos.inactivos, value:"N"}					   
				],
		width: 200,
		rowStriping : true,
		inputText:true,
		ordered:true
	});
	
	if(esUsuarioModificacion){
		$("#Cargos").rup_table({
			url: "../ab03b03t00",
			colNames: [
				$.rup.i18n.app.mantenimientos.id,
				$.rup.i18n.app.mantenimientos.descEs,
				$.rup.i18n.app.mantenimientos.descEu,
				$.rup.i18n.app.mantenimientos.ActiSN
			],
			colModel: [
				{ 	name: "id003", 
				 	label: "id003",
					align: "center", 
					width: 50, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					//resizable: true, 
					sortable: true
				},
				{ 	name: "descEs003", 
				 	label: "descEs003",
					align: "", 
					width: 200, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					//resizable: true, 
					sortable: true
				},
				{ 	name: "descEu003", 
				 	label: "descEu003",
					align: "", 
					width: 200, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					//resizable: true, 
					sortable: true
				},			
				{ 	name: "activoSn003", index: "activoSn003", editable:true, width: 60,
					edittype: "checkbox",
					formatter: "checkbox",
					align: "center",
					editoptions: {
						value:"S:N"
					},
					searchoptions:{
						rupType: "combo",
						source : [
						   //{label: "---", value:""},
						   {label: "Si", value:"S"},
						   {label: "No", value:"N"}
						]
					}
				}
	        ],
	        model:"Ab03b03t00",
	        usePlugins:[
				"formEdit",
	        	"feedback",
				"toolbar",
	        	"contextMenu",
	        	"fluid",
	        	"filter"//,
	        	//"search"
	        ],
	        /*core: {
	        	showOperations: {
	        		'delete': false
	        	}
	        },*/
			primaryKey: "id003",
			sortname: "id003",
			sortorder: "asc",
			loadOnStartUp: true,
			feedback:{
				config:{
					block: false
				}
			},
	        formEdit:{
	        	detailForm: "#Cargos_detail_div",
				fillDataMethod: "clientSide",
	         	validate:{ 
	    			rules:{
	    				"id003":{
	    					digits: true
	    					},
	    				"descEs003":{
	    					required: true
	    					},
	    				"descEu003":{
	    					required: true
	    				}
	    			}
	         	}
	        },
	        toolbar: {
	        	showOperations: {       		
	        		//'clone': false,
	        		'delete': false
	        	}
	        }
		});
	}else{
		$("#Cargos").rup_table({
			url: "../ab03b03t00",
			colNames: [
				$.rup.i18n.app.mantenimientos.id,
				$.rup.i18n.app.mantenimientos.descEs,
				$.rup.i18n.app.mantenimientos.descEu,
				$.rup.i18n.app.mantenimientos.ActiSN
			],
			colModel: [
				{ 	name: "id003", 
				 	label: "id003",
					align: "center", 
					width: 50, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					//resizable: true, 
					sortable: true
				},
				{ 	name: "descEs003", 
				 	label: "descEs003",
					align: "", 
					width: 200, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					//resizable: true, 
					sortable: true
				},
				{ 	name: "descEu003", 
				 	label: "descEu003",
					align: "", 
					width: 200, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					//resizable: true, 
					sortable: true
				},			
				{ 	name: "activoSn003", index: "activoSn003", editable:true, width: 60,
					edittype: "checkbox",
					formatter: "checkbox",
					align: "center",
					editoptions: {
						value:"S:N"
					},
					searchoptions:{
						rupType: "combo",
						source : [
						   //{label: "---", value:""},
						   {label: "Si", value:"S"},
						   {label: "No", value:"N"}
						]
					}
				}
	        ],
	        model:"Ab03b03t00",
	        usePlugins:[
	            "feedback",
	            "fluid",
				"filter"
	        ],
			primaryKey: "id003",
			sortname: "id003",
			sortorder: "asc",
			loadOnStartUp: true,
			feedback:{
				config:{
					block: false
				}
			}
		});
	}
	
	$("#Cargos_filter_form").rup_validate({
		feedback:$("#Cargos_feedback"),
		liveCheckingErrors: false,
		rules:{
			"id003":{digits:true}
		}
	});	
	
	
	$("#Cargos").on("rupTable_beforeFilter",
		function(){
			if(ab03bUtils.form.validate($("#Cargos_filter_form"))){	
				return true;
			} else {
				return false;
			}
		}
	);	
});


$("#Cargos").on("jqGridAddEditAfterShowForm", function(event,savedData, newData){
	$("#pag_Cargos").css("display",'none');
	var texto=$("#ui-dialog-title-Cargos_detail_div").html();
	if(texto=="Agregar registro"||texto=="Gehitu erregistroa"){
		setTimeout(function(){
			$("#activoSn003_detail_table").prop("checked",true);
		},100);
		$("#activoSn003_detail_table").attr("disabled",true);
	}else{
		$("#activoSn003_detail_table").attr("disabled",false);
	}
	$("#id003_detail_table").attr("disabled",true);
});	

//Funcion limpiar
$('#Cargos_filter_cleanLink').click(function(event){
	resetFiltro($("#Cargos_filter_form"));
	
	//se borran los mensajes de errores que se muestran en el feedback
	$("#Cargos_filter_form").validate().submitted = {};
	//se cierra el feedback
	$("#Cargos_feedback").rup_feedback("close");
	
	$("#Cargos").rup_table('filter'); 
	
	// se quitan las imagenes que marcan el error
	$(".rup-maint_validateIcon", $("#Cargos_filter_form")).remove();
});
