function FormataValor3(campo,tammax,teclapres)
{
	//alert(campo+'-'+tammax+'-'+teclapres.keyCode);
	var tecla = teclapres.keyCode;
	var vr = campo.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 2 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }

	if ( tecla == 8 || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105) ){
		if ( tam <= 2 ){
			campo.value = vr ; 
		}
		tam = tam - 1;
		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 <= 17) ){
			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) ;
		}
	}
}


function janela(www,h,w,nome)
{
	var height = window.screen.height - 160;
	var width = window.screen.width;
	var top = (height- h)/2;
	var left = (width - w)/2;
	if(nome=='')
		nome='NOVA';
	window.open(www,nome,"top=" + top + ",left="+ left +",width="+w+",height="+h+",toolbar=no,location=no,status=no,menubar=no,scrollbars=no,scrolling=no,resizable=no")
}

function getPage(url, campo){
	
	var browser = navigator.appName;

	if(browser == "Microsoft Internet Explorer"){
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request = new XMLHttpRequest();
	}
	request.open("GET", url, false);
	request.send(null);
	//parent.document.getElementById(campo).innerHTML= request.responseText;
	document.getElementById(campo).innerHTML= request.responseText;
	/*var xmlhttp = createRequestObject();
	//Exibe o texto carregando no div conte?do

	var conteudo=document.getElementById(campo);
	// conteudo.innerHTML='<div class="carregando">carregando...</div>';
	//Abre a url

	xmlhttp.open("GET", url,false);

	//Executada quando o navegador obtiver o c?digo

	xmlhttp.onreadystatechange=function() {

	if (xmlhttp.readyState==4){
	//L? o texto
	var texto=xmlhttp.responseText;
	//Desfaz o urlencode
	texto=texto.replace(/\+/g," ");
	texto=unescape(texto);
	texto = (texto);
	//            alert(texto);
	//Exibe o texto no div conte?do
	var conteudo=document.getElementById(campo);
	conteudo.innerHTML = (texto);
	conteudo.innerHTML = (texto);
	}
	}
	xmlhttp.send(null)*/
}

function val_cpf(numero2) {
	dig_1 = 0;
	dig_2 = 0;
	controle_1 = 10;
	controle_2 = 11;
	lsucesso = 1;

	var numero = numero2.substr(0,3) + numero2.substr(4,3) + numero2.substr(8,3) + numero2.substr(12,2);

	if (numero == "00000000000" || numero == "11111111111" || numero == "22222222222" || numero == "33333333333" || numero == "44444444444" || numero == "55555555555" || numero == "66666666666" || numero == "77777777777" || numero == "88888888888" || numero == "99999999999") {
		return false;
	}

	if ((numero.length != 11) && (numero.length != 0)) {
		return false;
	}
	else {
		for ( i=0 ; i < 9 ; i++) {
			dig_1 = dig_1 + parseInt(numero.substring(i, i+1) * controle_1);
			controle_1 = controle_1 - 1;
		}

		resto = dig_1 % 11;
		dig_1 = 11 - resto;
		if ((resto == 0) || (resto == 1)) {
			dig_1 = 0;
		}
		for ( i=0 ; i < 9 ; i++) {
			dig_2 = dig_2 + parseInt(numero.substring(i, i + 1) * controle_2);
			controle_2 = controle_2 - 1;
		}
		dig_2 = dig_2 + 2 * dig_1;
		resto = dig_2 % 11;
		dig_2 = 11 - resto;
		if ((resto == 0) || (resto == 1)) {
			dig_2 = 0;
		}
		dig_ver = (dig_1 * 10) + dig_2;
		if (dig_ver != parseFloat(numero.substring(numero.length-2,numero.length))) {
			return false;
		}
	}

	return true;
}

