<!-- 
// Java que faz os mouse serem over
/*******************************************************************
 * soopa-rollovers.js
 * 7/28/2001
 * www.youngpup.net
 *
 * easiest rollovers on earth, baby!
 * see www.youngpup.net for documentation.
 *******************************************************************/
function soopaSetup() {
	var img, sh, sn, sd
	for (var i = 0; (img = document.images[i]); i++) {
		if (img.getAttribute) {

			sn = img.getAttribute("src");
			sh = img.getAttribute("hsrc");
			sd = img.getAttribute("dsrc");

			if (sn != "" && sn != null) {
				img.n = new Image();
				img.n.src = img.src;
			
				if (sh != "" && sh != null) {
					img.h = new Image();
					img.h.src = sh;
					img.onmouseover = soopaSwapOn
					img.onmouseout  = soopaSwapOff
				}

				if (sd != "" && sd != null) {
					img.d = new Image();
					img.d.src = sd;
					img.onmousedown = soopaSwapDown
				}
			}
		}
	}
}

function soopaSwapOn() {
	this.src = this.h.src;
}

function soopaSwapOff() {
	this.src  = this.n.src;
}

function soopaSwapDown() {
	this.src  = this.d.src;
	this.temp = typeof(document.onmouseup) != 'undefined' && typeof(document.onmouseup) != 'unknown' ? document.onmouseup : "";
	soopaSwapUp.img = this;
	document.onmouseup = soopaSwapUp;
}

function soopaSwapUp() {
	var ths = soopaSwapUp.img;
	ths.src = ths.n.src;
	if (ths.temp) document.onmouseup = ths.temp;
}
//-->

// Java que faz abrir menus ao clicar
function MostraEsconde(idMostra, idEsconde) {
if (idMostra) {
var a = idMostra.split(/\W/);
for (var i in a) {
var e = document.all && document.all[a[i]] || document.getElementById && document.getElementById(a[i]);
if (e)
e.style.display = '';
}
}
if (idEsconde) {
var a = idEsconde.split(/\W/);
for (var i in a) {
var e = document.all && document.all[a[i]] || document.getElementById && document.getElementById(a[i]);
if (e)
e.style.display = 'none';
}
}
}

/*** Função para popups da Cadastra ***/
function focusWindow() {
    w = window.open("", "popup");
    w.focus();
}


// outras rotinas
<!--
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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
function abre(elem){
	estado = document.getElementById(elem);
	seta_div = 'setaDivSegmento' + elem.replace('divSegmento','');
	try{
		if (estado.style.display == '') {
			estado.style.display = 'none';
			document.getElementById(seta_div).className = 'listaSetaAzulFecha linkazul';
		}else{
			estado.style.display = '';
			document.getElementById(seta_div).className = 'listaSetaAzulAbre linkazul';
		}
		alert(document.style.display);
	}catch(e){
		erro = 'sim';
	}
}


// JavaScript Document
//adiciona mascara de cnpj
function MascaraCNPJ(cnpj, evento){
    if(mascaraInteiro(cnpj)==false){
        evento.returnValue = false;
    }    
    return formataCampo(cnpj, '00.000.000/0000-00', evento);
}

//adiciona mascara de cep
function MascaraCep(cep, evento){
    if(mascaraInteiro(cep)==false){
        evento.returnValue = false;
    }    
    return formataCampo(cep, '00.000-000', evento);
}

//adiciona mascara de data
function MascaraData(data, evento){
    if(mascaraInteiro(data)==false){
        evento.returnValue = false;
    }    
    return formataCampo(data, '00/00/0000', evento);
}

//adiciona mascara ao telefone
function MascaraTelefone(tel, evento){    
    if(mascaraInteiro(tel)==false){
        evento.returnValue = false;
    }    
    return formataCampo(tel, '(00) 0000-0000', evento);
}

//adiciona mascara ao CPF
function MascaraCPF(cpf, evento){
    if(mascaraInteiro(cpf)==false){
        evento.returnValue = false;
    }    
    return formataCampo(cpf, '000.000.000-00', evento);
}
//adiciona mascara ao CPF
function MascaraCPFContato(cpf, evento){
    if(mascaraInteiro(cpf)==false){
        evento.returnValue = false;
    }    
    return formataCampo(cpf, '000.000.000-00', evento);
}
//valida telefone
function ValidaTelefone(tel){
    exp = /\(\d{2}\)\ \d{4}\-\d{4}/
    if(!exp.test(tel.value))
        alert('Numero de Telefone Invalido!');
}

//valida CEP
function ValidaCep(cep){
    exp = /\d{2}\.\d{3}\-\d{3}/
    if(!exp.test(cep.value))
        alert('Numero de Cep Invalido!');        
}

//valida data
function ValidaData(data){
    exp = /\d{2}\/\d{2}\/\d{4}/
    if(!exp.test(data.value))
        alert('Data Invalida!');            
}


