function bwcheck (){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1) && window.opera 
    this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1) && window.opera   
    this.ie5 = (this.agent.indexOf("msie 5")>-1 && !this.op5 && !this.op6)
    this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
    this.ie6 = (this.agent.indexOf("msie 6")>-1 && !this.op5 && !this.op6)
	this.ie7 = (this.agent.indexOf("msie 7")>-1 && !this.op5 && !this.op6)
	this.ie7 = (this.agent.indexOf("msie 8")>-1 && !this.op5 && !this.op6)
	this.ie4=(this.agent.indexOf("msie")>-1 && document.all &&!this.op5 &&!this.op6 &&!this.ie5&&!this.ie6)
    this.ie = (this.ie4 || this.ie5 || this.ie6 || this.ie7)
	this.mac=(this.agent.indexOf("mac")>-1)
	this.ns6=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ns4=(!this.dom && document.layers)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6)
    this.usedom= this.ns6//Use dom creation
    this.reuse = this.ie||this.usedom //Reuse layers
    this.px=this.dom&&!this.op5?"px":""
	return this
}

//
// ajax.js
//

function extraiScript(texto){
//Maravilhosa função feita pelo SkyWalker.TO do imasters/forum
//http://forum.imasters.com.br/index.php?showtopic=165277&
    // inicializa o inicio ><
    var ini = 0;
    // loop enquanto achar um script
    while (ini!=-1){
        // procura uma tag de script
        ini = texto.indexOf('<script', ini);
        // se encontrar
        if (ini >=0){
            // define o inicio para depois do fechamento dessa tag
            ini = texto.indexOf('>', ini) + 1;
            // procura o final do script
            var fim = texto.indexOf('</script>', ini);
            // extrai apenas o script
            codigo = texto.substring(ini,fim);
            // executa o script
            //eval(codigo);
            /**********************
            * Alterado por Micox - micoxjcg@yahoo.com.br
            * Alterei pois com o eval não executava funções.
            ***********************/
            novo = document.createElement("script")
            novo.text = codigo;
            document.body.appendChild(novo);
        }
    }
}

/*  FUNÇÃO AJAX*/
function ajaxRead(file,destino,semaviso) {
  var xmlObj = null;
  if(window.XMLHttpRequest){
      xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
      return;
  }

xmlObj.onreadystatechange = function(){   
	
	if(xmlObj.readyState == 1){
		//**** USAR PARA ARQUIVOS HTML *****
		if (semaviso == 1) {
			updateObj(destino,"Aguarde ...");
		}
		if (semaviso == 2) {
			updateObj(destino,"<span class='carregando'><div align=\"center\"><img src=\"loading.gif\"></div></span>");
		}
    }

	if(xmlObj.readyState == 4){
		if (xmlObj.status == 200) { //se nao ocorreu nenhum erro
			//**** USAR PARA ARQUIVOS HTML *****
			texto=unescape(xmlObj.responseText.replace(/\+/g," "));
			updateObj(destino, xmlObj.responseText);
			extraiScript(texto);
			/* extraindo script e executando */			
		} else {
            alert("Houve um problema ao obter os dados:\n" + xmlObj.statusText);
        }
}
}
xmlObj.open ('GET', file, true);
xmlObj.send ('');
}

function ajaxReadPost(file,destino,semaviso,dados) {
  
  var xmlObj = null;
  if(window.XMLHttpRequest){
      xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
      return;
  }

xmlObj.onreadystatechange = function(){   
	
	
	if(xmlObj.readyState == 1){
		//**** USAR PARA ARQUIVOS HTML *****
		if (semaviso == 1) {
			updateObj(destino,"Aguarde ...");
		}
		if (semaviso == 2) {
			updateObj(destino,"<span class='carregando'><div align=\"center\"><img src=\"loading.gif\"></div></span>");
		}
    }

	if(xmlObj.readyState == 4){
		if (xmlObj.status == 200) { //se nao ocorreu nenhum erro
			//**** USAR PARA ARQUIVOS HTML *****
			texto=unescape(xmlObj.responseText.replace(/\+/g," "));
			updateObj(destino, xmlObj.responseText);
			extraiScript(texto);
			/* extraindo script e executando */			
		} else {
            alert("Houve um problema ao obter os dados:\n" + xmlObj.statusText);
        }
	}
}
xmlObj.open ('POST', file, true);
xmlObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlObj.send (dados);
}

//***********************************************************************************

function getDados(objForm) {
    
	var params = new Array();

    for (var i=0 ; i < objForm.elements.length; i++) {
        var parametro = encodeURIComponent(objForm.elements[i].name);
        parametro += "=";
        parametro += encodeURIComponent(objForm.elements[i].value);
        params.push(parametro);
    }

    return params.join("&");
	
}

function updateObj(obj, data){
	document.getElementById(obj).innerHTML = data;
}

//
//	FUNCOES COMUNS	////////////////////////////////////////////////////////////////////////////////////////////
//

// FUNCOES PARA CONTROLE DE AVANCO EM CAMPOS DE TEXTO
function semTab() { checatab = false; }
function comTab() { checatab = true; } 

