function rodaAjax(page){
	var ajaxTeste	= new ajax('GET', page, true, '', 'showConteudo');
	ajaxTeste.ajaxResponse();
	travaTela();
}

function showConteudo(tx_html) {
	// resolve problemas c/ acentuação [' e "]
	tx_html				= decodeURI(tx_html);
	// Pega elementos da div COLUNACTR
	var colunactr		= document.getElementById('colunactr');
	// escreve o retorno do AJAX na div
	colunactr.innerHTML	= tx_html;
	// remove o loadinf da tela
	loading(false);
	
	// Evita criar a div novamente
	if (!document.getElementById('colunactr')) {
		document.body.appendChild(colunactr);
	}

	window.setTimeout('destravaTela()', 100);
}

function rodaTudoSobre(page){
	var ajaxTeste	= new ajax('GET', page, true, '', 'showTudoSobre');
	ajaxTeste.ajaxResponse();
	travaTela();
}

function showTudoSobre(tx_html) {
	// resolve problemas c/ acentuação [' e "]
	tx_html				= decodeURI(tx_html);
	// Pega elementos da div COLUNACTR
	var conteudoTS		= document.getElementById('conteudoTS');
	// escreve o retorno do AJAX na div
	conteudoTS.innerHTML	= tx_html;
	// remove o loadinf da tela
	loading(false);
	
	// Evita criar a div novamente
	if (!document.getElementById('conteudoTS')) {
		document.body.appendChild(conteudoTS);
	}
	window.setTimeout('destravaTela()', 100);
}

/*# Utilizado para criar o efeito de loading */
function loading(opt) {
	if (opt == true) {
		// A tag que receberá a img de loading
		var colunactr = document.getElementById('colunactr');
		// Dizemos que os elementos dentro dela será alinhado ao centro
//		colunactr.style.textAlign = 'center';
		// Criamos uma imagem, img.
		var img = document.createElement('img');
		// Informamos o caminho da img
		img.setAttribute('src','imagens/loading.gif');
		// Setamos um atributo ID na img criada
		img.setAttribute('id','loading');
		// Dizemos que o margin-top será a metada do tamanho da div
		img.style.position = 'absolute'; //(bgBodyHeight[3]/2) + 'px';
		img.style.top = '400px'; //(bgBodyHeight[3]/2) + 'px';
		img.style.left = '180px'; //(bgBodyHeight[3]/2) + 'px';
		// Evita que seja criada duas ou mais img de loading
		if (!document.getElementById('loading')) {
			// Insere a img na tag informada na variável bgBody
			colunactr.insertBefore(img, colunactr.firstChild);
		}
	} else if (opt == false) {
		// Referenciamos a img de login através de seu ID
		var imgLoading = document.getElementById('loading');
		// Removemos a img de loading
		if (imgLoading) {
			imgLoading.parentNode.removeChild(imgLoading);
		}
	}
}

/* Retorna o tamanho da página */
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	
	return arrayPageSize;

}

/*# redireciona usuário
	@vc_redirect:String		=	página q o usuário será enviada
	@it_segundo	:Integer	=	número de segundos antes de redirecionar
								[opcional, padrão -> 3segundos]			*/
function redirect(vc_redirect, it_segundo) {
	it_segundo	= (it_segundo) ? parseInt(it_segundo * 1000) : 3000;
	setTimeout('self.location.href=\'' + vc_redirect + '\'', it_segundo)
}


function wordWrap(){
/******
* wordWrap - Efetua quebra em palavras que não cabem na largura
*            de seu elemento pai (até que chegue o CSS3)
* Use a vontade mas coloque meu nome nos créditos. Tenha ética.
* Dúvidas, me mande um email.
* Versão: 1.0 - 26/04/2006
* Autor: Micox - Náiron José C. Guimarães - micoxjcg@yahoo.com.br
* Uso: chame a função no onload do body.
*      coloque a classe "word-wrap" nos parágrafos que quiser a quebra
*******/
    var larg_total,larg_carac,quant_quebra,pos_quebra;
    var elementos,quem, caracs, texto, display_orig;
    
    elementos = document.getElementsByTagName("td")
    
    for(var i=0; i<elementos.length;i++){
        if(elementos[i].className=="td_01"){
            quem = elementos[i];
            
            quem.innerHTML = String(quem.innerHTML).replace(/ /g,"Ø")
            texto = String(quem.innerHTML)
            
            quem.innerHTML = " "
            
            display_orig = quem.style.display;
            quem.style.display="block";
            larg_oficial = quem.offsetWidth;
            //alert("oficial: " + larg_oficial)
            //alert("display " + quem.style.display)
            if(!document.all) quem.style.display="table";
            //alert("display " + quem.style.display)
            quem.innerHTML = texto;
            larg_total = quem.offsetWidth;
            //alert("total: " + larg_total)
            
            pos_quebra = 0;
            caracs = texto.length;
            texto = texto.replace(/Ø/g," ")
            larg_carac = larg_total / caracs
            if(larg_total>larg_oficial){
                quant_quebra = parseInt(larg_oficial/larg_carac)
                quant_quebra = quant_quebra - (parseInt(quant_quebra/6)) //quanto menor o num, maior a garantia;
                quem.innerHTML = ""
                while(pos_quebra<=caracs){
                    quem.innerHTML = quem.innerHTML + texto.substring(pos_quebra,pos_quebra + quant_quebra) + " "
                    pos_quebra = pos_quebra + quant_quebra;
                }
            }else{
                quem.innerHTML = texto;
            }//end if do larg_total>larg_oficial
            quem.style.display = display_orig;
        }//end if do word wrap
    }//end for loop dos elementos
}


