function verificaVazio(valor) {
	if (valor.length == 0) {
		return false;
	} else {
		return true;
	}
}

function verificaNumerico(valor) {
	var validchars = "0123456789";
	for (var i = 0; i < valor.length; i++ ) {
		var letra = valor.charAt(i).toLowerCase();
		if (validchars.indexOf(letra) != -1){
			continue;
		} else {
			return false;
			break;
		}
	}
	return true;
}

function verificaMoeda(valor) {
	var validchars = "0123456789,.";
	for (var i = 0; i < valor.length; i++ ) {
		var letra = valor.charAt(i).toLowerCase();
		if (validchars.indexOf(letra) != -1){
			continue;
		} else {
			return false;
			break;
		}
	}
	return true;
}

function verificaCpf(valor) {
  if (valor.match("^\\d{11}$") == null) {
    return false;
  } else {
    return true;
  }
}

function verificaCep(valor) {
  if ((valor.match("^\\d{5}-\\d{3}$") == null) && (valor.match("^\\d{8}$") == null)) {
    return false;
  } else {
    return true;
  }
}

function verificaData(valor) {
  if ((valor.match("^([1-9]|0[1-9]|[12][0-9]|3[01])/([1-9]|0[1-9]|1[012])/(19|20)\\d{2}$") == null)) {
    return false;
  } else {
    return true;
  }
}

function verificaEmail(valor) {
  if ((valor.match("^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$") == null)) {
    return false;
  } else {
    return true;
  }
}

function verificaNumericoTraco(valor) {
	var validchars = "0123456789-() ";
	for (var i = 0; i < valor.length; i++ ) {
		var letra = valor.charAt(i).toLowerCase();
		if (validchars.indexOf(letra) != -1){
			continue;
		} else {
			//alert("Pau no verificaNumerico");
			return false;
			break;
		}
	}
	return true;
}

function verificaLexico(valor) {
	var validchars = "0123456789abcdefghijklmnopqrstuvwxyz������������ ";
	for (var i = 0; i < valor.length; i++ ) {
		var letra = valor.charAt(i).toLowerCase();
		if (validchars.indexOf(letra) != -1){
			continue;
		} else {
			//alert("Pau no verificaNumerico");
			return false;
			break;
		}
	}
	return true;
}

function verificaLiteral(valor) {
	var validchars = "abcdefghijklmnopqrstuvwxyz������������ ";
	for (var i = 0; i < valor.length; i++ ) {
		var letra = valor.charAt(i).toLowerCase();
		if (validchars.indexOf(letra) != -1){
			continue;
		} else {
			//alert("Pau no verificaLiteral");
			return false;
			break;
		}
	}
	return true;
}

function varreInputs() {
  var range = document.forms[0].elements.length;
  for (var i = 0; i < range; i++) {
    if (document.forms[0].elements[i].type == "text") {
      var nome = document.forms[0].elements[i].name;
      var valor = document.forms[0].elements[i].value;

      if (nome.match(/NOME/) != null) {
        //if ((!verificaLiteral(valor)) || (!verificaVazio(valor))) {
        if (!verificaVazio(valor)) {
          alert("Campo nome preenchido indevidamente ou não preenchido!");
          return false;
        }
      } 
      
      if (nome.match(/CEP/) != null) {
        if ((verificaVazio(valor)) && (!verificaCep(valor))) {
          alert("Campo cep preenchido indevidamente.");
          return false;
        }
      }

      if (nome.match(/DATA/) != null) {
        if ((verificaVazio(valor)) && (!verificaData(valor))) {
          alert("Campo data preenchido indevidamente. Use o formato dd/mm/aaaa.");
          return false;
        }
      }

      if (nome.match(/EMAIL/) != null) {
        if ((verificaVazio(valor)) && (!verificaEmail(valor))) {
          alert("Campo email preenchido indevidamente.");
          return false;
        }
      }

      if (nome.match(/CPF/) != null) {
        if ((verificaVazio(valor)) && (!verificaCpf(valor))) {
          alert("Campo cpf preenchido indevidamente.");
          return false;
        }
      }
			/*
			else if ( nome.match(/NUMERO/) != null ) {
				if (! verificaNumerico(valor) || (!verificaVazio(valor)) ) {
					alert("Campo N�mero preenchido indevidamente ou n�o preenchido!");
					return false;
					break;
				}
			}
			else if ( nome.match(/ENDERECO/) != null ) {
				if (! verificaLexico(valor) || (!verificaVazio(valor)) ) {
					alert("Campo Endere�o / Complemento preenchido indevidamente ou n�o preenchido!");
					return false;
					break;
				}
			}
			else if ( nome.match(/CEP/) != null ) {
				if (! verificaNumerico(valor) || (!verificaVazio(valor)) ) {
					alert("Campo CEP preenchido indevidamente ou n�o preenchido!");
					return false;
					break;
				}
			}
			else if ( nome.match(/TEL/) != null ) {
				if (! verificaNumericoTraco(valor) ) {
					alert("Campo Telefone preenchido indevidamente!");
					return false;
					break;
				}
			}
			else if ( nome.match(/CIDADE/) != null ) {
				if (! verificaLiteral(valor) || (!verificaVazio(valor)) ) {
					alert("Campo Cidade preenchido indevidamente ou n�o preenchido!");
					return false;
					break;
				}
			}
			else if ( nome.match(/IDENTIDADE/) != null ) {
				if (!verificaVazio(valor) ) {
					alert("Campo Identidade n�o preenchido!");
					return false;
					break;
				}
			}
			else if ( nome.match(/CPF/) != null ) {
				if (! verificaNumerico(valor) || (!verificaVazio(valor)) ) {
					alert("Campo CPF preenchido indevidamente ou n�o preenchido!");
					return false;
					break;
				}
			}
			*/
		}
	}
	return true;
}

function verificaPreenchimento(button) {
	if (varreInputs() ) {
		sndToCntl(button);
	}
}

