function clickBotao(obj) {
  obj.value = "Aguarde...";
  obj.disabled = true;
}

// Abre um alerta e retorna falso //
function abreAlerta(msg){
  alert(msg);
  return false;
}

// Verifica se um objeto existe //
function validaObjeto(obj){
  if (typeof(obj) == "object") {
    return true;
  } else {
    return false;
  }
}

// Verifica a existência de caracteres especiais //
function validaEspeciais(obj){
  caracter = obj.value
  resp = false;
  for(c = 0; c < caracter.length; c++) {
    n = (caracter.substring(c,c+1)).charCodeAt();
    if(!(n > 47 && n < 58 || n > 96 && n <123) && !(n==46 || n==95 || n==45)) resp = true;
  }
  return resp;
}

// Verifica Caracteres //
function validaTexto(obj){
  caracter = obj.value;
  if (caracter.length == 0){
    return true;
  }
  return false;
}

// Verifica Radio buttom e Check box //
function validaOpcao(obj) {
  resp = true
  for(ii=0; ii < obj.length; ii++){
    if(obj[ii].checked) resp = false;
  }
  if(resp){
    return true;
  }else{
    return false;
  }
}

// Verifica Objetos SELECT do formulário //
function validaSelecao(obj){ 
  if(obj.options[obj.selectedIndex].value ==""){
    return true;
  }
  return false;
}

// Verifica data no formato brasil (dd/mm/aaaa) //
function validaData(obj){
  numero  = obj.value;
  partes  = numero.split("/");
  
  if (partes.length==3){
    numeros = partes[0] + partes[1] + partes[2]
    if (numeros.length ==0 ){
      return true;
    }
    if (partes[0] < 1 || partes[0] > 31){
      return true;
    }
    if (partes[1] < 1 || partes[1] > 12){
      return true;
    }
    if (partes[2].length < 4){
      return true;
    }
    if (partes[2] < 1900){
      return true;
    }
  }else{
    return true;
  }
  return false;
}

// Verifica email's quanto ao forma e carácteres válidos //
function validaEmail(obj){
  invalid = Array("~","!","@","#","$","%","^","&","*","(",")","+","=","[","]",":",";",",","\"","'","|","{","}","\\","/","<",">","?"," ");
  xemail = obj.value;
  
  if (xemail.indexOf("@")==-1){
    return true;
  }else{
    partes=xemail.split("@");
    if(partes[0]=="" || partes[0].length < 2){
      return true;
    }else{
      for(i=0;i < invalid.length;i++){
        if(partes[0].indexOf(invalid[i])!=-1){
          return true;
        }
      }
    }
    if(partes[1]==""){
      return true;
    }else{
      if (partes[1].indexOf(".")==-1){
        return true;
      }else{
        ponto=partes[1].split(".")
        if(ponto[0]=="" || ponto[0].length < 2){
          return true;
        }else{
          for(i=0;i < invalid.length;i++){
            if(ponto[0].indexOf(invalid[i])!=-1){
              return true;
            }
          }
        }
        if(ponto[1]==""){
          return true;
        }
      }
    }
  }
  return false;
}

// Valida CEP no formato 00000-000 //
function validaCep(obj){
  validos = Array("0","1","2","3","4","5","6","7","8","9");
  valor   = obj.value;
  partes  = valor.split("-");
  resp    = 0;
  
  if (partes.length ==2){
    numeros = partes[0] + partes[1];
    if (numeros.length ==0 ){
      return true;
    }
    for(i=0;i < validos.length; i++){
      for(j=0;j < numeros.length; j++){
        if(numeros.substring(j,j+1) == validos[i]) { resp++ }
      }
    }
    if (numeros.length != resp){
      return true;
    }
    if (partes[0].length != 5){
      return true;
    }
    if (partes[1].length != 3){
      return true;
    }
  }else{
    return true;
  }
  return false;
}

// Validar valores com 2 casas decimais no formato brasil (0.000,00) //
function validaValor(obj){
  valorx  = obj.value;
  virgula = valorx.split(",");
  
  if (virgula.length >=2){
    if (virgula[1].length ==2 && virgula[0].length !=0){
      ponto = virgula[0].split(".");
      if (ponto.length == 2){
        for(i=1; i< ponto.length; i++){
          if(ponto[i].length != 3){
            return true;
          }
        }
      }
    }else{
      return true;
    }
  }else{
    return true;
  }
  return false;
}

// Permite somente números inteiros //
function validaNumero(obj){
  numero = obj.value;
  resp   = 0;
  
  if(numero.length==0){
    return true;
  }
  for(i=0;i < numero.length; i++){
    for(j=0;j < 11; j++){
      if (numero.substring(i,i+1) == j) resp++;
    }
  }
  if (numero.length != resp){
    return true;
  }
  return false;
}

// Verifica se a imagem é gif ou jpg //
function validaImagem(obj){
  caracter = obj.value;
  extensao = caracter.substring(caracter.length-3,caracter.length);
  
  if (extensao.toLowerCase() != 'gif' && extensao.toLowerCase() != 'jpg'){
    return true;
  }
  
  return false;
}

function verificaTamanho(target) {
  var StrLen;
  var adicional;   
  StrLen = 0;
  
  if (document.getElementById("texto").value.length != "" ){
    StrLen = StrLen + document.getElementById("texto").value.length;
  }
  if (StrLen == 1 && document.getElementById("texto").value.substring(0,1) == " "){ 
    document.getElementById("texto").value = "";
    StrLen = StrLen - 1;
  }
  if (StrLen > 400){
    document.getElementById("texto").value = document.getElementById("texto").value.substring(0,400);
    StrLen = StrLen - 1;
  }
 document.getElementById("caract").value = 400 - StrLen;
}