
function AddFavoritos(pagina,titulo){
if(window.sidebar) // Gecko (Mozilla, Firefox, Firebird & Netscape)
	window.sidebar.addPanel(titulo,pagina,'')
else
	if(window.external) // Internet Explorer
		window.external.AddFavorite(pagina,titulo);

}

// Formata o campo valor
function formataValor(campo) {
 campo.value = filtraCampo(campo);
 vr = campo.value;
 tam = vr.length;

 if ( tam <= 2 ){
 campo.value = vr ; }
 if ( (tam > 2) && (tam <= 5) ){
 campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
 if ( (tam >= 6) && (tam <= 8) ){
 campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
 if ( (tam >= 9) && (tam <= 11) ){
 campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
 if ( (tam >= 12) && (tam <= 14) ){
 campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
 if ( (tam >= 15) && (tam <= 18) ){
 campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}

}
// Formata o campo valor
function formataNumerico(campo) {
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;
}

function filtraCampo(campo){
	var s = "";
	var cp = "";
	vr = campo.value;
	tam = vr.length;
	for (i = 0; i < tam ; i++) {
	if (vr.substring(i,i + 1) != "/" && vr.substring(i,i + 1) != "-" && vr.substring(i,i + 1) != "." && vr.substring(i,i + 1) != "," ){
	s = s + vr.substring(i,i + 1);}
	}
	campo.value = s;
	return cp = campo.value
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

var ___CountProtecaoTela = 0;
var ___ExibirProtecaoTela = 1000; //Milisegundo
var ___AlterarLinkProtecaoTela = 35000; //Milisegundo
var ___lastX = 0;
var ___lastY = 0;

function inicializarProtecao(){
	
	atualizarLinkIframe();
	setInterval('chamarProtecaoTela()', 1);
	setInterval('atualizarLinkIframe()', ___AlterarLinkProtecaoTela);	
	document.onmousemove= zerarProtecaoTela;

}




function chamarProtecaoTela(){
	___CountProtecaoTela++;	
	
	if (___CountProtecaoTela >= ___ExibirProtecaoTela)
		exibirProtecaoTela()
	else
		ocultarProtecaoTela();	
}

function zerarProtecaoTela(){
		if (document.all) {//IE
			try{
				if ((___lastX != event.clientX) || (___lastY != event.clientY)){			
					___CountProtecaoTela = 0;				
					___lastX = event.clientX;				
					___lastY = event.clientY;
				}
			}catch(e){
				___CountProtecaoTela = 0;
			}
		}else{
			___CountProtecaoTela = 0;	
		}
}

function exibirProtecaoTela(){
	
	var ProtecaoTela = document.getElementById('protecaoTela');
	var ProtecaoTelaSobreposta = document.getElementById('protecaoTelaSobreposta');
	var alturaProtecao = -80;
	

	if (document.all){ //IE
		if (document.documentElement && document.documentElement.scrollTop){
			ProtecaoTela.style.top = (alturaProtecao + document.documentElement.scrollTop) + 'px';
			ProtecaoTelaSobreposta.style.top = (alturaProtecao + document.documentElement.scrollTop) + 'px';			
		}
		else{
			ProtecaoTela.style.top = (alturaProtecao + document.body.scrollTop) + 'px';
			ProtecaoTelaSobreposta.style.top = (alturaProtecao + document.body.scrollTop)+ 'px';			
		}
	}else{ //Mozilla
		ProtecaoTela.style.top = (alturaProtecao + window.pageYOffset) + 'px';		
		ProtecaoTelaSobreposta.style.top = (alturaProtecao + window.pageYOffset) + 'px';				
	}
	
	//Corrigindo largura
	ProtecaoTela.style.width = (screen.availWidth - 30) + 'px';
	ProtecaoTelaSobreposta.style.width = (screen.availWidth - 30) + 'px';
	
	
	//Exibindo os Iframes
	ProtecaoTela.style.display = 'block';
	ProtecaoTelaSobreposta.style.display = 'block';	
	
}

function ocultarProtecaoTela(){
	document.getElementById('protecaoTela').style.display = 'none';
	document.getElementById('protecaoTelaSobreposta').style.display = 'none';	

}
function selecionarLinkRandomico(){
	var rand = oldLinkProtecaoTela;
	 while(rand == oldLinkProtecaoTela)
      {
        rand = Math.floor(Math.random()*linkProtecaoTela.length); 
      }
	  oldLinkProtecaoTela = rand;
	  
	  return linkProtecaoTela[rand];
}
function atualizarLinkIframe(){
	if ((___CountProtecaoTela >= ___ExibirProtecaoTela) || document.getElementById('protecaoTela').src == '')
		document.getElementById('protecaoTela').src = selecionarLinkRandomico();	
	
}
