/*
Função para validação de campos numericos, letras
Ex: onkeypress="return ValidaCaracteres(true,false,null,event)"
*/
function ValidaCaracteres(numbers,letters,others,e){
	if(window.event)key=window.event.keyCode
	else if(e)key=e.which
	else return true
	S=(others)?others:''
	if(numbers)S+='0123456789'
	if(letters)S+='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
	if(key==null||key==0||key==8||key==9||key==13||key==27)return true
	else if(S.indexOf(String.fromCharCode(key))!=-1)return true
	else return false
}

function maximizarJanela() {
    window.moveTo (-4,-4);
    window.resizeTo (screen.availWidth + 8, screen.availHeight + 8);
}

function ContaCaracteres(objArea,objConta) { 
    var limite = 255;
    var idArea=document.getElementById(objArea).value;
    var idConta=document.getElementById(objConta).value;
	var mais_um=eval(idArea.length-1); 
	mais_um++;
	if (idArea.length>limite) {
		idArea='';		
		idArea=valor_limite;				
		alert("Limite de "+limite+" caracteres");
	}else{
		  valor_limite=idArea;		
		  document.getElementById(objConta).value='';	
          document.getElementById(objConta).value=(limite-mais_um);			  
	}	
	document.getElementById(objArea).focus();
} 


function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
   aux = validos.indexOf(valor.substring(i, i+1));
   if (aux>=0) {
      result += aux;
   }
}
return result;
}

function contaCarac(id,limite,objCont) { 
	var param=document.getElementById(id).value;
	var mais_um=eval(id.value.length-1); 
	mais_um++;
	if (document.getElementById(id).value.length>limite) {
		document.getElementById(id).value='';		
		document.getElementById(id).value=valor_limite;				
		alert("Limite de "+limite+" caracteres");
	}else{
		  valor_limite=document.getElementById(id).value;		
		  document.getElementById(objCont).value='';	
          document.getElementById(objCont).value=(limite-mais_um);			  
	}	
	document.getElementById(id).focus();
} 

function Formata(campo,tammax,teclapres,decimal) {
//chamada: onKeydown="Formata(this,20,event,2)"
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal

if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

if (tecla == 8 )
{ tam = tam - 1 ; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
{

if ( tam <= dec )
{ campo.value = vr ; }

if ( (tam > dec) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, 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 - dec, 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 - dec, 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 ) ;}
} 

}

