$(document).ready(function()
{	
	//coloca a mascara nos campos numericos
	
	$("#c_telefone").mask("(99)9999-9999");
	
	///função para validar e-mail
	function checkMail(mail)
	{
    	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    	if(typeof(mail) == "string")
    	{
        	if(er.test(mail)) 
        		return true;
    	}
    	else if(typeof(mail) == "object")
    	{
        	if(er.test(mail.value))
        	{
                return true;
            }
    	}
    	else
       	 	return false;      
	};

	//validacao formulário de contato
	$("#FormContato").submit(function()
	{		
		if(!$("#c_nome").val())
		{
			$("#msg-status").text('Por favor preencha o campo Nome.');
			$("#c_nome").focus();
			return false;
		}
		
		if(!$("#c_email").val())
		{
			$("#msg-status").text('Por favor preencha o campo E-mail.');
			$("#c_email").focus();
			return false;
		}
		
		if(!checkMail($("input[id='c_email']").val()))
		{
			$("#msg-status").text('E-mail Inválido');
			$("input[id='c_email']").focus();
			return false;
		}
		
		if(!$("#c_assunto").val())
		{
			$("#msg-status").text('Por favor preencha o campo assunto.');
			$("#c_assunto").focus();
			return false;
		}
		
		if(!$("#c_mensagem").val())
		{
			$("#msg-status").text('Por favor preencha o campo Mensagem.');
			$("#c_mensagem").focus();
			return false;
		}
		return true;
	});	
})

function Limpa(ObjId)
{
	ObjId.value = '';
}

function GravaNewsletter()
{
	//grava a newsletter
	var $url   = 'http://localhost/sindicom/includes/InsertNews.php'; //altere o endereço deste arquivo aqui
	var email  = document.getElementById("email-news").value;
	var form   = document.getElementById("FormNews");
	var option = 'sim';
	
	if((email != 'Digite seu e-mail')&& (email != ''))
	{
		
		$url = $url + "?email=" + email + "&option=" + option;
		ajaxGet($url,form,false);
	}
	else
	{
		//faz alguma coisa
	}
}

