function ampliar(figura,texto,creditos) {
  url = "janfiguras.php?figura="+figura+"&texto="+texto+"&creditos="+creditos
  window.open(url ,"imagem","resizable,width=500px,height=450px,scrollbars=no")
}

function vai(endereco) {
  window.document.location.href = endereco;
}

function indique() {
  endereço = escape(window.document.location.href);
  window.open("indique.php?urlpagina="+endereço,"indique","width=380,height=302")
}

function addSWF (URL, WIDTH, HEIGHT, TRANSPARENT) {
  document.write (' <object classid="clsid:27CDB6E-AE6D-11cf-96B8-444553540000" ');
  document.write (' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" ');
  document.write (' width="'+ WIDTH +'" height="'+ HEIGHT +'">');
  document.write (' <param name="movie" value="'+ URL +'" />');
  document.write (' <param name="quality" value="high" />');
  if ( TRANSPARENT ) {
    document.write (' <param name="Wmode" value="Transparent" />'); 
  }
  document.write (' <embed src="'+ URL +'" quality="high" ');
  if ( TRANSPARENT ) {
    document.write (' Wmode = "transparent" ');
  }
  document.write (' pluginspage="http://www.macromedia.com/go/getflashplayer" ');
  document.write (' type="application/x-shockwave-flash" width="'+ WIDTH +'" height="'+ HEIGHT +'"></embed> ');
  document.write (' </object>');
}

function limpa_texto (texto,objeto) {
  if(objeto.value==texto){
    objeto.value='';
  }
}

function volta_texto (texto,objeto) {
  if(objeto.value==''){
    objeto.value=texto;
  }
}

function mostradorflutuante(mostrador,exibe) {
  // define o objeto mostrador
  if (mostrador != "") {
    if (document.layers){
      mostrador = document.layers[mostrador]; //nn
    } else {
      if (document.all){
        mostrador = document.all[mostrador]; 
      } else {
        if (document.getElementById){
          mostrador = document.getElementById(mostrador)
        }
      }
    }
  }
  if(exibe) {
    mostrador.style.display = "block";
  } else {
    mostrador.style.display = "none";
  }
}

function loja_amplia_foto(cod,largura,altura) {
  window.open("loja_amplia_foto.php?cod="+cod,"loja_amplia_foto","width="+largura+",height="+altura)
}


function pega_obj(nome) {
  if (document.layers) {
    nome = document.layers[nome];
  } //nn
  else {
    if (document.all) {
      nome = document.all[nome];
    } //ie6
    else {
      if (document.getElementById) {
        nome = document.getElementById(nome)
      }
    }
  } //ff
  return nome;
}



function zoom(acao,estilo) {

  var isIE = (/\bmsie\b/i.test(navigator.userAgent) // é Internet Explorer?

    && document.all && !(/\bopera\b/i.test(navigator.userAgent)));

  // propriedades que mudam de nome do IE para o Mozilla...

  var nome_da_regra = isIE ? 'rules' : 'cssRules';

  var no_dom = isIE ? 'owningElement' : 'ownerNode';

  var stl = document.styleSheets;

  for(var i = 0; i < stl.length; i++) { // para cada elemento de estilo na página

    for(var g = 0; g < stl[i][nome_da_regra].length; g++) { // para cada regra desse elemento

      if(stl[i][nome_da_regra][g].selectorText == estilo) {

        fontSize = parseInt(stl[i][nome_da_regra][g].style.fontSize);

        if(!isNaN( fontSize ) ){

          if(fontSize < 18 && acao == '+') {

            stl[i][nome_da_regra][g].style.fontSize = fontSize+1;

          }

          if(fontSize > 8 && fontSize < 20 && acao == '-') {

            stl[i][nome_da_regra][g].style.fontSize = fontSize-1;

          }

        }

      }

    }

  }

}



function abre_fundo2 () {
  div_temp = document.createElement("div");
  div_temp.setAttribute("id", "jan_fundo");
  div_temp.style.backgroundColor = "#000";
  div_temp.style.display = "block";
  div_temp.style.zIndex = "2000";
  div_temp.style.width = document.body.scrollWidth*4;
  div_temp.style.height = document.body.scrollHeight*4;
  div_temp.style.top = "0px";
  div_temp.style.left = "0px";
  div_temp.style.position = "absolute";
  div_temp.style.opacity = ".8";
  div_temp.style.MozOpacity = "0.8";
  div_temp.style.filter = "alpha(opacity=80)";
  div_temp.onclick = new Function("fecha_jan()");
  document.body.appendChild(div_temp);
  document.body.style.overflow = "hidden";
}


