//javascript:MM_openBrWindow('','','status=yes,scrollbars=yes,resizable=yes,width=500,height=400')
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function addToFavorite(favTitle){
  if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
    window.external.AddFavorite(location.href, unescape(favTitle));
  }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

<!--

/* 
function acentuacao(e, Maiuscula)
function Apaga()
function checkAll(campo, marcar)
function contacampo(campo, tamtxt) 
function esconde()
function Formata_CEP(campo) 
function FormataCgc(campo,tammax,teclapres) 
function FormataCpf(campo,tammax,teclapres) 
function formata_CPF_CGC(campo)
function FormataDado(campo,tammax,pos,teclapres)
function FormataData(Campo,teclapres) 
function Formata_Hora(campo,teclapres) 
function FormataValor(campo,tammax,teclapres) 
function limita(campo)
function main(campofoco)
function mostra()
function openBrWindow(theURL,winName,features) 
function printPage()
function SaltaCampo (campo,prox,tammax,teclapres)
function SetHelp(txt)
function Submit_combo(url, teclapres)
function tecladown (digito)
function teclaclick(tecla)
function teclaup(tecla)
function tiraVirgula(campo)
function validaCampoNumerico(campo, proximocampo)
function valida_CGC(campo)
function valida_CPF(campo)
function validaData(campo)
function valida_CPF_CGC(campo)
function validaVerifica_CPF_CGC(campo)
function Verifica_CGC(campo)
function Verifica_CPF(campo)
function verificaEmail(campo)
function VerificaJava()
*/

//Bloco de código para esconder e mostra form
var Ver4 = parseInt(navigator.appVersion) >= 4
var IE4 = ((navigator.userAgent.indexOf("MSIE") != -1) && Ver4)
var block = "formulario";
function esconde() {	document.form.style.visibility = "hidden" }
function mostra() { document.form.style.visibility = "visible" }
//Bloco de código para esconder e mostra form


// Código para o teclado
function tecladown (digito){
	if (digito == ''){
		document.form.senha.value = '';
		return;
	}
	var pass = document.form.senha.value;
	if (pass.length >= 8){
		return;
	}
	document.form.senha.value = document.form.senha.value + digito;
}
function teclaclick(tecla){
	return false;
}
function teclaup(tecla){
	tecladown(tecla);
}
// --


// -- Contador para objeto TextArea.
function limita(campo){
	var tamanho = document.form[campo].value.length;
	var tex=document.form[campo].value;
	if (tamanho>=1199) {
		document.form[campo].value=tex.substring(0,1199);
	}
	return true;
}

function contacampo(campo, tamtxt) {
	document.form[tamtxt].value =  1200-document.form[campo].value.length;
}
// --



function SetHelp(txt) { help.innerText = txt ; }

function main(campofoco) {
	if ( campofoco == '' || document.form.elements.length == 0 )
		return false;

	var num = parseInt(campofoco);

	if ( num || num == 0 )
	{
		if ( document.form[num] )
			document.form[num].focus();
	}
	else
	{
		if ( document.form[campofoco] )
			document.form[campofoco].focus();
	}
}

function Apaga(){
	if (document.form.elements.length != 0)
		for (i = 0; i < document.form.elements.length; i++)
		{
			if( document.form[i].type != "hidden" )
				document.form[i].value="";
		}
}


var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1);

function printPage()
{
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
    alert("Desculpe seu browser não suporta esta função. Por favor utilize a barra de trabalho para imprimir a página.");
  return false;
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}

function FormataDado(campo,tammax,pos,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( "-", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length ;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){ tam = tam - 1 ; }

	if ( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
	 		document.form[campo].value = vr ;}
		if ( tam > pos && tam <= tammax ){
			document.form[campo].value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );}
	}
}

