function ControlaMenu(menuAtivo, totalMenus)
{
	//função para ativar o menuAtivo e desativar todos os outros.
	for(var i = 1; i <= parseInt(totalMenus); i++)
	{
		var menu = eval("document.all.subMenu" + i);
		
		if(i == menuAtivo)
		{
			menu.style.visibility = 'visible';
		}
		else
		{
			menu.style.visibility = 'hidden';
		}
	}
}

function escreveData()
{
	if (idioma == "1")
	{
		NomeDia = new CriaArray(7)
			NomeDia[0] = "Domingo"
			NomeDia[1] = "Segunda-feira"
			NomeDia[2] = "Terça-feira"
			NomeDia[3] = "Quarta-feira"
			NomeDia[4] = "Quinta-feira"
			NomeDia[5] = "Sexta-feira"
			NomeDia[6] = "Sábado"

		 NomeMes = new CriaArray(12)
			NomeMes[0] = "Janeiro"
			NomeMes[1] = "Fevereiro"
			NomeMes[2] = "Março"
			NomeMes[3] = "Abril"
			NomeMes[4] = "Maio"
			NomeMes[5] = "Junho"
			NomeMes[6] = "Julho"
			NomeMes[7] = "Agosto"
			NomeMes[8] = "Setembro"
			NomeMes[9] = "Outubro"
			NomeMes[10] = "Novembro"
			NomeMes[11] = "Dezembro"
	}

	if (idioma == "2")
	{
		NomeDia = new CriaArray(7)
			NomeDia[0] = "Sunday"
			NomeDia[1] = "Monday"
			NomeDia[2] = "Tuesday"
			NomeDia[3] = "Wednesday"
			NomeDia[4] = "Thursday"
			NomeDia[5] = "Friday"
			NomeDia[6] = "Saturday"

		 NomeMes = new CriaArray(12)
			NomeMes[0] = "January"
			NomeMes[1] = "February"
			NomeMes[2] = "March"
			NomeMes[3] = "April"
			NomeMes[4] = "May"
			NomeMes[5] = "June"
			NomeMes[6] = "July"
			NomeMes[7] = "August"
			NomeMes[8] = "September"
			NomeMes[9] = "October"
			NomeMes[10] = "November"
			NomeMes[11] = "December"
	}

	if (idioma == "3")
	{
		NomeDia = new CriaArray(7)
			NomeDia[0] = "Domingo"
			NomeDia[1] = "Lunes"
			NomeDia[2] = "Martes"
			NomeDia[3] = "Miércoles"
			NomeDia[4] = "Jueves"
			NomeDia[5] = "Viernes"
			NomeDia[6] = "Sabado"

		 NomeMes = new CriaArray(12)
			NomeMes[0] = "Enero"
			NomeMes[1] = "Febrero"
			NomeMes[2] = "Marzo"
			NomeMes[3] = "Abril"
			NomeMes[4] = "Mayo"
			NomeMes[5] = "Junio"
			NomeMes[6] = "Julio"
			NomeMes[7] = "Agosto"
			NomeMes[8] = "Septiembre"
			NomeMes[9] = "Octubre"
			NomeMes[10] = "Noviembre"
			NomeMes[11] = "Diciembre"
	}


	if (idioma == "1")
	{
		document.write ("<b>" + NomeDia[dias] + ", " + dia + " de " + NomeMes[mes]+ " de " + ano + "</b>")
	}
	if (idioma == "2")
	{
		document.write ("<b>" + NomeDia[dias] + ", " + NomeMes[mes] + " " + dia + ", "  + ano + "</b>")
	}
	if (idioma == "3")
	{
		document.write ("<b>" + NomeDia[dias] + ", " + dia + " de " + NomeMes[mes]+ " de " + ano + "</b>")
	}
}

