



function exibe_flash(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 abrir_video(url_video){	
	
	
document.write("<object id='player'>
<param name='AutoStart' value='true'>
<param name='URL' value="'+url_video+'">
<param name='uiMode' value='full'>
<embed src="'+url_video+'" name='player' width='500' height='500' type='video/x-ms-wmv-plugin' pluginurl='http://www.microsoft.com/windows/windowsmedia' allowchangedisplaysize='1' autosize='1' displaysize='1' showcontrols='1' showstatusbar='1' autorewind='1' autostart='1'>
</embed>
</object>");


}

*/


function exibir_fotos(pagina){ 
                                                                  
window.open(pagina,'pagina',"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,WIDTH=710,HEIGHT=440,top=130,left=270");	


}






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 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;
			}
}

	

 