function FormataValor(campo,tammax,teclapres) {
/* Esta funcao formata um campo MOEDA. Deve ser passado como parametro o nome do campo, tamanho maximo e o 'event'. */

	var tecla = teclapres.keyCode;
	vr = document.form[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 + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }

	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
	 		document.form[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.form[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.form[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) ){
	 		document.form[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) ){
	 		document.form[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 SaltaCampo (campo,prox,tammax,teclapres){
/* Esta funcao salta para o proximo campo quando tiver completado todas as possiveis posicoes para a ditacao
do campo. Deve ser passado como parametro o nome do campo, nome do proximo campo, tamanho maximo do campo sem os 
separadores e o 'event'. */

	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		document.form[campo].value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	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 (tecla != 0 && tecla != 9 && tecla != 16 ){
			if ( tam == tammax ){
				if ( document.form[prox] )
					document.form[prox].focus();
			}
		}
	}
}

function FormataData(Campo,teclapres) {
/* Esta funcao formata a data e chama a funcao validaData() para veriricar se esta é valida.
Deve ser passado como parametro o nome do campo e o 'event'. */

	var tecla = teclapres.keyCode;
	vr = document.form[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.form[Campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.form[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
	validaData(Campo)
}

function VerificaJava()
 	{
	if (navigator.javaEnabled())
		document.form.javas.value="sim"
	}

function FormataCpf(campo,tammax,teclapres) {
/* Esta funcao formata um campo CPF. Mas nao valida, a funcao que formata e valida é a Verifica_CPF().
Deve ser passado como parametro o nome do campo, tamanho maximo e o 'event'. */

	var tecla = teclapres.keyCode;
	vr = document.form[campo].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( "-", "" );
	tam = vr.length;

	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 <= 2 ){
	 		document.form[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.form[campo].value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.form[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) ){
	 		document.form[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) ){
	 		document.form[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 Formata_Hora(campo,teclapres) {
/* Esta funcao formata o campo hora. Deve ser passado como parametro o nome do campo e 'event'. */
 
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	tam = vr.length + 1;

	if (tecla != 9 && tecla != 8){
		if (tam == 5)
			document.form[campo].value = vr.substr( 0, 2 ) + ':' + vr.substr( 2, 4 );
	}
}

function FormataCgc(campo,tammax,teclapres) {
/* Esta funcao formata um campo CNPJ. Mas nao valida, a funcao que formata e valida é a Verifica_CGC().
Deve ser passado como parametro o nome do campo, tamanho maximo e o 'event'. */

	var tecla = teclapres.keyCode;
	vr = document.form[campo].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 < 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 <= 2 ){
	 		document.form[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 6) ){
	 		document.form[campo].value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 7) && (tam <= 9) ){
	 		document.form[campo].value = vr.substr( 0, tam - 6 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 10) && (tam <= 12) ){
	 		document.form[campo].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) ){
	 		document.form[campo].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) ){
	 		document.form[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 valida_CGC(campo){
/* Esta funcao valida o CNPJ. Deve ser passado como parametro o nome do campo */

	aux_CGC = document.form[campo].value;
	CGC = "";
	if (aux_CGC != ''){
		for (i = 0; i<=17; i++){
			if (i != 2 && i != 6 && i != 10 && i != 15){
				CGC = CGC + aux_CGC.charAt(i);
			}
		}
		if (CGC.length != 14) {
		// tamanho invalido
  			sim=false;
			//alert ("Tamanho de CNPJ inválido!");
			//document.form[campo].value ="";
			//document.form[campo].focus();
			return false;
		}
		else {
			sim=true;
		}
		if (sim)  // verfica se e numero
		{
			for (i=0;((i<=(CGC.length-1))&& sim); i++){
				val = CGC.charAt(i);
				if  ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4")&&(val!="5")&&(val!="6")&&(val!="7")&&(val!="8")){
					sim=false;
					//alert ("CNPJ inválido!");
					//document.form[campo].value ="";
			        //document.form[campo].focus();
			        return false;
				}
			}
			if (sim)  // se for numero continua
			{
				m2 = 2;
				soma1 = 0;
				soma2 = 0;
				for (i=11;i>=0;i--){
					val = eval(CGC.charAt(i));
					//file://alert ("Valor do Val: "+val)
					m1 = m2;
					if (m2<9) {
						m2 = m2+1;
					}
					else {
						m2 = 2;
					}
					soma1 = soma1 + (val * m1);
					soma2 = soma2 + (val * m2);
				}  // fim do for de soma
				soma1 = soma1 % 11;
				if (soma1 < 2) {
					d1 = 0;
				}
				else {
					d1 = 11- soma1;
				}
				soma2 = (soma2 + (2 * d1)) % 11;
				if (soma2 < 2) {
					d2 = 0;
				}
				else {
					d2 = 11- soma2;
				}
			}
			if ((d1==CGC.charAt(12)) && (d2==CGC.charAt(13))){
				// alert("Valor Valido de CNPJ")
				return true;
			}
			else{
			    //alert ("CNPJ inválido!");
				//document.form[campo].value ="";
			    //document.form[campo].focus();
			    return false;
			}
		}
	}
}

function valida_CPF(campo){
/* Esta funcao valida o CPF. Deve ser passado como parametro o nome do campo */

	aux_CPF = document.form[campo].value;

	CPF = "";
	for (i = 0; i<=13; i++){
		if (i != 3 && i != 7 && i != 11){
			CPF = CPF + aux_CPF.charAt(i);
		}
	}

	if (document.form[campo].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;
		}
		else {
			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;
     			}
			else {
				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;
				}
				else{
				   return true;
				}
			}
		}
	}
}

function verificaEmail(campo){
/* Esta funcao valida o e-mail digitado. Deve ser passado como parametro o nome do campo */

	var email = document.form[campo].value;
	if (email != ''){
		var arroba = false;
		var ponto = false;
		for (var i = 0; i < email.length; i++)
		{
			if (email.substring(i-1,i) == "@")
			{
				arroba = true;
			}
			if (email.substring(i-1,i) == ".")
			{
				ponto = true;
			}
		}
		if ((arroba == false) || (ponto == false))
		{
			alert ("E-mail inválido!")
			document.form[campo].focus()
			return false
		}
		else{
		    return true
		}
	}
}


function Formata_CEP(campo) {
/* Esta funcao formata e o CEP. Deve ser passado como parametro o nome do campo */

	vr = document.form[campo].value;
	vr = vr.replace( "-", "" );
	tam = vr.length;

	if (tam == 8) {
	  document.form[campo].value = vr.substr(0, 5) +"-"+ vr.substr(5,3);
	 }
	else if (tam < 8 && tam > 0) {
	  alert ("Tamanho inválido de CEP");
	  document.form[campo].focus();
	}
}


function formata_CPF_CGC(campo){
/* Esta funcao formata e um campo que pode ser tanto o CPF ou o CNPJ. 
Deve ser passado como parametro o nome do campo */

	vr = document.form[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam == 14){
	    document.form[campo].value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ;
	}
	else if (tam == 11){
	    document.form[campo].value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '-' + vr.substr( 9, 2 ) ;
	}
}


function valida_CPF_CGC(campo){
/* Esta funcao valida o campo que pode ser tanto CPF ou CNPJ. Deve ser passado como parametro o nome do campo */

   vr = document.form[campo].value;
   tam = vr.length;

   if (tam == 18){
       return valida_CGC(campo);
   }
   else if (tam == 14){
       return valida_CPF(campo)
   }
}


function Verifica_CGC(campo){
/* Esta funcao formata e o CPF/CNPJ e chama a funcao valida_CPF_CGC para ver se este é valido.
Deve ser passado como parametro o nome do campo */

   formata_CPF_CGC(campo);
   if ((document.form[campo].value.length > 0) && (!valida_CPF_CGC(campo))){
       alert ("CNPJ/CPF inválido!!!");
       document.form[campo].focus();
   }
}


function Verifica_CPF(campo){
/* Esta funcao formata e o CPF/CNPJ e chama a funcao valida_CPF_CGC para ver se este é valido.
Deve ser passado como parametro o nome do campo */

   formata_CPF_CGC(campo);
   if ((document.form[campo].value.length > 0) && (!valida_CPF_CGC(campo))){
       alert ("CPF inválido!!!");
       document.form[campo].focus();
   }
}

function Submit_combo(url, teclapres){
/* Esta funcao da o submit no formulario quando este e feito de um combo box.
Deve ser passado como parametro ex: ('xxx.htm', event) */

   var tecla = teclapres.keyCode;
   if (tecla == 13){
      if (validaSubmit()){
         document.forms[0];
		 document.forms[0].method = "post";
         document.forms[0].action = url;
         document.forms[0].submit();
	  }
   }
}

function tiraVirgula(campo){
/* Esta funcao substritui a 'virgula' de um campo decimal por um 'ponto'.
Deve ser passado como parametro o nome do campo */

    if (document.form[campo].value.length > 0){
       conteudo = new String(document.form[campo].value);
       rExp = /,/gi;
       document.form[campo].value = conteudo.replace(rExp, new String("."));
    }
}

function openBrWindow(theURL,winName,features) {
/* Esta funcao abre uma nova janela do browser.
Ex: javascript:openBrWindow('xxx.htm', '', 'menubar=yes, scrollbar=yes, resize=yes') */

  window.open(theURL,winName,features);
}

function validaCampoNumerico(campo, proximocampo){
/*Esta funcao valida se o campo eh numerico ou nao. Deve ser passado como 
referencia apenas a referencia do campo (this) */
	if (campo != ''){
		if (campo.name != ''){
			valor = campo.value
			tam = campo.value.length

		   if (tam > 0){
				tiraVirgula(campo.name)
				valor = document.form[campo.name].value
				if (isNaN(valor)) {
					alert ("Este campo é númerico e não aceita letras!");
					document.form[campo.name].value = "";
					document.form[campo.name].focus();
					return false;
				}
				else{
					if (proximocampo != '') document.form[proximocampo].focus();
					return true;
				}
			}
		}
	}
	else{
		return true;
	}
}

function validaData(campo){
/* Esta funcao valida a data digitada. Esta sendo chamada pela funcao FormataData(). Se utiliza-lo isoladamente deve
ser passado como parametro o nome do campo */

	var data = document.form[campo].value;
	
	if (data.length > 0){
	
		var dia = parseInt(data.substring(0,2),10);
		var mes = parseInt(data.substring(3,5),10);
		var ano = parseInt(data.substring(6,10),10);
		
		if (dia <= 31 && mes <=12 && ano >= 1000){
			if (data.substring(0,1)=='0' && data.substring(1,2) != '0' || data.substring(0,1)!='0'){
				if (data.substring(2,3)=="/"){
					if (data.substring(3,4)=='0' && data.substring(4,5)!='0' || data.substring(3,4)!='0'){
						if (data.substring(5,6)=="/"){
							if (data.substring(6,7)== '0' || data.substring(6,7)=='' && data.substring(7,8)!='0'){
								window.alert('O ano que você digitou não existe!');
								document.form[campo].value = "";
								document.form[campo].focus();
								return false;
							}
							else {
								if (mes == 2){
									if ((dia > 0 ) && (dia <= 29)){
										if (dia == 29){
											if ((ano % 4) == 0){
												return true;
											}
											else{
												window.alert('Este dia não existe, certifique-se de que digitou corretamente!');
												document.form[campo].value = "";
												document.form[campo].focus();
												return false;
											}
										}
									}
									else {
										window.alert('Este dia não existe, certifique-se de que digitou corretamente!');
										document.form[campo].value = "";
										document.form[campo].focus();
										return false;
									}
								}
								if ((mes == 4)||(mes == 6)||(mes == 9)||(mes == 11)){
									if ((dia > 0 ) && (dia <= 30)){
										return true;
									}
									else{
										window.alert('Este dia não existe, certifique-se de que digitou corretamente!');
										document.form[campo].value = "";
										document.form[campo].focus();
										return false;
									}
								}
								if ((mes == 1)||(mes == 3)||(mes == 5)||(mes ==7)||(mes == 8)||(mes == 10)||(mes == 12)) {
									if ((dia > 0) && (dia <= 31)) {
										return true;
									}
									else{
										window.alert('Este dia não existe, certifique-se de que digitou corretamente!');
										document.form[campo].value = "";
										document.form[campo].focus();
										return false;
									}
								}
							}
						}
						else{
							window.alert('A data foi digitada fora do padrão(dd/mm/aaaa) !');
							document.form[campo].value = "";
							document.form[campo].focus();
							return false;
						}
					}
					else{
						window.alert('Você digitou um mês que não existe!');
						document.form[campo].value = "";
						document.form[campo].focus();
						return false;
					}
				}
				else{
					window.alert('A data foi digitada fora do padrão(dd/mm/aaaa)!');
					document.form[campo].value = "";
					document.form[campo].focus();
					return false;
				}
			}
			else{
				window.alert('Você digitou um dia que não existe!');
				document.form[campo].value = "";
				document.form[campo].focus();
				return false;
			}
		}
		else{
			window.alert('O dia e/ou o mês que você digitou não existe, ou Você digitou fora do padrão (dd/mm/aaaa) !');
			document.form[campo].value = "";
			document.form[campo].focus();
			return false;
		}
		return true;
	}
}

function acentuacao(e, Maiuscula)
{
   var Tecla = event.keyCode;
   
   if (Tecla > 0){  
	   if ((Tecla >= 65 && Tecla <= 90) || (Tecla >= 48 && Tecla <= 57)  || Tecla == 16 || Tecla == 20
			|| (Tecla >= 44 && Tecla <= 47) || Tecla == 32 || Tecla == 59 || (Tecla >= 33 && Tecla <= 40)
			|| Tecla == 188 || Tecla == 190 || Tecla == 191 || Tecla == 13 || (Tecla >= 8 && Tecla <=9))
		   return;
		   
	   if (Tecla >= 97 && Tecla <= 122){
		  if(Maiuscula == null || Maiuscula == true)
		  event.keyCode -= 32;
		  return;
	   }
	   alert("Atenção\n\nLetras acentuadas, cedilha e caracteres especiais não são permitidos neste campo !");
	   event.returnValue = false;	
   }
}

function validaVerifica_CPF_CGC(campo){
// valida e verifica o campo se for CPF ou CNPJ. Chamando tb a funcao que formata esses campos.
   formata_CPF_CGC(campo);
   if ((document.form[campo].value.length > 0) && (!valida_CPF_CGC(campo))){
	   alert ("CNPJ/CPF inválido!!!");
	   document.form[campo].value = '';
	   document.form[campo].focus();
   }
}

function checkAll(campo, marcar) {
	// marca todas as checkbox da tela
	val = document.form[campo.name].checked;
	len = document.form[marcar].length; 
	for( i=0 ; i<len ; i++)
		document.form[marcar][i].checked = val;
}

//-->