//onkeyUp="return FormataData(event,this)" onkeyDown="return SomenteNumeros();" onBlur="ValidaData1(this);"
function FormataData(e, campo)
{
	if(campo.value && campo.value.length == 10){
		if(!isDate(campo.value))
		{
			alert('Data Inválida');
			campo.focus();
			campo.select();
			return false;
		}
	}
	else
	{
		if(campo.value.length == 2 || campo.value.length == 5)
		{
			campo.value = campo.value + "/";
		}
	}
}

function openWin (url,name,w,h)
{	
	largura = screen.width;
	altura  = screen.height;
	XX =(largura-w)/2;
	YY =(altura-h)/2;
	action ="";
	newwindow = window.open(url,name,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,height='+h+',width='+w+',left='+XX+',top='+YY);
}
		
function openWinResize (url,name,w,h)
{	
	largura = screen.width;
	altura  = screen.height;
	XX =(largura-w)/2;
	YY =(altura-h)/2;
	action ="";
	newwindow = window.open(url,name,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height='+h+',width='+w+',left='+XX+',top='+YY);
}

function openWinResizeToolbar (url,name,w,h)
{	
	largura = screen.width;
	altura  = screen.height;
	XX =(largura-w)/2;
	YY =(altura-h)/2;
	action ="";
	newwindow = window.open(url,name,'toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height='+h+',width='+w+',left='+XX+',top='+YY);
}

function openWinNoScroll (url,name,w,h)
{	
	largura = screen.width;
	altura = screen.height;
	XX =(largura-w)/2;
	YY =(altura-h)/2;
	action ="";
	newwindow = window.open(url,name,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,height='+h+',width='+w+',left='+XX+',top='+YY);
}

function TiraEspacos(Texto)
{
   if (Texto.length > 0)
   {
      //Tira espaços da esquerda
      while (Texto.charAt(0) == " ")
      {
         Texto = Texto.substring(1, Texto.length)
      }

      if (Texto.length > 0)
      {
         //Tira espaços da direita
         while (Texto.charAt(Texto.length - 1) == " ")
         {
            Texto = Texto.substring(0, Texto.length - 1)
         }
      }
   }

   return Texto
}

function ValidaData(campo, obrigatorio)
{
	//exemplo
	// onBlur="ValidaData(this,false);"
	
	if(obrigatorio==true)
	{
		if(!isDate(campo.value))
		{
			alert('Data Inválida');
			campo.focus();
			return false;
		}	
	}
	else
	{
		if(campo.value.length>0)
		{
			if(!isDate(campo.value))
			{
				alert('Data Inválida');
				campo.focus();
				return false;
			}	
		}
	
	
	}

}


function isDate(ptexto) 
{
   //ptexto = trim(ptexto);
   if (ptexto.length !=10) {
      return false;
   }
   
   var dia = parseInt(ptexto.substring(0,2),10);
   var mes = parseInt(ptexto.substring(3,5),10);
   var ano = parseInt(ptexto.substring(6,10),10);
   
   if (isNaN(dia) || isNaN(mes) || isNaN(ano)) 
   {
      return false;
   }
   
   if (mes<1 || mes >12) return false;
   
   if (ptexto.substring(2,3) != "/") return false;
   
   if (dia<1 || dia > 31) return false;
   
   if (ptexto.substring(5,6) != "/") return false;
   
   if (ano<=1000) return false;
   
   if (mes==4 || mes==6 || mes==9 || mes==11) 
   {
      if (dia==31) return false;
   }
   
   if (mes==2) {
      var g = parseInt(ano/4,10);
      if (isNaN(g)) {
         return false;
      }
      if (dia>29) return false;
      if (dia==29 && ((ano/4)!=parseInt(ano/4,10))) return false;
   }
  
   return true;
} 


// Scripts para validacao de caracteres

	/*
		1. funções para validacao de caracteres
		
		dicionário utilizado
		
		letras
		- 65 até 90 para keyup e keydown
		- 97 até 122 para keypress
		
		números
		- 48 até 57 para keypress
		- 96 até 105 para keydown e keyup
			
		setas
		- 37 até 40 somente para keup e keydown
		
		delete
		- 46 para keyup e keydown
		
		control
		- 17 para keyup e keydown
		
		alt
		- 18 para keyup e keydown
		
		shift
		- 16 para keyup e keydown
		
		backspace
		- 8 para keyup e keydown
		
		espaço
		- 32 para keydown, keyup e keypress
		
		tab
		- 9 para keydown
		
		home
		- 36 para keydown e keyup
		
		end
		- 35 para keydown e keyup
		
		ponto
		- 194 e 190 para keyup e keydown
		- 46 para keypress
		
		virgula
		- 110 e 188 para keyup e keydown
		- 44 para keypress
		
		Arroba (@)
		- 64 para keypress
		
		Traco
		- 189 para keyup e keydown
		
		Underscore
		- 95 para keypress
		
		Dois Pontos
		- 58 para keypress
		
		Barra
		- 193 para keyup e keydown
		- 47 para keypress
		
		& comercial (somente para links)
		- 38 para keypress
		
		? (somente para links)
		- 63 para keypress
		
		% (somente para links)
		- 37 para keypress	
		
	*/

function RetornaTecla(e)
{
	if (document.all)
	{
		var tecla = event.keyCode;
	}
	else if(document.layers)
	{
		var tecla = e.which;
	}
	
	return tecla;
}
	
// função para aceitar somente letras
function SomenteLetras(e)
{
	// onkeydown="return SomenteLetras()" onkeypress="return SomenteLetras2()"
	
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 65 || tecla > 90) && (tecla < 37 || tecla > 40) && (tecla != 17) && (tecla != 18) && (tecla != 8) && (tecla != 9) && (tecla != 32) && (tecla != 46) && (tecla != 35) && (tecla != 36))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function SomenteLetras2(e) // exclusivamente para eventos keypress
{
	//onkeypress = return SomenteLetras2(2)

	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 97 || tecla > 122) && (tecla != 32) && (tecla < 65 || tecla > 90))
	{
		return false;
	}
	else
	{
		return true;
	}
}

