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_]+\.)+[A-Za-z]{2,4}$/

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

				cmp.style.backgroundColor = "#DBE4E6";

				document.getElementById("cmp_erro").value = 'O campo E-mail deve ser informado corretamente.';
				document.getElementById("erro").style.backgroundColor="#ffcccc";

				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] == 'XXX') {

			if(cmp.value.length < 1) {

				cmp.style.backgroundColor = "#DBE4E6";

				document.getElementById("cmp_erro").value = 'O campo '+m[1]+' deve ser informado.';
				
				document.getElementById("erro").style.backgroundColor="#ffcccc";

				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;

		}

	};

};
