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 janela_imagem() {
	//coloca o fundo preto
}

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


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";
	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.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);
	document.body.style.overflow = "auto";
}

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) {
	
	abre_fundo();
	
	div_jan = document.createElement("div");
	div_jan.setAttribute("id", "jan_imagem");
	div_jan.style.backgroundColor = "#FFF";
	div_jan.style.display = "block";
	div_jan.style.zIndex = "2001";	
	div_jan.style.position = "fixed";
	
	largura_jan = largura;
	div_jan.style.width = largura_jan+"px";
	
	altura_jan = altura+80;
	//div_jan.style.height = altura_jan+"px";
	
	largura_janela_visivel = document.body.clientWidth/2 + document.body.scrollLeft;
	esquerda = Math.ceil(largura_janela_visivel - largura_jan/2);
	if(esquerda<0) { esquerda = 0; }
	esquerda = esquerda+"px";
	div_jan.style.left = esquerda;
	
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	var scrolltop=document.all? iebody.scrollTop : pageYOffset	
	altura_janela_visivel = document.body.clientHeight/2 + scrolltop;
	// para position=absolute:
	//topo = Math.ceil(altura_janela_visivel - altura_jan/2); 
	// para position=fixed:
	topo = Math.ceil((document.body.clientHeight - altura_jan)/2);
	if(topo<0) { topo = 0; }
	topo = topo+"px";
	div_jan.style.top = topo;

	div_jan.onclick = new Function("fecha_jan()");
	titulo = (titulo=="")?(""):("<div class='titulo'>"+titulo+"</div>");
	imagem = (caminho=="")?(""):("<img src='"+caminho+"' width='"+largura+"' height='"+altura+"' title='Clique para fechar' class='imagem'>");
	legenda = (legenda=="")?(""):("<div class='legenda'>"+legenda+"</div>");
	div_jan.innerHTML = titulo+imagem+legenda;
	
	document.body.appendChild(div_jan);
	//Nifty('div#jan_imagem');

}

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