
// JavaScript Document
function startHint(param){
	var hintDiv = document.getElementById('suggest');
	if (param){
		hintDiv.style.display = 'block';
		sugestSearch(param);
		}
	else{
		hintDiv.style.display = 'none';
		}
	}
function destroyHint(){
	delayhide=setTimeout("reallyDestroyHint()",500)
	}
	
function reallyDestroyHint(){
	var hintDiv = document.getElementById('suggest');
	hintDiv.style.display = 'none';
	}
	
function detectMove(){
	if (typeof delayhide!="undefined"){
		if (window.event) event.cancelBubble=true
		clearTimeout(delayhide)
		}
}
	
function hintExists(param){
	var hintDiv = document.getElementById('suggest');
	if (param){
		hintDiv.style.display = 'block';
		}
	}
	
function hiddenContentAuthor(w){
	var textoDoAutor = document.getElementById('textoSobreAutor');
	var fotoDoAutor = document.getElementById('fotoDoAutor'); 
	var minimiza = document.getElementById('minimiza');
	var maximiza = document.getElementById('maximiza');
	if (w==1){
		textoDoAutor.style.display='none';
		fotoDoAutor.style.display='none';
		minimiza.style.display='none';
		maximiza.style.display='block';
		}
	else{
		textoDoAutor.style.display='block';
		fotoDoAutor.style.display='block';
		minimiza.style.display='block';
		maximiza.style.display='none';
		}
	}


//var catalogoWait = null;
//jQuery starts

jQuery(document).ready(function(){

	//Loading ajax hold

	$("#loading").hide();
	$("#loading").ajaxStart(function(){
		$('#campanha').hide('fast');
		$(this).show('fast');
		$('#info').css('opacity','0.1');
		$('.bookFound').css('opacity','0.1');
		//if (catalogoWait){alert('Mamão amarelo e verde');}
	 });
	$("#loading").ajaxStop(function(){
	   $('#campanha').show('fast');
	   $(this).hide('fast');
	   $('#info').css('opacity','1');
	   $('.bookFound').css('opacity','1');
	   //catalogoWait = null;
	});
	
	//btnMainSearchOk
	$("#btnMainSearchOk").click(function(){
		if($("#boxKeyword").val().length > 2){
			this.url = 'rbusca.asp?pc='+$('#boxKeyword').val();
			targetArea('wtf','script',this.url,0)
		}
		else{
			alert('Para efetuar a busca é necessário digitar\nno mínimo 3 caracteres no campo de busca.');	
		}
	});
	
	//btnNossaHistoria
	$('#btnNossaHistoria').click(function(){$('#wtf').load('htdocs/pages/historia.htm');})
	
	//btnDiaMae
	$('#btnDiaMae').click(function(){$('#wtf').load('/htdocs/folder/diaMaes/diaMae.html');})
	
	//espacoCultural
	//$('#btnEspaco').click(function(){$('#wtf').load('htdocs/pages/espaco_evento.html');})
	$('#btnEspaco').click(function(){abrePopup('/htdocs/folder/espacoCultural/default.html','ec','720','500','10','10','0','0','0','0','0')})
	
	//btnSejaNossoAutor
	$('#btnSejaNossoAutor').click(function(){$('#wtf').load('htdocs/pages/seja_autor.htm');})
	$('#btnAutorIbep').click(function(){$('#wtf').load('htdocs/pages/autor_ibep.asp')})
	$('#btnAutorNacional').click(function(){$('#wtf').load('htdocs/pages/autor_cen.asp')})
	
	//btnLivreiro
	$('#btnLivreiro').click(function(){window.open('/livreiros/')})
	
	
	//btnFolderes
	$('#btnLazuli').click(function(){window.open('/htdocs/folder/lazuli/','laz','width=650,height=510,top=10,left=10')})
	$('#btnPromobook').click(function(){window.open('/htdocs/folder/promobook/default.html','pro','width=640,height=480,top=10,left=10')})
	
	
	//btnSitesExternos
	$('#btnEaprender').click(function(){window.open('http://www.eaprender.com.br')})
	$('#btnEuGosto').click(function(){window.open('http://www.eugosto.net')})
	$('#btnGenteFeliz').click(function(){window.open('http://www.gentefeliz.net')})
	$('#btnBrasiliana').click(function(){window.open('http://www.editoranacional.com.br/brasiliana')})
	$('#btnBalao').click(function(){window.open('http://www.magicodobalao.com.br')})
	
	//btnFBusca
	$('#btnFBuscaDidat').click(function(){$('#wtf').load('htdocs/script/fbuscaMain.asp?categoria=1');})
	$('#btnFBuscaPI').click(function(){$('#wtf').load('htdocs/script/fbuscaMain.asp?categoria=2&subcategoria=3');})
	$('#btnFBuscaPJ').click(function(){$('#wtf').load('htdocs/script/fbuscaMain.asp?categoria=2&subcategoria=4');})
	$('#btnFBuscaLI').click(function(){$('#wtf').load('htdocs/script/fbuscaMain.asp?categoria=3&subcategoria=1');})
	$('#btnFBuscaLJ').click(function(){$('#wtf').load('htdocs/script/fbuscaMain.asp?categoria=3&subcategoria=2');})
	$('#btnFBuscaRF').click(function(){$('#wtf').load('htdocs/script/fbuscaMain.asp?categoria=4');})
	$('#btnFBuscaIG').click(function(){$('#wtf').load('htdocs/script/fbuscaMain.asp?categoria=5');})
	$('#btnFBuscaCol').click(function(){$('#wtf').load('htdocs/script/col.asp');})
	$('#btnLancamentos').click(function(){$('#wtf').load('htdocs/script/lancamentos.asp');})
	
	//Mapa lnkMapa
	$('#lnkMapa').click(function(){$('#wtf').load('htdocs/pages/mapa/mapa_ibep.htm');})
	
	//boxKeyword trigger
	$("#boxKeyword").autocomplete("/htdocs/script/jHint.asp",{
		delay:400,
		max:10,
		minChars:3
	});
	
	//Carrega os banners
	executaPops();
});

