function vai() {
self.scrollTo(0, 100)
}

function topo_pagina() {
self.scrollTo(0, 100)
}

var contador=0;

function incrementar()
{
  contador++;
  
  alert('El contador ahora vale :' + contador);
}


function alterar(valor,id,maximo){ 
obj = document.getElementById(id);
v = Number(obj.value) + Number(valor);
if(v<1){v=1;}
if(v>maximo){v=maximo;}
obj.value = v;
}







function exibir_fotos(pagina){ 
                                                                  
window.open(pagina,'pagina',"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,WIDTH=700,HEIGHT=460,top=130,left=270");	


}


function enviar_amigo(pagina){ 
                                                                  
window.open(pagina,'pagina',"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,WIDTH=600,HEIGHT=520,top=130,left=270");	


}


function enter(myform) {	
  if (window.event && window.event.keyCode == 13)
	  formulario.submit();  
  else
    return true;
}


function enter_cep() {
ajax('cep_pesquisa_lista_ajax.php','span_resultado_pesquisa_cep','POST', 'formulario'); limpa('span_cep');
}





function writeFlash_terminal(id,caminho,largura,altura) {

    document.getElementById(id).innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='"+largura+"' height='"+altura+"' id='myflash' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='"+caminho+"' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><embed src='"+caminho+"' quality='high' bgcolor='#ffffff' width='"+largura+"' height='"+altura+"' name='mymovie' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}
function writeFlash_terminal2(id,caminho,largura,altura) {


    document.getElementById(id).innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='"+largura+"' height='"+altura+"' id='myflash' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='"+caminho+"' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><embed src='"+caminho+"' quality='high' bgcolor='#ffffff' width='"+largura+"' height='"+altura+"' name='mymovie' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}