// Somente Letras e Acentos
function SomenteLetrasAcentos(e)
{
	// onkeydown="return SomenteLetrasAcentos()" onkeypress="return SomenteLetrasAcentos2()"
	
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 65 || tecla > 90) && (tecla < 37 || tecla > 40) && (tecla != 17) && (tecla != 18) && (tecla != 8) && (tecla != 9) && (tecla != 32) && (tecla != 46) && (tecla != 35) && (tecla != 36) && (tecla != 222) && (tecla != 219) && (tecla != 186) )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function SomenteLetrasAcentos2(e) // exclusivamente para eventos keypress
{
	//onkeypress = return SomenteLetras2(2)
	
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 97 || tecla > 122) && (tecla != 32) && (tecla < 65 || tecla > 90) && (tecla != 126) && (tecla != 180) && (tecla != 231) && (tecla < 224 || tecla > 250) && (tecla < 193 || tecla > 218))
	{
		return false;
	}
	else
	{
		return true;
	}
}

// função para validar o conteudo de letras e numeros para emails
function ValidarEmail(e)
{
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105) && (tecla < 65 || tecla > 90) && (tecla < 37 || tecla > 40) && (tecla != 17) && (tecla != 18) && (tecla != 8) && (tecla != 9) && (tecla != 32) && (tecla != 46) && (tecla != 35) && (tecla != 36) && (tecla != 190) && (tecla != 189) && (tecla != 190) && (tecla != 194))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ValidarEmail2(e) // exclusivamente para eventos keypress
{
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla < 97 || tecla > 122) && (tecla != 64) && (tecla != 95) && (tecla != 45) && (tecla < 65 || tecla > 90) && (tecla != 46))
	{
		return false;
	}
	else
	{
		return true;
	}
}

