/**
 * Registos Online v2.0
 * Copyright(c) 2008, Rui Lourenço, INPI
 * rui.lourenco@inpi.pt
 *
 * http://www.inpi.pt
 */
Inpi.Pesquisas.MarcasMain = Ext.extend(Ext.form.FormPanel, {

    frame: true,
    title: Inpi.lblPesquisaMarcas,
    width: 894,
    bodyStyle: 'padding-top: 5px; padding-left: 10px; padding-right: 10px;',
	
    
    constructor: function(config){
		
		var flagHidden;
		if (language == 'PT')
			flagHidden = false;
		else flagHidden = true;
		
		this.escolha1Id = Ext.id();
        this.escolha1 = Ext.ComponentMgr.create({
            xtype:'fieldset',
            title: Inpi.lblMainTitle1,
            autoHeight: true,
			width: 500,
            items: [{
	            xtype: 'radiogroup',
				id: this.escolha1Id,
				width: 450,
				hideLabel: true,
				columns: 1,
				vertical: true,
	            allowBlank: true,            
	            items: [{
	                boxLabel: Inpi.lblMainBoxLabel1,
	                name: 'escolha',
	                inputValue: 'N',
	                checked: false
	            },{
	                boxLabel: Inpi.lblMainBoxLabel2,
	                name: 'escolha',
	                inputValue: 'F',
	                checked: false
	            },{
	                boxLabel: Inpi.lblMainBoxLabel3,
	                name: 'escolha',
	                inputValue: 'I',
	                checked: false
	            }]
			}]
		});

		this.escolha2Id = Ext.id();	
        this.escolha2 = Ext.ComponentMgr.create({
            xtype:'fieldset',
            title: Inpi.lblMainTitle2,
            autoHeight: true,
			width: 500,			
            items: [{
	            xtype: 'radiogroup',
				id: this.escolha2Id,
				width: 450,				
				hideLabel: true,
				//fieldLabel: 'Para averiguar se já existe uma marca confundível:',		
				columns: 1,
				vertical: true,
	            allowBlank: true,	            
	            items: [{
	                boxLabel: Inpi.lblMainBoxLabel4,
	                name: 'escolha',
	                inputValue: 'D',
	                checked: false
	            },{
	                boxLabel: Inpi.lblMainBoxLabel5,
	                name: 'escolha',
	                inputValue: 'P',
	                checked: false
	            },{
	                boxLabel: Inpi.lblMainBoxLabel6,
	                name: 'escolha',
	                inputValue: 'S',
	                checked: false,
					hidden: flagHidden
	            }]
			}]
		});

			  
			  this.labelAvisoFCCN = Ext.ComponentMgr.create({
	  		xtype: 'inpi-label',
				id: 'labelAvisoFCCN',
				width : 400,
				html: Inpi.lblAvisoFCCN
				})
				
        config = Ext.apply({
            url: Inpi.Pesquisas.Config.serverController,
            //defaultType: 'textfield',
            monitorValid: true,
            items: [this.escolha1, this.escolha2,this.labelAvisoFCCN],
            buttonAlign: 'left',
            buttons: [{
                text: Inpi.lblContinuar,
                iconCls: 'registos-online-next-icn',
                handler: this.submitForm,
                scope: this
            }]
        }, config);
        Inpi.Pesquisas.MarcasMain.superclass.constructor.call(this, config);
		
    },
    
    submitForm: function(){
        if (this.validateForm()) {
			
			/*
            this.getForm().submit({
                method: 'POST',
                timeout: Inpi.Pesquisas.Config.timeout,
                params: {
                    cmd: 'EscolhaActoContinuar',
                    wega_codi: Inpi.Pesquisas.Context.wega_codi,
                    were_util: Inpi.Pesquisas.Context.were_util
                },
                waitTitle:Inpi.lblEspere, 
                waitMsg:Inpi.lblEnviar,          
                success: function(form, action){
                    var jsonData = Ext.util.JSON.decode(action.response.responseText);
                    
                    var redirect = jsonData.next;
                    showEcran(redirect, this.id);
                },
                failure: function(form, action){
                    if (action.failureType == Ext.form.Action.CONNECT_FAILURE) {
                        Ext.Msg.alert(Inpi.lblErro, Inpi.lblErr1);
                    }
                    else 
                        if (action.failureType == Ext.form.Action.SERVER_INVALID) {
                            obj = Ext.util.JSON.decode(action.response.responseText);
                            Ext.Msg.alert(Inpi.lblAtencao, obj.errors.reason);
                        };
                                    },
                scope: this
            });
			*/
			if (this.opcao == 'N') {
				showEcran('marcas-nome', this.id);
			}
			else 
				if (this.opcao == 'F') {
					showEcran('marcas-semelhanca', this.id);
				}
				else 
					if (this.opcao == 'I') {
						showEcran('marcas-identidade', this.id);
					}
					else 
						if (this.opcao == 'D') {
							showEcran('marcas-numero', this.id);
						}
						else 
							if (this.opcao == 'P') {
								showEcran('marcas-entidade', this.id);
							}
							else {
								showEcran('marcas-servicos', 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('marcas-main', Inpi.Pesquisas.MarcasMain);