function targetArea(area,section,page,ext){
	var url;
	var targetDiv;
	var page;
	var ext; //Para extensões diferentes;
	
	this.url = '/htdocs9/'+section+'/';
	if (page) {this.url+=page;}
	if (ext){
		switch (ext){
			case 1:
				this.url+='.asp';
				break;
			case 2:
				this.url+='.aspx';
				break;
			case 3:
				this.url+='.php';
				break;
			case 4:
				this.url+='.htm';
				break;
			case 5:
				this.url+='.html';
				break;
		}
	}
	this.targetDiv = "#"+area;
	//alert(this.url);
	//$(this.targetDiv).load(this.url);
	document.location.href = this.url;
	
	_uacct = "UA-2357565-2";
	urchinTracker(this.url);
	}
	
function targetAreaO(area,section,page,ext){
	var url;
	var targetDiv;
	var page;
	var ext; //Para extensões diferentes;
	
	this.url = '/htdocs/'+section+'/';
	if (page) {this.url+=page;}
	if (ext){
		switch (ext){
			case 1:
				this.url+='.asp';
				break;
			case 2:
				this.url+='.aspx';
				break;
			case 3:
				this.url+='.php';
				break;
			case 4:
				this.url+='.htm';
				break;
			case 5:
				this.url+='.html';
				break;
		}
	}
	this.targetDiv = "#"+area;
	//alert(this.url);
	$(this.targetDiv).load(this.url);
	//document.location.href = this.url;
	
	_uacct = "UA-2357565-2";
	urchinTracker(this.url);
	}

function showCatalog(isbn,tgDiv,wHide){
	//catalogoWait = 1;
	var url;
	var targetDiv;
	this.url = '/htdocs9/script/catalogo.asp?isbn='+isbn;
	/*
	if (wHide){
		var wHide = document.getElementById(wHide);
		wHide.style.display = 'none';
		this.url += '&src=y';
		}
	if (tgDiv){
		this.targetDiv = tgDiv;
		var isHidden = document.getElementById(tgDiv);
		if (isHidden.style.display == 'none'){
			isHidden.style.display = 'block';
			}
		}
	else{
		this.targetDiv = 'wtf';
		}
	this.targetDiv = "#"+this.targetDiv;
	*/
	
	//$(this.targetDiv).load(this.url);
	//alert(this.url);
	document.location.href = this.url;
	
	_uacct = "UA-2357565-2";
	urchinTracker(this.url);
	}

function showAuthor(id_autor){
	var url;
	var targetDiv;
	this.url = '/htdocs9/script/listaPorAutor.asp?pc='+id_autor;
	this.targetDiv = '#wtf';
	//$(this.targetDiv).load(this.url);
	document.location.href = this.url;
	
	_uacct = "UA-2357565-2";
	urchinTracker(this.url);
	}

//Toggle Autor
function crashToggle(wTog,wSH,customMsgIn,customMsgOut,ordem){
	var wTog = "#"+wTog;
	var wSH = "#"+wSH;
	
	if (!customMsgIn) {customMsgIn='exibir informa&ccedil;&atilde;o';}
	if (!customMsgOut) {customMsgOut='ocultar informa&ccedil;&atilde;o';}
	
	if (!ordem){
		$(wTog).toggle(function(){
			$(wSH).hide('fast');
			$(wTog).html(customMsgIn+' <img src="../../images/iconMaximizar.gif" border="0" title="Clique para ocultar as informa&ccedil;&otilde;es." />');
		},function(){
			$(wSH).show('fast');
			$(wTog).html(customMsgOut+' <img src="../../images/iconMinimizar.gif" border="0" title="Clique para ocultar as informa&ccedil;&otilde;es." />');
		});
	}
	else{
		$(wTog).toggle(function(){
			$(wSH).show('fast');
			$(wTog).html(customMsgOut+' <img src="../../images/iconMinimizar.gif" border="0" title="Clique para ocultar as informa&ccedil;&otilde;es." />');
		},function(){
			$(wSH).hide('fast');
			$(wTog).html(customMsgIn+' <img src="../../images/iconMaximizar.gif" border="0" title="Clique para ocultar as informa&ccedil;&otilde;es." />');
		});
	}
	}
	
