/**
 * Registos Online v2.0
 * Copyright(c) 2008, Rui Lourenço, INPI
 * rui.lourenco@inpi.pt
 *
 * http://www.inpi.pt
 */
Inpi.Pesquisas.DesignMain = Ext.extend(Ext.form.FormPanel, {

    frame: true,
    title: Inpi.lblPesquisaDesign,
    width: 894,
    bodyStyle: 'padding-top: 5px; padding-left: 10px; padding-right: 10px;',
	
    
    constructor: function(config){
		
		
		this.escolha1Id = Ext.id();
        this.escolha1 = Ext.ComponentMgr.create({
            xtype:'fieldset',
            title: Inpi.lblDesignMainTitle1,
            autoHeight: true,
			width: 500,
            items: [{
	            xtype: 'radiogroup',
				id: this.escolha1Id,
				width: 450,
				hideLabel: true,
				columns: 1,
				vertical: true,
	            allowBlank: true,            
	            items: [{
	                boxLabel: Inpi.lblDesignMainBoxLabel1,
	                name: 'escolha',
	                inputValue: 'N',
	                checked: false
	            }]
			}]
		});

		this.escolha2Id = Ext.id();	
        this.escolha2 = Ext.ComponentMgr.create({
            xtype:'fieldset',
            title: Inpi.lblDesignMainTitle2,
            autoHeight: true,
			width: 500,			
            items: [{
	            xtype: 'radiogroup',
				id: this.escolha2Id,
				width: 450,				
				hideLabel: true,		
				columns: 1,
				vertical: true,
	            allowBlank: true,	            
	            items: [{
	                boxLabel: Inpi.lblDesignMainBoxLabel4,
	                name: 'escolha',
	                inputValue: 'P',
	                checked: false
	            },{
	                boxLabel: Inpi.lblDesignMainBoxLabel5,
	                name: 'escolha',
	                inputValue: 'E',
	                checked: false
	            },{
	                boxLabel: Inpi.lblDesignMainBoxLabel6,
	                name: 'escolha',
	                inputValue: 'R',
	                checked: false
	            }]
			}]
		});

        config = Ext.apply({
            url: Inpi.Pesquisas.Config.serverController,
            //defaultType: 'textfield',
            monitorValid: true,
            items: [this.escolha1, this.escolha2],
            buttonAlign: 'left',
            buttons: [{
                text: Inpi.lblContinuar,
                iconCls: 'registos-online-next-icn',
                handler: this.submitForm,
                scope: this
            }]
        }, config);
        Inpi.Pesquisas.DesignMain.superclass.constructor.call(this, config);
		
    },
    
    submitForm: function(){
        if (this.validateForm()) {
			
			if (this.opcao == 'N') {
				showEcran('design-numero', this.id);
			}
			else 
				if (this.opcao == 'P') {
					showEcran('design-entidade', this.id);
				}
				else 
					if (this.opcao == 'E') {
						showEcran('design-epigrafe', this.id);
					}
					else {
						showEcran('design-resumo', this.id);
					}
							
        }
    },
    
    resetForm: function(){
        this.getForm().reset();
    },
    
    validateForm: function(){
		if (this.getForm().getValues().escolha == null) {
	        Ext.Msg.alert(Inpi.lblAtencao, Inpi.lblMainErr1);
	        return false;
        } else {
				this.opcao =this.getForm().getValues().escolha;
			}
		
        return true;
    }
    
});

Ext.reg('design-main', Inpi.Pesquisas.DesignMain);

