function valida_email(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;
                }
}


var credenciamento = new Array();

function validaInscricao(){
	    var formulario = document.getElementById("formNewsletter");
		var inputs = new Array();
		inputs["nome"] = formulario.nome;
		inputs["celular"] = formulario.celular;
		inputs["email"] = formulario.email;
		inputs["para"] = formulario.para;

		credenciamento["nome"] = formulario.nome.value;
		credenciamento["celular"] = formulario.celular.value;
		credenciamento["email"] = formulario.email.value;
		credenciamento["para"] = formulario.para.value;

		var branco = false;

		for(var i in credenciamento){

			if(credenciamento["nome"] == ""){
				  inputs["nome"].style.border = "1px solid red";
				  branco = true;
			
			}
			if(credenciamento["email"] == ""){
				  inputs["email"].style.border = "1px solid red";
				  branco = true;
			
			}
			//valida email
			if(!valida_email(credenciamento["email"])){
					inputs["email"].style.border = "1px solid red";
					branco = true;
			}
		}
		if(branco == true){
			if ($("#info").is(":visible")) {
				$("#info").fadeOut(300, function () {
					$("#feedbackfail").fadeIn(300,function () {
						$("#info").hide();
						$("#feedbackfail").delay(1500).fadeOut(300, function (){
							$("#info").fadeIn(300);
							$("#feedbackfail").hide();
						})}
					);
				});
			}
			return false;
		}else{
			var data = {
				nome: credenciamento["nome"],
				celular: credenciamento["celular"],
				email: credenciamento["email"],
				para: credenciamento["para"]
			};
			
			//jQuery(".txt_credenciamento span#aux").hide();
			//jQuery(".txt_credenciamento img").fadeIn(100);

				//alert('enviado');
			    jQuery.post(jQuery('#formNewsletter').attr('action'), data, function(response){
				//jQuery(".txt_credenciamento img").fadeOut(100);
				//$(".txt_credenciamento").css("color","#009933")
				//$(".txt_credenciamento span#aux").show();
				//jQuery(".txt_credenciamento span#aux").html(response);
				$("#info").fadeOut(300, function () {
					$("#feedback").html("Inscrição enviada com sucesso!").fadeIn(300);
				});
				formulario.reset();
				//alert('enviado');
			    })
			};

}