function writeFlash_terminal3(id,caminho,largura,altura) {


    document.getElementById(id).innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' align='left' width='"+largura+"' height='"+altura+"' id='myflash' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='"+caminho+"' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><embed src='"+caminho+"' quality='high' bgcolor='#ffffff' width='"+largura+"' height='"+altura+"' name='mymovie'  allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}






function abrir_cadastro_marca(pagina){ 
                                                                  
window.open(pagina,'pagina',"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,WIDTH=760,HEIGHT=350,top=130,left=270");	


}


function fechar_marca_produto(pagina){ 
                                                                  
window.close('marca_produto_apaga.php');

}



function percorre(obj) {
	var string = "";

	var child = obj.firstChild;
	while(child) {
		if (child.nodeType == 1) 
			if (child.tagName == "INPUT" && (child.type == "text" || child.type == "hidden") || child.tagName == "TEXTAREA") 
				string += (child.name + "=" + encodeURIComponent(child.value) + "&");
			else if (child.tagName == "INPUT" && (child.type == "radio" || child.type == "checkbox") && child.checked ) 
				string += (child.name + "=" + encodeURIComponent(child.value) + "&");
			else if (child.tagName == "SELECT")
				string += (child.name + "=" + encodeURIComponent(child.options[child.selectedIndex].value) + "&");
	
		string += percorre(child);
		child = child.nextSibling;
		}
	return string;		
	}

function escolhe_pessoa(valor, campo, id_pessoa) {
			
	if(valor== "fisica"){
		ajax("pessoa_fisica.php?ajax=1&id_pessoa="+id_pessoa,campo);
	}
	else{
		
	ajax("pessoa_juridica.php?ajax=1&id_pessoa="+id_pessoa,campo);
	}
	
	}
	
	
	


/*function lerolero() {
	
	 window.setInterval(outro(), 1000000);
	 clearInterval(intervalo);

}


function outro()
{
	ajax2('include/direito_minhas_compras.php?sessao=1','atualizar_carrinho', 'POST','formulario2');

}*/


	
	
	

	 function chama_pagina(){
	 	
 	 	window.setTimeout(chama_ajax(),100000);
 	}
	
	
   
 	 function chama_ajax(){ 
		ajax('include/direito_minhas_compras.php?sessao=1','atualizar_carrinho', 'GET',null);
	 } 

	
	
	
	
	
	
	
	
function cpf_site(valor, campo, id_pessoa) {
			
	if(valor== "fisica"){
		ajax("pessoa_fisica_site.php?ajax=1&id_pessoa="+id_pessoa,campo);
	}
	else{
		
	ajax("pessoa_juridica_site.php?ajax=1&id_pessoa="+id_pessoa,campo);
	}
	
	}
	
	
	
function escolhe_pessoa2(valor, campo, id_pessoa) {
	if(valor== "fisica")
		ajax("cliente_pesquisa_pessoa_fisica.php?ajax=1&id_pessoa="+id_pessoa,campo);
	if(valor== "juridica")
		ajax("cliente_pesquisa_pessoa_juridica.php?ajax=1&id_pessoa="+id_pessoa,campo);
	
	}
	
function limpa (campo) {
	document.getElementById(campo).innerHTML ='';
	}
	
function formatar(src, mask) {
	var i = src.value.length;
	var saida = '#';
	var texto = mask.substring(i);
	if (texto.substring(0,1) != saida)
		src.value += texto.substring(0,1);
	}

function envia (formulario, url) {
	formulario = document.getElementById(formulario);
	formulario.action = url;
	formulario.submit();	
	}

function show(id_div,img, ap_patrocinador) {
	url = "rede_ajax.php?ap_patrocinador="+ap_patrocinador;
	

	if(id_div.style.display == 'block')
		id_div.style.display = 'none';
	else {
		id_div.style.display = 'block';
		ajax(url,id_div.id);
		}
		
	if(img.src.indexOf('img/icones/up.gif') > 0)
		img.src = "img/icones/down.gif";
	else 
		img.src = "img/icones/up.gif";
	}
	


function FormataValor(objeto, teclapres, tammax, decimais) {
	var tecla			= teclapres.keyCode;
	var tamanhoObjeto	= objeto.value.length;

	if ((tecla == 8) && (tamanhoObjeto == tammax))
		tamanhoObjeto = tamanhoObjeto - 1 ;



	if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax)) {
		
		vr	= objeto.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 > 1)){
			tam = tam - 1 ;
			vr = objeto.value;
			vr = vr.replace( "/", "" );
			vr = vr.replace( "/", "" );
			vr = vr.replace( ",", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			}
	
		//Cálculo para casas decimais setadas por parametro
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
			if (decimais > 0) {
				if ( (tam <= decimais) )
					objeto.value = ("0," + vr) ;
					
				if( (tam == (decimais + 1)) && (tecla == 8))
					objeto.value = vr.substr( 0, (tam - decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;	
					
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) == "0"))
					objeto.value = vr.substr( 1, (tam - (decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
					
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) != "0"))
				    objeto.value = vr.substr( 0, tam - decimais ) + ',' + vr.substr( tam - decimais, tam ) ; 
					
				if ( (tam >= (decimais + 4)) && (tam <= (decimais + 6)) )
			 		objeto.value = vr.substr( 0, tam - (decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;

			 	if ( (tam >= (decimais + 7)) && (tam <= (decimais + 9)) )
			 		objeto.value = vr.substr( 0, tam - (decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;

				if ( (tam >= (decimais + 10)) && (tam <= (decimais + 12)) )
			 		objeto.value = vr.substr( 0, tam - (decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;

				if ( (tam >= (decimais + 13)) && (tam <= (decimais + 15)) )
			 		objeto.value = vr.substr( 0, tam - (decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;

			}
			else if(decimais == 0) {
				if ( tam <= 3 )
			 		objeto.value = vr ;
					
				if ( (tam >= 4) && (tam <= 6) ) {
					if(tecla == 8) {
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
						}
					objeto.value = vr.substr(0, tam - 3) + '.' + vr.substr( tam - 3, 3 ); 
					}
					
				if ( (tam >= 7) && (tam <= 9) ) {
					if(tecla == 8) {
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
						}
					objeto.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
					}

				if ( (tam >= 10) && (tam <= 12) ) {
			 		if(tecla == 8) {
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
						}
					objeto.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
					}

				if ( (tam >= 13) && (tam <= 15) ){
					if(tecla == 8) {
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
						}
					objeto.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, 3 ) ;
					}			
				}
			}
		}
	else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46)) {
			window.event.cancelBubble = true;
			window.event.returnValue = false;
			}
}

	

 
