<?php

class Atendimento_Form_ContatoEndereco extends Agro_Form {
	
	public function init() {
		$this->addElement('hidden', 'id', array('decorators' => $this->elementDecorator));
		$this->addElement('hidden', 'id_estado', array('decorators' => $this->elementDecorator));
		$this->addElement('hidden', 'id_municipio', array('decorators' => $this->elementDecorator));
		
		$this->addElement('text', 'ds_nome_estado', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Estado',
			'class' => 'upper',
			'disabled' => true,
			'maxlength' => 100,
			'size' => 40
		));
		
		$this->addElement('text', 'ds_nome_municipio', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Município',
			'class' => 'upper',
			'disabled' => true,
			'maxlength' => 100,
			'size' => 40
		));
		
		$this->addElement('text', 'ds_endereco_rua', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Endereço',
			'class' => 'upper',
			'required' => true,
			'maxlength' => 100,
			'size' => 40
		));
		
		$this->addElement('text', 'ds_endereco_nro', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Número',
			'required' => true,
			'maxlength' => 100,
			'size' => 10
		));
		
		$this->addElement('text', 'ds_endereco_bairro', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Bairro',
			'class' => 'upper',
			'required' => true,
			'maxlength' => 100,
			'size' => 40
		));
		
		$this->addElement('text', 'ds_endereco_cep', array(
			'decorators' => $this->elementDecorator,
			'label' => 'CEP',
			'class' => 'cep',
			'required' => true,
			'maxlength' => 9,
			'size' => 9
		));
		
		$this->addElement('text', 'ds_endereco_complemento', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Comp.',
			'maxlength' => 100,
			'size' => 10,
			'class' => 'upper'
		));
		
		$this->addElement('checkbox', 'fl_principal', array(
			'decorators' => $this->elementDecorator,
			'label' => 'Endereço Principal'
		));		
	}
	
	public function populate(array $values) {
		if ($values['id_municipio']) {
			$Municipios = new Sistema_Model_Municipios();
			$Municipio = $Municipios->find($values['id_municipio'])->current();
			$values['ds_nome_municipio'] = $Municipio->ds_nome_municipio;
			
			$Estados = new Sistema_Model_Estados();
			$Estado = $Estados->find($Municipio->id_estado)->current();
			$values['ds_nome_estado'] = $Estado->ds_sigla;
		}
		
		return parent::populate($values);
	}
}