jQuery(function($){
	
	$('#activoSn044').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){
		$("#Documentos").rup_table({
			url: "../ab03b44t00",
			colNames: [
				$.rup.i18n.app.mantenimientos.id,
				$.rup.i18n.app.mantenimientos.descEs,
				$.rup.i18n.app.mantenimientos.descEu,
				$.rup.i18n.app.mantenimientos.ActiSN
			],
			colModel: [
				{ 	name: "id044", 
				 	label: "id044",
					align: "center", 
					width: 150, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "descEs044", 
				 	label: "descEs044",
					align: "", 
					width: 150, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "descEu044", 
				 	label: "descEu044",
					align: "", 
					width: 150, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "activoSn044",index: "activoSn044", 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:"Ab03b44t00",
	        usePlugins:[
				"formEdit",
	        	"feedback",
				"toolbar",
	        	"contextMenu",
	        	"fluid",
	        	"filter"
	         	],
         	core: {	
            	showOperations: {
            		'delete': false
            	}
            },
			primaryKey: "id044",
			sortname: "id044",
			sortorder: "asc",
			loadOnStartUp: true,
			feedback:{
				config:{
					block: false
				}
			},
	        formEdit:{
	        	detailForm: "#Documentos_detail_div",
				fillDataMethod: "clientSide",
	         	validate:{ 
	    			rules:{
	    				"descEs044":{
							required: true,
							maxlength: 100			
	    					},
	    				"descEu044":{
							required: true,
							maxlength: 100
	    					}
	    				}
	    		}
	        }
		});
	}else{
		$("#Documentos").rup_table({
			url: "../ab03b44t00",
			colNames: [
				$.rup.i18n.app.mantenimientos.id,
				$.rup.i18n.app.mantenimientos.descEs,
				$.rup.i18n.app.mantenimientos.descEu,
				$.rup.i18n.app.mantenimientos.ActiSN
			],
			colModel: [
				{ 	name: "id044", 
				 	label: "id044",
					align: "center", 
					width: 150, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "descEs044", 
				 	label: "descEs044",
					align: "", 
					width: 150, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "descEu044", 
				 	label: "descEu044",
					align: "", 
					width: 150, 
					editable: true, 
					fixed: false, 
					hidden: false, 
					resizable: true, 
					sortable: true
				},
				{ 	name: "activoSn044",index: "activoSn044", 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:"Ab03b44t00",
	        usePlugins:[
	        	"feedback",
	        	"fluid",
	        	"filter"
	         	],
         	core: {	
            	showOperations: {
            		'delete': false
            	}
            },
			primaryKey: "id044",
			sortname: "id044",
			sortorder: "asc",
			loadOnStartUp: true,
			feedback:{
				config:{
					block: false
				}
			}
		});
	}
	
	$("#Documentos_filter_form").rup_validate({
		feedback:$("#Documentos_feedback"),
		liveCheckingErrors: false,
		rules:{
			"id044":{digits:true}
		}
	});	
	
	$("#Documentos").on("rupTable_beforeFilter",
		function(){
			if(ab03bUtils.form.validate($("#Documentos_filter_form"))){	
				return true;
			} else {
				return false;
			}
		}
	);	
});

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

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