// JavaScript Document
// ===========================================================
// script: EUNANET - 08/2008
// http://www.eunanet.net
// ===========================================================
// Controle Número de Caracteres na Digitiação
// ===========================================================
contenido_textarea = ""
textovar = ""
function valida_longitud(num,varpost){
	var vpost       = document.getElementsByName(varpost);
	var num_caracteres_permitidos = num;
	var num_caracteres = vpost[0].value.length
	if (num_caracteres <= num_caracteres_permitidos){
		contenido_textarea = vpost[0].value	
	}else{
		vpost[0].value = contenido_textarea
	}
	
	if (num_caracteres >= num_caracteres_permitidos){

		// document.forms['formeditor'].caracteres.style.color="#ff0000";
	}else{
		// document.forms['formeditor'].caracteres.style.color="#000000";
	}
	cuenta(vpost[0].value.length)
}
function cuenta(vp){
	// document.forms['formeditor'].caracteres.value=vp
}
// ===========================================================
// Carrega Flash 
function carregaFlash(caminho,largura,altura) {
	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="'+largura+'" height="'+altura+'">');
	document.write('<param name="movie" value="'+caminho+'">');
	document.write('<param name="quality" value="high">');
//	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="menu" value="false">');
	document.write('<embed src="'+caminho+'" quality="high" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+largura+'" height="'+altura+'"></embed>');
	document.write('</object>');
}
// Flash com Fundos Transparentes
function carregaFlashTransparente(caminho,largura,altura) {
	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="'+largura+'" height="'+altura+'">');
	document.write('<param name="movie" value="'+caminho+'">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="menu" value="false">');
	document.write('<embed src="'+caminho+'" wmode="transparent" quality="high"  menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+largura+'" height="'+altura+'"></embed>');
	document.write('</object>');
}
// ===========================================================
function exibeagenda(dia,mes,ano,vusu) {
	exibeget('agendaeu/agenda.php?usu='+vusu+'&mes='+mes+'&ano='+ano+'&dia='+dia,'div1','L','D','D','D');
	exibeget('agendaeu/agendalista.php?usu='+vusu+'&mes='+mes+'&ano='+ano+'&dia='+dia,'div2','L','L','D','D');
	return false;
}
function filtragenda(vdia) {
	var mes      = document.getElementsByName('mes_calend'); 
	var ano      = document.getElementsByName('ano_calend'); 
	var vusu     = document.getElementsByName('id_usue');
	exibeagenda(vdia,mes[0].value,ano[0].value,vusu[0].value);
	return false;
}
function delevento(id,mes,ano,dia,usu) {
	if (confirm("Confirma a Exclusão do Evento?")) {
		exibeget('agendaeu/agendamanut.php?usu='+usu+'&acao=E&id='+id+'&mes='+mes+'&ano='+ano+'&dia='+dia,'div3','D','D','L','D');
	} else {
		alert("Exclusão Concelada!");
	}
	return false; 
}
// ===========================================================
function moveofoco(varfocus) {
	var vtab    = document.getElementsByName(varfocus);
	move_o_foco = vtab[0].focus();
	return false;
}
function tabselect(tabela) {
	if (tabela == "pais") {
		var box    = document.getElementById("campo_bloco_pais");
		var vartab = document.getElementsByName('id_pai');
	} else {
		var box    = document.getElementById("campo_bloco_estado");
		var vartab = document.getElementsByName('id_est');
	}	
	box.style.display = (vartab[0].value == "999999" ? "inline" : "none" );
	return false; 
}
function mudatitulologin() {
	var vselect  = document.getElementsByName('tipolog');
	var vfocus   = document.getElementsByName('login');
	if(document.all) {
		if (vselect[0].value == "A") {
			document.getElementById('tit_login').innerText = "Login:";
		} else {
			document.getElementById('tit_login').innerText = "e-Mail:";	
		}
	} else {
		if (vselect[0].value == "A") {
			document.getElementById('tit_login').textContent = "Login:";			
		} else {
			document.getElementById('tit_login').textContent = "e-Mail:";			
		}
	}	
	var vpesqfoc = vfocus[0].focus();
	return false; 
}
function adicionaemail() {
	var vemail    = document.getElementsByName('id_cli');
	var vtexto    = document.getElementsByName('emails');
	if(vtexto[0].value=="Todos" || vtexto[0].value=="") {
		vtexto[0].value = vemail[0].value;
	} else {
		vtexto[0].value = vtexto[0].value+","+vemail[0].value;
	}
	if(vemail[0].value=="Todos") {
		vtexto[0].value = "Todos";
	}
	return false;
}
function tipocli(variavel) {
	var varnada = variavel;
	var boxtipocli  = document.getElementsByName("tipo_cli");
	var varnome     = document.getElementsByName('nome');
	var boxim    	= document.getElementById("campo_bloco_im");
	var boxec    	= document.getElementById("campo_bloco_ec");
	var boxsx    	= document.getElementById("campo_bloco_sx");
	var boxnasc    	= document.getElementById("campo_bloco_nasc");	
	if(document.all) {
		if (boxtipocli[0].value == "J") {
			document.getElementById('tit_cnpjcpf_cli').innerText = "Nº CNPJ*:";
			document.getElementById('tit_rginsc_cli').innerText = "Nº Insc. Est.:";
			document.getElementById('tit_nome_cli').innerText = "Razão Social*:";
			document.getElementById('tit_fone1_cli').innerText = "Fone*:";			
			document.getElementById('tit_fone2_cli').innerText = "Fax:";			
			boxec.style.display = "none";
			boxsx.style.display = "none";
			boxnasc.style.display = "none";						
			boxim.style.display = "inline";
		} else {
			document.getElementById('tit_cnpjcpf_cli').innerText = "Nº CPF*:";
			document.getElementById('tit_rginsc_cli').innerText = "Nº do RG:";		
			document.getElementById('tit_nome_cli').innerText = "Nome*:";		
			document.getElementById('tit_fone1_cli').innerText = "Fone Residencial*:";			
			document.getElementById('tit_fone2_cli').innerText = "Fone Comercial:";			
			boxec.style.display = "inline";
			boxsx.style.display = "inline";			
			boxnasc.style.display = "inline";
			boxim.style.display = "none";			
		}
	} else {
		if (boxtipocli[0].value == "J") {
			document.getElementById('tit_cnpjcpf_cli').textContent = "Nº CNPJ*:";
			document.getElementById('tit_rginsc_cli').textContent = "Nº Insc. Est.:";
			document.getElementById('tit_nome_cli').textContent = "Razão Social*:";
			document.getElementById('tit_fone1_cli').textContent = "Fone*:";			
			document.getElementById('tit_fone2_cli').textContent = "Fax:";			
			boxec.style.display = "none";
			boxsx.style.display = "none";			
			boxnasc.style.display = "none";
			boxim.style.display = "inline";				
		} else {
			document.getElementById('tit_cnpjcpf_cli').textContent = "Nº CPF*:";
			document.getElementById('tit_rginsc_cli').textContent = "Nº do RG:";		
			document.getElementById('tit_nome_cli').textContent = "Nome*:";		
			document.getElementById('tit_fone1_cli').textContent = "Fone Residencial*:";			
			document.getElementById('tit_fone2_cli').textContent = "Fone Comercial:";
			boxec.style.display = "inline";
			boxsx.style.display = "inline";
			boxnasc.style.display = "inline";						
			boxim.style.display = "none";			
		}
	}	
	var vpesqfoc = varnome[0].focus();
	return false; 
}
function tipoclicarrinho(variavel) {
	var varnada = variavel;
	var boxtipocli  = document.getElementsByName("tipo_cli");
	var varnome     = document.getElementsByName('nome');
	if(document.all) {
		if (boxtipocli[0].value == "J") {
			document.getElementById('tit_cnpjcpf_cli').innerText = "Nº CNPJ:(números)";
			document.getElementById('tit_nome_cli').innerText = "Razão Social:";
		} else {
			document.getElementById('tit_cnpjcpf_cli').innerText = "Nº CPF:(números)";
			document.getElementById('tit_nome_cli').innerText = "Nome:";				
		}
	} else {
		if (boxtipocli[0].value == "J") {
			document.getElementById('tit_cnpjcpf_cli').textContent = "Nº CNPJ:(números)";
			document.getElementById('tit_nome_cli').textContent = "Razão Social:";		
		} else {
			document.getElementById('tit_cnpjcpf_cli').textContent = "Nº CPF:(números)";
			document.getElementById('tit_nome_cli').textContent = "Nome:";				
		}
	}	
	var vpesqfoc = varnome[0].focus();
	return false; 
}
// ===========================================================
function atualizacarrinho(acao,id,ordem) {
	var quant = document.getElementsByName("qde"+ordem);
	window.location.href="carrinho.php?pro="+id+"&acao="+acao+"&qde="+quant[0].value;	
	return false;  
}
function atucompra(ordem) {
	var quant  = document.getElementsByName("qde"+ordem);
	var valor  = document.getElementsByName("val"+ordem);
	var totval = document.getElementsByName("valtot"+ordem);
	//alert(quant[0].value);
	valorx = valor[0].value.replace('.',"");
	valorx = valorx.replace(',',".");
	totval[0].value  = formatCurrency(valorx*quant[0].value); 
	exibepost('tabelaprod','pedcompraprodatu.php','totalcompra','L','L','D','D')
	return false;
}
function enviaformulario(formulario,pagina,div1,div2) {
	exibe(div1,'none');
	exibe(div2,'inline');
	micoxUpload(formulario,pagina,div2,'images/loading.gif','Erro ao carregar');
	return false;
}
function autenticacli(formulario,pagina) {
	exibe('divlogincli','none');
	exibe('divloginrsp','inline');
	micoxUpload(formulario,pagina,'divloginrsp','images/loading.gif','Erro ao carregar');
	return false;
}
function exibecarrinho(pag,div) {
	var ajax     = new AJAX();
	ajax.Updater(pag,div,"GET","<img src='images/loading.gif' />");
	return false;
}
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+'.'+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + ',' + cents);
}
// ===========================================================
function exibedivs(cdiv1,cdiv2,cdiv3,cdiv4) {
	var box1 = document.getElementById('div1');
	var box2 = document.getElementById('div2');
	var box3 = document.getElementById('div3');
	var box4 = document.getElementById('div4');
	box1.style.display = (cdiv1 == "L" ? "inline" : "none" );
	box2.style.display = (cdiv2 == "L" ? "inline" : "none" );
	box3.style.display = (cdiv3 == "L" ? "inline" : "none" );
	box4.style.display = (cdiv4 == "L" ? "inline" : "none" );
	return false;
}
function esconde(divesconde) {
	var boxesconde = document.getElementById(divesconde);
	boxesconde.style.display="none";
	return false;
}
function exibe(divesconde,tipo) {
	var boxesconde = document.getElementById(divesconde);
	boxesconde.style.display=tipo;
	return false;
}
function nadafaz(nada) {
	return true;
}
function exibeget(varpag,vardiv,cd1,cd2,cd3,cd4) {
	var vcd1     = cd1;
	var vcd2     = cd2;
	var vcd3     = cd3;
	var vcd4     = cd4;
	exibedivs(vcd1,vcd2,vcd3,vcd4);
	var vpag     = varpag;
	var vdiv     = vardiv;
	var ajax     = new AJAX();
	ajax.Updater(vpag,vdiv,"GET","<img src='images/loading.gif' />");
	return false;
}
function exibepost(varform,varpag,vardiv,cd1,cd2,cd3,cd4) {
	var vcd1     = cd1;
	var vcd2     = cd2;
	var vcd3     = cd3;
	var vcd4     = cd4;	
	var vform    = varform;	
	var vpag     = varpag;
	var vdiv     = vardiv;
	exibedivs(vcd1,vcd2,vcd3,vcd4);
	micoxUpload(vform,vpag,vdiv,'images/loading.gif','Erro ao carregar');			
	return false;
}
function exibegetmenu(varpag,vardiv) {
	var vpag     = varpag;
	var vdiv     = vardiv;
	var ajax     = new AJAX();
	ajax.Updater(vpag,vdiv,"GET","<img src='images/loading.gif' />");
	return false;
}
function exibetab(vartab) {
	var vtabmenu        = vartab+".php";
	var vtablista       = vartab+"lista.php?cks=&acao=L";
	exibedivs("L","D","D","D")
	var ajax = new AJAX();
	// exibeget('pedvendaeditaprod.php?id_pdv=".$id_tab."&acao=I','div2','L','L','D','D') 
	ajax.Updater(vtabmenu,'div1',"GET","<img src='images/loading.gif' />");
	setTimeout("exibeget(\'"+vtablista+"\',\'div2\',\'L\',\'L\',\'D\',\'D\')",1000);
}
function exibeperfil(tipo,codigo) {
	var vtablista = 'perfilmens.php?tipo='+tipo+'&codigo='+codigo;
	exibedivs("L","D","D","D")
	var ajax = new AJAX();
	// exibeget('pedvendaeditaprod.php?id_pdv=".$id_tab."&acao=I','div2','L','L','D','D') 
	ajax.Updater('perfil.php?tipo='+tipo+'&codigo='+codigo,'div1',"GET","<img src='images/loading.gif' />");
	setTimeout("exibeget(\'"+vtablista+"\',\'div2\',\'L\',\'L\',\'D\',\'D\')",1000);
}
function exibetabprod(varpdv) {
	var vtabmenu        = "pedvendaeditaprod.php?id_pdv="+varpdv+"&acao=I";
	var vtablista       = "pedvendalistaprod.php?id_pdv="+varpdv;
	exibedivs("L","L","D","D")
	var ajax = new AJAX();
	ajax.Updater(vtabmenu,'div2',"GET","<img src='images/loading.gif' />");
	setTimeout("exibeget(\'"+vtablista+"\',\'div3\',\'L\',\'L\',\'L\',\'D\')",1000);
}
function exibetabuni(vartab) {
	var vtabmenu        = vartab+".php";
	var vtablista       = vartab+"lista.php";
	exibedivs("L","D","D","D")
	var ajax = new AJAX();
	ajax.Updater(vtabmenu,'div1',"GET","<img src='images/loading.gif' />");
}
function exibegettram(id) {
	var vtabmenu        = "processostramita.php?id="+id;
	var vtablista       = "processostramitalista.php?id="+id;
	exibedivs("L","D","D","D")
	var ajax = new AJAX();
	ajax.Updater(vtabmenu,'div1',"GET","<img src='images/loading.gif' />");
	setTimeout("exibeget(\'"+vtablista+"\',\'div2\',\'L\',\'L\',\'D\',\'D\')",1000);
}
function exibeoscli(vartab) {
	var vtablista       = vartab+".php";
	var os            = document.getElementsByName('id_os');
	var fone          = document.getElementsByName('fone');
	var vtablista     = vtablista+"?txt="+os[0].value+"&fone="+fone[0].value;	
	exibedivs("D","L","D","D")
	var ajax = new AJAX();
	ajax.Updater(vtablista,'div2',"GET","<img src='images/loading.gif' />");
}
function zaracache(aurl){
        var dt = new Date();
        if(aurl.indexOf("?")>=0){// já tem parametros
            return aurl + "&" + encodeURI(Math.random() + "_" + dt.getTime());
        }else{ return aurl + "?" + encodeURI(Math.random() + "_" + dt.getTime());}
    }