// função para validar o conteudo de letras e numeros para emails
function ValidarLink(e)
{
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105) && (tecla < 65 || tecla > 90) && (tecla < 37 || tecla > 40) && (tecla != 17) && (tecla != 18) && (tecla != 8) && (tecla != 9) && (tecla != 32) && (tecla != 46) && (tecla != 35) && (tecla != 36) && (tecla != 190) && (tecla != 189) && (tecla != 193) && (tecla != 194) && (tecla != 190) && (tecla != 191))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ValidarLink2(e) // exclusivamente para eventos keypress
{		
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla < 97 || tecla > 122) && (tecla != 63) && (tecla != 38) && (tecla != 37) && (tecla != 58) && (tecla != 47) && (tecla != 95) && (tecla != 45) && (tecla != 46) && (tecla < 65 || tecla > 90))
	{
		return false;
	}
	else
	{
		return true;
	}
}


// função para aceitar somente números
function SomenteNumeros(e)
{
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105) && (tecla < 37 || tecla > 40) && (tecla != 17) && (tecla != 18) && (tecla != 8) && (tecla != 9) && (tecla != 32) && (tecla != 46) && (tecla != 35) && (tecla != 36) && (tecla != 13))
	{
		return false;
	}
	else
	{
		return true;
	}
}
function SomenteNumeros2(e) // exclusivamente para eventos keypress
{
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla != 13))
	{
		return false;
	}
	else
	{
		return true;
	}
}

// função para aceitar letras e numeros
function LetrasNumeros(e)
{
	//onkeydown="return LetrasNumeros()" onkeypress="return LetrasNumeros2()"

	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105) && (tecla < 65 || tecla > 90) && (tecla < 37 || tecla > 40) && (tecla != 17) && (tecla != 18) && (tecla != 8) && (tecla != 9) && (tecla != 32) && (tecla != 46) && (tecla != 35) && (tecla != 36) && (tecla != 13))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function LetrasNumeros2(e) // exclusivamente para evento keypress
{
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla < 97 || tecla > 122) && (tecla != 32) && (tecla < 65 || tecla > 90) && (tecla != 13))
	{
		return false;
	}
	else
	{
		return true;
	}
}

// função para aceitar letras e numeros com letras acentuadas
function LetrasNumerosAcentos(e)
{
	//onkeydown="return LetrasNumerosAcentos()" onkeypress="return LetrasNumerosAcentos2()"

	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105) && (tecla < 65 || tecla > 90) && (tecla < 37 || tecla > 40) && (tecla != 17) && (tecla != 18) && (tecla != 8) && (tecla != 9) && (tecla != 32) && (tecla != 46) && (tecla != 35) && (tecla != 36) && (tecla != 13) && (tecla != 222) && (tecla != 219) && (tecla != 186) )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function LetrasNumerosAcentos2(e) // exclusivamente para evento keypress
{
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla < 97 || tecla > 122) && (tecla != 32) && (tecla < 65 || tecla > 90) && (tecla != 13)  && (tecla != 180) && (tecla != 231) && (tecla < 224 || tecla > 250) && (tecla < 193 || tecla > 218))
	{
		return false;
	}
	else
	{
		return true;
	}
}

// função para aceitar letras e numeros
function NumerosDecimais(e,campo)
{
	//onkeydown="return NumerosDecimais()" onkeypress="return NumerosDecimais2()"
	
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105) && (tecla < 37 || tecla > 40) && (tecla != 17) && (tecla != 18) && (tecla != 8) && (tecla != 9) && (tecla != 32) && (tecla != 46) && (tecla != 35) && (tecla != 36) && (tecla != 110) && (tecla != 188))
	{
		return false;
	}
	else
	{
		// verifica se a virgula já está presente no campo e não deixa inserir mais uma
		if (tecla == 110 || tecla == 188)
		{
			var posicao =  campo.value.indexOf(',')
			if(posicao >= 0)
			{
				return false;
			}
		}
		
		// verifica se a string do texto começa com zero e não adiciona mais zeros em duplicação no inicio
		if (tecla == 96 || tecla == 48)
		{
			if (campo.value == '0')
			{
				return false;
			}
		}
		
		// verifica se a string começa com zero. se a tecla for numero diferente de zero, apaga o zero e a string passará a começar com o numero informado
		if (tecla != 96 && tecla != 48)
		{
			if (campo == '0')
			{
				campo.value = '';
			}
		}
		
		return true;
	}
}
	
