jQuery(function($){
	
	$('#activoSn041').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: 120,
		rowStriping : true,
		inputText:true,
		ordered:true
	});
	
	$('#friable041').rup_combo({
		source : [
				   {label: $.rup.i18n.app.mantenimientos.todas, value:"0"},
				   {label: $.rup.i18n.app.mantenimientos.friable, value:"S"},
				   {label: $.rup.i18n.app.mantenimientos.no_friable, value:"N"}					   
				],
		width: 120,
		rowStriping : true,
		inputText:true,
		ordered:true
	});

	if(esUsuarioModificacion){
		$("#TipoMaterial").rup_table({
			url: "../ab03b41t00",
			colNames: [
			         $.rup.i18n.app.mantenimientos.id,
			         $.rup.i18n.app.mantenimientos.descEs,
			         $.rup.i18n.app.mantenimientos.descEu,	        
			         $.rup.i18n.app.mantenimientos.codMCA,
			         $.rup.i18n.app.mantenimientos.friable,
			         $.rup.i18n.app.mantenimientos.ActiSN
			],
			colModel: [
				{ 	name: "id041", 
				 	label: "id041",
					align: "center", 
					width: 60, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "descEs041", 
				 	label: "descEs041",
					align: "", 
					width: 180, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "descEu041", 
				 	label: "descEu041",
					align: "", 
					width: 180, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "codMca041", 
				 	label: "codMca041",
					align: "center", 
					width: 150, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "friable041", 
					label: "friable041",
					width: 60, 
					edittype: "checkbox",
					formatter: "checkbox",
					align: "center",
					editoptions: {
						value:"S:N"
					},
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
						
				},
				{ 	name: "activoSn041", 
					label: "activoSn041", 
					editable:true, 
					width: 60, 
					edittype: "checkbox",
					formatter: "checkbox",
					align: "center",
					editoptions: {
						value:"S:N"
					},
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
					
				}
	        ],
	
	        model:"Ab03b41t00",
	        usePlugins:[
				"formEdit",
	        	"feedback",
				"toolbar",
	        	"contextMenu",
	        	"fluid",
	        	"filter"
	         ],
	     	core: {
	        	showOperations: {
	        		'delete': false
	        	}
	        },
			primaryKey: "id041",
			sortname: "id041",
			sortorder: "asc",
			loadOnStartUp: true,
			feedback:{
				config:{
					block: false
				}
			},
	        formEdit:{
	        	detailForm: "#TipoMaterial_detail_div",
				fillDataMethod: "clientSide",
	         	validate:{ 
	         		rules:{
	    				"descEs041":{
							required: true,
							maxlength: 100
	    					},
	    				"descEu041":{
							required: true,
							maxlength: 100
	    					},
	    				"codMca041":{
							required: true,
							maxlength: 4
	    					},
	    				"friable041":{
							required: false
	    					},
	    				"activoSn041":{
	    					required: false
	        				}
	    				}
	    		}
	        }
		});
	}else{
		$("#TipoMaterial").rup_table({
			url: "../ab03b41t00",
			colNames: [
			         $.rup.i18n.app.mantenimientos.id,
			         $.rup.i18n.app.mantenimientos.descEs,
			         $.rup.i18n.app.mantenimientos.descEu,	        
			         $.rup.i18n.app.mantenimientos.codMCA,
			         $.rup.i18n.app.mantenimientos.friable,
			         $.rup.i18n.app.mantenimientos.ActiSN
			],
			colModel: [
				{ 	name: "id041", 
				 	label: "id041",
					align: "center", 
					width: 60, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "descEs041", 
				 	label: "descEs041",
					align: "", 
					width: 180, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "descEu041", 
				 	label: "descEu041",
					align: "", 
					width: 180, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "codMca041", 
				 	label: "codMca041",
					align: "center", 
					width: 150, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "friable041", 
					label: "friable041",
					width: 60, 
					edittype: "checkbox",
					formatter: "checkbox",
					align: "center",
					editoptions: {
						value:"S:N"
					},
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
						
				},
				{ 	name: "activoSn041", 
					label: "activoSn041", 
					editable:true, 
					width: 60, 
					edittype: "checkbox",
					formatter: "checkbox",
					align: "center",
					editoptions: {
						value:"S:N"
					},
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
					
				}
	        ],
	
	        model:"Ab03b41t00",
	        usePlugins:[
	        	"feedback",
	        	"fluid",
	        	"filter"
	         ],
	     	core: {
	        	showOperations: {
	        		'delete': false
	        	}
	        },
			primaryKey: "id041",
			sortname: "id041",
			sortorder: "asc",
			loadOnStartUp: true,
			feedback:{
				config:{
					block: false
				}
			}
		});
	}
	
	$("#TipoMaterial_filter_form").rup_validate({
		feedback:$("#TipoMaterial_feedback"),
		liveCheckingErrors: false,
		rules:{
			"id041":{digits:true}
		}
	});	
	
	
	$("#TipoMaterial").on("rupTable_beforeFilter",
		function(){
			if(ab03bUtils.form.validate($("#TipoMaterial_filter_form"))){	
				return true;
			} else {
				return false;
			}
		}
	);	
	
});

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


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