function swapDivs(toHide,toShow){
	if (toHide){
		toHide = "#"+toHide;
		$(toHide).hide();
		}
	if (toShow){
		toShow = "#"+toShow;
		$(toShow).show();
		}
	}
function colShow(wCol){
	var page = 'colShow.asp?colecao='+wCol;
	targetArea('wtf','script',page);
	}
function fBuscaShow(params){
	var page = 'fBuscaMain.asp?'+params;
	//alert (page)
	targetArea('wtf','script',page);
	}
//TogAutores
var tog=0;
function togAutor(){
	if (tog==0){
		$('#conteudoDoAutor').hide('fast');
		$('#togAut').html('exibir informa&ccedil;&atilde;o <img src="../../images/iconMaximizar.gif" border="0" title="Clique para ocultar as informa&ccedil;&otilde;es." />');
		tog=1;
		}
	else{
		$('#conteudoDoAutor').show('fast');
		$('#togAut').html('ocultar informa&ccedil;&atilde;o <img src="../../images/iconMinimizar.gif" border="0" title="Clique para ocultar as informa&ccedil;&otilde;es." />');
		tog=0;
		}
	}
	
//PopupOppener
function abrePopup(url,wName,width,height,top,left,scrlBar,statBar,toolBar,resizable,menubar){
	window.open(url,wName,"width="+width+",height="+height+",top="+top+",left="+left+",scrollbars="+scrlBar+",status="+statBar+",toolbar="+toolBar+",resizable="+resizable+",menubar="+menubar);
	}
//Flash banner controls
function executeCall(arg){
	cmd = arg.replace(/[!]+/g,'"');
	cmd = cmd.replace(/[|]+/g,"'");
	eval(cmd);
	}
	 
function openwdwVenda(isbn){        
        var futdate = new Date();
        var expdate = futdate.getTime();
        var winX = 720
        var winY = 700
        chamada="https://paravola.kinghost.net/~paginaviva-ecommerce/lojas/ibep/carrinho.cfm?id_ProdutoLoja="+isbn+"&time="+expdate
        janela_inferface = window.open(chamada,"LojaVenda","toolbar=no,directories=no,menubar=no, scrollbars=yes,status=no,width="+winX+", height="+winY+",left=0, right=0");
        //janela_inferface.focus();        
     }
	
function gotoLoca(url){
	if (url=="y"){window.open('/htdocs/folder/fundacao/default.asp','frm','width=607,height=550,top=10,left=10');return false;}
	if (url=="z"){window.open('/htdocs/folder/lazuli/','laz','width=650,height=510,top=10,left=10');return false;}
	if (url!="x"){
		if (url.indexOf("/")==0){
			document.location.href=url;
			}
		else {
			window.open(url);
		}
		}
	}
	
	
//CrashFunction for Show and Hide Divs...

function crashHouldini(param,timelapse){
	var hintDiv = document.getElementById(param);
	if (!timelapse){
		hintDiv.style.display = 'block';
		}
	else{
		destroyElement(param,timelapse);
		}
	}
function destroyElement(param,timelapse){
	var who = "reallyDestroyElement('"+param+"')";
	delayhide=setTimeout(who,timelapse);
	}
	
function reallyDestroyElement(param){
	var hintDiv = document.getElementById(param);
	hintDiv.style.display = 'none';
	}
	
function detectMove(){
	if (typeof delayhide!="undefined"){
		if (window.event) event.cancelBubble=true
		clearTimeout(delayhide)
		}
	}
	
	
//Função para deixar o submenu ativo.
function holdOn(wFunc, params, timelapse){
	var params = replaceAll(params,"|", "'");
	var trigger = wFunc+"("+params+")";
	delayhide=setTimeout(trigger,timelapse);
	}
	
function replaceAll(string, token, newtoken) {
	while (string.indexOf(token) != -1) {
 		string = string.replace(token, newtoken);
	}
	return string;
}

function subMenuActive(wItem){
	document.getElementById(wItem).firstChild.style.background='#e7e7e7';
	document.getElementById(wItem).firstChild.style.color='#114211';
	}
function subMenuDeactive(wItem){
	document.getElementById(wItem).firstChild.style.background='none';
	document.getElementById(wItem).firstChild.style.color='#fff';
	}
	
function openwdwConta(){
           var winX = 770;
	   var winY = 600;
           var chamada="https://paravola.kinghost.net/~paginaviva-ecommerce/lojas/IBEP/login_pedidos1.cfm";
           janela_inferface = window.open(chamada,"MinhaConta","toolbar=no,directories=no,menubar=no, scrollbars=yes,status=no,width="+winX+", height="+winY+",left=0, right=0");
	   janela_inferface.focus();
        }
