	function testaRadio(obj) {

		for (var x1=0; x1<obj.length; x1++)

			if (obj[x1].checked)

				return true;

		return '';

	}



	function tiraEspaco(value) {

		return value.replace(new RegExp(unescape("%20"), "g"), "");

	}



	function addCampo(obj, caption) {

		if (typeof obj == "undefined") {

			alert("Campo não existe!\n" + caption);

			return;

		}



		if ((obj.tagName == "INPUT" && obj.type == "radio") || obj.name.indexOf("[") != -1) {

			obj = document.getElementsByName(obj.name);

			if (obj.length == 1)

				obj = obj[0];

		}



		this.campos[this.campos.length] = obj;

		this.caption[this.caption.length] = caption;

	}



	function validar() {

		if ((this.p1 || this.p2) && (this.p1.value != this.p2.value)) {

			alert("A confirmação da senha não confere!");

			this.p2.focus();



			return false;

		}



		result = true;

		var campoFoco = '';

		for (var x = 0; x < this.campos.length; x++) {

			// verifica se o elemento ou seus parents estão visíveis

			if (this.campos[x].length > 0)

				if (!isVisible(this.campos[x][0]) && this.campos[x][0].getAttribute("forcerequire") != "true")

					continue;



			if (this.campos[x])

				if (!isVisible(this.campos[x]) && this.campos[x].getAttribute("forcerequire") != "true")

					continue;

			



			if (this.campos[x].type && this.campos[x].type.toLowerCase() == 'select-multiple') {

				if (this.campos[x].options.length == 0) {

					this.msg+=this.caption[x] + '\n';

					result = false;

				}

			}

			else

			if (this.campos[x].type && this.campos[x].type.toLowerCase() == 'select-one') {

				if ((!this.campos[x].value) || (tiraEspaco(this.campos[x].value)=="//") || (this.campos[x].value == -1)) {

					this.msg+=this.caption[x] + '\n';

					result = false;

				}

			}

			else

			if (this.campos[x].length > 0) {

				//alert(this.campos[x][0].name +" = "+ this.campos[x][0].type.toLowerCase() +" - "+ testaRadio(this.campos[x]));



				if (!testaRadio(this.campos[x])) {

					this.msg+=this.caption[x] + '\n';

					result = false;

				}

			}

			else

			if (this.campos[x].type.toLowerCase()=='checkbox') {

				if (!this.campos[x].checked) {

					this.msg+=this.caption[x] + '\n';

					result = false;

				}

			}

			else {

				if ((!this.campos[x].value) ||

					(tiraEspaco(this.campos[x].value)=="//")  ||

					(!this.campos[x].value.replace(/[^a-z0-9]+/ig,""))) {

					this.msg+=this.caption[x] + '\n';

					result = false;

				}

				else

				if (parseFloat(strToFloat(this.campos[x].value)) < 0) {

					this.msg+=this.caption[x] + '\n';

					result = false;

				}

			}



			if (!result)

				if (!campoFoco) {

					try {

						campoFoco = this.campos[x];

						campoFoco.focus();

					}

					catch (e) {

					}

				}

		}



		if (!result)

			alert(this.msg);

		return result;

	}



	function validaForm() {

		this.campos = new Array();

		this.caption = new Array();

		this.p1 = "";

		this.p2 = "";



		this.msg="Você deve preencher os campos abaixo!\n\n";



		this.validar  = validar;

		this.addCampo = addCampo;



		this.setFrom = function (f) {

			for(var i = 0; i < f.length; i++) {

				if (f[i].getAttribute("required") == "true" || f[i].getAttribute("forcerequire") == "true") {

					if (label = f[i].getAttribute("label"))

						this.addCampo(f[i], '- ' + label);

					else

						this.addCampo(f[i], '- ' + f[i].name);

				}

			}

		}



		this.cmpPassword = function (p1, p2) {

			this.p1 = p1;

			this.p2 = p2;

		}

	}



	function valSenha(campo1, campo2, msg) {

		if (typeof msg == "undefined")

			msg = 'A confirmação não confere com a senha!';



		if (campo1.value != campo2.value) {

			if (msg)

				alert(msg);

			campo2.focus();

			return false;

		}

		return true;

	}



	function validateForm(f, callback) {

		var v = new validaForm()

		v.setFrom(f);



		if (v.validar()) {

			if (typeof callback != "undefined")

				if (!callback())

					return false;

			return true;

		}



		return false;

	}
