
MantenedorAyudas = function(config){ 

	this.dh 	= Ext.DomHelper;
	// captura la configuracion para los metodos 
	this.config = config;

	// crea el elemento para el dialogo
	el = this.dh.append(document.body, {tag: 'div' }, true);
	YAHOO.util.Dom.generateId(el);
	
	// crea los elementos para el dialogo
	this.hd = this.dh.append(el.id , {tag: 'div', cls : 'x-dlg-hd' }, true);
	YAHOO.util.Dom.generateId(this.hd);
	this.hd.update(this.config.titulo);

	this.bd  	= this.dh.append(el.id 	   		,{tag: 'div', cls : 'x-dlg-bd'  }, true);
	this.td  	= this.dh.append(this.bd.id		,{tag: 'div', cls : 'x-dlg-tab'  , title : this.config.subTitulo}, true);
	this.intd  	= this.dh.append(this.td.id		,{tag: 'div', cls : 'inner-tab'}, true);
	//this.png  	= this.dh.append(this.intd.id	,{tag: 'div'}, true);								// crea el panel para el colapsador
					// crea el elemento para el colapsador
	
	// invoca al constructor BasicDialog
	MantenedorAyudas.superclass.constructor.call(this, el.id, this.config.dialog);
	this.gd  	= this.dh.append(this.intd.id	,{tag: 'div'}, true);
	
	// agrega botones aceptar cancelar 

	//this.btnCancela   = this.addButton('Cerrar', this.hide, this);
	
	this.on('hide', this.destruir, this, true);
	this.addKeyListener(27, this.hide, this);
};


Ext.extend(MantenedorAyudas, Ext.BasicDialog, {
	
	verMantenedor: function(){
		
		//obtiene el perfil del usuarrio
		var perfil = '';
		if (YAHOO.gestorAST.usuario.campos['PFL_NOMBRE'].valor) perfil = YAHOO.gestorAST.usuario.campos['PFL_NOMBRE'].valor;

		this.btnGuardar   = this.addButton('Guardar' , this.guardarCambios , this);
			
		config = { webservice		: 'modulos/ayudas/ingresar.asp?OBJ_ID=' + this.config.objId + '&perfil=' + perfil,
					grupoExpandido  : '1',
					navRapida		: false,
					key				: '',
					form   		   	: { action 	: 'modulos/ayudas/guardar.asp?perfil=' + perfil,
										method	: 'POST'
									 }
				 };
		this.colap = new capsadorForm(this.gd, config); 
		this.show(this.config.tarjetEl);
		
	},
	
	guardarCambios : function(){
		
			var tipoId = this.config.tipoId;
			var gthis  = this;
			
			var callback = { 
				success: function(o){
								var contenido = o.responseText.htmlDecode();
								
								new mensaje('Guardar.',
												'Ayuda guardada exitosamente.',
												{ modal:true,
												  width:380,
												  height:80,
												  shadow:true,
												  closable:true 
												}
												).show(gestorAST.animacion);
								gthis.hide();
							}, 
				failure: function(o){
								new mensaje('Error al registrar.',
											o.responseText,
											{ modal:true,
											  width:500,
											  height:500,
											  shadow:true,
											  closable:true 
											}
								 			).show(gestorAST.animacion);	
								return; 
							},
				 timeout: 5000
	       };

			YAHOO.util.Connect.setForm(this.colap.form().name, false);
			YAHOO.util.Connect.asyncRequest('POST', this.colap.form().action, callback );

	},
	
	
	verAyuda : function(){
		
		var perfil = '';
		if (YAHOO.gestorAST.usuario.campos['PFL_NOMBRE'].valor) perfil = YAHOO.gestorAST.usuario.campos['PFL_NOMBRE'].valor;

		this.btnCerrar   = this.addButton('Cerrar' , this.hide , this);
		
		var um = Ext.get(this.gd.id).getUpdateManager();
		um.disableCaching = true;
		um.showLoadIndicator = false;

		url = 'modulos/ayudas/mostrar.asp?OBJ_ID=' + this.config.objId + '&perfil=' + perfil
		um.update(url);
		this.show(this.config.tarjetEl);
	},

	destruir : function(){
		this.destroy(true);
	}
	
} );


