//####################################################################

//#Esse script foi criado por:                                       #

//#Eric Maicon Silva Sousa                                           #

//#ericmaicon@jovenet.com.br                                         #

//#eric@ericmaicon.com.br                                            #

//#Todos os JS do site                                               #

//####################################################################



//www.ericmaicon.com.br

//formulario = Formulário (this)

function valida(formulario) {

	var total = formulario.elements.length;

	var x = 0;



	for(i=0;i<=total;i++) {

		var m = formulario.elements[i].name.split('_');

		var cmp = formulario.elements[i];

		var cmp2 = formulario.elements[i+1];



		if(m[0] == 'EMA') {

			er = /^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/

			if (!er.test(cmp.value)) {

				cmp.style.backgroundColor = "#ffcccc";

				document.getElementById("cmp_erro").value = 'O campo E-mail deve ser preenchido corretamente!';

				document.getElementById("erro").style.display="block";

				cmp.focus();

				return false;

			} else {

				document.getElementById("erro").style.display="none";

				cmp.style.backgroundColor = "#ffffff";

			};

			

		} else if(m[0] == 'RGE') {

			if(cmp.value.length < 3) {

				cmp.style.backgroundColor = "#ffcccc";

				document.getElementById("cmp_erro").value = 'The Field '+m[1]+' must be filled in correctly!';

				document.getElementById("erro").style.display="block";

				cmp.focus();

				return false;

			} else {

				document.getElementById("erro").style.display="none";

				cmp.style.backgroundColor = "#ffffff";

			};



		} else if(m[0] == 'SEN') {

			if(cmp.value.length < 3) {

				cmp.style.backgroundColor = "#ffcccc";

				document.getElementById("cmp_erro").value = 'The Field '+m[1]+' must be filled in correctly!';

				document.getElementById("erro").style.display="block";

				cmp.focus();

				return false;

			} else {

				document.getElementById("erro").style.display="none";

				cmp.style.backgroundColor = "#ffffff";

			};

			if(cmp.value != cmp2.value) {

				cmp2.style.backgroundColor = "#ffcccc";

				document.getElementById("cmp_erro").value = 'The fields should be equal!';

				document.getElementById("erro").style.display="block";

				cmp2.focus();

				return false;

			} else {

				document.getElementById("erro").style.display="none";

				cmp2.style.backgroundColor = "#ffffff";

			};



		} else if(m[0] == 'XXX') {

			if(cmp.value.length < 1) {

				cmp.style.backgroundColor = "#ffcccc";

				document.getElementById("cmp_erro").value = 'O campo '+m[1]+' deve ser preenchido corretamente!';

				document.getElementById("erro").style.display="block";

				cmp.focus();

				return false;

			} else {

				document.getElementById("erro").style.display="none";

				cmp.style.backgroundColor = "#ffffff";

			};

		}

		if(cmp.type == 'submit' || cmp.type == 'hidden' || cmp.type == 'reset' || cmp.type == 'radio') {

			continue;

		}

	};

};