function exibepesq(vartab) {
	var vtablista       = vartab+"lista.php";
	var pesq            = document.getElementsByName('pesquisa_tab');
	var vpesq           = pesq[0].value;
	if(vpesq.length <= 0) {
		alert("Digite algo para pesquisar!")
		return false
	}
	exibedivs("L","L","D","D");
	var ajax = new AJAX();
	ajax.Updater(vtablista+'?txt='+vpesq,'div2',"GET","<img src='images/loading.gif' />");
}
function exibepesqdia(vartab) {
	var vtablista       = vartab+"lista.php";
	var pesq            = document.getElementsByName('pesquisa_tab');
	var vpesq           = pesq[0].value;
	var pesqdata        = document.getElementsByName('pesquisa_dia');
	var vpesqdata       = pesqdata[0].value;	
	if(vpesq.length <= 0 && vpesqdata.length <= 0) {
		alert("Digite algo para pesquisar!")
		return false
	}
	exibedivs("L","L","D","D");
	var ajax = new AJAX();
	ajax.Updater(vtablista+'?txt='+vpesq+'&dia='+vpesqdata,'div2',"GET","<img src='images/loading.gif' />");
}
function exibepesqdup(vartab) {
	var vtablista       = vartab+"lista.php";
	var pag_out       = document.getElementsByName('filtra_out');	
	var vpag_out      = pag_out[0].value;	
	var pesq            = document.getElementsByName('pesquisa_tab');
	var vpesq           = pesq[0].value;
	if(vpesq.length <= 0) {
		alert("Digite algo para pesquisar!")
		return false
	}
	exibedivs("L","L","D","D");
	var ajax = new AJAX();
	ajax.Updater(vtablista+'?txt='+vpesq+'&out='+vpag_out,'div2',"GET","<img src='images/loading.gif' />");
}
function exibepaginacao(vartab) {
	var vtablista     = vartab+"lista.php";
	if (vartab == "estados" || vartab == "cidades" || vartab == "subcategorias") {
		var pag_out       = document.getElementsByName('filtra_out');	
		var vpag_out      = pag_out[0].value;
	}
	if (vartab == "diario") {
		var pesqdata        = document.getElementsByName('pesquisa_dia');
		var vpesqdata       = pesqdata[0].value;
	}	
	var pag_tab       = document.getElementsByName('numpag_tab');
	var vpag_tab      = pag_tab[0].value;
	var pesq          = document.getElementsByName('pesquisa_tab');
	var vpesq         = pesq[0].value;
	var vpesqfoc      = pesq[0].focus();
	if(vpesq.length > 0) {
		vpesq = "&txt="+vpesq
	} else {
	    vpesq = ""
		pesq[0].value = ""
	}
	exibedivs("L","L","D","D");
	var ajax = new AJAX();
	ajax.Updater(vtablista+'?nreg='+vpag_tab+'&txt='+vpesq+'&out='+vpag_out+'&dia='+vpesqdata,'div2',"GET","<img src='images/loading.gif' />");
}
function exibepesqmes(vartab) {
	var vtablista       = vartab+"lista.php";
	var pesq            = document.getElementsByName('pesquisa_tab');
	var vpesq           = pesq[0].value;
	var pmes          = document.getElementsByName('mes_tab');
	var vmes          = pmes[0].value;	
	var pano          = document.getElementsByName('ano_calend');
	var vano          = pano[0].value;	
	var ppdv          = document.getElementsByName('pdv_mes');
	var vpdv          = ppdv [0].value;		
	if(vpesq.length <= 0) {
		alert("Digite algo para pesquisar!")
		return false
	}
	exibedivs("L","L","D","D");
	var ajax = new AJAX();
	ajax.Updater(vtablista+'?mes='+vmes+'&ano='+vano+'&txt='+vpesq+'&pdv='+vpdv,'div2',"GET","<img src='images/loading.gif' />");
}
function exibepaginacaomes(vartab) {
	var vtablista     = vartab+"lista.php";
	var pag_tab       = document.getElementsByName('numpag_tab');
	var vpag_tab      = pag_tab[0].value;
	var pesq          = document.getElementsByName('pesquisa_tab');
	var vpesq         = pesq[0].value;
	var pmes          = document.getElementsByName('mes_tab');
	var vmes          = pmes[0].value;	
	var pano          = document.getElementsByName('ano_calend');
	var vano          = pano[0].value;	
	var ppdv          = document.getElementsByName('pdv_mes');
	var vpdv          = ppdv [0].value;		
	var vpesqfoc      = pesq[0].focus();
	if(vpesq.length > 0) {
		vpesq = "&txt="+vpesq
	} else {
	    vpesq = ""
		pesq[0].value = ""
	}
	exibedivs("L","L","D","D");
	var ajax = new AJAX();
	ajax.Updater(vtablista+'?mes='+vmes+'&ano='+vano+'&nreg='+vpag_tab+'&txt='+vpesq+'&pdv='+vpdv,'div2',"GET","<img src='images/loading.gif' />");
}
function exibetodosmes(vartab) {
	var vtablista     = vartab+"lista.php";
	var pag_tab       = document.getElementsByName('numpag_tab');
	var vpag_tab      = pag_tab[0].value;	
	var pesq          = document.getElementsByName('pesquisa_tab');
	pesq[0].value     = "";
	var pmes          = document.getElementsByName('mes_tab');
	var vmes          = pmes[0].value;	
	var pano          = document.getElementsByName('ano_calend');
	var vano          = pano[0].value;		
	var ppdv          = document.getElementsByName('pdv_mes');
	ppdv [0].value	  = "T";		
	exibedivs("L","L","D","D");
	var ajax = new AJAX();
	ajax.Updater(vtablista+'?mes='+vmes+'&ano='+vano+'&nreg='+vpag_tab,'div2',"GET","<img src='images/loading.gif' />");
}
function exibepagmes(vartab) {
	var vtablista     = vartab+"lista.php";
	var pag_tab       = document.getElementsByName('numpag_tab');
	var vpag_tab      = pag_tab[0].value;
	var pesq          = document.getElementsByName('pesquisa_tab');
	var vpesq         = pesq[0].value;
	var pmes          = document.getElementsByName('mes_tab');
	var vmes          = pmes[0].value;	
	var pano          = document.getElementsByName('ano_calend');
	var vano          = pano[0].value;	
	var ppdv          = document.getElementsByName('pdv_mes');
	var vpdv          = ppdv [0].value;		
	var vpesqfoc      = pesq[0].focus();
	if(vpesq.length > 0) {
		vpesq = "&txt="+vpesq
	} else {
	    vpesq = ""
		pesq[0].value = ""
	}
	exibedivs("L","L","D","D");
	var ajax = new AJAX();
	ajax.Updater(vtablista+'?mes='+vmes+'&ano='+vano+'&nreg='+vpag_tab+'&txt='+vpesq+'&pdv='+vpdv,'div2',"GET","<img src='images/loading.gif' />");
}
function exibeprodcat(vartab) {
	var vtablista     = vartab+"lista.php";
	var pesq1         = document.getElementsByName('id_for');
	var pesq2         = document.getElementsByName('id_cat');
	window.focus();
	exibedivs("L","L","D","D");
	var ajax = new AJAX();
	ajax.Updater(vtablista+"?for="+pesq1[0].value+"&cat="+pesq2[0].value,'div2',"GET","<img src='images/loading.gif' />");
}
function geracompra() {
	if (confirm("Confirma a Geração dos Pedidos de Compras?")) {
		exibeget('pedcompraprodgera.php','div1','L','L','D','D');
		exibetab('pedcompra');
	} else {
		alert("Geração de Pedidos Cancelada!");
	}
	return false; 
}
function exibetodos(vartab) {
	var vtablista     = vartab+"lista.php";
	var pesq          = document.getElementsByName('pesquisa_tab');
	pesq[0].value     = "";
	exibedivs("L","L","D","D");
	var ajax = new AJAX();
	ajax.Updater(vtablista,'div2',"GET","<img src='images/loading.gif' />");
}
function exibetodosdia(vartab) {
	var vtablista     = vartab+"lista.php";
	var pesq          = document.getElementsByName('pesquisa_tab');
	pesq[0].value     = "";
	var pesqdata      = document.getElementsByName('pesquisa_dia');
	pesqdata[0].value = "";
	exibedivs("L","L","D","D");
	var ajax = new AJAX();
	ajax.Updater(vtablista,'div2',"GET","<img src='images/loading.gif' />");
}
function exibetodosdup(vartab) {
	var vtablista     = vartab+"lista.php";
	var pesq          = document.getElementsByName('pesquisa_tab');
	pesq[0].value     = "";
	var pag_out       = document.getElementsByName('filtra_out');	
	pag_out[0].value  = "0";
	exibedivs("L","L","D","D");
	var ajax = new AJAX();
	ajax.Updater(vtablista,'div2',"GET","<img src='images/loading.gif' />");
}
function exibeselect(pag,div,psq,acao) {
	var vpag          = pag;
	var vdiv          = div;
	var vacao         = acao;
	var pesq          = document.getElementsByName(psq);
	var vpsq          = pesq[0].value;
	var ajax = new AJAX();
	ajax.Updater(vpag+"?var="+vpsq+"&acao="+vacao,vdiv,"GET","<img src='images/loading.gif' />");
}
function exibeselectprod(pag,div,psq,acao) {
	var vpag          = pag;
	var vdiv          = div;
	var vacao         = acao;
	var pesq          = document.getElementsByName(psq);
	var foco          = document.getElementsByName('qde_pvp');
	var vpsq          = pesq[0].value;
	var vfoco 		  = foco[0].focus();
	var ajax = new AJAX();
	ajax.Updater(vpag+"?var="+vpsq+"&acao="+vacao,vdiv,"GET","<img src='images/loading.gif' />");
}
function aplicadesconto(pag,div,psq,acao) {
	var vpag          = pag;
	var vdiv          = div;
	var vacao         = acao;
	var pdesc         = document.getElementsByName('desconto_pvp');
	var pesq          = document.getElementsByName(psq);
	var vpsq          = pesq[0].value;
	var ajax = new AJAX();
	ajax.Updater(vpag+"?var="+vpsq+"&acao="+vacao+"&desc="+pdesc[0].value,vdiv,"GET","<img src='images/loading.gif' />");
}
function exibeselectcli(pag,div,psq,acao) {
	var vpag          = pag;
	var vdiv          = div;
	var vacao         = acao;
	var pesq          = document.getElementsByName(psq);
	var vpsq          = pesq[0].value;
	var ajax = new AJAX();
	ajax.Updater(vpag+"?var="+vpsq+"&acao="+vacao,vdiv,"GET","<img src='images/loading.gif' />");	
}
function marcaregtab() {
   var cks = document.getElementsByName('marcadel[]');
   for (i=0;i<cks.length;i++) 
	  if(cks[i].type == "checkbox") 
		if(cks[i].checked==1)
			cks[i].checked=0
		else	 
			cks[i].checked=1
		 return false;
}		
function delregtab(tab) {
   var tabela = tab;
   var varcks = "";
   var separa = "";
   var temreg = 0;
   var cks = document.getElementsByName('marcadel[]');
   for (i = 0; i < cks.length; i++) {
		if(cks[i].checked) {
			varcks = varcks+separa+cks[i].value; 
			separa = "|";
			temreg = 1;
		}
	}
	if (temreg == 1) { 
		if (confirm("Confirma a Exclusão dos Registros Marcados?")) {
			exibeget(tabela+".php?acao=D&cks="+varcks,'div2','L','L','D','D');
		} else {
			alert("Exclusão Concelada!");
		}
		return false; 
	}
	alert("Selecione pelo menos um Registro para apagar!!!"); 
	return false; 
}
function delmens(tab) {
   var tabela = tab;
   var varcks = "";
   var separa = "";
   var temreg = 0;
   var cks = document.getElementsByName('marcadel[]');
   for (i = 0; i < cks.length; i++) {
		if(cks[i].checked) {
			varcks = varcks+separa+cks[i].value; 
			separa = "|";
			temreg = 1;
		}
	}
	if (temreg == 1) { 
		if (confirm("Confirma a Exclusão dos Registros Marcados?")) {
			exibeget(tabela+"&acao=D&cks="+varcks,'div2','L','L','D','D');
		} else {
			alert("Exclusão Concelada!");
		}
		return false; 
	}
	alert("Selecione pelo menos um Registro para apagar!!!"); 
	return false; 
}
function delregtabprod(tab,pdv) {
   var tabela = tab;
   var varcks = "";
   var separa = "";
   var temreg = 0;
   var cks = document.getElementsByName('marcadel[]');
   for (i = 0; i < cks.length; i++) {
		if(cks[i].checked) {
			varcks = varcks+separa+cks[i].value; 
			separa = "|";
			temreg = 1;
		}
	}
	if (temreg == 1) { 
		if (confirm("Confirma a Exclusão dos Registros Marcados?")) {
			exibeget(tabela+".php?id_pdv="+pdv+"&acao=D&cks="+varcks,'div3','L','L','L','D');
		} else {
			alert("Exclusão Concelada!");
		}
		return false; 
	}
	alert("Selecione pelo menos um Registro para apagar!!!"); 
	return false; 
}
function lancaestoque(tab,pdc) {
   	var tabela = tab;
	if (confirm("Confirma o Lançamento dos Produtos no Estoque?")) {
		exibeget(tabela+".php?pdc="+pdc,'div2','L','L','D','D');
	} else {
		alert("Lançamento no Estoque Concelado!");
	}
	return false; 
}
function parcelamento(acao_sis) {
	var numparc = document.getElementsByName('numparcelas_pdv');
	var iguais 	= document.getElementsByName('igparcelas_pdv');
	exibedivs("L","L","D","D");
	var ajax = new AJAX();
	ajax.Updater('pedvendapag.php?np='+numparc[0].value+'&ig='+iguais[0].value+'&acao='+acao_sis,'campo_bloco_parcelas',"GET","<img src='images/loading.gif' />");
}
function bonus(acao_sis) {
	var numbonus = document.getElementsByName('quantidade_bon');
	var ajax = new AJAX();
	ajax.Updater('bonusnum.php?nb='+numbonus[0].value+'&acao='+acao_sis,'campo_bloco_parcelas',"GET","<img src='images/loading.gif' />");
}
function pegaprod(acao) {
	var codbar  = document.getElementsByName('codbar_pro');
	var codbarra = codbar[0].value;
	var vacao         = acao;	
	var pos           = codbarra.length;
	/*alert(codbarra.charCodeAt(pos-1));*/
	var ajax = new AJAX();
	ajax.Updater("selectcodbar.php?var="+codbarra+"&acao="+vacao,'campo_bloco_cidade',"GET","<img src='images/loading.gif' />");	
	/*setTimeout("exibeselect(\'selectvalprod.php\',\'campo_bloco_estado\',\'id_pro\',\'"+vacao+"\')",4000);*/
	return false;
}
function impvda() {
	var dataini   = document.getElementsByName('data_ini');
	var datafim   = document.getElementsByName('data_fim');
	var cliente   = document.getElementsByName('id_cli');
	var ordenacao = document.getElementsByName('tiporel');	
	var desempenho = document.getElementsByName('desempenho');	
	var semcomp   = document.getElementsByName('semcompras');		
    for (var i=0; i < ordenacao.length; i++)
        if ( ordenacao[i].checked )
            ordem = ordenacao[i].value;	
    for (var i=0; i < desempenho.length; i++)
        if ( desempenho[i].checked )
            desmp = desempenho[i].value;	
    for (var i=0; i < semcomp.length; i++)
        if ( semcomp[i].checked )
            compras = semcomp[i].value;			
	window.open('relatorio_vendas_visualizacao.php?di='+dataini[0].value+"&df="+datafim[0].value+"&cli="+cliente[0].value+"&ord="+ordem+"&compras="+compras+"&desempenho="+desmp);
	return false;
}
function impcomvda() {
	var dataini   = document.getElementsByName('data_ini');
	var datafim   = document.getElementsByName('data_fim');
	var vendedor   = document.getElementsByName('id_vdo');
	var ordenacao = document.getElementsByName('tiporel');	
	var desempenho = document.getElementsByName('desempenho');	
	var semcomp   = document.getElementsByName('semcompras');		
    for (var i=0; i < ordenacao.length; i++)
        if ( ordenacao[i].checked )
            ordem = ordenacao[i].value;	
    for (var i=0; i < desempenho.length; i++)
        if ( desempenho[i].checked )
            desmp = desempenho[i].value;	
    for (var i=0; i < semcomp.length; i++)
        if ( semcomp[i].checked )
            compras = semcomp[i].value;			
	window.open('relatorio_comvendas_visualizacao.php?di='+dataini[0].value+"&df="+datafim[0].value+"&vdo="+vendedor[0].value+"&ord="+ordem+"&compras="+compras+"&desempenho="+desmp);
	return false;
}
function imprelprod(tipo) {	
	var cat   = document.getElementsByName('id_cat');
	var email = document.getElementsByName('email_cli');
	window.open('relatorio_produtos_gera.php?tipo='+tipo+'&cat='+cat[0].value+"&email="+email[0].value);
	return false;
}
function impbalancete() {
	var ano_bal = document.getElementsByName('ano_bal');
	var mes_bal = document.getElementsByName('mes_bal');
	window.open('imprime_balancete.php?ano='+ano_bal[0].value+"&mes="+mes_bal[0].value);
	return false;
}
function impcompra() {
	var dataini = document.getElementsByName('data_ini');
	var datafim = document.getElementsByName('data_fim');
	var cliente = document.getElementsByName('id_cli');
	window.open('relatorio_compras_gera.php?di='+dataini[0].value+"&df="+datafim[0].value+"&cli="+cliente[0].value);
	return false;
}
function impreceber() {
	var dataini = document.getElementsByName('data_ini');
	var datafim = document.getElementsByName('data_fim');
	var cliente = document.getElementsByName('id_cli');
	var abrange = document.getElementsByName('abrange');
	window.open('relatorio_receber_gera.php?di='+dataini[0].value+"&df="+datafim[0].value+"&cli="+cliente[0].value+"&abr="+abrange[0].value);
	return false;
}
function imppagar() {
	var dataini = document.getElementsByName('data_ini');
	var datafim = document.getElementsByName('data_fim');
	var cliente = document.getElementsByName('id_cli');
	var abrange = document.getElementsByName('abrange');
	window.open('relatorio_pagar_gera.php?di='+dataini[0].value+"&df="+datafim[0].value+"&cli="+cliente[0].value+"&abr="+abrange[0].value);
	return false;
}
/**  
 * Função para aplicar máscara em campos de texto
 * Copyright (c) 2008, Dirceu Bimonti Ivo - http://www.bimonti.net 
 * All rights reserved. 
 * @constructor  
 */ 
 
