function substituir(texto,caractere_original,novo_caractere){
	while (texto.indexOf(caractere_original) != -1) {
 		texto = texto.replace(caractere_original,novo_caractere);
		}
	return texto;
	}

/////////////////////////////////////////////////////

function lote_proposta_insere(id_lote){
	
	texto = $("#cp_proposta").val();
	texto = substituir(texto,"+","__mais__");
	texto = escape(texto);

	if(texto==''){
		alert('Preencha sua proposta');
		return false;
		}

	carregaAjax('php/recinto_lote_proposta_insere.php?id_lote='+id_lote+'&texto='+texto,'dv_lote_prosposta_palco','dv_lote_prosposta_palco_carregando');
	
	}

/////////////////////////////////////////////////////

function lote_proposta(id){
	fn_ampliar_conteudo('php/recinto_lote_proposta.php?id_busca='+id,600,20);	
	}

/////////////////////////////////////////////////////

function ocultaCorte(alvo,funcao,vars){
	
	if(typeof(alvo)=='string'){
		alvo = document.getElementById(alvo);
		}
	
	$(alvo).slideUp("fast",function(){
									 if(funcao!=undefined){
										exec = funcao;
										exec(vars);
										}
									 });
	}
	
/////////////////////////////////////////////////////

function exibeCorte(alvo,funcao,vars){
	
	if(typeof(alvo)=='string'){
		alvo = document.getElementById(alvo);
		}
	
	$(alvo).slideDown("fast",function(){
									 if(funcao!=undefined){
										exec = funcao;
										exec(vars);
										}
									 });
	
	}
	
/////////////////////////////////////////////////////

function fn_ampliar_conteudo(url,largura,topo,funcao,vars,drag){
	
		if(drag==undefined){
			drag='s';
			}
	
		margem_topo = $(window).scrollTop();
		topo = topo+margem_topo;

		var n = $("#dv_ampliar").length;
		
		if(n==0){
$('<style>#dv_ampliar{ position:absolute; left:0px; top:0px; width:100%; height:100%; z-index:500; } #dv_ampliar_fundo{ position:absolute; left:0px; top:0px; background-color:#000000; width:100%; height:100%; z-index:501; filter: Alpha(Opacity=40); opacity: .4; } #btn_fechar_ampliado{ cursor:pointer;  position:absolute;  right:15px;  top:15px;  z-index:1001 } #dv_ampliar_borda_top_esq,#dv_ampliar_borda_top_dir,#dv_ampliar_borda_top,#dv_ampliar_borda_esq,#dv_ampliar_borda_dir,#dv_ampliar_borda_bot_esq,#dv_ampliar_borda_bot_dir,#dv_ampliar_borda_bot{ position:absolute; z-index:1000; background-repeat:repeat; clear:both; } #dv_ampliar_borda_top_esq{ left:0px; top:0px; background-image:url(imagens/ampliar/ampliar_top_esq.png); width:20px; height:20px; } #dv_ampliar_borda_top_dir{ right:0px; top:0px; background-image:url(imagens/ampliar/ampliar_top_dir.png); width:20px; height:20px; }		 #dv_ampliar_borda_top{ left:20px; right:20px; top:0px; background-image:url(imagens/ampliar/ampliar_top.png); height:20px; } #dv_ampliar_borda_esq{ left:0px; top:20px; width:20px; bottom:20px; background-image:url(imagens/ampliar/ampliar_esq.png); } #dv_ampliar_borda_dir{ right:0px; top:20px; width:20px; bottom:20px; background-image:url(imagens/ampliar/ampliar_dir.png); } #dv_ampliar_borda_bot_dir{ right:0px; bottom:0px; background-image:url(imagens/ampliar/ampliar_bot_dir.png); width:20px; height:20px; } #dv_ampliar_borda_bot_esq{ left:0px; bottom:0px; background-image:url(imagens/ampliar/ampliar_bot_esq.png); width:20px; height:20px; }	 #dv_ampliar_borda_bot{ left:20px; right:20px; bottom:0px; background-image:url(imagens/ampliar/ampliar_bot.png); height:20px; }							 #dv_ampliar_palco{ position:relative; left:50%; top:20px; z-index:1001; } #dv_conteudo_ampliado{ position:relative; left:0px; top:0px; display:table; z-index:1000; } #dv_ampliar_conteudo_palco{ position:relative; left:0px; top:0px; display:table; clear:both; background-color:#FFFFFF; } </style><div id="dv_ampliar"><div id="dv_ampliar_palco"><img id="btn_fechar_ampliado" src="imagens/icones/fechar.jpg"><div id="dv_ampliar_borda_top_esq"></div><div id="dv_ampliar_borda_top"></div><div id="dv_ampliar_borda_top_dir"></div><div id="dv_ampliar_borda_dir"></div><div id="dv_ampliar_borda_esq"></div><div id="dv_ampliar_borda_bot_esq"></div><div id="dv_ampliar_borda_bot"></div><div id="dv_ampliar_borda_bot_dir"></div><div id="dv_conteudo_ampliado"><div style="margin:20px;background-color:#FFFFFF;"><div id="dv_ampliar_conteudo_palco"></div></div></div></div><div id="dv_ampliar_carregando"></div><div id="dv_ampliar_fundo"></div></div>').appendTo("body")

				$("#dv_ampliar_fundo").click(function(event){
					ocultaCorte('dv_ampliar');
				 	});
				
				$("#btn_fechar_ampliado").click(function(event){
					ocultaCorte('dv_ampliar');
				 	});

				 if(drag=='s'){
				 	$("#dv_ampliar_palco").draggable();
				 	}
				 
			} else {
			 exibeCorte('dv_ampliar');
			}

		carregaAjax(url,'dv_ampliar_conteudo_palco','dv_ampliar_carregando',funcao,vars);

		//OCULTAR AO ESC
		$(document).one("keydown", function(event){
					if(event.keyCode==27){
						ocultaCorte('dv_ampliar');
						}
					});

		altura = $(document).height();
		if((largura=='') || (largura==undefined)){
			largura=780;
			}
		if((topo=='') || (topo==undefined)){
			topo=20;
			}
		
		largura = largura+40;
		margem_esq = largura-(largura+(largura/2));
		
		if(drag=='s'){
			$("#dv_ampliar_palco").draggable();
			} else {
			$("#dv_ampliar_palco").draggable('disable');	
			}
		
		$("#dv_ampliar").css("height",altura+"px");
		$("#dv_ampliar_palco").css("width",largura+"px");
		$("#dv_ampliar_palco").css("margin-left",margem_esq+"px");
		$("#dv_ampliar_palco").css("margin-top",topo+"px");
		}


