function ofertas_pub(){

	var centro = viewport.getComponent('center-panel');
	
	if(!centro.findById('detalle-ofertas')){
		centro.add({
			id:'detalle-ofertas',
			title:'Ofertas',
			closable:true,
			autoScroll:true
		}).show();
		centro.activate('detalle-ofertas');
		$('detalle-ofertas').innerHTML = '<div id="ofertas-grid" style="width:100%"></div>';
		
		centro.findById('detalle-ofertas').on("beforedestroy", function() {
			top.destroy();
			win.destroy();
			nav.destroy();
		});
		
		var myPageSize = Math.round((altura)/30);
		var id_oferta = "";
		
		var ds = new Ext.data.Store({
			proxy:new Ext.data.HttpProxy({url:'ofertas_pub/leeOfertas.jsp'}),
			reader:new Ext.data.JsonReader({
				root:'results',
				totalProperty:'totalCount'
			},[
				{name:'ID'},
				{name:'FECHA2'},
				{name:'FFIN'},
				{name:'PUESTO'},
				{name:'REQUISITOS'},
				{name:'POBLACION'},
				{name:'PROVINCIA'},
				{name:'EMPRESA'},
				{name:'DESCRIPCION'},
				{name:'PRO_NOMBRE'},
				{name:'POB_NOMBRE'}
			]),
			remoteSort: true
		});
		
		var ds_provincias = new Ext.data.Store({
			proxy:new Ext.data.HttpProxy({url:'ofertas_pub/proOfertas.jsp'}),
			reader:new Ext.data.JsonReader({
				root:'results',
				totalProperty:'totalCount'
			},[{name:'PROVINCIA'},{name:'PRO_NOMBRE'}])
		});
		ds_provincias.load();
		
		var ds_poblaciones = new Ext.data.Store({
			proxy:new Ext.data.HttpProxy({url:'ofertas_pub/pobOfertas.jsp'}),
			reader:new Ext.data.JsonReader({
				root:'results',
				totalProperty:'totalCount'
			},[{name:'POBLACION'},{name:'POB_NOMBRE'}])
		});
		
		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 renderID(value,p,record){
			return String.format('<b style="display:block;font-family:tahoma, verdana;line-height:18px;vertical-align:middle;">{0}</b>', value);
		}
		
		function renderPlace(value,p,record){
			return String.format('<div style="display:block;font-family:tahoma, verdana;line-height:18px;vertical-align:middle;">'+record.data['POB_NOMBRE']+' ('+record.data['PRO_NOMBRE']+')</div>');
		}
		
		function cr(){
			return "<input type='image' src='../icons/book_edit.png' />";
		}
		
		var cm = new Ext.grid.ColumnModel([{
				header:"Inscribirse",
				align:'center',
				width:Math.round(0.08*anchura),
				renderer:cr
			},{
				header:"Fecha",
				dataIndex:'FECHA2',
				align:'center',
				renderer:renderDate,
				width:Math.round(anchura*0.11)
			},{
				header:"Puesto",
				dataIndex:'PUESTO',
				align:'center',
				width:Math.round(anchura*0.21)
			},{
				header:"Empresa",
				dataIndex:'EMPRESA',
				align:'center',
				width:Math.round(anchura*0.28)
			},{
				header:"Localidad",
				dataIndex:'PRO_NOMBRE',
				align:'center',
				renderer:renderPlace,
				width:Math.round(anchura*0.17)
			},{
				header:"Fin publicación",
				dataIndex:'FFIN',
				align:'center',
				renderer:renderDate,
				width:Math.round(anchura*0.13)
			}
		]);
		
		cm.defaultSortable = false;
		
		var mySelectionModel = new Ext.grid.CellSelectionModel();
		
		mySelectionModel.on("cellselect",function(objeto, rowIndex, colIndex){
			if(colIndex == 0){
				row = ds.getAt(rowIndex);
				function act(btn){
					if(btn=='yes'){
						win.show();
						if(!top.rendered) top.render('dialog-form-ofertas');
						top.getForm().reset();
						lopd.setValue(false);
						oeo.setValue(row.data.ID);
						publico.setValue(true);
						publico.setReadOnly(false);
						curriculum.setValue("");
						puesto.setValue(row.data.PUESTO);
						puesto.disable();
					}
				}
				Ext.MessageBox.show({
					title:row.data.PUESTO,
					msg:"<b>Empresa: </b>"+row.data.EMPRESA+", "+row.data.POB_NOMBRE+"("+row.data.PRO_NOMBRE+")<br><br><div style='width:560px;height:200px;overflow-y:scroll;'><b>Requisitos</b> : "+row.data.REQUISITOS+"<br><br><b>Descripción</b> : "+row.data.DESCRIPCION+"</div><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>¿Desea adjuntar su currículum y datos personales a esta oferta?</b>",
					width:600,
					buttons:Ext.MessageBox.YESNO,
					fn:act
				});
			}
		});
		
		var insertaDemandaBtn = new Ext.Button({
			text:'Insertar Currículum PÚBLICO',
			tooltip:'<b>Currículum público</b><br/>Haz click aquí para añadir una currículum público para todos los propietarios de farmacias',
			cls:'x-btn-text-icon add-opt',
			icon:'../icons/add.png',
			handler:function(){
				Ext.MessageBox.show({
					title:"Currículum Público",
					msg:"Cualquier usuario registrado como propietario de una de farmacia tendrá acceso a su currículum y datos personales introducidos.",
					width:500,
					buttons:Ext.MessageBox.OK,
					fn:function(btn){
						if(btn=='ok'){
							win.show();
							if(!top.rendered) top.render('dialog-form-ofertas');
							top.getForm().reset();
							lopd.setValue(false);
							oeo.setValue("");
							publico.setValue(true);
							publico.setReadOnly(true);
							curriculum.setValue("");
							puesto.enable();
						}
					}
				});
			}
		});
		
		var grid = new Ext.grid.GridPanel({
			el:'ofertas-grid',
			width:anchura,
			height:altura,
			title:'Ofertas de Empleo',
			store:ds,
			cm:cm,
			trackMouseOver:false,
			sm:mySelectionModel,
			loadMask: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:['-', insertaDemandaBtn]
			})
		});
	
		grid.render();
		
		ds.load({params:{start:0,limit:myPageSize}});  
		
		function insDemanda(){
			
			if(!top.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;
			}
			
			top.getForm().submit({
				url:'../Demanda',
				waitMsg:'Enviando información...',
				success:function(form, o) {
		    		mensaje = 'Su demanda se ha tramitado correctamente. En breve recibirá'
		    		mensaje += ' un correo cofirmando la operación.'
		        	Ext.Msg.alert('Trámite ', mensaje); 
		        	form.reset();
		        	win.hide();
				},
		        failure: function(form, o){
		            if (o.failureType === Ext.form.Action.CONNECT_FAILURE){
		                Ext.Msg.alert('Error', 'Respuesta del servidor: '+o.response.status+' '+o.response.statusText);
		            }
		            if (o.failureType === Ext.form.Action.SERVER_INVALID){
		               Ext.Msg.alert('Alerta', o.result.errormsg);
		            }
		            else Ext.Msg.alert('Alerta', o.result.msg); 
		            win.hide();
		        }
			});
			
		}
		
		var nav = new Ext.Panel({
			region:'center',
			width:350,
			margins:'3 0 3 3',
			cmargins:'3 3 3 3',
			items:[{title:'', border:false, html:'<div id="dialog-form-ofertas"></div>'}]
		});
		
		var win = new Ext.Window({
			title:'<b>Currículum Público</b>',
			closable:true,
			width:835,
			height:565,
			plain:true,
			closeAction:'hide',
			layout:'border',
			items:[nav]
		});
		
		//Formulario de insercion
		var oeo = new Ext.form.Hidden({name:'oeo',value:""});
		
		var puesto = new Ext.form.TextField({
			name:'puesto',
			fieldLabel:'Puesto',
			width:225,
			allowBlank:false,
			labelWidth:25,
			height:18
		});
		
		var estudiosT = [['B','Básicos'],['M','Medios'],['S','Superiores']]; 
		
		var estudiosS = new Ext.data.SimpleStore({fields:['Abreviado','Completo'], data:estudiosT});
		
		var estudios = new Ext.form.ComboBox({
			hiddenName:'estudios',
			fieldLabel:'Estudios',
			displayField:'Completo',
			valueField:'Abreviado',
			store:estudiosS,
			typeAhead:true,
			mode:'local',
			triggerAction:'all',
			emptyText:'Selecciona estudios...',
			selectOnFocus:true,
			width:225,
			allowBlank:false,
			labelWidth:25,
			editable:false
		});
		
		var ffin = new Ext.form.DateField({
			name:'ffin',
			fieldLabel:'Publicar CV hasta',
			format:'d/m/Y',
			width:225,
			labelWidth:25
		});
		
		var curriculum = new Ext.form.TextArea({
			name:'curriculum',
			hideLabel:true,
			allowBlank:true,
			width:370,
			height:180
		});
	
		var mail = new Ext.form.TextField({
			name:'mail',
			fieldLabel:'Mail',
			width:225,
			allowBlank:false,
			labelWidth:25,
			height:18
		});
		
		var nombre = new Ext.form.TextField({
			name:'nombre',
			fieldLabel:'Nombre',
			width:225,
			labelWidth:25,
			height:18
		});
		
		var telefono = new Ext.form.TextField({
			name:'telefono',
			fieldLabel:'Teléfono',
			width:225,
			height:18,
			labelWidth:25
		});
		
		var edad = new Ext.form.TextField({
			name:'edad',
			fieldLabel:'Edad',
			width:225,
			allowBlank:false,
			labelWidth:25,
			height:18
		});
		
		var poblacion = new Ext.form.ComboBox({
			hiddenName:'poblacion',
			store:ds_poblaciones,
			displayField:'POB_NOMBRE',
			valueField:'POBLACION',
			fieldLabel:'Población',
			typeAhead:true,
			mode:'local',
			triggerAction:'all',
			emptyText:'Población...',
			selectOnFocus:true,
			allowBlank:false,
			width:225,
			editable:false
		});
		
		var provincia = new Ext.form.ComboBox({
			hiddenName:'provincia',
			store:ds_provincias,
			displayField:'PRO_NOMBRE',
			valueField:'PROVINCIA',
			fieldLabel:'Provincia',
			typeAhead:true,
			mode:'local',
			triggerAction:'all',
			emptyText:'Provincia...',
			selectOnFocus:true,
			allowBlank:false,
			width:225,
			editable:false
		});
		
		provincia.on('select',function(combo,record,index){
			poblacion.reset();
			ds_poblaciones.load({params:{pro:provincia.getValue()}})
		});
		
		var sexoT = [['H','Hombre'],['M','Mujer']];
		
		var sexoS = new Ext.data.SimpleStore({fields:['Abreviado','Completo'], data:sexoT});
		
		var sexo = new Ext.form.ComboBox({
			hiddenName:'sexo',
			fieldLabel:'Sexo',
			displayField:'Completo',
			valueField:'Abreviado',
			allowBlank:false,
			store:sexoS,
			typeAhead:true,
			mode:'local',
			triggerAction:'all',
			emptyText:'Selecciona sexo...',
			selectOnFocus:true,
			width:225,
			labelWidth:25,
			editable:false
		});

		var publico = new Ext.form.Checkbox({name:'publico', fieldLabel:'Público'});
		
		var lopd = new Ext.form.Checkbox({name:'lopd', fieldLabel:'Estoy de acuerdo'});
		
		var lopdlabel = new Ext.form.Label({
			 html:'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 Leó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.cofleon.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 León, C/Del Fuero, 15 - 24001 León.<br/><br/>'
		});
		
		var top = new Ext.FormPanel({
			labelAlign:'left',
			border:false,
			bodyStyle:'padding:10px',
			width:900,
			fileUpload:true,
			items:[{
				layout:'column',
				border:false,
				items:[{
					columnWidth:.45,
					layout:'form',
					border:false,
					items:[{
						xtype:'fieldset',
						title:'Descripción',
						collapsible:false,
						autoHeight:true,
						items:[puesto,estudios,ffin]
					},{
						xtype:'fieldset',
						title:'Currículum',
						collapsible:false,
						autoHeight:true,
						items:[curriculum, {
							xtype:'fileuploadfield',
							emptyText:'Seleccione su curriculum',
							fieldLabel:'Curriculum',
					        width:250,
							id:'image-path',
							name:'image-path',
							buttonCfg:{text:'', iconCls:'upload-icon', icon:'../icons/add.png'}
						}, publico]
					}]
				},{
					columnWidth:.45,
					layout:'form',
					border:false,
					style:'margin-left:10px',
					items:[{
						xtype:'fieldset',
						title:'Información de Contacto',
						collapsible:false,
						autoHeight:true,
						items:[nombre,mail,telefono,edad,provincia,poblacion,edad,sexo]
					},{
						xtype:'fieldset',
						title:'Ley Orgánica de Protección de Datos',
						collapsible:false,
						autoHeight:true,
						items:[lopdlabel,lopd]
					}]
				}]
			}],
			buttons:[{
				text:'Suscribirse',
				handler:insDemanda
			},{
				text:'Cancelar',
				handler:function(){win.hide();}
			}]
		});
		
	}
	else {
		centro.activate('detalle-ofertas');
    	centro.findById('detalle-ofertas').show();
	}
}
