//-------------------------------------------------------------------------------------------------------
// Verifica se e-mail é válido
//-------------------------------------------------------------------------------------------------------
  function isEmail(str) {
	//verifica se o e-mail digitado é válido 
	var strAlfa = "ABCDEFGHIJKLMNOPQRSTUWVXYZ";
	var strNum = "0123456789";
	var strSpecial = "_.-@/";
	var strValid = strAlfa + strNum + strSpecial;
	var email = str.toUpperCase();
	//verifica se os caracteres do e-mail são válidos
	for (i=0; i<email.length; i++) {
	  if (strValid.indexOf(email.charAt(i)) < 0) {
		return false;
	  }
	}

	var strC = "@."; 
	//verifica se o e-mail contém @ e . (caracteres obrigatórios)
	for (i=0; i<strC.length; i++) {
	  if (email.indexOf(strC.charAt(i)) < 0) 
		return false;
	  }

	if (email.indexOf("@") != email.lastIndexOf("@"))
	  return false;
	if (email.indexOf("@") > email.lastIndexOf("."))
	  return false;
	if (email.charAt(email.indexOf("@") + 1) == ".")
	  return false;
	if (!(email.indexOf("@") != 0 && email.lastIndexOf(".") != email.length-1))
	  return false;
						
	return true;
  }
  
	function retiraEspaco(theString) {
		//retira todos os espaços de uma string
		if (theString.indexOf(" ") >= 0) {
			var i = 0;
			while (theString.indexOf(" ") >= 0) {
				if (theString.charAt(i) == " ") 
					theString = theString.substring(0,i) + theString.substring(i+1,theString.length);
				else i++
			}
			newString = theString;
		} 
		else newString = theString;
		return newString;
	}

    function isEmpty(str) {
		//verifica se alguma coisa foi digitada num determinado campo
		if (str == null || str == "")
			return true;
		return false;
	}

	function isNumeric(strTexto)
	{
		//verifica se uma string é um número inteiro
		//Obs.: utiliza a função isEmpty
		if (isEmpty(strTexto)) 
			return false;
		var strNum = "0123456789";
		
		for (var i=0; i < strTexto.length; i++) {
			if (strNum.indexOf(strTexto.charAt(i)) < 0)
				return false;			
		}
		return true;
	}
	
	function isValor(strTexto)
	{
		//verifica se uma string é um número decimal
		//Obs.: utiliza a função isEmpty
		
		if (isEmpty(strTexto)) 
			return false;
		
		strTexto = retiraEspaco(strTexto);
		
		var strNum = "0123456789,";
		
		for (var i=0; i < strTexto.length; i++) {
			if (strNum.indexOf(strTexto.charAt(i)) < 0)
				return false;			
		}

		if (strTexto.lastIndexOf(",") == strTexto.length-1) {
			return false
		}
		return true;
	}

	// recebe uma string e retorna somente os números que ela contém
	function pegaNumeros(sValor)
	{
		var sValida = "0123456789", i = 0;
		while (i < sValor.length) 
		{
			if (sValida.indexOf(sValor.charAt(i)) < 0) 
			{
				sValor = sValor.substring(0,i) + sValor.substring(i+1,sValor.length)
			} else i++;	
		}
		return sValor
	}

	function isCPF(sCpf) 
	{
		sCpf = pegaNumeros(sCpf);
		if (sCpf.length != 11 || sCpf == "00000000000" || sCpf == "11111111111" ||	sCpf == "22222222222" ||	sCpf == "33333333333" || sCpf == "44444444444" ||	sCpf == "55555555555" || sCpf == "66666666666" || sCpf == "77777777777" ||		sCpf == "88888888888" || sCpf == "99999999999")
			return false;
		soma = 0;
		for (i=0; i < 9; i ++)
			soma += parseInt(sCpf.charAt(i)) * (10 - i);
		resto = 11 - (soma % 11);
		if (resto == 10 || resto == 11)
			resto = 0;
		if (resto != parseInt(sCpf.charAt(9)))
			return false;
		soma = 0;
		for (i = 0; i < 10; i ++)
			soma += parseInt(sCpf.charAt(i)) * (11 - i);
		resto = 11 - (soma % 11);
		if (resto == 10 || resto == 11)
			resto = 0;
		if (resto != parseInt(sCpf.charAt(10)))
			return false;
		return true;
	}
	
	function isCNPJ(CNPJ) {
	  if (CNPJ.length < 18) return false;
      if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")) return false
      //substituir os caracteres que não são números
	  if (document.layers && parseInt(navigator.appVersion) == 4) {
        x = CNPJ.substring(0,2);
        x += CNPJ.substring (3,6);
        x += CNPJ.substring (7,10);
        x += CNPJ.substring (11,15);
        x += CNPJ.substring (16,18);
        CNPJ = x; 
      }
	  else {
        CNPJ = CNPJ.replace (".","");
        CNPJ = CNPJ.replace (".","");
        CNPJ = CNPJ.replace ("-","");
        CNPJ = CNPJ.replace ("/","");
      }

      var nonNumbers = /\D/;
      if (nonNumbers.test(CNPJ)) return false; 
      var a = [];
      var b = new Number;
      var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
      for (i=0; i<12; i++) {
        a[i] = CNPJ.charAt(i);
        b += a[i] * c[i+1];
	  }
      if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
      b = 0;
      for (y=0; y<13; y++) {
        b += (a[y] * c[y]); 
      }
      if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
      if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])) return false;
      return true;
    }

  function Botao() {
    if (document.form1.acao.value=='S') document.getElementById('btnSelImovel').style.display='';
    else if (document.form1.acao.value=='R') document.getElementById('btnRemImovel').style.display='';
  }
	
	function navegador() {
		if (navigator.appName=='Microsoft Internet Explorer') return 0;
		else return 1;
	}