addEvent = function(o, e, f, s){
	var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
	r[r.length] = [f, s || o], o[e] = function(e){
		try{
			(e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
			e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
			e.target || (e.target = e.srcElement || null);
			e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
		}catch(f){}
		for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
		return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
	for(var i = (e = o["_on" + e] || []).length; i;)
		if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
			return delete e[i];
	return false;
};

function formataMoeda(o, n, dig, dec){
	o.c = !isNaN(n) ? Math.abs(n) : 2;
	o.dec = typeof dec != "string" ? "," : dec, o.dig = typeof dig != "string" ? "." : dig;
	addEvent(o, "keypress", function(e){
		if(e.key > 47 && e.key < 58){
			var o, s, l = (s = ((o = this).value.replace(/^0+/g, "") + String.fromCharCode(e.key)).replace(/\D/g, "")).length, n;
			if(o.maxLength + 1 && l >= o.maxLength) return false;
			l <= (n = o.c) && (s = new Array(n - l + 2).join("0") + s);
			for(var i = (l = (s = s.split("")).length) - n; (i -= 3) > 0; s[i - 1] += o.dig);
			n && n < l && (s[l - ++n] += o.dec);
			o.value = s.join("");
		}
		e.key > 30 && e.preventDefault();
	});
}

function formatarTelefone(campo)
{	
	//Permitir somente a digitação de "(" , ")" , "-".	
	if ((event.keyCode != 40) && (event.keyCode != 41) && (event.keyCode != 45))
	{
		//Permitir somente a digitação de números 0-9.					
		bloqueia_alfa();
	}
	if  (campo.value.length == 0)
	{
		campo.value += "(";
	}
	if  (campo.value.length == 3)
	{
		campo.value += ")";
	}
	if  (campo.value.length == 8)
	{
		campo.value += "-";
	}
}

function buscarCaracteres(campo)
{				
	if ((campo.indexOf('(') != -1) || (campo.indexOf(')') != -1) || (campo.indexOf('-') != -1))
	{
	return false;
	}			
}

function alterarBordaIFrame(estilo)
{
	parent.document.getElementById('dvfooterNoticia').style.display = estilo;
}
	
function alterarCorLinha(cor)
{		
	var corAntiga = '';
	var linhaMarcada = cor;	

	var linha = window.event.srcElement;
		    
	while((linha != null)&&(linha.tagName != "TR"))
	{
		linha = linha.parentElement;
	}
			       
	corAntiga = linha.style.backgroundColor;
				 
	for(var i=0; i < tabela.rows.length; i++)
	{
		tabela.rows[i].style.backgroundColor = '';
	}
				
	if(corAntiga=='')
	{			
		linha.style.backgroundColor = linhaMarcada;			
	}		
	else
	{
		linha.style.backgroundColor = '';
	}
}

function bloqueia_alfa()	
{
	//Função que permite a digitação de números 0-9
	if (event.keyCode < 47 || event.keyCode >57)	
	{
		event.keyCode = 0;
		return false;
	}
	else	
	{
		if (event.keyCode == 47)	
		{
			event.keyCode = 0;
			return false;
		}
	}
}

//Função que permite a digitação de números 0-9 e vírgula
  function bloqueia_alfa_NRV(){
    if (event.keyCode >= 48 && event.keyCode <= 57||event.keyCode==44){
       return true;
  }
    else{
       event.keyCode = 0;
       return false;
  }
  }

//Função que permite a digitação somente Letras
  function bloqueia_nr(){
    if (event.keyCode >= 48 && event.keyCode <= 57||event.keyCode==44){
       event.keyCode = 0;
       return false;
  }
    else{
       return true;
  }
  }



function KPress(campo){
var tecla = window.event.keyCode;
if(tecla==13){
   document.formulario[campo].focus();
}
}


function compara_datas(campo1,campo2)   
{	
	//Funcionalidade: Verificar se uma data (campo2) é maior que a outra (campo1)
	//retorna: 0 se as datas forem iguais, 1 se a primeira for menor que a segunda, e -1 se a primeira for maior que a segunda
	
	var data1, data2;
	data1 = campo1;	
	data2 = campo2;
	
	data1 = data1.substr(6,4)+data1.substr(3,2)+data1.substr(0,2);	
	data2 = data2.substr(6,4)+data2.substr(3,2)+data2.substr(0,2);
	
	if (parseFloat(data1) == parseFloat(data2))
	{
		return 0;
	}
	else if (parseFloat(data1) < parseFloat(data2))
	{
		return 1;
	}
	else if (parseFloat(data1) > parseFloat(data2))
	{
		return -1;
	}	
}

function mascara_data(param)	
{
	bloqueia_alfa();
	if (param.value.length==2)	
	{
		param.value = param.value + "/";
		return;
	}
	if (param.value.length==5)	
	{
		param.value = param.value + "/";
		return;
	}
}

function valida_data(dia,mes,ano)
{
	//Funcionalidade:	Valida a Data retornando True se for uma Data 
	//					válida e False se não for.
	//					Antes de se usar esta função deve-se garantir que os parâmetros
	//					passados sejam numéricos e inteiros.
	// PARÂMETROS: 
	//		Dia = Dia da Data(caracteres numericos), 
	//		Mes = Mes da Data(caracteres numericos), 
	//		Ano = Ano da Data(caracteres numericos)
		
	var v_dia;
	var v_mes;
	var v_ano;
	

	if (!valida_inteiro(dia))
	{
		return (false);		
	
	}
	if (!valida_inteiro(mes))
	{
		return (false);		
	}
	if (!valida_inteiro(ano))
	{
		return (false);		
	}

	v_dia = dia;
	v_mes = mes;
	v_ano = ano;

	if (v_dia.length < 2)
	{
		return(false);
	}

	if (v_mes.length < 2)
	{
		return(false);
	}

	if (v_ano.length < 4)
	{
		return(false);
	}

	if (((v_ano < 1900) || (v_ano > 2079)) && (v_ano.length != 0))
	{
		return(false);
	}

	if (v_dia > 31 || v_dia < 1)
	{
		return(false);
	}

	if (v_mes > 12 || v_mes < 1)
	{
		return(false);
	}

	if (v_dia == "31") 
	{
		if ((v_mes == "04") || (v_mes == "06") || (v_mes == "09") || (v_mes == "11"))
		{
			return(false);
		}
	}

	//Validação de Ano Bissexto
	if (v_mes == "02")
	{
		if (!(v_ano%4)) 
		{
			if (v_dia > 29)
			{
				return(false);
			}
		}
		else if (v_dia > 28)
		{
			return(false);
		}
	}

	//o -if- abaixo testa se algum campo foi preenchido e outro deixado em branco deixando a data incompleta

	if (((v_dia != "") || (v_mes != "") || (v_ano != "")) && ((v_dia == "") || (v_mes == "") || (v_ano == "")))
	{
		return(false);
	}
	return(true);
}

function valida_inteiro(parametro)  //FUNCAO PARA VALIDACAO DE NÚMEROS INTEIROS, E ESPAÇOS EM BRANCO
{
	if (parametro.length != 0)
	{
		if (!verifica_branco(parametro))
		{
			return true;
		}

		teste_ponto = "false";
		tamanho_parametro = parametro.length;

		if (isNaN(parametro)) //valor digitado não é numérico
		{
			return false;
		}
		else //valor digitado é um numérico válido
		{	
			for (k = 0; k < tamanho_parametro; k++)
			{if ((parametro.charAt(k) == '.') || (parametro.charAt(k) == '-') || (parametro.charAt(k) == '+'))
				{
					teste_ponto = "true"; /*existe caracter ponto*/
				}
			}

			if (teste_ponto == "true") //encontrou caracter ponto(numero real)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
	}
	else
	{
		return true;
	}
}

function verifica_branco(parametro)   // FUNCAO PARA VERIFICAÇÃO DE CAMPOS NÃO PREENCHIDOS
									// OU PREENCHIDOS APENAS COM ESPAÇOS EM BRANCO
{
	var tamanho_parametro = 0;
	teste_parametro = "false"; //variavel para teste de espacos em branco
	tamanho_parametro = parametro.length;
	if (tamanho_parametro != 0)
	{
		for (i = 0; i < tamanho_parametro; i++)
			{if (parametro.charAt(i) != " ")
				{
					teste_parametro = "true"; /*existe caracter diferente de branco*/
				}
			}
		if (teste_parametro == "false")  //todos os caracteres digitados são brancos
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return false;
	}
}

function mascaraHora(campo)
{
	if ((campo.value.length == 2))
	{
		campo.value += ":";
	}	
}

function validaHora(campo)
{	
	if (campo.value.length < 5)
	{
		return false;	
	}
	if (campo.value.substr(0,2) > 23)
	{		
		return false;
	}				
	if (campo.value.substr(3,2) > 59)
	{		
		return false;
	}
	if (campo.value.substr(2,1) != ":")
	{		
		return false;
	}
	return true;
}

function comparaHora(hora1,hora2)
{ 
	var horainicial = new Date();
	var horafinal= new Date();
	horainicial = hora1;
	horafinal = hora2;	
	if((horainicial>horafinal)||(horainicial==horafinal))
	{
		return false;		
	}
	return true;
}

function MM_checkBrowser(NSvers,NSpass,NSnoPass,IEvers,IEpass,IEnoPass,OBpass,URL,altURL) { //v5.0
  var newURL='', userAgent=navigator.userAgent, version=0;
  if (userAgent.indexOf('Netscape') != -1) {
  	version = parseFloat(userAgent.substring(userAgent.indexOf('Netscape')+9,userAgent.length));
    if (version >= NSvers) {if (NSpass>0) newURL=(NSpass==1)?URL:altURL;}
    else {if (NSnoPass>0) newURL=(NSnoPass==1)?URL:altURL;}
  } else if (userAgent.indexOf('MSIE') != -1) {
  	version = parseFloat(userAgent.substring(userAgent.indexOf('MSIE')+4,userAgent.length));
    if (version >= IEvers)
     {if (IEpass>0) newURL=(IEpass==1)?URL:altURL;}
    else {if (IEnoPass>0) newURL=(IEnoPass==1)?URL:altURL;}
  } else if (OBpass>0) newURL=(OBpass==1)?URL:altURL;
  if (newURL) { window.location=unescape(newURL); document.MM_returnValue=false; }
}


//adiciona mascara de cnpj
function MascaraCNPJ(cnpj){
	if(mascaraInteiro(cnpj)==false){
		event.returnValue = false;
	}	
	return formataCampo(cnpj, '00.000.000/0000-00', event);
}

//adiciona mascara de cep
function MascaraCep(cep){
		if(mascaraInteiro(cep)==false){
		event.returnValue = false;
	}	
	return formataCampo(cep, '00.000-000', event);
}

//adiciona mascara de data
function MascaraData(data){
	if(mascaraInteiro(data)==false){
		event.returnValue = false;
	}	
	return formataCampo(data, '00/00/0000', event);
}

//adiciona mascara ao telefone
function MascaraTelefone(tel){	
	if(mascaraInteiro(tel)==false){
		event.returnValue = false;
	}	
	return formataCampo(tel, '(00) 0000-0000', event);
}

//adiciona mascara ao Valor monetário
function MascaraMoney(obj){	
	var vlr=document.getElementById(obj).value;
	if(mascaraInteiro(vlr)==false){
		event.returnValue = false;
	}
    var tam=vlr.length;
    if(tam==9) {
	   return formataCampo(document.getElementById(obj), '000.000.000,00', event);
    }
    else if(tam==8) {
	   return formataCampo(document.getElementById(obj), '00.000.000,00', event);
    }
    else if(tam==7) {
	   return formataCampo(document.getElementById(obj), '0.000.000,00', event);
    }
    else if(tam==6) {
	   return formataCampo(document.getElementById(obj), '000.000,00', event);
    }
    else if(tam==5) {
	   return formataCampo(document.getElementById(obj), '00.000,00', event);
    }
    else if(tam==4) {
	   return formataCampo(document.getElementById(obj), '00.000,00', event);
    }
    else if(tam<=3) {
	   return formataCampo(document.getElementById(obj), '000,00', event);
    }
}

//adiciona mascara ao CPF
function MascaraCPF(cpf){
	if(mascaraInteiro(cpf)==false){
		event.returnValue = false;
	}	
	return formataCampo(cpf, '000.000.000-00', event);
}

function ValidaDataDigitada(campo1)
{
	var data1;
	data1=campo1 
	
	var dia;
	var mes;
	var ano;
	dia = data1.substr(0,2);
	mes = data1.substr(3,2);
	ano = data1.substr(6,4);
	
	if ((dia == "") && (mes == "") && (ano == ""))
	{
		return(false);
	}

	
	if (((ano < 1900) || (ano > 2079)) && (ano.length != 0))
	{
		alert("Ano Incorreto ");
		return(false);
	}

	if (dia > 31 || dia < 1)
	{
		alert("Dia Incorreto ");
		return(false);
	}

	if (mes > 12 || mes < 1)
	{
		alert("Mês Incorreto");
		return(false);
	}

	if (dia == "31") 
	{
		if ((mes == "04") || (mes == "06") || (mes == "09") || (mes == "11"))
		{
			return(false);
		}
	}

	//Validação de Ano Bissexto
	if (mes == "02")
	{
		if (!(ano%4)) 
		{
			if (dia > 29)
			{
				return(false);
			}
		}
		else if (dia > 28)
		{
			return(false);
		}
	}

	//o -if- abaixo testa se algum campo foi preenchido e outro deixado em branco deixando a data incompleta

	if (((dia != "") || (mes != "") || (ano != "")) && ((dia == "") || (mes == "") || (ano == "")))
	{
		return(false);
	}
	return(true);
}

//valida o CPF digitado
function ValidarCPF(Objcpf){
	var cpf = Objcpf.value;
	if (cpf == "")
	{
		return(false);
	}
	
	exp = /\.|\-/g
	cpf = cpf.toString().replace( exp, "" ); 
	var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
    var soma1=0, soma2=0;
	var vlr =11;
	
	for(i=0;i<9;i++){
        soma1+=eval(cpf.charAt(i)*(vlr-1));
        soma2+=eval(cpf.charAt(i)*vlr);
        vlr--;
    }	
    soma1 = (((soma1*10)%11)==10 ? 0:((soma1*10)%11));
    soma2=(((soma2+(2*soma1))*10)%11);
	
    var digitoGerado=(soma1*10)+soma2;
	if(digitoGerado!=digitoDigitado)	
		alert('CPF Inválido!');
		//Objcpf.focus();		
}

//Retira os espaços em branco existentes antes e depois do texto.
function trim(str)
{
	if (str.charAt(0) == ' ')
		str = trim(str.substr(1));
	if (str.charAt(str.length - 1) == ' ')
		str = trim(str.substr(0, str.length - 1));
	return str;
}	

//Retira caracteres de separação de uma String, ("/", "-", ".", ",", ";", "|", " ", "\", ":", "(", ")"). EXEMPLO DE USO = "12122001" = retiraCaracteresSeparacao("12-12.2001");
function retiraCaracteresSeparacao(Str) 
{
  var s = "";
  var espaco = "X X";
  Str = trim(Str);
  for (i = 0; i < Str.length ; i++) {
    if (Str.charAt(i) != "/" && Str.charAt(i) != "-" && Str.charAt(i) != "."  && Str.charAt(i) != "," &&
        Str.charAt(i) != ";" && Str.charAt(i) != "|" && Str.charAt(i) != espaco.charAt(1) && Str.charAt(i) != "\\" &&
        Str.charAt(i) != ":" && Str.charAt(i) != "(" && Str.charAt(i) != ")"){
      s = s + Str.charAt(i);
    }
  }

 return s;
}

//valida o CPF digitado e informa se o CPF é válido (true) ou não (false)
function validarCPFComResult(objCPF)
{    
    var CPF = retiraCaracteresSeparacao(objCPF.value);

    if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
            CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
            CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
            CPF == "88888888888" || CPF == "99999999999")
            return false;
    soma = 0;
    for (i=0; i < 9; i ++)
            soma += parseInt(CPF.charAt(i)) * (10 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
            resto = 0;
    if (resto != parseInt(CPF.charAt(9)))
            return false;
    soma = 0;
    for (i = 0; i < 10; i ++)
            soma += parseInt(CPF.charAt(i)) * (11 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
            resto = 0;
    if (resto != parseInt(CPF.charAt(10)))
            return false;

    return true;
}

//valida numero inteiro com mascara
function mascaraInteiro(){
	if (event.keyCode < 48 || event.keyCode > 57){
		event.returnValue = false;
		return false;
	}
	return true;
}

//valida o CNPJ digitado
function ValidarCNPJ(ObjCnpj){
	var cnpj = ObjCnpj.value;
	
	if (cnpj == "")
	{
		return(false);
	}
	var valida = new Array(6,5,4,3,2,9,8,7,6,5,4,3,2);
	var dig1= new Number;
	var dig2= new Number;
	
	exp = /\.|\-|\//g
	cnpj = cnpj.toString().replace( exp, "" ); 
	var digito = new Number(eval(cnpj.charAt(12)+cnpj.charAt(13)));
		
	for(i = 0; i<valida.length; i++){
		dig1 += (i>0? (cnpj.charAt(i-1)*valida[i]):0);	
		dig2 += cnpj.charAt(i)*valida[i];	
	}
	dig1 = (((dig1%11)<2)? 0:(11-(dig1%11)));
	dig2 = (((dig2%11)<2)? 0:(11-(dig2%11)));
	
	if(((dig1*10)+dig2) != digito)	
		alert('CNPJ Invalido!');
		//ObjCnpj.focus();		
}

//valida o CNPJ digitado
function ValidarCNPJvalue(ValueCnpj){
	var cnpj = ValueCnpj;
	if (cnpj == "")
	{
		return(false);
	}
	var valida = new Array(6,5,4,3,2,9,8,7,6,5,4,3,2);
	var dig1= new Number;
	var dig2= new Number;
	
	exp = /\.|\-|\//g
	cnpj = cnpj.toString().replace( exp, "" ); 
	var digito = new Number(eval(cnpj.charAt(12)+cnpj.charAt(13)));
		
	for(i = 0; i<valida.length; i++){
		dig1 += (i>0? (cnpj.charAt(i-1)*valida[i]):0);	
		dig2 += cnpj.charAt(i)*valida[i];	
	}
	dig1 = (((dig1%11)<2)? 0:(11-(dig1%11)));
	dig2 = (((dig2%11)<2)? 0:(11-(dig2%11)));
	
	if(((dig1*10)+dig2) != digito)	
		return(false);	
}

//INICIO FUNCOES OFICIAIS P/CNPJ
function FormataCNPJ(Formulario, Campo, TeclaPres) 
{ 
var tecla = TeclaPres.keyCode; 
var strCampo; 
var vr; 
var tam; 
var TamanhoMaximo = 14; 
eval("strCampo = document." + Formulario + "." + Campo); 
vr = strCampo.value; 
vr = vr.replace("/", ""); 
vr = vr.replace("/", ""); 
vr = vr.replace("/", ""); 
vr = vr.replace(",", ""); 
vr = vr.replace(".", ""); 
vr = vr.replace(".", ""); 
vr = vr.replace(".", ""); 
vr = vr.replace(".", ""); 
vr = vr.replace(".", ""); 
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 < TamanhoMaximo && tecla != 8) 
{ 
  tam = vr.length + 1; 
} 

if (tecla == 8) 
{ 
  tam = tam - 1; 
} 
if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105) 
{ 
  if (tam <= 2) 
  { 
    strCampo.value = vr; 
  } 
   if ((tam > 2) && (tam <= 6)) 
   { 
     strCampo.value = vr.substr(0, tam - 2) + '-' + vr.substr(tam - 2, tam); 
   } 
   if ((tam >= 7) && (tam <= 9)) 
   { 
     strCampo.value = vr.substr(0, tam - 6) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
  } 
   if ((tam >= 10) && (tam <= 12)) 
   { 
     strCampo.value = vr.substr(0, tam - 9) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
  } 
   if ((tam >= 13) && (tam <= 14)) 
   { 
     strCampo.value = vr.substr(0, tam - 12) + '.' + vr.substr(tam - 12, 3) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
  } 
   if ((tam >= 15) && (tam <= 17)) 
   { 
     strCampo.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 valida_cnpj(Formulario, Campo) 
 { 
 eval("strCampo = document." + Formulario + "." + Campo); 
 vr = strCampo.value;
 if(vr.length > 0) { 
	 if(VerifyCNPJ(vr) == 0) 
	   { 
	  alert("CNPJ inválido. Digite novamente!"); 
	  strCampo.focus(); 
	   
	 } 
 }
 }

function VerifyCNPJ(CNPJ) 
 { 
 CNPJ = LIMP(CNPJ); 
 if(isNUMB(CNPJ) != 1) 
  { 
  return(0); 
  } 
 else 
  { 
  if(CNPJ == 0) 
   { 
   return(0); 
   } 
  else 
   { 
   g=CNPJ.length-2; 
   if(validaparteint(CNPJ,g) == 1) 
    { 
    g=CNPJ.length-1; 
    if(validaparteint(CNPJ,g) == 1) 
     { 
     return(1); 
     } 
    else 
     { 
     return(0); 
     } 
    } 
   else 
    { 
    return(0); 
    } 
   } 
  } 
 } 

function validaparteint(CNPJ,g) 
 { 
 var VerCNPJ=0; 
 var ind=2; 
 var tam; 
 for(f=g;f>0;f--) 
  { 
  VerCNPJ+=parseInt(CNPJ.charAt(f-1))*ind; 
  if(ind>8) 
   { 
   ind=2; 
   } 
  else 
   { 
   ind++; 
   } 
  } 
  VerCNPJ%=11; 
  if(VerCNPJ==0 || VerCNPJ==1) 
   { 
   VerCNPJ=0; 
   } 
  else 
   { 
   VerCNPJ=11-VerCNPJ; 
   } 
 if(VerCNPJ!=parseInt(CNPJ.charAt(g))) 
  { 
  return(0); 
  } 
 else 
  { 
  return(1); 
  } 
 } 

function LIMP(c) 
 { 
 while((cx=c.indexOf("-"))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf("/"))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf(","))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf("."))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf("("))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf(")"))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 while((cx=c.indexOf(" "))!=-1) 
  { 
  c = c.substring(0,cx)+c.substring(cx+1); 
  } 
 return(c); 
 } 

function isNUMB(c) 
 { 
 if((cx=c.indexOf(","))!=-1) 
  { 
  c = c.substring(0,cx)+"."+c.substring(cx+1); 
  } 
 if((parseFloat(c) / c != 1)) 
  { 
  if(parseFloat(c) * c == 0) 
   { 
   return(1); 
   } 
  else 
   { 
   return(0); 
   } 
  } 
 else 
  { 
  return(1); 
  } 
 } 
//FIM FUNCOES OFICIAIS P/CNPJ

//formata de forma generica os campos
function formataCampo(campo, Mascara, evento) { 
	var boleanoMascara; 
	
	var Digitato = evento.keyCode;
	exp = /\-|\.|\/|\(|\)| /g
	campoSoNumeros = campo.value.toString().replace( exp, "" ); 
   
    var posicaoCampo = 0;     
	var NovoValorCampo="";
    var TamanhoMascara = campoSoNumeros.length;; 
	
	if (Digitato != 8) { // backspace 
		for(i=0; i<= TamanhoMascara; i++) { 
    		boleanoMascara  = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".")
                                || (Mascara.charAt(i) == "/")) 
    		boleanoMascara  = boleanoMascara || ((Mascara.charAt(i) == "(") 
                                || (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " ")) 
    		if (boleanoMascara) { 
    			NovoValorCampo += Mascara.charAt(i); 
    		  	TamanhoMascara++;
			}else { 
    			NovoValorCampo += campoSoNumeros.charAt(posicaoCampo); 
		    	posicaoCampo++; 
      		}       	 
      	}	 
		campo.value = NovoValorCampo;
      	return true; 
	}else { 
    	return true; 
	}
}
//Função que abre uma janela lateral   
function Janela(endereco) {
	var velocidadev = 5; 
	var topo = 100;
	var esquerda = 250;
	var velocidadeh = 8;
	if (document.all) {
		var tamlar = window.screen.availHeight - topo;
		var tamjan = window.screen.availWidth - esquerda;
		var tamanho = window.open("","","left=" + esquerda + ",top=" + topo + ",width=1,height=1");
		for (sizeheight = 1; sizeheight < tamlar; sizeheight += velocidadev) {
			tamanho.resizeTo("1",sizeheight -10);}
		for (sizewidth = 1; sizewidth < tamjan; sizewidth += velocidadeh) {
			tamanho.resizeTo(sizewidth+ -200,sizeheight+ -10);}
			tamanho.location = endereco;}
		else
			window.location = endereco;
}

