function anuncio(tipo){

	var centro = viewport.getComponent('center-panel');
	
	if(!centro.findById('detalle-anuncios-'+tipo)){
		centro.add({
			id:'detalle-anuncios-'+tipo,
			title:'Anuncios',
			closable:true,
			autoScroll:true
		}).show();
		centro.activate('detalle-anuncios-'+tipo);
		$('detalle-anuncios-'+tipo).innerHTML = '<div id="anuncios'+tipo+'-grid" style="width:100%;"></div>';

		centro.findById('detalle-anuncios-'+tipo).on("beforedestroy",function(){
			form.destroy();
			win.destroy();
			nav.destroy();
		});
		
		var myPageSize = Math.round((altura)/30);
		var icono;
		
		if(tipo=='F') icono = "cross1.gif";
		else if(tipo=='E') icono = "bullet_wrench.png";
		else icono = "database_add.png";
		
		var ds = new Ext.data.Store({
			proxy:new Ext.data.HttpProxy({url:'anuncios/leeAnuncios.jsp?tipo='+tipo}),
			reader:new Ext.data.JsonReader({
				root:'results',
				totalProperty:'totalCount'
			},[
				{name:'ID'},
				{name:'FECHA2'},
				{name:'NOMBRE'},
				{name:'DESCRIPCION'},
				{name:'TITULO'},
				{name:'FFIN'},
				{name:'MAIL'},
				{name:'TELEFONO'}
			]),
			remoteSort:true
		});
		
		function renderTopic(value,p,record){
			return String.format('<b style="background:transparent url(../icons/'+icono+') no-repeat scroll left 1px;color:#333333;display:block;font-family:tahoma, verdana;padding-left:18px;"><font color="maroon">{0}</font> .- {1}</b>',record.data['FECHA2'], value);
		}
		
		function renderDate(value,p,record){
			return String.format('<b style="display:block;font-family:tahoma, verdana;line-height:18px;vertical-align:middle;"><font color="maroon">{0}</font></b>', value);
		}
		
		function cr(){
			return "<input type='image' src='../icons/magnifier.png' />";
		}
		
		var cm = new Ext.grid.ColumnModel([{
				header:"Titulo",
				dataIndex:'TITULO',
				align:'left',
				renderer:renderTopic,
				width:Math.round(0.62*anchura)
			},{
				header:"Fin de Publicación",
				dataIndex:'FFIN',
				align:'center',
				renderer:renderDate,
				width:Math.round(0.12*anchura)
			},{
				header:"Nombre",
				dataIndex:'NOMBRE',
				align:'center',
				width:Math.round(0.19*anchura)
			},{
				header:"Detalles",
				dataIndex:'NOMBRE',
				align:'center',
				renderer:cr,
				width:Math.round(0.07*anchura)
			}
		]);
		
		cm.defaultSortable = false;
		
		function onInsAnuncio(){
			win.show();
			if(!form.rendered){
				form.render('dialog-form-anuncios-'+tipo);
			}
			form.getForm().reset();
		}
		
		var insButton = new Ext.Button({
			text:'Nuevo Anuncio',
			tooltip:'<b>Nuevo Anuncio</b><br/>Haz click aquí para añadir un anuncio al tablón',
			cls:'x-btn-text-icon',
			icon:'../icons/add.png',
			handler:onInsAnuncio
		});
		
		// create the editor grid
		var mySelectionModel = new Ext.grid.CellSelectionModel();
		mySelectionModel.on("cellselect", function(objeto, rowIndex, colIndex){
			if(colIndex == 3) {
				var row = ds.getAt(rowIndex);
		        if(row.data.DESCRIPCION.length>1300){
		            Ext.MessageBox.show({
		                title:row.data.TITULO,
		                msg:"<b>Direcci&oacute;n de correo electr&oacute;nico: </b>"+row.data.MAIL+"<br><br><b>N&uacute;mero de Tel&eacute;fono: </b>"+row.data.TELEFONO+"<br><br><div style='width:600px;height:200px;overflow:auto;'><font color='maroon'><b>"+row.data.FECHA2+"</b></font> .- "+row.data.DESCRIPCION+"</div>",
		                buttons:Ext.MessageBox.OK,
		                width:600
		            });
		        }
		        else{
		            Ext.MessageBox.show({
		                title:row.data.TITULO,
		                msg:"<b>Direcci&oacute;n de correo electr&oacute;nico: </b>"+row.data.MAIL+"<br><br><b>N&uacute;mero de Tel&eacute;fono: </b>"+row.data.TELEFONO+"<br><br><font color='maroon'><b>"+row.data.FECHA2+"</b></font> .- "+row.data.DESCRIPCION,
		                buttons:Ext.MessageBox.OK,
		                width:400
		            });
		        }
			}
		});
		
		
		var grid = new Ext.grid.GridPanel({
			el:'anuncios'+tipo+'-grid',
			title:'Anuncios',
			store:ds,
			cm:cm,
			sm:mySelectionModel,
			enableColLock:false,
			width:anchura,
			height:altura,
			loadMask:true,
			trackMouseOver:false,
			viewConfig:{forceFit:true},
			bbar:new Ext.PagingToolbar({
				pageSize:myPageSize,
				store:ds,
				displayInfo:true,
				displayMsg:'Mostrando registros {0} - {1} de {2}',
				emptyMsg:"No hay registros que mostrar",
				items:['-',insButton]
			})
		});
		
		grid.render();
		
		var nav = new Ext.Panel({
			region:'center',
			width:350,
			margins:'3 0 3 3',
			cmargins:'3 3 3 3',
			items:[{html:'<div id="dialog-form-anuncios-'+tipo+'"></div>'}]
		});
		
		var win = new Ext.Window({
			title:'<b>Insertar Anuncio</b>',
			closable:true,
			width:625,
			height:500,
			plain:true,
			closeAction:'hide',
			layout:'border',
			items:[nav]
		});
		
		function insAnuncio(){
	        if(!form.getForm().isValid()){
	            Ext.MessageBox.alert("Campos obligatorios vacios", "Por favor rellene todos los campos obligatorios.");
	            return 0;
	        }
	        if(lopd.getValue()==false){
	        	Ext.MessageBox.alert("Ley Orgánica de Protección de Datos", "Para continuar debe aceptar el cumplimiento de la Ley Orgánica de Protección de Datos.");
	            return 0;
	        }
	        Ext.MessageBox.show({
	            msg:"El anuncio va a ser enviado al moderador. ¿Desea continuar?",
	            title:"Confirmación",
	            buttons:Ext.Msg.OKCANCEL,
	            width:420,
	            fn:ins
	        });
	        function ins(btn){
	            if(btn=='ok'){
	                var account_data = new Ext.data.Store({
	                    proxy:new Ext.data.HttpProxy({url:"anuncios/modAnuncios.jsp"}),
	                    reader:new Ext.data.JsonReader({root:"results", totalProperty: "totalCount"},[{name:"STATUS"}])
	                });
	                account_data.load({params:{tit:escape(titulo2.getValue()),des:escape(descripcion2.getValue()),mail:escape(mail2.getValue()),tlf:escape(telefono2.getValue()),nom:escape(nombre2.getValue()),tipo:tipo}});
	                Ext.MessageBox.show({
	                    msg:"El anuncio ha sido enviado y está pendiente de validación",
	                    title:"Inserción",
	                    buttons:Ext.Msg.OK,
	                    width:400,
	                    fn:dsReload
	                });
	            }
	        }
	    }
	    
	    function canAnuncio() {
	        Ext.MessageBox.show({
	            msg:"Los cambios introducidos se perderán. ¿Desea continuar?",
	            title:"Confirmación",
	            buttons:Ext.Msg.OKCANCEL,
	            width:400,
	            fn:can
	        });
	        function can(btn) {
	            if(btn=='ok') win.hide();
	        }
	    }
	    
	    function dsReload(){
	        win.hide();
	        ds.reload();
	    }
	    
	    var nombre2 = new Ext.form.TextField({
	        fieldLabel:'Nombre',
	        allowBlank:false,
	        width:260
	    });
	    var titulo2 = new Ext.form.TextField({
	        fieldLabel:'Título del anuncio',
	        allowBlank:false,
	        width:260
	    });
	    var telefono2 = new Ext.form.TextField({
	        fieldLabel:'Número de teléfono',
	        allowBlank:false,
	        width:260
	    });
	    var mail2 = new Ext.form.TextField({
	        fieldLabel:'Dirección de correo electrónico',
	        allowBlank:false,
	        width:260
	    });
	    var descripcion2 = new Ext.form.TextArea({
	        fieldLabel:'Descripcion',
	        allowBlank:true,
	        width:260,
	        height:150
	    });
	    var lopd = new Ext.form.Checkbox({fieldLabel:'Estoy de acuerdo'});
	    var lopdlabel = new Ext.form.Label({
			 html:'<div style="text-align:justify;">A los efectos de lo que dispone la Ley Organica 15/1999, de 13 de diciembre, de Protección de Datos de Carácter Personal, le informamos que sus datos personales incluidos en esta solicitud, serán incorporados a un tratamiento de datos denominado Gestión de Administración, cuyo responsable es el Ilustre Colegio Oficial de Farmacéuticos de Castellón. Usted autoriza expresamente el tratamiento de sus datos por el Responsable del Tratamiento de Datos y su publicación en la pagina web www.cofcastellon.org. Usted tiene derecho de acceso a la información que le concierne, rectificarla de ser errónea o de cancelarla en la siguiente dirección Ilustre Colegio Oficial de Farmacéuticos de Castellón, C/Ebanista Hervás, 51 - 12004 Castellón de La Plana.<br><br></div>'
		});
	    
	    form = new Ext.form.FormPanel({
	        id:'anuncioForm'+tipo,
	        labelAlign:'top',
			border:false,
	        bodyStyle:'padding:10px',
	        width:700,
	        height:460,
	        items:[{
	            layout:'column',
				border:false,
	            items:[{
	                columnWidth:0.42,
	                layout:'form',
	    			border:false,
	                items:[{
	                	xtype:'fieldset',
			            title:'Anuncio',
			            collapsible:false,
			            autoHeight:true,
			            items:[nombre2,mail2,telefono2,titulo2,descripcion2]
			        }]
	            },{
	                style:'margin-left:10px',
	                columnWidth:0.42,
	                layout:'form',
	    			border:false,
	                items:[{
	                	xtype:'fieldset',
			            title:'Ley Orgánica de Protección de Datos',
			            collapsible:false,
			            autoHeight:true,
			            items:[lopdlabel,lopd]
			        }]
	            }]
	        }],
	        buttons:[{text:'Insertar', handler:insAnuncio},
	                 {text:'Cancelar', handler:canAnuncio}]
	    });

	    ds.load({params:{start:0,limit:myPageSize}});
	    
    }
    else{
    	centro.activate('detalle-anuncios-'+tipo);
    	centro.findById('detalle-anuncios-'+tipo).show();
    }
}