function val_cnpj(numero) {
	//numero = numero1.value;
	dig_1 = 0;
	dig_2 = 0;
	controle_1 = 5;
	controle_2 = 6;

if ( (numero.length != 18)  || (numero.substring(2, 3) != ".") || (numero.substring(6, 7) != ".") || (numero.substring(10, 11) != "/") || (numero.substring(15, 16) != "-") ) {
     return false;
}else{ 
  	   numero = (numero.substring(0, 2)) + "" + (numero.substring(3, 6)) + "" + (numero.substring(7, 10))+ "" + (numero.substring(11, 15)) + "" + (numero.substring(16, 18)) 
	   for ( i=0 ; i < 12 ; i++) {
	        dig_1 = dig_1 + parseFloat(numero.substring(i, i+1) * controle_1);
	          controle_1 = controle_1 - 1;
	        if (i == 3) {
	           controle_1 = 9;
	        }
	   }
	   
	   resto = dig_1 % 11;
	   dig_1 = 11 - resto;
	   
	   if ((resto == 0) || (resto == 1)){
	        dig_1 = 0;
	   }
	   
	   for ( i=0 ; i < 12 ; i++) {
	        dig_2 = dig_2 + parseInt(numero.substring(i, i+1) * controle_2);
	          controle_2 = controle_2 - 1;
	        if (i == 4) {
	           controle_2 = 9;
	        }
	   }
	   
	   dig_2 = dig_2 + (2 * dig_1);
	   resto = dig_2 %11;
	   dig_2 = 11 - resto;
	   
	   if ((resto == 0) || (resto == 1)){
	        dig_2 = 0;
	   }
	   
	   dig_ver = (dig_1 * 10) + dig_2;
	   
	   if (dig_ver != parseFloat(numero.substring(numero.length-2,numero.length))) {
	          return false;
	   }
 }
 return true;
}

//Checa o campo E-Mail
function verifica_mail(email){
	var campo = email;
	//se a "@" não existe e é o primeiro caractere 
	if (campo.indexOf("@") < 1) return false
	//se o caracter antes da "@" é "." 
	if(campo.charAt(campo.indexOf("@")-1) == ".") return false;
	//se a última incidência de "." está antes da @ 
	if (campo.lastIndexOf(".") <= campo.indexOf("@")) return false;
	//se o último caracter é ponto,
	if (campo.lastIndexOf(".")  == (campo.length-1)) return false; 
	
	return true;
}
function formatar(src, mask) 
{
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida) 
  {
	src.value += texto.substring(0,1);
  }
}
function evita_letra(tecla) {
	if (tecla.keyCode < 44 || tecla.keyCode > 57)
		tecla.returnValue = false;
}
function createRequestObject(){
	var request_;
	var browser = navigator.appName;

	if(browser == "Microsoft Internet Explorer"){
		request_ = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_ = new XMLHttpRequest();
	}

	return request_;
}

function getPage2(url, campo){

	var xmlhttp = createRequestObject();
	//Exibe o texto carregando no div conte?do
	var conteudo=parent.document.getElementById(campo);
	//conteudo.innerHTML='<div class="carregando">carregando...</div>';
	xmlhttp.open("GET", url,true);

	//Executada quando o navegador obtiver o c?digo

	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4){
			//L? o texto
			var texto=xmlhttp.responseText;
			texto = (texto);
			//Desfaz o urlencode
			//texto=texto.replace(/\+/g," ");
			texto=unescape(texto);
			texto = (texto);
			//Exibe o texto no div conte?do
			//var conteudo=parent.document.getElementById(campo);
			//    conteudo.innerHTML= "< ?xml version='1.0' encoding='UTF-8'?>"+(texto);
			conteudo.innerHTML= (texto);
		}
	}
	xmlhttp.send(null);
}


function mostraDiv(id) {
	document.getElementById(id).style.display = "block";
}
function escondeDiv(id) {
	document.getElementById(id).style.display = "none";
}
//
//

//
var myTime;
function scrollUp(){	
	window.frameGal.scrollBy(-5,0);//sobe a barra de rolagem
	myTime = setTimeout('scrollUp()', 5);//myTime objeto q mantém a recursividade
}

function scrollDown(){
	window.frameGal.scrollBy(5,0);//desce a barra de rolagem
	myTime = setTimeout('scrollDown()', 5);//myTime objeto q mantém a recursividade
}
//
function overImg(id){
	document.getElementById(id).style.border = "1px solid red";
}
function outImg(id){
	document.getElementById(id).style.border = "1px solid #828180";
}

function mudaDiv(div){
	div = document.getElementById(div);
	//alert(div.style);
	if(div.style.display=='none'){
		div.style.display='block';
	}else{
		div.style.display='none';
	}
}