/*# trava a tela com div branca c/ opacidade */
function travaTela() {
	// Seleciona a tag body. item(0) por que só existe uma tag body
	var tagBody						= document.getElementsByTagName('body').item(0);
	// Pega os tamanhos atuais da página, como largura, altura, ...
	var sizesPage					= getPageSize();
	// Vamos criar uma tag div
	var bgBody						= document.createElement('div');
	// Setar o atributo ID a div criada
	bgBody.setAttribute('id','bgBody');
	with (bgBody.style) {
		top				= '122px';
		left			= (sizesPage[0]-395)/2 + 'px';
		// Essa div terá o tamanho exato da página
		height			= sizesPage[1] + 'px';
		// Essa div terá a largura exata da página
		width			= '395px';
	}
	
	// Evita criar a div novamente
	if (!document.getElementById('bgBody')) {
		tagBody.insertBefore(bgBody, tagBody.firstChild);
	}	
}

/*# Destrava a tela */
function destravaTela() {
	if (document.getElementById('bgBody')) {
		var bgBody		= document.getElementById('bgBody');
		with (bgBody.parentNode) {
			removeChild(bgBody);
		}
	}
}


/*# mostra/esconde Curiosidades */
function showHideResposta(vc_obj,li_obj) {
	// verifica se o elemento existe
	if (document.getElementById(vc_obj)) {
		var obj_detalhe		= document.getElementById(vc_obj);
		var obj_lista		= document.getElementById(li_obj);
		
		if (obj_detalhe.style.display != 'none'){
	// define variáveis para diminuir a altura do iFrame
			var altura_pagina	= parent.document.getElementById('colunactr').offsetHeight;
			var altura_detalhe	= document.getElementById(vc_obj).offsetHeight;

	// apaga div de detalhe
			obj_detalhe.style.display	= 'none'
			obj_lista.style.backgroundPosition	= 'top left';

	// diminui altura do iFrame
			parent.document.getElementById('colunactr').style.height = altura_pagina - altura_detalhe +'px';
			parent.document.getElementById('the_iframe').style.height = altura_pagina - altura_detalhe +'px';
			
		}else{
	// mostra div de detalhe
			obj_detalhe.style.display	= 'inline'
			obj_lista.style.backgroundPosition	= 'top right';

	// define variáveis para diminuir a altura do iFrame
			var altura_pagina	= parent.document.getElementById('colunactr').offsetHeight;
			var altura_detalhe	= document.getElementById(vc_obj).offsetHeight;

	// aumenta altura do iFrame
			parent.document.getElementById('colunactr').style.height = altura_pagina + altura_detalhe +'px';
			parent.document.getElementById('the_iframe').style.height = altura_pagina + altura_detalhe +'px';
		}
	}
}

/*# redimensionamento */
function resizerTS(){
	var alturaDir		=	parent.document.getElementById('colunadir').offsetHeight;
	var alturaCenter	=	document.getElementById('container2').offsetHeight+40;

	
	if(alturaDir > alturaCenter){
		parent.document.getElementById('colunactr').style.height=parent.document.getElementById('colunadir').offsetHeight+'px';
		parent.document.getElementById('the_iframe').style.height=parent.document.getElementById('colunadir').offsetHeight+'px';
	}else{
		parent.document.getElementById('colunactr').style.height=document.getElementById('container2').offsetHeight+40+'px';
		parent.document.getElementById('the_iframe').style.height=document.getElementById('container2').offsetHeight+30+'px';
	}
}

function resizer(){
	parent.document.getElementById('colunactr').style.height=document.getElementById('container2').offsetHeight+40+'px';
	parent.document.getElementById('the_iframe').style.height=document.getElementById('container2').offsetHeight+30+'px';
}