checatab = true;

// PULA PARA A CAIXA DE TEXTO DEFINIDA AO ALCANCAR O TAMANHO MAXIMO DE CARACTERES
function pula(origem, tamanho, destino) {
	if ((origem.value.length == tamanho) && checatab)
		destino.focus();
}

var ver4 = parseInt(navigator.appVersion) >= 4
var ie4  = ((navigator.userAgent.indexOf("MSIE") != -1) && ver4)
var ff   = ((navigator.userAgent.indexOf("Gecko") != -1) && ver4)

// FILTRA AS TECLAS PRESSIONADAS
function filtra(obj, padrao) {
	//tk    = (ie4) ? event.keyCode : event.which;
	if (ie4) { tk = event.keyCode; } else { tk = obj.which; }
	letra = String.fromCharCode(tk);
	
	for (x = 0; x < padrao.length; x++)
		if (padrao.slice(x, x + 1) == letra) return true;
	
	return true;
}

function IsNumeric(sText){
   
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

// VALIDACAO DE CPJ/CNPJ

function validaCNPJ() {
	
	CNPJ = document.form_cadastro_int.cnpj_1.value + "." + document.form_cadastro_int.cnpj_2.value + "." + document.form_cadastro_int.cnpj_3.value + "/" + document.form_cadastro_int.cnpj_4.value + "-" + document.form_cadastro_int.cnpj_5.value;
	var erro = new String;
	if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ! \n\n";
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
	if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! \n\n";
	}
	//substituir os caracteres que não são números
	if(document.layers && parseInt(navigator.appVersion) == 4){
		x = CNPJ.substring(0,2);
		x += CNPJ. substring (3,6);
		x += CNPJ. substring (7,10);
		x += CNPJ. substring (11,15);
		x += CNPJ. substring (16,18);
		CNPJ = x;
	}
	else {
		CNPJ = CNPJ. replace (".","");
		CNPJ = CNPJ. replace (".","");
		CNPJ = CNPJ. replace ("-","");
		CNPJ = CNPJ. replace ("/","");
	}
	
	var nonNumbers = /\D/;
	
	if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n\n";
		var a = [];
		var b = new Number;
		var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
		
		for (i=0; i<12; i++){
			a[i] = CNPJ.charAt(i);
			b += a[i] * c[i+1];
		}
	
	if ((x = b % 11) < 2){ 
		a[12] = 0
	} 
	else { 
		a[12] = 11-x 
	}
	
	b = 0;
	for (y=0; y<13; y++) {
		b += (a[y] * c[y]);
	}
	if ((x = b % 11) < 2) {
		a[13] = 0;
	} 
	else { 
		a[13] = 11-x; 
	}
	
	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
		erro +="Dígito verificador com problema ou CNPJ inválido !";
	}
	
	if (erro.length > 0){
		alert(erro);
		document.form_cadastro_int.cnpj_1.focus();
		ret = 1
		return false;
	}
	ret = 0;
	return true;
}

function validacpf(prefixo){ 
		 
	cpf = document.form_cadastro_int.cpf_1.value + document.form_cadastro_int.cpf_2.value + document.form_cadastro_int.cpf_3.value + document.form_cadastro_int.cpf_4.value; 
	if (cpf == 11111111111 || cpf == 22222222222 || cpf == 33333333333 || cpf == 44444444444 || cpf == 55555555555 || cpf == 66666666666 || cpf == 77777777777 || cpf == 88888888888 || cpf == 99999999999){ 	  
		alert("CPF Inválido!")
		ret = 1
		return false; 	  
	}
	
	var i; 
		  
	//s = document.frmCli.txtCpf.value; 
	s = cpf;
		  
	var c = s.substr(0,9); 
		  
	var dv = s.substr(9,2); 
		  
	var d1 = 0; 
		  
	for (i = 0; i < 9; i++) 	  
	{ 	  
		d1 += c.charAt(i)*(10-i);  
	} 
		  
	if (d1 == 0){ 	  
		alert("CPF Inválido!")
		ret = 1
		return false; 	  
	} 
		  
	d1 = 11 - (d1 % 11); 
		  
	if (d1 > 9) d1 = 0; 
		  
	if (dv.charAt(0) != d1){		  
		alert("CPF Inválido!")
		ret = 1
		return false;  
	} 
	  
	d1 *= 2; 
		  
	for (i = 0; i < 9; i++){ 
		d1 += c.charAt(i)*(11-i);   
	} 
		  
	d1 = 11 - (d1 % 11); 
		  
	if (d1 > 9) d1 = 0; 
	  
	if (dv.charAt(1) != d1){ 	  
		alert("CPF Inválido!")
		ret = 1
		return false;   
	}
	ret = 0;
	return true;
}