//Função que transfere valores de uma caixa text para um textarea.  
function TrocaList(ListOrigem,ListDestino) 
{
	var i;
	for (i = 0; i < ListOrigem.options.length ; i++)
	{
		if (ListOrigem.options[i].selected == true)
		{
			var Op = document.createElement("OPTION");
			Op.text = ListOrigem.options[i].text;
			Op.value = ListOrigem.options[i].value;
			ListDestino.options.add(Op);
			ListOrigem.options.remove(i);
			i--;
		}
	}
}

//Função que deleta valores de uma textarea. 
function DeletaCGC(LDestino)
{
var i;
	for (i = 0; i < LDestino.options.length ; i++)
	{
		if (LDestino.options[i].selected == true)
		{
			var Op = document.createElement("OPTION");
			Op.value = LDestino.options[i].value;
			LDestino.options.remove(i);
			i--;
		}
	}
}
//Função que seleciona todos os valores para captura.
function Seleciona(ListDestino)
{
	for (j = 0; j < ListDestino.options.length ; j++)
	{
		ListDestino.options[j].selected = true;
	}
}

//Função que troca as cores dos campo quando passa o mouse. 
function ApplyXPOverStyle(obj,color,color2,addborder) { 
	 obj.style.backgroundColor = color;
	 obj.style.borderColor = color2;
    if (addborder=='true') {obj.style.borderStyle='solid';obj.style.borderWidth='1px'}
}

