function showDiv(quem){
	if($(quem).style.display == 'none'){
		$(quem).style.display = 'block';
	}else{
		$(quem).style.display = 'none';	
	}
}

function showAtu(url,target, id) {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target, id);};
        req.open("GET", url, true);
		req.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		req.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		req.setRequestHeader("Pragma", "no-cache");
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone(target, id);};
            req.open("GET", url, true);
            req.send();
        }
    }
	window.scrollTo(0,0);
}

showDet = onnavigate("showDet", function(id){
	$('preDetalhe').innerHTML = '<p>carregando informações...</p>';
	$('detalhe').innerHTML = '';
	showAtu('retornaTitulo.asp?id_arquivo='+id, 'preDetalhe', id);
});

function jahDone(target, id) {
    // only if req is "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            results = req.responseText;
			//alert(results.split(' ').join('').length);
			if(target == 'detalhe'){
				if(results.split(' ').join('').length == 0){
					$('detalhe').style.display = 'none';
				}else{
					$('detalhe').style.display = '';
					$('detalhe').innerHTML = results;	
				}
			}else{
	            $(target).innerHTML = results;
				showAtu('retornaDetalhe.asp?id_arquivo='+id, 'detalhe');
			}
        } else {
            document.getElementById(target).innerHTML = "jah error:\n" + req.statusText;
        }
    }
}

function abreArquivo(id_arquivo){
	alert('AVISO:\n\nTodo o material do Acervo Klauss Vianna está protegido pela Lei de Direito Autoral (lei nº 8.610/98) e não pode ser reproduzido, copiado ou divulgado sem prévia autorização de seus titulares.');
	//window.location = 'download.asp?id_arquivo='+id_arquivo;
	window.open('download2.asp?id_arquivo='+id_arquivo);
}

function abreTexto(){
	window.open('texto.asp', '', 'width=550, height=400, scrollbars=yes');
}
function validaContato(){
	if($F('nome') == ""){
		alert('Preencha o campo Nome.');
		return false;
	}
	if($F('email') == ""){
		alert('Preencha o campo E-mail.');
		return false;
	}
	if($F('telefone') == ""){
		alert('Preencha o campo Telefone.');
		return false;
	}
	if($F('mensagem') == ""){
		alert('Preencha o campo Mensagem.');
		return false;
	}
}
function validaPesquisadores(){
	if($F('nome') == ""){
		alert('Preencha o campo Nome.');
		return false;
	}
	if($F('email') == ""){
		alert('Preencha o campo E-mail.');
		return false;
	}
	if($F('telefone') == ""){
		alert('Preencha o campo Telefone.');
		return false;
	}
	if($F('instituicao') == ""){
		alert('Preencha o campo Instituição de Ensino / Pesquisa.');
		return false;
	}
	if($F('mensagem') == ""){
		alert('Preencha o campo Mensagem.');
		return false;
	}
}