function resizerProf(){
	var alturaDir		=	parent.document.getElementById('colunadir').offsetHeight;
	var alturaCenter	=	document.getElementById('container2').offsetHeight+40;

	if(alturaDir > alturaCenter){
		parent.document.getElementById('colunactr').style.height=parent.document.getElementById('colunadir').offsetHeight+'px';
		parent.document.getElementById('the_iframe').style.height=parent.document.getElementById('colunadir').offsetHeight+'px';
	}else{
		parent.document.getElementById('colunactr').style.height=document.getElementById('container2').offsetHeight+'px';
		parent.document.getElementById('the_iframe').style.height=document.getElementById('container2').offsetHeight+'px';
	}
}

function emailcuriosidade(id)
	{
window.open("email_curiosidade.asp?id="+id,"livro","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=380,height=300,top=20,left=20")
	}
	
function printcuriosidade(id)
	{
window.open("print_curiosidade.asp?id="+id,"livro","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=no,copyhistory=no,width=395,height=420,top=20,left=20")
	}
	
function trocaMenu(id_botao){
	parent.parent.document.getElementById('ebom_01').style.backgroundPosition='left';
	parent.parent.document.getElementById('ebom_02').style.backgroundPosition='left';
	parent.parent.document.getElementById('ebom_03').style.backgroundPosition='left';
	parent.parent.document.getElementById('ebom_04').style.backgroundPosition='left';
	parent.parent.document.getElementById('ebom_05').style.backgroundPosition='left';
	parent.parent.document.getElementById('ebom_06').style.backgroundPosition='left';
	parent.parent.document.getElementById('ebom_07').style.backgroundPosition='left';

	parent.parent.document.getElementById('esq_01').style.backgroundPosition='left';
	parent.parent.document.getElementById('esq_02').style.backgroundPosition='left';
	//parent.parent.document.getElementById('esq_03').style.backgroundPosition='left';
	parent.parent.document.getElementById('esq_04').style.backgroundPosition='left';
	//parent.parent.document.getElementById('esq_05').style.backgroundPosition='left';
	//parent.parent.document.getElementById('esq_06').style.backgroundPosition='left';
	parent.parent.document.getElementById('esq_07').style.backgroundPosition='left';
	parent.parent.document.getElementById('esq_08').style.backgroundPosition='left';
	//parent.parent.document.getElementById('esq_09').style.backgroundPosition='left';
	//parent.parent.document.getElementById('esq_10').style.backgroundPosition='left';
	
	if(id_botao){
		parent.parent.document.getElementById(id_botao).style.backgroundPosition='right';
	}
}

function boldText(id_tit){
	document.getElementById('e01').style.textDecoration='none';
	document.getElementById('e02').style.textDecoration='none';
	document.getElementById('e03').style.textDecoration='none';
	document.getElementById('e04').style.textDecoration='none';
	document.getElementById('e05').style.textDecoration='none';
	document.getElementById('e06').style.textDecoration='none';
		
	if(id_tit){
		document.getElementById(id_tit).style.textDecoration='underline';
	}
}

function boldText2(id_tit){
	document.getElementById('s01').style.textDecoration='none';
	document.getElementById('s02').style.textDecoration='none';
	document.getElementById('s03').style.textDecoration='none';
	
	if(id_tit){
		document.getElementById(id_tit).style.textDecoration='underline';
	}
}

function openGlossario(id) {
		window.open("glossario.asp?id="+id,"glossario","left=25,top=25,width=395,height=300,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no");
}

/*# aceita só números digitados num campo */
function soNumero(evtKeyPress) {
	var nTecla;
	nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
	
	if((nTecla > 47 && nTecla < 58) || nTecla == 8 || nTecla == 9 || nTecla == 37 || nTecla == 39 || nTecla == 46)
		return true;
	else
		return false;
}

/*# muda status através do resultado da pesquisa */
function changeStatus(obj_dd, vc_script) {
	codigo.location.href	= '../codigos/' + vc_script + '?act=5' + '&it_status=' + obj_dd.value + '&id=' + obj_dd.id;
}

/*# Exclui um registro */
function excluir(vc_pagina, id) {
	if (confirm('Deseja apagar o registro?')) codigo.location.href = '../codigos/' + vc_pagina + '?act=3&id='+id;
}

/*# Exclui imagem post */
function excluirImg(vc_pagina, id_blog, vc_imagem) {
	if (confirm('Deseja apagar a imagem?')) codigo.location.href = '../codigos/' + vc_pagina + '?act=4&id_blog='+id_blog+'&vc_imagem='+vc_imagem;
}