// FIM VALIDACAO CPF/CNPJ

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function js_busca_padrao( texto_padrao ) {

	var erro = false;
	var txtbusca = document.snet_busca.pesquisa.value;
	
	if (texto_padrao != '' && texto_padrao == txtbusca) { alert('Informe o que deseja buscar !'); document.snet_busca.pesquisa.focus(); erro = true; }
	if (document.snet_busca.pesquisa.value == '' && erro == false) { alert('Informe o que deseja procurar !'); document.snet_busca.pesquisa.focus(); erro = true; }
	if (txtbusca.length < 3 && erro == false) { alert('Para a busca informe no mínimo 3 caracteres !'); document.snet_busca.pesquisa.focus(); erro = true; }

	if (erro == false) { document.snet_busca.submit(); }

}

// INICIO - FUNÇÃO PARA VERIFICAR ANTI-POPUP

var aviso;

function verificarAntiPopup(avisodiv,urlpop) {
	tempo = 2
	delay = tempo*100
	count = 0
	antipopup = true
	window.open('antipopup_verificar.htm','teste','width=1 ,height=1')
	window.focus()
	aviso = avisodiv;
	Timer()
}

function Timer() {
	if (count >= delay && antipopup == true) {
		alert("Para melhor navegação neste site pedimos que você desabilite o seu Anti-Popup.");
		if (aviso == 1) { $('#div_aviso_pop').show(); }
	} else if (!antipopup) {}
	else if (count < delay)
	{
		count++
		setTimeout("Timer()", 1)
	}
}
function PopupOK()
{
	window.opener.antipopup = false
	setTimeout("window.close()", 100)
}
// FIM - FUNÇÃO PARA VERIFICAR ANTI-POPUP


function FormataValor(campo,tammax,teclapres) {

	var bw = new bwcheck()
	
	if (bw.ie == true) {

		var tecla = teclapres.keyCode;
	//	vr = document.form[campo].value;
		vr = event.srcElement.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 ; 
		 		event.srcElement.value = vr ; 
			}
		 	if ( (tam > 2) && (tam <= 5) ){
		 		//document.form[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; 
		 		event.srcElement.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 ) ; 
		 		event.srcElement.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 ) ; 
		 		event.srcElement.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 ) ; 
		 		event.srcElement.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 ) ;
		 		event.srcElement.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 ) ;
			}
		}
	
	} else {
	
		document.form[campo].value = FiltraCampo(campo);
		vr = document.form[campo].value;
		tam = vr.length;
		
		if ( tam <= 3 ) 
	 		document.form[campo].value = vr ; 
	 	if ( (tam > 3) && (tam <= 6) ) 
	 		document.form[campo].value = vr.substr( 0, tam - 3 ) + '.' + vr.substr( tam - 3, tam ) ; 
	 	if ( (tam >= 7) && (tam <= 9) ) 
	 		document.form[campo].value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, tam ) ; 
	 	if ( (tam >= 10) && (tam <= 12) ) 
	 		document.form[campo].value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, tam ) ; 
	 	if ( (tam >= 13) && (tam <= 15) ) 
	 		document.form[campo].value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, tam ) ; 
	 	if ( (tam >= 16) && (tam <= 18) )
	 		document.form[campo].value = vr.substr( 0, tam - 15 ) + '.' + vr.substr( tam - 15, 3 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, tam ) ;
			
	}

}

function FormataValorMoz(campo,teclapres) {

	var tecla = teclapres.keyCode;
	
	if ( tecla != 9 ) {

		campo.value = FiltraCampo(campo);
		vr = campo.value;
		tam = vr.length;
		
		if (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 ) 
		 		campo.value = vr ; 
		 	if ( (tam > 2) && (tam <= 5) ) 
		 		campo.value = vr.substr( 0, tam - 2 ) + '.' + vr.substr( tam - 2, tam ) ; 
		 	if ( (tam >= 6) && (tam <= 8) ) 
		 		campo.value = vr.substr( 0, tam - 5 ) + '' + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ; 
		 	if ( (tam >= 9) && (tam <= 11) ) 
		 		campo.value = vr.substr( 0, tam - 8 ) + '' + vr.substr( tam - 8, 3 ) + '' + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ; 
		 	if ( (tam >= 12) && (tam <= 14) ) 
		 		campo.value = vr.substr( 0, tam - 11 ) + '' + vr.substr( tam - 11, 3 ) + '' + vr.substr( tam - 8, 3 ) + '' + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ; 
		 	if ( (tam >= 15) && (tam <= 17) )
		 		campo.value = vr.substr( 0, tam - 14 ) + '' + vr.substr( tam - 14, 3 ) + '' + vr.substr( tam - 11, 3 ) + '' + vr.substr( tam - 8, 3 ) + '' + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ;
			
		}
	}
		
}

function FiltraCampo(campo){
	var s = "";
	var cp = "";
	vr = campo.value;
	tam = vr.length;
	for (i = 0; i < tam ; i++) {  
		if (vr.substring(i,i + 1) != "/" && vr.substring(i,i + 1) != "-" && vr.substring(i,i + 1) != "."  && vr.substring(i,i + 1) != "," ){
		 	s = s + vr.substring(i,i + 1);}
	}
	campo.value = s;
	return cp = campo.value
}