// função para aceitar letras e numeros
function NumerosDecimais2(e) // exclusivamente para eventos keypress
{
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla != 44))
	{
		return false;
	}
	else
	{
		return true;
	}
}
	
function SomenteMoeda(e)
{
	//Exemplo
	//onkeyDown="return SomenteMoeda();"

	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105) && (tecla < 37 || tecla > 40) && (tecla != 17) && (tecla != 18) && (tecla != 8) && (tecla != 9) && (tecla != 32) && (tecla != 46) && (tecla != 35) && (tecla != 36) && (tecla != 188))
	{
		return false;
	}
	else
	{
		return true;
	}
}
	
	
//função replace em javascript
function Replace(campo,valorant, valornovo )
{
   var r, re;
   var ss = "" + campo;
   r = ss.replace(valorant, valornovo);
   return(r);
}
	
	
	
 //formatar nº com casas decimais
function FormatNumber(numero,decimais)
{ 
  if (isNaN(numero)) { return '0,00' };
   if (numero=='') { return '0,00'}; 
 
   var IsNegative=(parseInt(numero)<0);
   if(IsNegative)numero=-numero;
  
  var snum = new String(numero); 
   var sec = snum.split('.'); 
  var whole = parseInt(sec[0]); 
  var result = '';
  if(sec.length > 1)
  {
   var dec = new String(sec[1]); 
   dec = parseInt(dec)/Math.pow(10,parseInt(dec.length-decimais-1));
   Math.round(dec);
   dec = parseInt(dec)/10;
 
   if(IsNegative)
   {
    var x = 0-dec;
    x = Math.round(x);
    dec = - x;
   }
   else
   {
    dec = Math.round(dec);
   }
 
   /*
   * If the number was rounded up from 9 to 10, and it was for 1 'decimal'
   * then we need to add 1 to the 'whole' and set the dec to 0.
   */
   if(decimais==1 && dec==10)
   {
    whole+=1;
    dec="0";
   }
 
   dec = String(whole) + "." + String(dec); 
   var dot = dec.indexOf('.'); 
   if(dot == -1)
   { 
    dec += '.'; 
    dot = dec.indexOf('.'); 
   }
 
   var l=parseInt(dot)+parseInt(decimais);
   while(dec.length <= l) { dec += '0'; } 
   result = dec; 
  } 
  else
  { 
   var dot; 
   var dec = new String(whole); 
   dec += '.'; 
   dot = dec.indexOf('.'); 
   var l=parseInt(dot)+parseInt(decimais);
   while(dec.length <= l) { dec += '0'; } 
   result = dec; 
  } 
  
  if(IsNegative)result="-"+result;
  
  return result; 
}
		

