//Descobre o navegador do cliente e seta a altura da div de conteúdo
function AjustarAltura(){
	var altura;
	if(navigator.appName.indexOf("Netscape") != -1) {
		altura = window.innerHeight - 174;
	}else{
		altura = document.body.clientHeight - 174;
	}
	document.getElementById("div_cont").style.height = altura;
}

//Redireciona o cliente conforme a opção da combo
function pular_para(){
	if (document.getElementById("cboMnuRapido").options[document.getElementById("cboMnuRapido").selectedIndex].value != "nulo"){
		window.location = document.getElementById("cboMnuRapido").options[document.getElementById("cboMnuRapido").selectedIndex].value;
	}
}

function EnviaPesquisa(){
	
	var strUrl;

	if(Trim(document.getElementById('str').value) == ""){
		alert("Informe a palavra a ser pesquisada.");
		document.getElementById('str').focus();
		return false;
	}
	strUrl = "./busca.php";
	strUrl += "?p=";
	strUrl += "&str=" + document.getElementById('str').value;
	strUrl += "&opt=" + document.getElementById('opt').value;
	window.location.href= strUrl;
}

//Aciona o envio de pesquisa quando o usuário pressiona ENTER no campo de string

function PegaEnter(event){
	if ((event && event.which == 13) || (window.event && window.event.keyCode == 13))
		EnviaPesquisa();
	else
		return true;
}

//Controla a visibilidade do menu
function DivCat(flag){
	if(flag){
		document.getElementById('div_menu').style.visibility='visible';
		document.getElementById('opt').style.visibility='hidden';
		document.getElementById('cboMnuRapido').style.visibility='hidden';
	}else{
		document.getElementById('div_menu').style.visibility='hidden';
		document.getElementById('opt').style.visibility='visible';
		document.getElementById('cboMnuRapido').style.visibility='visible';
	}	
}	

//Abre a PopUp com os detalhes do livro
function DetVitrine(intLivro){
	window.open('./detlivro.php?l=' + intLivro, '' ,'width=350,height=350,top=250,left=350,scrollbars=yes');
}

//Abre a PopUp com os detalhes da Gravura
function DetGravura(intGravura){
	window.open('./detgravura.php?g=' + intGravura, '' ,'width=550,height=550,top=100,left=160,scrollbars=yes');
}

//Redireciona o visitante para a página selecionada
function Redir(opt){
	var strPagina;

	strPagina = '';
	switch(opt){
		case "inst":
			strPagina = "./institucional.php";
			break;
		case "midi":
			strPagina = "./bazarmidia.php";
			break;
		case "voz":
			strPagina = "./lrecados.php";
			break;
		case "cont":
			strPagina = "./contato.php";
			break;
		case "home":
			strPagina = "./index.php";
			break;
		case "duvi":
			strPagina = "./duvidas.php";
			break;
		case "vend":
			strPagina = "./venda.php";
			break;
		case "carr":
			strPagina = "./carrinho.php?m=";
			break;
	}
	window.location.href = strPagina;
}

function LTrim(valor) {
	var re = /\s*((\S+\s*)*)/;
	return valor.replace(re, "$1");
}

function RTrim(valor) {
	var re = /((\s*\S+)*)\s*/;
	return valor.replace(re, "$1");
}

function Trim(valor){
	return LTrim(RTrim(valor));	
}