//=============== FUNÇÕES DE VALIDAÇÃO DURANTE A DIGITAÇÃO ================================================

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
	if (IE) {
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else {
		tempX = e.pageX;
		tempY = e.pageY;
	}
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}
	if (tempX > 700){tempX = 700;}
	if (tempY > 450){tempY = 450;}
	if (document.getElementById('divGrifes') != null) {
		if (document.getElementById('divGrifes').style.visibility == 'visible') {
			tempX = tempX + 20;
			tempY = tempY - 70;
			document.getElementById('divGrifes').style.top  = tempY;
			document.getElementById('divGrifes').style.left = tempX;
		}
	}
	if (document.getElementById('divLetras') != null) {
		if (document.getElementById('divLetras').style.visibility == 'visible') {
			tempX = tempX - 70;
			tempY = tempY + 50;
			document.getElementById('divLetras').style.top  = tempY;
			document.getElementById('divLetras').style.left = tempX;
		}
	}
	return true;
}

/*----------------------------------------------------------------------------------------------------
Conta a quantidade de caracteres no textarea
----------------------------------------------------------------------------------------------------*/
function fnTamanho(strTexto, intMax, tecla) 
{
   tecla = String.fromCharCode(tecla);
	if (strTexto.value.length >= intMax) return false;
	return true;
}

/*----------------------------------------------------------------------------------------------------
Não deixa o cara digitar nada além de números
----------------------------------------------------------------------------------------------------*/
function fnTiraCharEspeciaisNumeros(tecla)
{
   if ((tecla > 32 && tecla < 48) || tecla > 57)  event.returnValue = false;
}

/*----------------------------------------------------------------------------------------------------
Não deixa o cara digitar nada além de letras e números
----------------------------------------------------------------------------------------------------*/
function fnTiraCharEspeciais(tecla)
{
   if ((tecla >= 0 && tecla < 32) || (tecla > 32 && tecla < 48) || (tecla > 57 && tecla < 65) || (tecla > 90 && tecla < 94) || (tecla > 94 && tecla < 96) || (tecla > 122 && tecla < 192)) event.returnValue = false;
}

/*----------------------------------------------------------------------------------------------------
Analisa o conteúdo de uma string e retira caracteres especiais
----------------------------------------------------------------------------------------------------*/
function fnRetiraCharEspeciais(texto)
{
   var textoFinal, auxiliar = "";
   for (x=0; x<texto.lenght; x++) {
		if (fnTiraCharEspeciais(escape(texto.substring(x,x+1)).substring(1,2))) auxiliar += texto.substring(x,x+1);
   }
   return textoFinal;
}

/*----------------------------------------------------------------------------------------------------
Não deixa o cara digitar nada além de letras e números sem espaços
----------------------------------------------------------------------------------------------------*/
function fnCodigo(tecla)
{
   if ((tecla > 31 && tecla < 48) || (tecla > 57 && tecla < 65) || (tecla > 90 && tecla < 97) || tecla > 122) event.returnValue = false;
}

/*----------------------------------------------------------------------------------------------------
Não deixa o cara digitar nada além de letras, números, arroba e pontos 
----------------------------------------------------------------------------------------------------*/
function fnValidaEmail(campo)
{
   if (fnTiraEspaco(campo.value) != "" && campo.value != " ") {
      if ((campo.value.indexOf("@") <= -1) || (campo.value.indexOf(".") <= -1)) {
         alert("e-mail inválido");
         campo.focus();
         return false;
      }
   }
}

/*----------------------------------------------------------------------------------------------------
Não deixa o cara digitar nada em branco, nem um espaço
----------------------------------------------------------------------------------------------------*/
function fnEmBranco(str) {
	tamanho  = str.length;
	contador = 0;
	for (x=0; x<tamanho; x++) {
		if (str.substring(x,x+1) == " ") { ++contador;}
	}
  return ((contador == tamanho) || (str == ""));
}

/*----------------------------------------------------------------------------------------------------
Retira todos os espaços em branco de uma string
----------------------------------------------------------------------------------------------------*/
function fnTiraEspaco(string) {
   var temp = "";
   string = '' + string;
   splitstring = string.split(" ");
   for(i = 0; i < splitstring.length; i++)
   temp += splitstring[i];
   return temp;
}

function Tooltip(nome, acao) {
	if (acao == 'mostra') {
		document.getElementById(nome).style.visibility='visible';
		MostraTooltip(nome, 20);
	}
	if (acao == 'esconde') {
		document.getElementById(nome).style.visibility='hidden';
	}
}

function MostraTooltip(nome, num) {
	if (num > 100) return;
	eval("document.getElementById('" + nome + "').style.filter = 'alpha (opacity=" + num + ")';");
	num = num + 10;
	setTimeout("MostraTooltip('" + nome + "', " + num + ");", 1);
}