// Função para validação do CNPJ
function ValidaCNPJ(campo)
{
	cnpj = campo.value;

	// validacao dos numeros informados para o CNPJ ou CGC
	if(cnpj)
	{
		if(!ChecaForm(cnpj,campo))
		{
			return false;
		}
		
		return true;

		function ValChar(ch) 
		{
			if (ch=="0") return 0
			else if (ch=="1") return 1
			else if (ch=="2") return 2
			else if (ch=="3") return 3
			else if (ch=="4") return 4
			else if (ch=="5") return 5
			else if (ch=="6") return 6
			else if (ch=="7") return 7
			else if (ch=="8") return 8
			else if (ch=="9") return 9
			else return 10
		}

		// Verifica se o argumento é um CGC válido de 8 dígitos
		function ChecaCGC8 (CKCGC) 
		{
			var CGC = CKCGC;
			var NewCGC = "";
			
			// Elimina todos os espaços, pontos, barras e traços do CGC
			for (i=0;i<CGC.length;i++) 
			{ 
				if (CGC.charAt(i) != " " && CGC.charAt(i) != "." && CGC.charAt(i) != "/" && CGC.charAt(i) != "-") 
					NewCGC = NewCGC + CGC.charAt(i);
			}

			// Verifica tamanho do CGC
			if (NewCGC.length!=8) 
			{
				return false;
			}
			
			// verifica se todos os caracteres são numéricos
			var Numerico = false;
			var Numeros = "0123456789";
			for (i=0;i<NewCGC.length;i++) 
			{
				Numerico = false;
				for (j=0;j<Numeros.length;j++) 
				{
					if (NewCGC.charAt(i) == Numeros.charAt(j)) 
					{
						Numerico = true;
						break;
					}
				}
				
				if (!Numerico) 
				{
					return false;
				}
			}

			// Calcula os dígitos verificadores
			var s1 = 0;
			aux = 0;
			soma = 0
			for (i=1;i<=8;i++) 
			{
				aux = (ValChar(NewCGC.charAt(i-1)))*((i % 2)+1);
				if (aux>9) 
					aux = aux-9;
				soma = soma + aux;
			}
			
			r1 = soma % 10;
			
			if(r1==0)
			{
				return true;
			}
			else 
			{
				return false;
			}
		}

		// Verifica se o argumento é um CGC válido
		function ChecaCGC (CKCGC) 
		{
			var CGC = CKCGC;
			var NewCGC = "";

			// Verifica tamanho do CGC
			if (CGC.length!=14) 
			{
				return false;
			}
		
			// Calcula os dígitos verificadores
			// Guarda os 12 primeiros digitos
			
			var DVCGC = CGC.substring(0,12);
			
			// calcula o primeiro digito verificador
			var s1 = 0;
			for (i=1;i<=4;i++) 
				s1 = s1 + (ValChar(DVCGC.charAt(i-1))*(6-i));

			for (i=5;i<=12;i++) 
				s1 = s1 + (ValChar(DVCGC.charAt(i-1))*(14-i));
				
			r1 = s1 % 11;
			if(r1<2) 
				dv1 = 0;
			else 
				dv1 = 11 - r1;
			
			//calcula o segundo digito verificador
			var s2 = dv1*2;
			for (i=1;i<=5;i++) 
				s2 = s2 + (ValChar(DVCGC.charAt(i-1))*(7-i));

			for (i=6;i<=12;i++) 
				s2 = s2 + (ValChar(DVCGC.charAt(i-1))*(15-i));
			
			r2 = s2 % 11;
			if (r2<2) 
				dv2=0;
			else 
				dv2 = 11 - r2;
		
			// junta os digitos verificadores
			var DV = "";
			DV = DV + dv1 + dv2;
		
			// guarda os digitos verificadores do CGC digitado (últimas duas posições no string)
			var NewDV = CGC.substring(12,14)
			if (NewDV==DV) //se o DV calculado for igual ao digitado, retorna true
			{ 
				return true
			}
			else 
			{
				return false
			}
			//return true
		}

		function ChecaForm(theField, campo) 
		{
			if(theField.length > 0)
			{
				var a = theField;
				var b = "";
				var c = "";
				var d = 0;
				for(cont=0;cont<a.length;cont++)
				{
					if(	a.charAt(cont)=="0" || a.charAt(cont)=="1" || a.charAt(cont)=="2" || a.charAt(cont)=="3" || a.charAt(cont)=="4" || a.charAt(cont)=="5" || a.charAt(cont)=="6" || a.charAt(cont)=="7" || a.charAt(cont)=="8" || a.charAt(cont)=="9")
					{
						b = b + a.charAt(cont);
					}
				}
				a = b;

				// SE NÃO FOR IDENTIFICADO NENHUM NÚMERO - "CNPJ Inválido"
				if(a.length=="")
				{
					return false;
				}

				if (a!="") 
				{
					var checkOK = "0123456789-";
					var checkStr = a;
					var allValid = true;
					var decPoints = 0;
					var allNum = "";
					for (i = 0;  i < checkStr.length;  i++)
					{
						ch = checkStr.charAt(i);
						for (j = 0;  j < checkOK.length;  j++)
							if (ch == checkOK.charAt(j)) break;
						
						if (j == checkOK.length)
						{
							allValid = false;
							break;
						}
						allNum += ch;
					}
		
					if (!allValid)
					{
						return false;
					}
					
					//checa se o campo é CPF válido, retorna true e envia o formulário
					if (ChecaCGC(a) || ChecaCGC8(a))
					{
						b = "99.999.999/9999-99";
						for(cont = 0; cont < b.length; cont++)
						{
							numero = b.charAt(cont);
							if(numero == "9")
							{
								if(a.charAt(cont-d)!="")
								{
									c = c + a.charAt(cont-d);
								}
								else
								{
									c = c + "0";
								}
							}
							else
							{
								c = c + b.charAt(cont);
								d = d + 1;
							}
							numero = "";
						}

						campo.value= c;
						
						return true;
					}
					else
					{
						return (false);
					}
					return true
				}
			}
		}
	}
}