/* Version 0.27 */

/**  
  * Função Principal 
  * @param w - O elemento que será aplicado (normalmente this).
  * @param e - O evento para capturar a tecla e cancelar o backspace.
  * @param m - A máscara a ser aplicada.
  * @param r - Se a máscara deve ser aplicada da direita para a esquerda. Veja Exemplos.
  * @param a - 
  * @returns null  
  */
function maskIt(w,e,m,r,a){
    
    // Cancela se o evento for Backspace
    if (!e) var e = window.event
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    
    // Variáveis da função
    var txt  = (!r) ? w.value.replace(/[^\d]+/gi,'') : w.value.replace(/[^\d]+/gi,'').reverse();
    var mask = (!r) ? m : m.reverse();
    var pre  = (a ) ? a.pre : "";
    var pos  = (a ) ? a.pos : "";
    var ret  = "";

    if(code == 9 || code == 8 || txt.length == mask.replace(/[^#]+/g,'').length) return false;

    // Loop na máscara para aplicar os caracteres
    for(var x=0,y=0, z=mask.length;x<z && y<txt.length;){
        if(mask.charAt(x)!='#'){
            ret += mask.charAt(x); x++;
        } else{
            ret += txt.charAt(y); y++; x++;
        }
    }
    
    // Retorno da função
    ret = (!r) ? ret : ret.reverse()    
    w.value = pre+ret+pos;
}

// Novo método para o objeto 'String'
String.prototype.reverse = function(){
    return this.split('').reverse().join('');
};