//Função que transfere valores de uma textarea para outra textarea.
function TrocaLista(LOrigem,LDestino) 
{
var Origem=LOrigem.value

		if (Origem != "")
		{		
			var Op = document.createElement("OPTION");
			Op.text =Origem;
			Op.value =Origem;
			LDestino.options.add(Op);
			LOrigem.value = "";
			LOrigem.focus();	
			}else { 
    		event.returnValue = false; 
   			}
}

//Função que seleciona os valores da textarea para captura. 
function SelecionaDestinatarios(ListDestino)
{
	for (j = 0; j < ListDestino.options.length ; j++)
	{
		ListDestino.options[j].selected = true;
	}
}

// Início - Função que faz o Painel de Controle ser arrastado a qq lugar da página
var checkZIndex = true;
var dragobject = null;
var tx;
var ty;
var ie5 = document.all != null && document.getElementsByTagName != null;
function getReal(el) {
temp = el;
while ((temp != null) && (temp.tagName != "BODY")) {
if ((temp.className == "moveme") || (temp.className == "handle")){
el = temp;
return el;
}
temp = temp.parentElement;
}
return el;
}
function moveme_onmousedown() {
el = getReal(window.event.srcElement)
if (el.className == "moveme" || el.className == "handle") {
if (el.className == "handle") {
tmp = el.getAttribute("handlefor");
if (tmp == null) {
dragobject = null;
return;
}
else
dragobject = eval(tmp);
}
else 
dragobject = el;
if (checkZIndex) makeOnTop(dragobject);
ty = window.event.clientY - getTopPos(dragobject);
tx = window.event.clientX - getLeftPos(dragobject);
window.event.returnValue = false;
window.event.cancelBubble = true;
}
else {
dragobject = null;
}
}