function FormataCNPJ(campo, e)
{
	var tamanhoCampo = campo.value.length;
	var texto = campo.value
	
	tecla = RetornaTecla(e);

	if (  (tecla >= 96 && tecla <= 105) )
	{
		if (tamanhoCampo == 2)
		{
			texto = texto + '.';
		}
		if (tamanhoCampo == 6)
		{
			texto = texto + '.';
		}
	
		if (tamanhoCampo == 10)
		{
			texto = texto + '/';
		}
		if (tamanhoCampo == 15)
		{
			texto = texto + '-';
		}
		campo.value = texto;
	}
}

function ValidaCPF(cpf)
{
	var novovalor = "";
	for(i=0;i<cpf.length;i++)
	{
		if(cpf.charAt(i)==0 || cpf.charAt(i)==1 || cpf.charAt(i)==2 || cpf.charAt(i)==3 || cpf.charAt(i)==4 || cpf.charAt(i)==5 || cpf.charAt(i)==6 || cpf.charAt(i)== 7 || cpf.charAt(i)==8 || cpf.charAt(i)==9)
		{
			novovalor = novovalor + '' +  cpf.charAt(i);
		}
	}
	
	cpf = novovalor;
	
	// formula para validacao do CPF
	x = 0;
	soma = 0;
	dig1 = 0;
	dig2 = 0;
	texto = "";
	cpf1="";
	len = cpf.length; x = len -1;
	for (var i=0; i <= len - 3; i++)
	{
		y = cpf.substring(i,i+1);
		soma = soma + ( y * x);
		x = x - 1;
		texto = texto + y;
	}

	dig1 = 11 - (soma % 11);
	if (dig1 == 10) dig1=0 ;
	if (dig1 == 11) dig1=0 ;
	cpf1 = cpf.substring(0,len - 2) + dig1 ;
	x = 11; soma=0;

	for (var i=0; i <= len - 2; i++)
	{
		soma = soma + (cpf1.substring(i,i+1) * x);
		x = x - 1;
	}

	dig2= 11 - (soma % 11);
	if (dig2 == 10) dig2=0;
	if (dig2 == 11) dig2=0;
	if ((dig1 + "" + dig2) != cpf.substring(len,len-2))
	{
		//alert ("O número de CPF informado não é válido.");
		return false;
	}

	if (cpf == '11111111111')
	{
		//alert('Preencha o campo CPF corretamente.');
		return false;
	}

	return true;
}	