function fecha_fundo () {
  document.body.removeChild(pega_obj("jan_fundo"));
  document.body.style.overflow = "auto";
}


function fecha_jan () {
  document.body.removeChild(pega_obj("jan_fundo"));
  document.body.removeChild(pega_obj("jan_imagem"));
  document.body.style.overflow = "auto";
}

function abre_imagem(caminho,largura,altura,titulo,legenda,autor) {	
  cria_fundo();	

  div_jan = document.createElement("div");
  div_jan.setAttribute("id", "Lbox");
  div_jan.style.zIndex = "2001";	
  div_jan.style.display = "none";
  div_jan.style.position = "absolute";

  largura_janela_visivel = document.body.clientWidth/2 + document.body.scrollLeft;
  esquerda = Math.ceil(largura_janela_visivel - largura/2)+"px";
  div_jan.style.left = esquerda;	

  altura_janela_visivel = document.body.clientHeight/2 + document.body.scrollTop;
  topo = Math.ceil((altura_janela_visivel - altura/2)-30);
  if(topo<0) {
    topo = 0;
  }
  topo = topo+"px";	
  div_jan.style.top = topo;

  div_jan.onclick = new Function("remove_fundo('#Lbox')");
  if(autor!="") {
    autor = " <span>Foto: "+autor+"</span>";
    if(legenda!="") {
      autor = "<br>"+autor;
    }
  }
  div_jan.innerHTML = "<div class='titulo'>"+titulo+"</div><div class='autor'>"+autor+"</div><img src='"+caminho+"' width='"+largura+"' height='"+altura+"' title='Clique para fechar'><div class='legenda'>"+legenda+autor+"</div>";	

  document.body.appendChild(div_jan);
  $("#Lbox").slideDown(500);

}


function cria_fundo() {
  //usa jquery para criar um fundo
  pag = tamanhoPagina();
  largura_janela = pag[0];
  altura_janela = pag[1];
  if ($('#jan_fundo_dinamico').length) {
  } else {
    html_fundo = '<div id="jan_fundo_dinamico" style="position:absolute;top:0;left:0;background-color:#000;display:none;z-index:2000;width:'+largura_janela+'px;height:'+altura_janela+'px"></div>';
		
    $("body").append(html_fundo);
    $("#jan_fundo_dinamico").css("opacity", 0.7).show();
    $("#jan_fundo_dinamico").click(function() {
      remove_fundo();
    });
  }
}


function remove_fundo() {
  if ($('#jan_fundo_dinamico').length ) {
    $("#Lbox").slideUp("fast",function() { 
      $("#Lbox").remove(); 
    });
    $("#jan_fundo_dinamico").slideUp().fadeIn().remove();
  } else {
    alert("não tem nada para ocultar");
  }
}




function formatar_mascara(src, mascara, evento) {

  /*
	exemplo de aplicação para CEP:
	onkeydown="formatar_mascara(this, '#####-###', event)"
	*/

  //exceto as teclas necessárias para a edição de texto:

  if(
    evento.keyCode == '8'  || //backspace
    evento.keyCode == '46' || //delete
    evento.keyCode == '37' || //seta esq
    evento.keyCode == '39' || //seta dir
    evento.keyCode == '36' || //home
    evento.keyCode == '35' || //end
    evento.keyCode == '9'  || //tab
    evento.keyCode == '45' //insert
    ) {
    return true;
  }

  var campo = src.value.length;
  var saida = mascara.substring(0,1);
  var texto = mascara.substring(campo);
	
  if(texto.substring(0,1) != saida) {
    src.value += texto.substring(0,1);
  }

}