//valida o CPF digitado
function ValidarCPFContato(){
	//var cpf = Objcpf.value;  ;
	var cpf = document.getElementById('cpfCadCont').value; 
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   //document.getElementById('fldstrMensagemDocEXCadastroContato').innerHTML='1';
   if(!filtro.test(cpf)){
     document.getElementById("fldstrMensagemCPFCadastroContato").innerHTML = ' CPF Inválido!';
	 return false;
   }
   
   cpf = remove(cpf, ".");
   cpf = remove(cpf, "-");
    
   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  cpf == "88888888888" || cpf == "99999999999"){
	  document.getElementById("fldstrMensagemCPFCadastroContato").innerHTML = ' CPF Inválido!';
	  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))){
	 document.getElementById("fldstrMensagemCPFCadastroContato").innerHTML = ' CPF Inválido!';
	 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))){
    //document.getElementById("fldstrMensagemCPFCadastroContato").innerHTML = '2';
	 return false;
   }
   //document.getElementById("fldstrMensagemCPFCadastroContato").innerHTML = '3';
   //document.getElementById('btPostouDoc').value = 1;
   return true;
 }
 
 function remove(str, sub) {
   i = str.indexOf(sub);
   r = "";
   if (i == -1) return str;
   r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
   return r;
 }



//valida o CPF digitado
function ValidarCPF(Objcpf){
	//alert("ok");
	document.getElementById("fldstrMensagemCPF").style.display=''
	var cpf = Objcpf.value;  ;
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   if(!filtro.test(cpf)){
     document.getElementById("fldstrMensagemCPF").innerHTML = ' CPF Inválido!';
	 return false;
   }
   
   cpf = remove(cpf, ".");
   cpf = remove(cpf, "-");
    
   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  cpf == "88888888888" || cpf == "99999999999"){
	  document.getElementById("fldstrMensagemCPF").innerHTML = ' CPF Inválido!';
	  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))){
	 document.getElementById("fldstrMensagemCPF").innerHTML = ' CPF Inválido!';
	 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))){
   document.getElementById("fldstrMensagemCPF").innerHTML = '';
	 return false;
   }
//   alert("OK");
   document.getElementById("fldstrMensagemCPF").innerHTML = '';
    document.getElementById("fldstrMensagemCPF").style.display='none' ;
   return true;
 }
 
 function ValidarCPF2(Objcpf){
	//alert("ok");
	document.getElementById("fldstrMensagemCPF2").style.display=''
	var cpf = Objcpf.value;  ;
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   if(!filtro.test(cpf)){
     document.getElementById("fldstrMensagemCPF2").innerHTML = ' CPF Inválido!';
	 return false;
   }
   
   cpf = remove(cpf, ".");
   cpf = remove(cpf, "-");
    
   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  cpf == "88888888888" || cpf == "99999999999"){
	  document.getElementById("fldstrMensagemCPF2").innerHTML = ' CPF Inválido!';
	  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))){
	 document.getElementById("fldstrMensagemCPF2").innerHTML = ' CPF Inválido!';
	 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))){
   document.getElementById("fldstrMensagemCPF2").innerHTML = '';
	 return false;
   }
//   alert("OK");
   document.getElementById("fldstrMensagemCPF2").innerHTML = '';
    document.getElementById("fldstrMensagemCPF2").style.display='none' ;
   return true;
 }
 
 function remove(str, sub) {
   i = str.indexOf(sub);
   r = "";
   if (i == -1) return str;
   r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
   return r;
 }

//valida numero inteiro com mascara
function mascaraInteiro(input){
	var	value = input.value.replace(/\D/g, '');
	if (input.value != value) input.value = value;	
	//if(typeof(tecla) == 'undefined')
	// var tecla = window.event;
	//var eventoTipo = (tecla.which ? tecla.which : tecla.keyCode ? tecla.keyCode : tecla.charCode);
	//var eventoTipo = (event.which ? event.which : event.keyCode ? event.keyCode : event.charCode);
	//if ( (eventoTipo >= 48 && eventoTipo <= 57) || (eventoTipo >= 96 && eventoTipo <= 105) || eventoTipo == 8 || eventoTipo == 46 || eventoTipo == 9 ){
     //   return true;
	//}else{ 
	//    return false;
//	}
}

//valida o CNPJ digitado
function ValidarCNPJ(ObjCnpj){
    var cnpj = ObjCnpj.value;
    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){    
		document.getElementById("fldstrMensagemCNPJ").innerHTML = ' CNPJ Inválido!';
	} else {
		document.getElementById("fldstrMensagemCNPJ").innerHTML = '';
	}
}

function ValidarCNPJ2(ObjCnpj){
    var cnpj = ObjCnpj.value;
    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){    
		document.getElementById("fldstrMensagemCNPJ2").innerHTML = ' CNPJ Inválido!';
	} else {
		document.getElementById("fldstrMensagemCNPJ2").innerHTML = '';
	}
}

//formata de forma generica os campos
function formataCampo(campo, Mascara, evento) {
   var boleanoMascara;
   var Digitato = (evento.which ? evento.which : evento.keyCode ? evento.keyCode : evento.charCode);
   // if(window.event) { // Internet Explorer
   //   Digitato = evento.keyCode; }
   // else if(evento.which) { // Nestcape / firefox
   //   Digitato = evento.which;
    //}
   
  //  var Digitato = evento.which;
	//alert (Digitato);
    exp = /\-|\.|\/|\(|\)| /g
    campoSoNumeros = document.getElementById(campo.id).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++;
              }           
          }    
        document.getElementById(campo.id).value = NovoValorCampo;
          return true;
    }else {
        return true;
    }
}