function anuncio_clique(id,hiperlink,janela){
	$.ajax(
		{
		  url: 'anuncio_registra_clique.php?id_busca='+id,
		  cache: false,
		  beforeSend: function(){
		  		},
		  success: function(html){
			  	if(janela=='n'){
		  			window.location.href=hiperlink;
					} else {
					window.open(hiperlink,'janela');	
					}
				}
			}
		);
	}

function navegador(){

	var navegador = window.navigator.userAgent;
  	if(navegador.indexOf('Firefox')!=-1){
		return "Firefox";
		}
	if(navegador.indexOf('WebKit')!=-1){
		return "WebKit";
		}
	if(navegador.indexOf('MSIE')!=-1){
		return "IE";
		}

	}

function relogio(){ 
		var restante = document.getElementById('tempo_restante').childNodes[0].nodeValue;
		restante = restante-1
		
		var completo='';
		
		var dias = parseInt(restante/86400);		
		if(dias>0){
			
				if(dias==1){
					var rotulo_dias='dia';
					} else {
					var rotulo_dias='dias';
					}
				completo+=dias+' '+rotulo_dias;
			
			}
			
		var restante_horas = parseInt(restante%86400);
		var horas = parseInt(restante_horas/3600);
		
		if(horas>0){
			
			if(dias>0){
				completo+=' e ';
				}
			
				if(horas==1){
					var rotulo_horas='hora';
					} else {
					var rotulo_horas='horas';
					}
				completo+=' '+horas+' '+rotulo_horas;
			
			}
		
		var restante_minutos = parseInt(restante_horas%3600);
		var minutos = parseInt(restante_minutos/60);
	
	if(restante<86400){
			if(minutos>0){
				
					if(minutos==1){
						var rotulo_minutos='minuto';
						} else {
						var rotulo_minutos='minutos';
						}
					completo+=' '+minutos+' '+rotulo_minutos;
				
				}
			
			var segundos = parseInt(restante_minutos%60);
			
				if(segundos==1){
					var rotulo_segundos='segundo';
					} else {
					var rotulo_segundos='segundos';
					}
					
				completo+=' '+segundos+' '+rotulo_segundos;
			}
			
			
			document.getElementById("tempo_restante").childNodes[0].nodeValue = restante;
			document.getElementById("tempo_exibe").childNodes[0].nodeValue = completo;
			
			if(restante==0){
				document.location.reload();
				}
				
			if(restante>0){
				setTimeout("relogio()",1000) 
				}

		} 
		
function numeros(e){

	
	  if(navigator.appName=="Microsoft Internet Explorer"){ // Internet Explorer
		 var tecla = event.keyCode;
	 	 } else {
		 var tecla = e.which;
		 }
	
	  if(tecla > 47 && tecla < 58) // numeros de 0 a 9
		 return true;
	  else {
			if (tecla != 8) // backspace
			  return false;
			else
			  return true;
		 }
	}

function mudarEstilo(alvo,estilo){
	alvo = document.getElementById(alvo);
	alvo.className=estilo;
	}

function alternaEstilo(alvo,estilo1,estilo2){
	alvo = document.getElementById(alvo);
	if(alvo.className==estilo1){
			alvo.className=estilo2;
		} else {
			alvo.className=estilo1;
		}
	}

function mudar_abas(total,atual) {
	for(i=1;i<=total;i++){
		document.getElementById("aba_"+i).className="aba_off";
		}
		document.getElementById("aba_"+atual).className="aba_on";
}
function mudarImg(id,img) {
		alvo = document.getElementById(id)
		alvo.src=img;
}
function mudarImgFundo(id,img) {
		alvo = document.getElementById(id)
		alvo.style.backgroundImage='url('+img+')';
	}