function moveme_onmouseup() {
if(dragobject) {
dragobject = null;
}
}

function moveme_onmousemove() {
if (dragobject) {
if (window.event.clientX >= 0 && window.event.clientY >= 0) {
dragobject.style.left = window.event.clientX - tx;
dragobject.style.top = window.event.clientY - ty;
}
window.event.returnValue = false;
window.event.cancelBubble = true;
}
}

function getLeftPos(el) {
if (ie5) {
if (el.currentStyle.left == "auto")
return 0;
else
return parseInt(el.currentStyle.left);
}
else {
return el.style.pixelLeft;
}
}

function getTopPos(el) {
if (ie5) {
if (el.currentStyle.top == "auto")
return 0;
else
return parseInt(el.currentStyle.top);
}
else {
return el.style.pixelTop;
}
}

function makeOnTop(el) {
var daiz;
var max = 0;
var da = document.all;
for (var i=0; i<da.length; i++) {
daiz = da[i].style.zIndex;
if (daiz != "" && daiz > max)
max = daiz;
}
el.style.zIndex = max + 1;
}

if (document.all) { //This only works in IE4 or better
document.onmousedown = moveme_onmousedown;
document.onmouseup = moveme_onmouseup;
document.onmousemove = moveme_onmousemove;
}

document.write("<style>");
document.write(".moveme {cursor: move;}");
document.write(".handle {cursor: move;}");
document.write("</style>");
// Fim - Função que faz o Painel de Controle ser arrastado a qq lugar da página

