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 validaContato(){
	    var formulario = document.getElementById("formContato");
		var inputs = new Array();
		inputs["nome"] = formulario.nome;
		inputs["telefone"] = formulario.telefone;
		inputs["celular"] = formulario.celular;
		inputs["email"] = formulario.email;
		inputs["msg"] = formulario.mensagem;
		inputs["contato"] = formulario.contato;
		inputs["para"] = formulario.para;

		credenciamento["nome"] = formulario.nome.value;
		credenciamento["telefone"] = formulario.telefone.value;
		credenciamento["celular"] = formulario.celular.value;
		credenciamento["email"] = formulario.email.value;
		credenciamento["msg"] = formulario.mensagem.value;
		credenciamento["contato"] = formulario.contato.value;
		credenciamento["para"] = formulario.para.value;
		
		var branco = false;
		for(var i in credenciamento){
			if(credenciamento["nome"] == "" || credenciamento["nome"] == "Nome Completo"){
				  inputs["nome"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["telefone"] == "" || credenciamento["telefone"] == "Telefone"){
				  inputs["telefone"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["celular"] == "" || credenciamento["celular"] == "Celular"){
				  inputs["celular"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["msg"] == "" || credenciamento["msg"] == "Mensagem"){
				  inputs["msg"].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){
			$("#contato_top #feedbackfail").fadeIn(300,function () {
				$("#contato_top #feedbackfail").delay(1500).fadeOut(300, function (){
					$("#contato_top #feedbackfail").hide();
				})}
			);
			return false;
		}else{
			var data = {
				nome: credenciamento["nome"],
				telefone: credenciamento["telefone"],
				celular: credenciamento["celular"],
				email: credenciamento["email"],
				msg: credenciamento["msg"],
				contato: credenciamento["contato"],
				para: credenciamento["para"]
			};
			    jQuery.post(jQuery('#contato_top #formContato').attr('action'), data, function(response){
				$("#contato_top #info").fadeOut(300, function () {
					$("#contato_top #feedback").html("Inscrição enviada com sucesso!").fadeIn(300);
				});
				formulario.reset();
			    })
			};

}
function validaContato2(){
	    var formulario = document.getElementById("formContato2");
		var inputs = new Array();
		inputs["nome"] = formulario.nome;
		inputs["telefone"] = formulario.telefone;
		inputs["celular"] = formulario.celular;
		inputs["email"] = formulario.email;
		inputs["msg"] = formulario.mensagem;
		inputs["contato"] = formulario.contato;
		inputs["para"] = formulario.para;

		credenciamento["nome"] = formulario.nome.value;
		credenciamento["telefone"] = formulario.telefone.value;
		credenciamento["celular"] = formulario.celular.value;
		credenciamento["email"] = formulario.email.value;
		credenciamento["msg"] = formulario.mensagem.value;
		credenciamento["contato"] = formulario.contato.value;
		credenciamento["para"] = formulario.para.value;
		
		var branco = false;
		for(var i in credenciamento){
			if(credenciamento["nome"] == "" || credenciamento["nome"] == "Nome Completo"){
				  inputs["nome"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["telefone"] == "" || credenciamento["telefone"] == "Telefone"){
				  inputs["telefone"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["celular"] == "" || credenciamento["celular"] == "Celular"){
				  inputs["celular"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["msg"] == "" || credenciamento["msg"] == "Mensagem"){
				  inputs["msg"].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){
			  $("#contato_bot #feedbackfail").fadeIn(300,function () {
				  $("#contato_bot #feedbackfail").delay(1500).fadeOut(300, function (){
					  $("#contato_bot #feedbackfail").hide();
				  })}
			  );
			return false;
		}else{
			var data = {
				nome: credenciamento["nome"],
				telefone: credenciamento["telefone"],
				celular: credenciamento["celular"],
				email: credenciamento["email"],
				msg: credenciamento["msg"],
				contato: credenciamento["contato"],
				para: credenciamento["para"]
			};
			    jQuery.post(jQuery('#formContato2').attr('action'), data, function(response){
				$("#contato_bot #info").fadeOut(300, function () {
					$("#contato_bot #feedback").html("Email enviada com sucesso!").fadeIn(300);
				});
				formulario.reset();
			    })
			};

}



function validaNews(){
	    var formulario = document.getElementById("formNewsletter");
		var inputs = new Array();
		inputs["nome"] = formulario.nome;
		inputs["email"] = formulario.email;
		
		var branco = false;
		for(var i in credenciamento){
			if(credenciamento["nome"] == "" || credenciamento["nome"] == "Nome Completo"){
				  inputs["nome"].style.border = "1px solid red";
				  branco = true;
			}
			if(!valida_email(credenciamento["email"])){
					inputs["email"].style.border = "1px solid red";
					branco = true;
			}
		}
		if(branco == true){
			$("#newsletter_top #feedbackfail").fadeIn(300,function () {
				$("#newsletter_top #feedbackfail").delay(1500).fadeOut(300, function (){
					$("#newsletter_top #feedbackfail").hide();
				})}
			);
			return false;
		}else{
		var data = {
			nome: credenciamento["nome"],
			email: credenciamento["email"]
		};
			jQuery.post(jQuery('#newsletter_top #formNewsletter').attr('action'), data, function(response){
			$("#newsletter_top #info").fadeOut(300, function () {
				$("#newsletter_top #feedback").html("Inscrição enviada com sucesso!").fadeIn(300);
			});
			formulario.reset();
			})
		};

}
function validaNews2(){
	    var formulario = document.getElementById("formNewsletter2");
		var inputs = new Array();
		inputs["nome"] = formulario.nome;
		inputs["email"] = formulario.email;
		
		var branco = false;
		for(var i in credenciamento){
			if(credenciamento["nome"] == "" || credenciamento["nome"] == "Nome Completo"){
				  inputs["nome"].style.border = "1px solid red";
				  branco = true;
			}
			if(!valida_email(credenciamento["email"])){
					inputs["email"].style.border = "1px solid red";
					branco = true;
			}
		}
		if(branco == true){
			$("#newsletter_bot #feedbackfail").fadeIn(300,function () {
				$("#newsletter_bot #feedbackfail").delay(1500).fadeOut(300, function (){
					$("#newsletter_bot #feedbackfail").hide();
				})}
			);
			return false;
		}else{
		var data = {
			nome: credenciamento["nome"],
			email: credenciamento["email"]
		};
			jQuery.post(jQuery('#newsletter_bot #formNewsletter2').attr('action'), data, function(response){
			$("#newsletter_bot #info").fadeOut(300, function () {
				$("#newsletter_bot #feedback").html("Inscrição enviada com sucesso!").fadeIn(300);
			});
			formulario.reset();
			})
		};

}





/* CADASTRO PRE-PAGO ESTACIONAMENTO */
function validaCadastro(){
	    var formulario = document.getElementById("pp");
		var inputs = new Array();
		inputs["nome_pp"] = formulario.nome_pp;
		inputs["telefone_pp"] = formulario.telefone_pp;
		inputs["email_pp"] = formulario.email_pp;
		inputs["cpf"] = formulario.cpf;
		inputs["rg"] = formulario.rg;
		inputs["cartao"] = formulario.cartao;
		inputs["marca"] = formulario.marca;
		inputs["modelo"] = formulario.modelo;
		inputs["placa"] = formulario.placa;
		inputs["cor"] = formulario.cor;
		inputs["para"] = formulario.para;

		credenciamento["nome_pp"] = formulario.nome_pp.value;
		credenciamento["telefone_pp"] = formulario.telefone_pp.value;
		credenciamento["email_pp"] = formulario.email_pp.value;
		credenciamento["cpf"] = formulario.cpf.value;
		credenciamento["rg"] = formulario.rg.value;
		credenciamento["cartao"] = formulario.cartao.value;
		credenciamento["marca"] = formulario.marca.value;
		credenciamento["modelo"] = formulario.modelo.value;
		credenciamento["placa"] = formulario.placa.value;
		credenciamento["cor"] = formulario.cor.value;
		credenciamento["para"] = formulario.para.value;
		
		var branco = false;
		for(var i in credenciamento){
			if(credenciamento["nome_pp"] == "" || credenciamento["nome_pp"] == "NOME"){
				  inputs["nome_pp"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["telefone_pp"] == "" || credenciamento["telefone_pp"] == "TELEFONE"){
				  inputs["telefone_pp"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["cpf"] == "" || credenciamento["cpf"] == "CPF"){
				  inputs["cpf"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["rg"] == "" || credenciamento["rg"] == "RG"){
				  inputs["rg"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["cartao"] == "" || credenciamento["cartao"] == "NÚMERO DO CARTÃO"){
				  inputs["cartao"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["marca"] == "" || credenciamento["marca"] == "MARCA"){
				  inputs["marca"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["modelo"] == "" || credenciamento["modelo"] == "MODELO"){
				  inputs["modelo"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["placa"] == "" || credenciamento["placa"] == "PLACA"){
				  inputs["placa"].style.border = "1px solid red";
				  branco = true;
			}
			if(credenciamento["cor"] == "" || credenciamento["cor"] == "COR"){
				  inputs["cor"].style.border = "1px solid red";
				  branco = true;
			}
			//valida email
			if(!valida_email(credenciamento["email_pp"])){
					inputs["email_pp"].style.border = "1px solid red";
					branco = true;
			}
		}
		if(branco == true){
			  $("#pp .feedbackfail").fadeIn(300,function () {
				$("#pp .feedbackfail").delay(1500).fadeOut(300, function (){
					$("#pp .feedbackfail").hide();
				})}
			);
			return false;
		}else{
			var data = {
				nome: credenciamento["nome_pp"],
				cpf: credenciamento["cpf"],
				rg: credenciamento["rg"],
				cartao: credenciamento["cartao"],
				email: credenciamento["email_pp"],
				telefone: credenciamento["telefone_pp"],
				marca: credenciamento["marca"],
				modelo: credenciamento["modelo"],
				placa: credenciamento["placa"],
				cor: credenciamento["cor"],
				para: credenciamento["para"]
			};
			    jQuery.post(jQuery('#pp').attr('action'), data, function(response){
				$("#pp .feedback").fadeOut(300, function () {
					$("#pp .feedback").html("Cadastro enviado com sucesso!").fadeIn(300, function(){
						$("#pp .feedback").delay(1500).fadeOut(300);
					});
				});
				formulario.nome_pp.value = "NOME";
				formulario.telefone_pp.value = "TELEFONE";
				formulario.email_pp.value = "E-MAIL";
				formulario.cpf.value = "CPF";
				formulario.rg.value = "RG";
				formulario.cartao.value = "NÚMERO DO CARTÃO";
				formulario.marca.value = "MARCA";
				formulario.modelo.value = "MODELO";
				formulario.placa.value = "PLACA";
				formulario.cor.value = "COR";
				
				})
			};

}