function mudarImagens(imagem,alvo){
	document.images[alvo].src = imagem;
	}
	
//////////////////////////////////////////////////////////

function carregaAjax(url,alvo,carregando,funcao,vars){

	if(typeof(alvo)=='string'){
		alvo = document.getElementById(alvo);
		}
	if(typeof(carregando)=='string'){
		carregando = document.getElementById(carregando);
		}

	$.ajax(
		{
		  url: url,
		  cache: false,
		  beforeSend: function(){
			  	if((carregando!=undefined) && (carregando!='')){
		  			$(carregando).show();
					}
				if((alvo!=undefined) && (alvo!='')){	
					$(alvo).hide();
					}
		  		},
		  success: function(html){
		  		if((carregando!=undefined) && (carregando!='')){
					$(carregando).hide();
					}
				if((alvo!=undefined) && (alvo!='')){	
					$(alvo).show();
					$(alvo).html(html);
					}
				
				if(funcao!=undefined){
					if(funcao!=''){
						
						exec = funcao;
						if(vars!=undefined){
							if(vars!=''){
								exec(vars);
								} else {
								exec();			
								}
							} else {
							exec();	
							}
						}
					}
				
				}
			}
		);
	}

/*

function carregaAjax(url,alvo,carregando){
	$.ajax(
		{
		  url: url,
		  cache: false,
		  beforeSend: function(){
		  		$(carregando).show();
				$(alvo).hide();
		  		},
		  success: function(html){
		  		$(carregando).hide();
				$(alvo).show();
				$(alvo).html(html);
				//$("#conteudo").innerHTML(html); -> ADICIONAR AO CONTEUDO EXISTENTE
				}
			}
		);
	}

*/

///////////////////////////////////////////////////////

function ampliarFoto(foto,legenda){
			tabelafoto = document.getElementById("tabelatransparenciafotoampliada")
			tabelafoto1 = document.getElementById("basefotoampliada")
			tabelafoto1.style.paddingTop=document.body.scrollTop

			var alturatabela = document.body.scrollHeight ;
			tabelafoto.height = alturatabela;

			var alturaTelaCheia = screen.availHeight;
			if(alturaTelaCheia>alturatabela){
				alturatabela = alturaTelaCheia;
				}
				
			tabelafoto1.style.height = screen.availHeight-50;

			alvo = document.getElementById("fotoAmpliada")
			
			if(alvo.style.display=="inline"){
				
					alvo.style.display="none"	
					document.images["foto_ampliada"].src = "imagens/carregando2.gif";
					document.getElementById("legendafotoampliada").childNodes[0].nodeValue = "";
				
					} else {
					
						alvo.style.display="inline"
						
						var imagem_preview = new Image(420,420)
						imagem_preview.src = foto;
					
						var intervalo_foto_ampliada = window.setInterval(
							
							function (){
						
								if(imagem_preview.complete){
									document.images["foto_ampliada"].src = foto;
									document.getElementById("legendafotoampliada").childNodes[0].nodeValue = legenda
									clearInterval(intervalo_foto_ampliada);
									}
									
							}
					,1000);
		
					}
			}

function mudaDisplay(alvo){
	alvo = document.getElementById(alvo)
	if(alvo.style.display=="block"){
		alvo.style.display="none"
		} else {
		alvo.style.display="block"
		}
	}
	
function exibe(alvo){
	alvo = document.getElementById(alvo)
	alvo.style.display="block"
	}
	
function oculta(alvo){
	alvo = document.getElementById(alvo)
	alvo.style.display="none"
	}
	
function mudarTexto(alvo,conteudo){
	document.getElementById(alvo).innerHTML = conteudo;
	}
	
function mudarSrcIframe(alvo,arquivo){
	document.getElementById(alvo).src= arquivo;
	}
	
function pos_x(posicao, alvo){
		$(document).ready(function() {
			$(alvo).animate({left: posicao}, "normal");
		});
	}
	
function pos_y(posicao, alvo){
		$(document).ready(function() {
			$(alvo).animate({top: posicao}, "normal");
		});
	}
	
function tam_x(posicao, alvo){
		$(document).ready(function() {
			$(alvo).animate({width: posicao}, "normal");
		});
	}
	
function tam_y(posicao, alvo){
		$(document).ready(function() {
			$(alvo).animate({height: posicao}, "normal");
		});
	}
	
function verificarCamposForm(campo,form){
	if (document.forms[form].elements[campo].value=="") {
	alert("Preencha o campo selecionado!")
		document.forms[form].elements[campo].focus();
		document.forms[form].elements[campo].className="erro";
		return false
		} else {
		document.forms[form].elements[campo].className="";
		return true
		}
	}

function mudarCorFundo(elem,cor) {
	if (elem.style) {
		elem.style.backgroundColor = cor
		}
	}
function mudarBorda(alvo,cor){
		alvo_borda = document.getElementById(alvo);
		alvo_borda.style.borderColor=cor;
		}