package modules.contato 
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import genericos.*;
	import flash.net.*;
	import modules.menu.Menu;
		//Matuto
	import classes.fl.motion.easing.*;
	import classes.greensock.*;
	import classes.matuto.core.*;
	import classes.matuto.core.module.*;
	import classes.matuto.events.*;
	import classes.matuto.interfaces.*;
	import classes.matuto.model.*;
	import classes.matuto.mtween.textinho.*;
	import classes.matuto.ui.*;
	import classes.matuto.utils.display.*;
	import classes.matuto.utils.model.*;
	import flash.utils.*;
	
	public class FormContato extends MovieClip
	{
		
		
		private var form		:Form;

		public function FormContato() 
		{

			form = new Form("contato", "Enviado com sucesso", "enviando mensagem");	
			form.addField("nome", _nome, "Seu nome", Form.ALL);
			form.addField("email", _email, "contato@email.com", Form.MAIL);
			form.addField("ddd", _ddd, "DDD", Form.NUMBER,null,2);
			form.addField("telefone",_telefone, "Telefone", Form.ALL);
			form.addField("assunto", _assunto, "Assunto", Form.STRING);
			form.addField("mensagem", _mensagem, "Mensagem", Form.ALL);

			new Mask(_telefone, "99999-9999");
			_telefone.text = "Telefone";
			
			form.addEventListener(FormEvent.STATUS, status);
			_send.addEventListener(MouseEvent.CLICK, onClick);

		}
		
		private function onClick(e:MouseEvent):void 
		{
			
			if (!form.validation()) {

				Menu.INSTANCE.DIALOG_OK(form.message);
				return;
			}
				
			if (form.validation())
			{
				

	
				
				Menu.INSTANCE.DIALOG_SIMPLES("Enviando.");
				var urlvars		:URLVariables = new URLVariables;
				
				urlvars.email 		=  _email.text;
				urlvars.ddd 		=  _ddd.text;
				urlvars.telefone 	=  _telefone.text;
				urlvars.assunto 	=  _assunto.text;
				urlvars.mensagem 	=  _mensagem.text;
				urlvars.nome 		=  _nome.text;
				
				Model.PHP_CONNECT(APP.MODEL_CONTATO,urlvars, onComplete, function(e:Object) { } );	
		
				
			}
			
		}
		
		public function onComplete(e:Event)
		{
			
			//trace(e.currentTarget.data.status);
			
			Menu.INSTANCE.simples.click();
			
			if (e.currentTarget.data.status == 1)
			{
				
				Menu.INSTANCE.DIALOG_OK_FORM();
				
				setTimeout(function() {
				
					limparCampos();
					if (Menu.INSTANCE.formOk != null)
					Menu.INSTANCE.formOk.click();
					
				}, 3000);
				
			}else {
				
				
				Menu.INSTANCE.DIALOG_ERRO_FORM();
				
				setTimeout(function() {
				
					if (Menu.INSTANCE.formErro != null)
					Menu.INSTANCE.formErro.click();
					
				}, 3000);
				
			}
			
		}
		
		private function limparCampos()
		{
			 _nome.text = "Seu nome";
			_email.text = "contato@email.com";
			_ddd.text = "DDD";
			_telefone.text = "(99)9999-9999";
			 _assunto.text = "Assunto";
			_mensagem.text = "Mensagem";
			
		}
		
		private function status(e:FormEvent):void
		{
			var resp:String 		= e.params.message;
			
		}
		

		
	}//END CLASS

}