// Função que mostra e esconde o link de Informações
function Esconde(){document.all.Floater1.style.visibility = "hidden";}	
	function WM_toggle(id,ordem){ 
		if(ordem == 'A'){ 
			document.getElementById(id+'_F').style.display = 'none'; 
			document.getElementById(id+'_A').style.display = ''; 
		} else { 
			document.getElementById(id+'_A').style.display = 'none'; 
			document.getElementById(id+'_F').style.display = ''; 
		}
	}		
// Função que detecta bloqueador de poup-up
	function janela (url,winName,features){
		win = window.open(url,winName,features);
		text = "Se a janela não estiver abrindo, talvez seja por causa de algum programa bloqueador de pop-up!\nObservacao » O windows XP service pack 2 já vem com bloqueador de pop-ups!\n\n Equipe SURET";
		if(win == null) { alert(text); return; }
	}
// Função que mostra o div carregando a janela	
 function Carrega_Janela(){
	Aguarde.style.display="none";
  }
  				function janelanimada(endereco) {
					var velocidadev = 5; 
					var topo = 0;
					var esquerda = 0;
					var velocidadeh = 8;
					if (document.all) {
						var tamlar = window.screen.availHeight - topo;
						var tamjan = window.screen.availWidth - esquerda;
						var tamanho = window.open("","","left=" + esquerda + ",top=" + topo + ",width=1,height=1,scrollbars=yes");
						for (sizeheight = 1; sizeheight < tamlar; sizeheight += velocidadev) {
							tamanho.resizeTo("1",sizeheight );}
							for (sizewidth = 1; sizewidth < tamjan; sizewidth += velocidadeh) {
								tamanho.resizeTo(sizewidth+6,sizeheight );}
								tamanho.location = endereco;}
					else
						window.location = endereco;}