function FormataCPF(campo, e)
{
	var tamanhoCampo = campo.value.length;
	var texto = campo.value
	
	tecla = RetornaTecla(e);

	if (  (tecla >= 96 && tecla <= 105) )
	{
		if (tamanhoCampo == 3)
		{
			texto = texto + '.';
		}
		if (tamanhoCampo == 7)
		{
			texto = texto + '.';
		}
	
		if (tamanhoCampo == 11)
		{
			texto = texto + '-';
		}
		
		campo.value = texto;
	}
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Esta função verifica a validade do email
		function ValidaEmail(Email)
		{
			if(Email != "")
			{
				strEmail = Email;
				strArroba = strEmail.indexOf("@")
				strPonto = strEmail.indexOf(".")
				strUltimoCaracter = strEmail.substring(strEmail.length, strEmail.length - 1)
				strMaisPontos = strEmail.indexOf("..")
				if(
					(strArroba == 0) ||
					(strArroba == -1) ||
					(strEmail.indexOf("@.") != -1) ||
					(strPonto == -1) ||
					(strUltimoCaracter == ".") ||
					(strMaisPontos != -1)
				  )
				{
					return false;
				}
				else
				{
					return true;
				}
			}
			else
			{
				return false;
			}
		}
function RodarFlash(path,variaveis,_width,_height)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+_width+'" height="'+_height+'">')
		document.write('<param name="movie" value="'+path+'?'+variaveis+'">')
		document.write('<param name="quality" value="high">')
		document.write('<param name="wmode" value="transparent">')
		document.write('<embed src="'+path+'?'+variaveis+'" width="'+_width+'" height="'+_height+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>')
	document.write('</object>')
}

function PossuiLetras(valor)
{
  	ERaz = /[a-z]/;
  	ERAZ = /[A-Z]/;
  	ER09 = /[0-9]/;
  	ERxx = /[@!#$%&*+=?|-]/;
	if(valor.length > 0)
	{
	   if(valor.search(ERaz) != -1 || valor.search(ERAZ) != -1)
	   {
		   return true;
	   }
	   else
	   {
		   return false;
	   }
	}
}

function PossuiNumeros(valor)
{
  	ERaz = /[a-z]/;
  	ERAZ = /[A-Z]/;
  	ER09 = /[0-9]/;
  	ERxx = /[@!#$%&*+=?|-]/;
	if(valor.length > 0)
	{
	   if(valor.search(ER09) != -1)
	   {
		   return true;
	   }
	   else
	   {
		   return false;
	   }
	}
}

function PossuiAspas(valor)
{
	if(valor.length > 0)
	{
	   if(valor.indexOf('"') != -1 || valor.indexOf("'") != -1)
	   {
		   return true;
	   }
	   else
	   {
		   return false;
	   }
	}
}

function PossuiPontos(valor)
{
	if(valor.length > 0)
	{
	   if(valor.indexOf('.') != -1 || valor.indexOf(',') != -1 || valor.indexOf(';') != -1 || valor.indexOf(':') != -1 || valor.indexOf('/') != -1 || valor.indexOf('_') != -1 || valor.indexOf(')') != -1 || valor.indexOf('(') != -1)
	   {
		   return true;
	   }
	   else
	   {
		   return false;
	   }
	}
}

function PossuiCaracteresEspeciais(valor)
{
  	ERaz = /[a-z]/;
  	ERAZ = /[A-Z]/;
  	ER09 = /[0-9]/;
  	ERxx = /[@!#$%&*+=?|-]/;
	if(valor.length > 0)
	{
	   if(valor.search(ERxx) != -1 || PossuiAspas(valor) || PossuiPontos(valor))
	   {
		   return true;
	   }
	   else
	   {
		   return false;
	   }
	}
}

function PossuiEspaco(valor)
{
	if(valor.length > 0)
	{
	   if(valor.indexOf(' ') != -1)
	   {
		   return true;
	   }
	   else
	   {
		   return false;
	   }
	}
}

function chamaLayer(qualLayer, parametro)
{
	if(parametro == 1)
	{
		var l = eval("document.all." + qualLayer);
		l.style.display = 'block';
	}
	else
	{
		var l = eval("document.all." + qualLayer);
		l.style.display = 'none';
	}
}