//valida contato
$(document).ready(function()
{
		$("#form_contato").submit(function()
	{
		
		if($("#form_contato #nome").val() == "" ){
			
			$("#msgbox2").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Por favor preencha corretamente o campo nome').addClass('messageboxerror2').fadeTo(900,1);
			});		
			return false;
		}
		if($("#form_contato #email").val() == "" ){
			
				$("#msgbox2").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Por favor preencha corretamente o campo email').addClass('messageboxerror2').fadeTo(900,1);
			});	
			return false;
		}
		
		var d = document;
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(d.getElementById("email").value))) {
			$("#msgbox2").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('É necessário o preenchimento de um endereço de e-mail válido').addClass('messageboxerror2').fadeTo(900,1);
			});	
	
		return false;
	}
	
		if($("#form_contato #mensagem").val() == "" ){
			
				$("#msgbox2").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Por favor preencha corretamente o campo mensagem').addClass('messageboxerror2').fadeTo(900,1);
			});	
			return false;
		}
		
		
		
		//remove all the class add the messagebox classes and start fading
		$("#msgbox2").removeClass().addClass('messagebox2').text('Aguarde ... ').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("sendmail.php",{ nome:$('#nome').val(), email:$('#email').val(), mensagem:$('#mensagem').val(),rand:Math.random() } ,function(data)
        {
			//alert("["+data+"]");
		 if(data=="yes") //if correct login detail
		  {
		  	$("#msgbox2").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Sua mensagem foi enviada com sucesso!').addClass('messageboxok2').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 //document.location='lista_user.php';			
				 $("#form_contato")[0].reset();
				 $("#msgbox2").css("display","none");
			  });
			  
			});
		  }
		  else 
		  {
		  	$("#msgbox2").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			   $(this).html(data).addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
	
});