//Função abre em nova janela passando o parametro de tamanho através do link Ex.: href="javascript:Abrir_Nova('pagina.asp','pagina',800,650,0);"						
function Abrir_Nova(url,tit,w,h,sc) {
jan = window.open(url, tit,"toolbar=0,scrollbars=" + sc + ",status=0,width=" + w + ",height=" + h + ",resizable=0");
	if (parseInt(navigator.appVersion)>=4){
		jan.moveTo((window.screen.width-w)/2,(window.screen.height-h)/2);
	}
}
function openW(mypage,myname,w,h,features) {
   if(screen.width){
      var winl = (screen.width-w)/2;
      var wint = (screen.height-h)/2;
   }else{winl = 0;wint =0;}
      if (winl < 0) winl = 0;
      if (wint < 0) wint = 0;
   var settings = 'height=' + h + ',';
   settings += 'width=' + w + ',';
   settings += 'top=' + wint + ',';
   settings += 'left=' + winl + ',';
   settings += features;
   win = window.open(mypage,myname);
   win.window.focus();
}


try
	{
		xmlhttp = new XMLHttpRequest();
	}
	catch(ee)	
		{
			try
				{
					xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e)
					{
						try
							{
								xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
							}	
							catch(E)
								{
									xmlhttp = false;
								}
					}
		}


function ValidaTecla(){
    var key = window.event.keyCode;  
    if ((key!=34)&&(key!=39)){
	  return;
    }  
    else{
      window.event.returnValue == null;	
	  alert("Esta tecla é inválida!");
    }  
  }
	
