
MantenedorPTT = 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
	MantenedorPTT.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.btnAceptar   = this.addButton('Guardar' , this.guardarCambios , this);
	//this.btnCancela   = this.addButton('Cerrar', this.hide, this);
	
	this.on('hide', this.destruir, this, true);
	this.addKeyListener(27, this.hide, this);
};


Ext.extend(MantenedorPTT, Ext.BasicDialog, {
	
	init		: function(){

		config = { webservice		: "modulos/tipoTrabajo/ingresar.asp?TT_ID=" + this.config.tipoId,
					grupoExpandido  : "1",
					navRapida		: false,
					key				: '',
					form   		   	: { action 	: 'modulos/tipoTrabajo/guardar.asp',
										method	: 'POST'
									 }/*,
					botones		   	:[{
										id:'guardarMTT-btn', 
										text: 'Guardar', 
										cls:'x-btn-text-icon guardar',																			
										tooltip: {text:'Guarda los datos en la base de datos.', title:'Guardar.', autoHide:true},
										handler:  this.guardarCambios.createDelegate(this) // gestorAST.registrar
									  }]*/
				 };
		this.colap = new capsadorForm(this.gd, config); 
		this.show(this.config.objeto);
	},
	
	guardarCambios : function(){
		
			var tipoId = this.config.tipoId;
			var gthis  = this;
			
			var callback = { 
				success: function(o){
								var contenido = o.responseText.htmlDecode();
								
								new mensaje('Guardar.',
												'Plantilla guardada exitosamente.',
												{ modal:true,
												  width:380,
												  height:80,
												  shadow:true,
												  closable:true 
												}
												).show(gestorAST.animacion);

								// obtiene panel activo y actualiza contenido de secciones
								for(var oName in YAHOO.gestorAST.objetos){
									if (YAHOO.gestorAST.objetos[oName].layout.active){
										oo = YAHOO.gestorAST.objetos[oName];
										oo.objetoAnexo().actualizar('modulos/ast/ingresar/actualizarSecciones.asp?TIPO_TRAB_ID=' + tipoId);
									}
								}
								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 );

	},

	destruir : function(){
		this.destroy(true);
	}
	
} );