function number_format( number, decimals, dec_point, thousands_sep ) {

  // %        nota 1: Para 1000.55 retorna com precisão 1 no FF/Opera é 1,000.5, mas no IE é 1,000.6
		
  // *     exemplo 1: number_format(1234.56);
  // *     retorno 1: '1,235'
		
  // *     exemplo 2: number_format(1234.56, 2, ',', ' ');
  // *     retorno 2: '1 234,56'
		
  // *     exemplo 3: number_format(1234.5678, 2, '.', '');
  // *     retorno 3: '1234.57'
		
  // *     exemplo 4: number_format(67, 2, ',', '.');
  // *     retorno 4: '67,00'
		
  // *     exemplo 5: number_format(1000);
  // *     retorno 5: '1,000'
		
  // *     exemplo 6: number_format(67.311, 2);
  // *     retorno 6: '67.31'

  var n = number, prec = decimals;
  n = !isFinite(+n) ? 0 : +n;
  prec = !isFinite(+prec) ? 0 : Math.abs(prec);
  var sep = (typeof thousands_sep == "undefined") ? ',' : thousands_sep;
  var dec = (typeof dec_point == "undefined") ? '.' : dec_point;
 
  var s = (prec > 0) ? n.toFixed(prec) : Math.round(n).toFixed(prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;

  var abs = Math.abs(n).toFixed(prec);
  var _, i;
 
  if (abs >= 1000) {
    _ = abs.split(/\D/);
    i = _[0].length % 3 || 3;
 
    _[0] = s.slice(0,i + (n < 0)) +
    _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
 
    s = _.join(dec);
  } else {
    s = s.replace('.', dec);
  }
 
  return s;
}

function tamanhoPagina(){
  if (window.innerHeight && window.scrollMaxY) {// Firefox
    var	y = window.innerHeight + window.scrollMaxY;
    var	x = window.innerWidth + window.scrollMaxX;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    var	y = document.body.scrollHeight;
    var	x = document.body.scrollWidth;
  } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    var	y = document.body.offsetHeight;
    var	x = document.body.offsetWidth;
  }
  var array_tamanho_da_pg_com_rolagem = new Array(x,y);
  return array_tamanho_da_pg_com_rolagem;
}


function abre_imagem2(caminho,largura,altura,titulo,legenda) {
  cria_fundo();
  pega_obj(camada).style.display = "block";
  altura_subcamada = pega_obj(camada).clientHeight;
  altura_janela_visivel = document.body.clientHeight/2 + document.body.scrollTop;
  topo = Math.ceil(altura_janela_visivel - altura_subcamada/2)+"px";	
  largura_subcamada = pega_obj(camada).clientWidth;
  largura_janela_visivel = document.body.clientWidth/2 + document.body.scrollLeft;
  esquerda = Math.ceil(largura_janela_visivel - largura_subcamada/2)+"px";
  pega_obj(camada).style.left = esquerda;
  pega_obj(camada).style.top = topo;
}

function abre_janela (camada,fundo) {
  cria_fundo();
  pega_obj(camada).style.display = "block";
  altura_subcamada = pega_obj(camada).clientHeight;
  altura_janela_visivel = document.body.clientHeight/2 + document.body.scrollTop;
  topo = Math.ceil(altura_janela_visivel - altura_subcamada/2)+"px";	
  largura_subcamada = pega_obj(camada).clientWidth;
  largura_janela_visivel = document.body.clientWidth/2 + document.body.scrollLeft;
  esquerda = Math.ceil(largura_janela_visivel - largura_subcamada/2)+"px";
  pega_obj(camada).style.left = esquerda;
  pega_obj(camada).style.top = topo;
}
function fecha_janela (camada) {
  remove_fundo();
  pega_obj(camada).style.display = "none";
}

function abre_fundo () {
  var div_temp = document.createElement("div");
  div_temp.setAttribute("id", "jan_fundo");
  div_temp.style.backgroundColor = "#000";
  div_temp.style.display = "block";
  div_temp.style.zIndex = "2000";
  var pag = tamanhoPagina();
  div_temp.style.width = pag[0]+"px";
  div_temp.style.height = pag[1]+"px";
  div_temp.style.top = "0px";
  div_temp.style.left = "0px";
  div_temp.style.position = "absolute";
  //div_temp.style.float = "left";
  div_temp.style.opacity = ".7";
  div_temp.style.MozOpacity = "0.7";
  div_temp.style.filter = "alpha(opacity=70)";
  // div_temp.onclick = new Function("fecha_jan()");
  document.body.appendChild(div_temp);
}

