// Es necesario sobrescribir el Radio para corregir el bug del evento check
// (solo se dispara una vez)
Ext.override(Ext.form.Radio, {
    onClick : function(){
        if(this.el.dom.checked != this.checked){
            var els = this.el.up('form').select('input[name='+this.el.dom.name+']');
            els.each(function(el){
                if(el.dom.id == this.id){
                    this.setValue(true);
                }else{
                    Ext.getCmp(el.dom.id).setValue(false);
                }
            }, this);
        }
    }
});

var VExpImpresion, FTabs, tabPanel;

// Ext.BLANK_IMAGE_URL = '../ext-2.2/resources/images/default/s.gif';

// Funcion principal
function fExportarPDF(){

    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
//     Ext.form.Field.prototype.msgTarget = 'side';

    // Carga de los valores para el formato
    sel_format = xGetElementById('pdfFormat');
    opc_format = xGetElementsByTagName('option', sel_format);
    var val_format = new Array();
    cad_format = '';
    for (i=0; i<opc_format.length; i++) {
        val_format[i] = [opc_format[i].value];
        cad_format += val_format[i] + ', ';
    }

    var store_format = new Ext.data.SimpleStore({
      fields: [{name: 'valor'}],
      data: val_format,
      autoLoad: true
    });

    // Carga de los valores para la resolucion
    sel_resolution = xGetElementById('pdfResolution');
    opc_resolution = xGetElementsByTagName('option', sel_resolution);
    var val_resolution = new Array();
    cad_resolution = '';
    for (i=0; i<opc_resolution.length; i++) {
        val_resolution[i] = [opc_resolution[i].value];
        cad_resolution += val_format[i] + ', ';
    }

    var store_resolution = new Ext.data.SimpleStore({
      fields: [{name: 'valor'}],
      data: val_resolution,
      autoLoad: true
    });

    // Carga de los valores para la escala
    sel_scale = xGetElementById('pdfScale');
    opc_scale = xGetElementsByTagName('option', sel_scale);
    var val_scale = new Array();
    cad_scale = '';
    for (i=0; i<opc_scale.length; i++) {
        val_scale[i] = [opc_scale[i].value];
        cad_scale += opc_scale[i] + ', ';
    }

    var store_scale = new Ext.data.SimpleStore({
      fields: [{name: 'valor'}],
      data: val_scale,
      autoLoad: true
    });

/*------------------------------------------------------------------------------
    Declaracion de COMPONENTES
-----------------------------------------------------------------------------*/

    // Combo Resoluciones
    var cb_resoluciones = new Ext.form.ComboBox({
        id: 'cb_resolution',
        mode: 'local',
        store: store_resolution,
        displayField:'valor',
        typeAhead: false,
        triggerAction: 'all',
        width: 50,
        forceSelection:true,
        editable: false,
        value: document.getElementById("pdfResolution").value,
        selectOnFocus:true,
        fieldLabel: 'Resoluci&oacute;n',
        listeners: {
            select: function(){
                document.getElementById("pdfResolution").value = this.value;
                //mainmap.updatePdfFeature('map');
        }}
    });

    // Para recargar el combo de las resoluciones
    function reloadres(){
        opc_resolution = xGetElementsByTagName('option', sel_resolution);
        var val_resolution = new Array();
        cad_resolution = '';
        for (i=0; i<opc_resolution.length; i++) {
            val_resolution[i] = [opc_resolution[i].value];
            cad_resolution += val_format[i] + ', ';
        }
        cb_resoluciones.store.loadData(val_resolution);
        cb_resoluciones.setValue(document.getElementById("pdfResolution").value);
    };

    // Formato de pagina

    var cbxTamanno = new Ext.form.ComboBox({
        id: 'cbxTamanno',
        hideLabel: false,
        mode: 'local',
        store: store_format,
        displayField: 'valor',
        typeAhead: false,
        triggerAction: 'all',
        forceSelection: true,
        editable: false,
        value: document.getElementById("pdfFormat").value,
        selectOnFocus: true,
        fieldLabel: 'Tama&ntilde;o',
        name: 'tamHoja',
        width: 70,
        listeners: {
            select: function(){
                document.getElementById("pdfFormat").value = this.value;
                updateResolutions(96);
                reloadres();

                actualizarEscalaPdf();
            }
        }
    });

    // Radios Orientacion (Vertical u Horizontal)

    // Radio Vertical
    radioV = new Ext.form.Radio({
        id: 'radioV',
        fieldLabel: 'Orientaci&oacute;n',
        boxLabel: 'Vertical',
        name: 'pdfOrientation',
        checked: true,
        listeners: {
            check: function(cb, checked) {
                if (checked == true) {
                    document.getElementById("ptt").checked = true;
                    actualizarEscalaPdf();
                }
            }
        }
    });

    // Radio Horizontal
    radioH = new Ext.form.Radio({
        id: 'radioH',
        fieldLabel: '&nbsp;',
        labelSeparator: '',
        boxLabel: 'Horizontal',
        name: 'pdfOrientation',
        listeners: {
            check: function(cb, checked) {
                if (checked == true) {
                    document.getElementById("lsp").checked = true;
                    actualizarEscalaPdf();
                }
            }
        }
    });

    // TextArea: titulo
    var txb_titulo = new Ext.form.TextField({
            hideLabel: true,
            fieldLabel: 'T&iacute;tulo',
            id: 'txb_titulo',
            maxLength: 35,
            maxLengthText: 'El m&aacute;ximo n&uacute;mero de car&aacute;racteres permitido es 35',
            disabled: true,
            width: '100%',
            name: 'tbx_titulo',
            value: ''
        });

    // TextArea: nota
    var txa_nota = new Ext.form.TextArea({
            hideLabel: true,
            fieldLabel: 'Nota',
            id: 'txa_nota',
            maxLength: 90,
            maxLengthText: 'El m&aacute;ximo n&uacute;mero de car&aacute;racteres permitido es 90',
            disabled: true,
            width: '100%',
            height: 40,
            name: 'tbx_nota',
            value: ''
        });

    // Coordenadas
    var coordSIXg = new Ext.ux.form.Spinner({
            id: 'txbCoordSIXg',
            strategy: new Ext.ux.form.Spinner.CoordStrategy({minValue: -90,
                  maxValue: 90, incrementValue: 1}),
//             vtype: 'validaCoordSIXg'
//             vtype: 'validaPdfXCoordInterface'
        });

    var coordSIXm = new Ext.ux.form.Spinner({
            id: 'txbCoordSIXm',
            value: 0,
            allowBlank: false,
            blankText: 'Debe tener un valor',
            maskRe: /^[0-9]{0,2}$/,
            strategy: new Ext.ux.form.Spinner.CoordStrategy({minValue: 0,
                  maxValue: 59, incrementValue: 1}),
//             vtype: 'validaCoordSIXms'
//             vtype: 'validaPdfXCoordInterface'
        });

    var coordSIXs = new Ext.ux.form.Spinner({
            id: 'txbCoordSIXs',
            value: 0,
            allowBlank: false,
            blankText: 'Debe tener un valor',
            maskRe: /^\d{0,2}(\.\d{1,2})?$/,
            strategy: new Ext.ux.form.Spinner.CoordStrategy({minValue: 0,
                  maxValue: 100, incrementValue: .01}),
//             vtype: 'validaCoordSIXms'
//             vtype: 'validaPdfXCoordInterface'
        });

    var coordSIYg = new Ext.ux.form.Spinner({
            id: 'txbCoordSIYg',
            value: 0,
            strategy: new Ext.ux.form.Spinner.CoordStrategy({minValue: -90,
                  maxValue: 180, incrementValue: 1}),
//             vtype: 'validaCoordSIYg'
//             vtype: 'validaPdfXCoordInterface'
        });

    var coordSIYm = new Ext.ux.form.Spinner({
            id: 'txbCoordSIYm',
            value: 0,
            strategy: new Ext.ux.form.Spinner.CoordStrategy({minValue: 0,
                  maxValue: 59, incrementValue: 1}),
//             vtype: 'validaCoordSIYms'
//             vtype: 'validaPdfXCoordInterface'
        });

    var coordSIYs = new Ext.ux.form.Spinner({
            id: 'txbCoordSIYs',
            value: 0,
            strategy: new Ext.ux.form.Spinner.CoordStrategy({minValue: 0,
                  maxValue: 100, incrementValue: .01}),
//             vtype: 'validaCoordSIYms'
//             vtype: 'validaPdfXCoordInterface'
        });

    var coordIDXg = new Ext.ux.form.Spinner({
            id: 'txbCoordIDXg',
            value: 0,
            strategy: new Ext.ux.form.Spinner.CoordStrategy({minValue: -90,
                  maxValue: 90, incrementValue: 1}),
//             vtype: 'validaCoordIDXg'
        });

    var coordIDXm = new Ext.ux.form.Spinner({
            id: 'txbCoordIDXm',
            value: 0,
            strategy: new Ext.ux.form.Spinner.CoordStrategy({minValue: 0,
                  maxValue: 59, incrementValue: 1}),
//             vtype: 'validaCoordIDXms'
        });

    var coordIDXs = new Ext.ux.form.Spinner({
            id: 'txbCoordIDXs',
            value: 0,
            strategy: new Ext.ux.form.Spinner.CoordStrategy({minValue: 0,
                  maxValue: 100, incrementValue: .01}),
//             vtype: 'validaCoordIDXms'
        });

    var coordIDYg = new Ext.ux.form.Spinner({
            id: 'txbCoordIDYg',
            value: 0,
            strategy: new Ext.ux.form.Spinner.CoordStrategy({minValue: -90,
                  maxValue: 180, incrementValue: 1}),
//             vtype: 'validaCoordIDYg'
        });

    var coordIDYm = new Ext.ux.form.Spinner({
            id: 'txbCoordIDYm',
            value: 0,
            strategy: new Ext.ux.form.Spinner.CoordStrategy({minValue: 0,
                  maxValue: 59, incrementValue: 1}),
//             vtype: 'validaCoordIDYms'
        });

    var coordIDYs = new Ext.ux.form.Spinner({
            id: 'txbCoordIDYs',
            value: 0,
            strategy: new Ext.ux.form.Spinner.CoordStrategy({minValue: 0,
                  maxValue: 100, incrementValue: .01}),
//             vtype: 'validaCoordIDYms'
        });

    // fieldset para coordenadas geograficas
    var fstCoordsGeograficas = new Ext.form.FieldSet({
        title: 'Coordenadas',
        autoHeight: true,
        style: 'border:1px solid #cccccc; padding:5 5 5 5;',
        items:[{
            layout: 'column',
            border: false,
            width: 175,
            defaults: { border: false },
            items:[{
                columnWidth: .12,
                defaults:{ border: false, width: 60, },
                items:[
                    { xtype: 'panel', height: 15 },
                    { xtype: 'panel', html: '<font size="2">X1: </font>', style: 'padding: 5 0 5 0', },
                    { xtype: 'panel', height: 5, },
                    { xtype: 'panel', html: '<font size="2">Y1:</font>' },
                    { xtype: 'panel', height: 15 },
                    { xtype: 'panel', html: '<font size="2">X2:</font>', style: 'padding: 5 0 5 0', },
                    { xtype: 'panel', height: 5, },
                    { xtype: 'panel', html: '<font size="2">Y2:</font>' }
                ]
            },{
                columnWidth: .29,
                defaults:{
                    border: false,
                    style: 'padding: 0 0 5 0;',
                    width: 45,
                    value: 0,
                    allowBlank: false,
                    blankText: 'Debe tener un valor',
                    maskRe: /^(\d|-)?$/,
                },
                items: [
                    { xtype: 'panel', html: '&deg;', style: 'padding:0'},
                    coordSIXg, { xtype: 'panel', height: 5, },
                    coordSIYg, { xtype: 'panel', height: 10, },
                    coordIDXg, { xtype: 'panel', height: 5, },
                    coordIDYg
                ]
            },{
                columnWidth: .26, // 3ra columna
                defaults:{
                    border: false,
                    style: 'padding: 0 0 5 3;',
                    width: 40,
                },
                items: [
                    { xtype: 'panel', html: '&quot;', style: 'padding:0'},
                    coordSIXm, { xtype: 'panel', height: 5, },
                    coordSIYm, { xtype: 'panel', height: 10, },
                    coordIDXm, { xtype: 'panel', height: 5, },
                    coordIDYm
                ]
            },{
                columnWidth: .33,
                defaults:{
                    border: false,
                    style: 'padding: 0 0 5 2;',
                    width: 56,
                },
                items: [
                    { xtype: 'panel', html: '&quot;&quot;', style: 'padding:0'},
                    coordSIXs, { xtype: 'panel', height: 5, },
                    coordSIYs, { xtype: 'panel', height: 10, },
                    coordIDXs, { xtype: 'panel', height: 5, },
                    coordIDYs
              ]
            }]
        }]
    });

    // toolbar area
    var tbarArea = new Ext.Toolbar({ // tbar para el area
        id: 'tbarArea',
        defaults: {
            xtype: 'button',
            layout: 'form'
        },
        items: [{
                xtype: 'tbspacer'
            },/*{
                xtype: 'checkbox',
                id: 'cbxProporcional',
                hideLabel: true
            },new Ext.BoxComponent({autoEl: {tag: 'img', src:'./geoweb/plugins/exportPdf/htdocs/gfx/ico_exp_pagina.png'}}),
            */{
                xtype: 'tbspacer'
            },{
//                 text: 'Libre',
                icon: './geoweb/plugins/exportPdf/htdocs/gfx/selectorR.png',
                cls: 'x-btn-icon',
                enableToggle: true,
                toggleGroup: 'grupoSelM',
                id: 'btnSeleccionarArea',
                toggleHandler: onItemToggle,
                tooltip:'Seleccionar &aacute;rea libre'
            },{
//                 text: 'Proporcional',
                id: 'btnSeleccionarAreaProp',
                icon: './geoweb/plugins/exportPdf/htdocs/gfx/ico_exp_pagina.png',
                cls: 'x-btn-icon',
                enableToggle: true,
                toggleGroup: 'grupoSelM',
                toggleHandler: onItemToggle,
                tooltip:'Seleccionar &aacute;rea proporcional al tama&ntilde;o'
                        + ' de la p&aacute;gina'
            },{
                xtype: 'tbseparator'
            },{
                id: 'btnRecentrar',
                text: 'Recentrar',
                tooltip:'Recentrar',
                handler: function(){
                    mainmap.pdfRecenter();
                }
            }
        ]
    });

    // fieldset coordenadas cartesianas
     var fstCoordsCartesianas = new Ext.form.FieldSet({
        title: 'Coordenadas',
        autoHeight: true,
        style: 'border:1px solid #cccccc; padding:5 5 5 5;',
        items:[{
            layout: 'column',
            border: false,
            width: 175,
            defaults: { border: false },
            items:[{
                columnWidth: .5,
                defaults:{ border: false, width: 60, },
                items:[
                    { xtype: 'panel', height: 15 },
                    { xtype: 'panel', html: 'X1:', style: 'padding: 5 0 5 0', },
                    { xtype: 'panel', height: 5, },
                    { xtype: 'panel', html: 'Y1:' },
                    { xtype: 'panel', height: 15 },
                    { xtype: 'panel', html: 'X2:', style: 'padding: 5 0 5 0', },
                    { xtype: 'panel', height: 5, },
                    { xtype: 'panel', html: 'Y2:' }
                ]
            },{
                columnWidth: .5,
                defaults:{
                    border: false,
                    style: 'padding: 0 0 5 0;',
                    width: 45
                },
                items: [
                    { xtype: 'panel', height: 15 },
                    { xtype: 'panel', html: 'X1:', style: 'padding: 5 0 5 0', },
                    { xtype: 'panel', height: 5, },
                    { xtype: 'panel', html: 'Y1:' },
                    { xtype: 'panel', height: 15 },
                    { xtype: 'panel', html: 'X2:', style: 'padding: 5 0 5 0', },
                    { xtype: 'panel', height: 5, },
                    { xtype: 'panel', html: 'Y2:' }
                ]
            }]
        }]
    });

/*------------------------------------------------------------------------------
    Estructuracion de los formularios
-----------------------------------------------------------------------------*/
    tabPanel = new Ext.TabPanel({
        resizeTabs: true,
        layoutOnTabChange: true,
        deferredRender: false, // para crear los componentes desde el inicio
        minTabWidth: 30,
        tabWidth: 25,
        activeTab: 0,
        //plain: true,
        enableTabScroll:true,
        height:300,
        defaults: {
            autoScroll: true,
            xtype: 'form',
            style: 'margin:0px',
            bodyStyle: 'padding:5 5 0 5',
            bodyBorder: false,
            autoHeight: true
        },
        items:[{
//             title:'&Aacute;rea',
            title:'&nbsp;',
            autoScroll: true,
            height: 300,
            iconCls: 'export-area',
            tbar: tbarArea,
            defaults: {
                xtype:'fieldset',
                anchor: '100%',
                style: 'padding: 0 5 10 5'
            },
            items: [
                fstCoordsGeograficas,
            {
                title: 'Rotaci&oacute;n',
                autoHeight: true,
                style: 'border:1px solid #cccccc; padding:5 5 5 5;',
                items:[{ // rotacion
                    xtype: 'panel',
                    style: 'padding:10 0 0 10',
                    layout:'column',
                    width: 175,
                    border: false,
                    items :[{
                        columnWidth: .75,
                        layout: 'form',
                        border: false,
                        labelWidth: 53,
                        items:[{
                            xtype: 'numberfield',
                            hideLabel: false,
                            fieldLabel: '&Aacute;ngulo',
                            id: 'txfAngulo',
                            vtype: 'rangoRotacion',
                            enableKeyEvents: true,
                            allowBlank:false,
                            blankText:'Este campo es obligatorio',
                            width: 50,
                            value: '0'
                        }]
                    },{
                        columnWidth: .25,
                        border: false,
                        xtype: 'panel',
                        html: '&deg;',
                        style: 'padding:0'
                    }]
                },{ // seleccion manual del box
                    layout: 'column',
                    border: false,
                    width: 170,
                    style: 'padding:10 0 0 0',
                    defaults: { border: false},
                    items:[{
                        columnWidth: .65
                    },{
                        columnWidth: .35
                    }]
                }]
            }/*,{
                // El button no es subclase de Field por eso debe ser
                // incluido dentro de un panel para poder pocicionarlo
                // (eso es cuando la posicion es absoluta solamente)
                xtype: 'panel',
                border: false,
                bodyStyle: 'margin: 0 0 10 40;',
                items: {
                    xtype:'button',
                    name: 'pdfRecenter',
                    text : 'Centrar &Aacute;rea',
                    disabled : false,
                    value: 'PDF recenter',
                    //icon: './images/icon/ver1.png',
                    //cls: 'x-btn-text-icon', // clase para iconos
                    tooltip:'Recentrar el rectangulo',
                    handler: function(){
                        mainmap.pdfRecenter();
                    }
                }
            }*/]
        },{ // ESCALA
//             title:'Escala',
            title:'&nbsp;',
            iconCls: 'export-escala',
            gTips: 'Escala',
            defaults: {
                xtype:'fieldset',
                anchor: '100%'
            },
            items:[{
                title: 'Escala',
                style: 'border:1px solid #cccccc;',
                autoHeight: true,
                labelWidth: 10,
                anchor: '100% 100%',
                items:[{
                    xtype: 'combo',
                    id: 'cb_scale',
                    mode: 'local',
                    store: store_scale,
                    displayField:'valor',
                    typeAhead: false,
                    triggerAction: 'all',
                    width: 90,
                    forceSelection:true,
                    editable: false,
                    value: document.getElementById("pdfScale").value,
                    selectOnFocus:true,
                    fieldLabel: '1',
                    listeners: {
                        select: function(){
                            document.getElementById("pdfScale").value = this.value;
                            mainmap.updatePdfFeature('map');
                    }}
                }]
            },{
                // El button no es subclase de Field por eso debe ser
                // incluido dentro de un panel para poder pocicionarlo
                // (eso es cuando la posicion es absoluta solamente)
                xtype: 'panel',
                border: false,
                bodyStyle: 'margin: 0 0 10 40;',
                items: {
                    xtype:'button',
                    name: 'pdfRecenter',
                    text : 'Centrar &Aacute;rea',
                    disabled : false,
                    value: 'PDF recenter',
                    //icon: './images/icon/ver1.png',
                    //cls: 'x-btn-text-icon', // clase para iconos
                    tooltip:'Recentrar el rectangulo',
                    handler: function(){
                        mainmap.pdfRecenter();
                    }
                }
            }]
        },{ // PAGINA
//             title:'P&aacute;gina',
            title:'&nbsp;',
            iconCls: 'export-pagina',
            defaults: {
                xtype:'fieldset',
                autoHeight: true,
                anchor: '100%',
                labelWidth: 65
            },
            items:[{
                title: 'Formato',
                style: 'border:1px solid #cccccc;',
                defaults: {
                    xtype:'fieldset'
                },
                items:[ cbxTamanno, cb_resoluciones, radioV, radioH ]
            }]
        },{ // OPCIONES
            title:'&nbsp;',
            iconCls: 'export-opciones',
            defaults: {
                xtype:'fieldset',
                anchor: '100%'
            },
            items:[{
                    title: 'R&oacute;tulos',
                    autoHeight: true,
                    items:[{
                        xtype: 'checkbox',
                        hideLabel: true,
                        id: 'cbx-titulo',
                        boxLabel: 'T&iacute;tulo',
                        name: 'cbx-titulo',
                        listeners: {
                            check: function(cb, checked) {
                                if (checked == true) {
                                    txb_titulo.enable();
                                    txb_titulo.focus();
                                }
                                else {
                                    txb_titulo.disable();
                                }
                            }
                        }
                    }, txb_titulo,
                    {
                        xtype: 'checkbox',
                        hideLabel: true,
                        id: 'cbx-nota',
                        boxLabel: 'Nota',
                        name: 'cbx-nota',
                        listeners: {
                            check: function(cb, checked) {
                                if (checked == true) {
                                    txa_nota.enable();
                                    txa_nota.focus();
                                }
                                else {
                                    txa_nota.disable();
                                }
                            }
                        }
                    }, txa_nota
                    ]
                },{
                    xtype:'fieldset',
                    title: 'Incluir',
                    layout:'form',
                    bodyBorder: false,
                    anchor: '100% 100%',
                    //collapsible: true,
                    //collapsed: false,
                    autoHeight:true,
                    hideBorders: true,
                    bodyStyle:'margin: 0;',
                    items:[{
                        xtype: 'checkbox',
                        hideLabel: true,
                        labelAlign: 'left',
                        id: 'cbx-escala',
                        boxLabel: 'Escala',
                        name: 'cbx-escala',
                        listeners: {
                            check: function(cb, checked) {
                                if (checked == true) {
                                    document.getElementById("pdfScalebar").checked = true;
                                }
                                else {
                                    document.getElementById("pdfScalebar").checked = false;
                                }
                            }
                        }
                    },{
                        xtype: 'checkbox',
                        hideLabel: true,
                        id: 'cbx-mapareferencia',
                        boxLabel: 'Mapa de referencia',
                        name: 'cbx-mapareferencia',
                        listeners: {
                            check: function(cb, checked) {
                                if (checked == true) {
                                    document.getElementById("pdfOverview").checked = true;
                                }
                                else {
                                    document.getElementById("pdfOverview").checked = false;
                                }
                            }
                        }
                    }]
                }]
            }]

    });

    // Pressed del boton toggle Seleccionar
    function onItemToggle(item, pressed){
        if (pressed == true){
            hidePdfFeature('map');
            mainmap.temp_rectangle("map");
            //VExpImpresion.show();
//             Ext.getCmp('cbxProporcional').disable();
        } else {
//             Ext.getCmp('cbxProporcional').enable();
            mainmap.getDisplay("map").clearLayer('drawing');
            mainmap.showPdfFeature("map");
            mainmap.pdfrotate("map");
            //VExpImpresion.show();
        }
    };

    Ext.apply(Ext.form.VTypes, {
        rangoRotacion: function(val, field) {
            if ((val < -359) || (val > 359)) {
                field.markInvalid();
                field.invalidText = "Debe ser un valor mayor que -359 y menor que 359.";
                return false;
            } else {
                field.clearInvalid();
                return true;
            }
        }
    });

/*------------------------------------------------------------------------------
    Ventana: Exportar PDF
-----------------------------------------------------------------------------*/
/*var posX = document.body.clientWidth - 235;

    if(!VExpImpresion){
        VExpImpresion = new Ext.Window({
            id: 'v-exportarpdf',
            title: 'Exportar (PDF)',
            renderTo: document.body,
            bodyStyle: 'padding: 0 1 1 0;',
            layout: 'fit',
            width: 215,
            x: posX,
            y: 110,
            closable : false,
            buttonAlign:'center',
//             closeAction: 'hide',
            resizable: true,
            plain: true,
            tools:[{
                id: 'help',
                qtip: 'Ayuda',
                hidden: false,
                handler: function(event, toolEl, panel){
                    Ext.Msg.alert('Informaci&oacute;n',
                    'Este contenido todav&iacute;a no est&aacute; disponible.');
                }
            },{
                id: 'close',
                qtip: 'Cerrar',
                hidden: false,
                handler: function(event, toolEl, panel){
                    var aDisplay = mainmap.getDisplay('map');
                    hidePdfFeature(aDisplay);
                    enableTool('pan');
                }
            }],
            items: tabPanel,
            buttons: [{
                text: 'Exportar',
                //icon: './images/icon/salir.png',
                //cls: "x-btn-text-icon",
                value: 'Print',
                handler: function(){
                    document.getElementById("pdfTitle").value = Ext.get("txb_titulo").getValue();
                    document.getElementById("pdfNote").value = Ext.get("txa_nota").getValue();
                    pdfFormSubmit(document.getElementById('carto_form'));
                }
            },{
                text: 'Restaurar',
                handler: function(){
                    mainmap.resetPdfFeature('map');
                }
            }]
        });
    }*/
    
    var pExportar = new Ext.Panel({
		id:'Exportar',
		border:false,
        title: 'Exportar',
		items:[tabPanel],
		buttons:[{
            text: 'Exportar',
            value: 'Print',
            handler: function(){
                document.getElementById("pdfTitle").value = Ext.get("txb_titulo").getValue();
                document.getElementById("pdfNote").value = Ext.get("txa_nota").getValue();
                pdfFormSubmit(document.getElementById('carto_form'));
            }
        },{
                text: 'Restaurar',
                handler: function(){
                    mainmap.resetPdfFeature('map');
                }
        }]
	});
    
    DestruirMontarPanel(pExportar);
    
    /*//VExpImpresion.show();
*/
    pExportar.on('remove', function() {
        var aDisplay = mainmap.getDisplay('map');
        hidePdfFeature(aDisplay);
        //enableTool('zoomin');
    });

    // Capturar cuando se presiona ENTER

    var filter = Ext.get('txfAngulo');
    filter.on('keypress', function(e) {
      if(e.getKey() == e.ENTER && Ext.getCmp('txfAngulo').isValid()) {
          var angulo = parseInt(Ext.getCmp('txfAngulo').getValue());
          document.getElementById("pdfrotatefreevalue").value = angulo;
          mainmap.rotatePdfFeature(angulo, true);
      }
    });
    filter.on('blur', function(e) {
      if(Ext.getCmp('txfAngulo').isValid()) {
          var angulo = parseInt(Ext.getCmp('txfAngulo').getValue());
          document.getElementById("pdfrotatefreevalue").value = angulo;
          mainmap.rotatePdfFeature(angulo, true);
      }
    });

    // Obtener los valores del box para llenar los campos de texto de las coordenadas
    updatePdfCoordInterface();

    // Captura eventos keypress y blur de campos coordenadas

    var txbCoordSIXg = Ext.get('txbCoordSIXg');
    txbCoordSIXg.on('keypress', function(e) {
      if(e.getKey() == e.ENTER) {
          if (validaPdfXCoordInterface())
              actualizarBoxPorFormulario();
      }
    });

    var txbCoordSIXg = Ext.get('txbCoordSIXg');
    txbCoordSIXg.on('blur', function(e) {
          if (validaPdfXCoordInterface())
              actualizarBoxPorFormulario();
    });

//     Ext.getCmp('txbCoordSIXg').validate();

    var txbCoordSIXm = Ext.get('txbCoordSIXm');
    txbCoordSIXm.on('keypress', function(e) {
      if(e.getKey() == e.ENTER) {
          if (validaPdfXCoordInterface())
              actualizarBoxPorFormulario();
      }
    });

    var txbCoordSIXm = Ext.get('txbCoordSIXm');
    txbCoordSIXm.on('blur', function(e) {
          if (validaPdfXCoordInterface())
              actualizarBoxPorFormulario();
    });

//     Ext.getCmp('txbCoordSIXm').validate();

    var txbCoordSIXs = Ext.get('txbCoordSIXs');
    txbCoordSIXs.on('keypress', function(e) {
      if(e.getKey() == e.ENTER) {
          if (validaPdfXCoordInterface())
              actualizarBoxPorFormulario();
      }
    });

    var txbCoordSIXs = Ext.get('txbCoordSIXs');
    txbCoordSIXs.on('blur', function(e) {
          if (validaPdfXCoordInterface())
              actualizarBoxPorFormulario();
    });

//     Ext.getCmp('txbCoordSIXs').validate();

    var txbCoordSIYg = Ext.get('txbCoordSIYg');
    txbCoordSIYg.on('keypress', function(e) {
      if(e.getKey() == e.ENTER) {
          if (validaPdfYCoordInterface())
              actualizarBoxPorFormulario();
      }
    });

    var txbCoordSIYg = Ext.get('txbCoordSIYg');
    txbCoordSIYg.on('blur', function(e) {
          if (validaPdfYCoordInterface())
              actualizarBoxPorFormulario();
    });

//     Ext.getCmp('txbCoordSIYg').validate();

    var txbCoordSIYm = Ext.get('txbCoordSIYm');
    txbCoordSIYm.on('keypress', function(e) {
      if(e.getKey() == e.ENTER) {
          if (validaPdfYCoordInterface())
              actualizarBoxPorFormulario();
      }
    });

    var txbCoordSIYm = Ext.get('txbCoordSIYm');
    txbCoordSIYm.on('blur', function(e) {
          if (validaPdfYCoordInterface())
              actualizarBoxPorFormulario();
    });

//     Ext.getCmp('txbCoordSIYm').validate();

    var txbCoordSIYs = Ext.get('txbCoordSIYs');
    txbCoordSIYs.on('keypress', function(e) {
      if(e.getKey() == e.ENTER) {
          if (validaPdfYCoordInterface())
              actualizarBoxPorFormulario();
      }
    });

    var txbCoordSIYs = Ext.get('txbCoordSIYs');
    txbCoordSIYs.on('blur', function(e) {
          if (validaPdfYCoordInterface())
              actualizarBoxPorFormulario();
    });

//     Ext.getCmp('txbCoordSIYs').validate();

    // Segundo punto

    var txbCoordIDXg = Ext.get('txbCoordIDXg');
    txbCoordIDXg.on('keypress', function(e) {
      if(e.getKey() == e.ENTER) {
          if (validaPdfXCoordInterface())
              actualizarBoxPorFormulario();
      }
    });

    var txbCoordIDXg = Ext.get('txbCoordIDXg');
    txbCoordIDXg.on('blur', function(e) {
          if (validaPdfXCoordInterface())
              actualizarBoxPorFormulario();
    });

//     Ext.getCmp('txbCoordIDXg').validate();

    var txbCoordIDXm = Ext.get('txbCoordIDXm');
    txbCoordIDXm.on('keypress', function(e) {
      if(e.getKey() == e.ENTER) {
          if (validaPdfXCoordInterface())
              actualizarBoxPorFormulario();
      }
    });

    var txbCoordIDXm = Ext.get('txbCoordIDXm');
    txbCoordIDXm.on('blur', function(e) {
          if (validaPdfXCoordInterface())
              actualizarBoxPorFormulario();
    });

//     Ext.getCmp('txbCoordIDXm').validate();

    var txbCoordIDXs = Ext.get('txbCoordIDXs');
    txbCoordIDXs.on('keypress', function(e) {
      if(e.getKey() == e.ENTER) {
          if (validaPdfXCoordInterface())
              actualizarBoxPorFormulario();
      }
    });

    var txbCoordIDXs = Ext.get('txbCoordIDXs');
    txbCoordIDXs.on('blur', function(e) {
          if (validaPdfXCoordInterface())
              actualizarBoxPorFormulario();
    });

//     Ext.getCmp('txbCoordIDXs').validate();

    var txbCoordIDYg = Ext.get('txbCoordIDYg');
    txbCoordIDYg.on('keypress', function(e) {
      if(e.getKey() == e.ENTER) {
          if (validaPdfYCoordInterface())
              actualizarBoxPorFormulario();
      }
    });

    var txbCoordIDYg = Ext.get('txbCoordIDYg');
    txbCoordIDYg.on('blur', function(e) {
          if (validaPdfYCoordInterface())
              actualizarBoxPorFormulario();
    });

//     Ext.getCmp('txbCoordIDYg').validate();

    var txbCoordIDYm = Ext.get('txbCoordIDYm');
    txbCoordIDYm.on('keypress', function(e) {
      if(e.getKey() == e.ENTER) {
          if (validaPdfYCoordInterface())
              actualizarBoxPorFormulario();
      }
    });

    var txbCoordIDYm = Ext.get('txbCoordIDYm');
    txbCoordIDYm.on('blur', function(e) {
          if (validaPdfYCoordInterface())
              actualizarBoxPorFormulario();
    });

    Ext.getCmp('txbCoordIDYm').validate();

    var txbCoordIDYs = Ext.get('txbCoordIDYs');
    txbCoordIDYs.on('keypress', function(e) {
      if(e.getKey() == e.ENTER) {
          if (validaPdfYCoordInterface())
              actualizarBoxPorFormulario();
      }
    });

    var txbCoordIDYs = Ext.get('txbCoordIDYs');
    txbCoordIDYs.on('blur', function(e) {
          if (validaPdfYCoordInterface())
              actualizarBoxPorFormulario();
    });



}; // Fin funcion: Mostrar Ventana

