﻿//** Pesquisa de Acervos **********************************************************************************************************************
function IWB_Limpar(strFormName)
{
    var lstMateriais = document.getElementById("lstMateriais");
    var chkPesquisaResumida = document.getElementById("chkPesquisaResumida");
    var edtAssunto = document.getElementById("edtAssunto");

    if ((lstMateriais == null) || (chkPesquisaResumida == null) || (edtAssunto == null))
    {
        alert(ComponentNotFound);
        return false;
    }

    try
    {
        edtAssunto.value = "";
        chkPesquisaResumida.checked = true;
        lstMateriais.selectedIndex = 0;
        edtAssunto.focus();
    }
    catch (e)
    {
    }
}

//** Pesquisa de Acervos **********************************************************************************************************************
function PesquisarAcervos(url, strSender, FormName)
{
    var dibBoxPesquisaInterna = document.getElementById("dibBoxPesquisaInterna");
    var dibBoxPesquisa = document.getElementById("dibBoxPesquisa");

    if ((dibBoxPesquisaInterna != null) && (dibBoxPesquisa != null))
    {
        dibBoxPesquisaInterna.parentNode.removeChild(dibBoxPesquisaInterna);
        dibBoxPesquisaInterna = null;
    }

    var lstMateriais = document.getElementById("lstMateriais");
    var lstBilbliotecas = document.getElementById("lstBibliotecas");
    var chkPesquisaResumida = document.getElementById("chkPesquisaResumida");
    var edtAssunto = document.getElementById("edtAssunto");

    if ((lstMateriais == null) || (lstBilbliotecas == null) || (chkPesquisaResumida == null) || (edtAssunto == null))
    {
        alert(ComponentNotFound);
        return false;
    }

    var Assunto = edtAssunto.value;
    var PesquisaResumida = chkPesquisaResumida.checked;
    var Material = lstMateriais.value;
    var Biblioteca = lstBilbliotecas.value;

    PesquisarAcervosByPag(url, strSender, FormName, 1, 20, Assunto, Material, Biblioteca, PesquisaResumida);
}

function PesquisarAcervosByPag(url, strSender, FormName, Pg, QtByPage, Assunto, Material, Biblioteca, PesquisaResumida)
{
    var Sender = document.getElementById(strSender);

    if (Sender)
    {
        Y = getElementPositionById(strSender).top;
        window.scroll(0, Y);
    }

    try
    {
        ShowAguarde(true);
        JRAjax.PesquisarAcervos(ID, SessionID, Pg, QtByPage, Assunto, Material, Biblioteca, PesquisaResumida, url, strSender, FormName, cbk_PesquisarAcervosByPag);
    }
    catch (e)
    {
        ShowAguarde(false);
    }
}

function cbk_PesquisarAcervosByPag(Request)
{
    ShowAguarde(false);

    if (!Request.value[0])
    {
        alert(Request.value[1]);
        self.document.getElementById("edtAssunto").value = "";
        FocusControl('edtAssunto');
        return
    }

    var divIW = document.getElementById(Request.value[5]);

    if (divIW)
        divIW.innerHTML = Request.value[3];

    CloseForm(Request.value[4]);
}

function showPrincipal()
{
    var divPrincipal = document.getElementById("divPrincipal");
    var divExemplares = document.getElementById("divExemplares");

    if (divPrincipal != null && divExemplares != null)
    {
        divPrincipal.style.visibility = 'visible';
        divExemplares.style.visibility = 'hidden';
    }
}

function showExemplares()
{
    var divPrincipal = document.getElementById("divPrincipal");
    var divExemplares = document.getElementById("divExemplares");

    if (divPrincipal != null && divExemplares != null)
    {
        divExemplares.style.visibility = 'visible';
        divPrincipal.style.visibility = 'hidden';
    }
}

function IWB_ReservarAcervo(ID, SessionID, matricula, acervo)
{    
    try
    {
        if (confirm('Deseja efetuar a reserva do acervo ' + acervo + '?'))
        {
            ShowAguarde(true);
            JRAjax.IWB_ReservarAcervo(ID, SessionID, matricula, acervo, cbk_GenericCallBack);
        }
    }
    catch (e)
    {
        ShowAguarde(false);
        alert(AjaxNotFound);
    }
}

function IWB_RenovarAcervo(ID, SessionID, tipoSistema, matricula, numLivro)
{
    try
    {
        if (confirm('Deseja renovar o livro ' + numLivro + '?'))
        {
            ShowAguarde(true);
            JRAjax.IWB_RenovarAcervo(ID, SessionID, tipoSistema, matricula, numLivro, cbk_GenericCallBack);
        }
    }
    catch (e)
    {
        ShowAguarde(false);
        alert(AjaxNotFound);
    }
}
