var forminputs = null;

function checkItems(ids){
    /* 2010-03-15 DS. Kol kas palieku. Reikes salinti si bloka.
    var xmlHttp;
    try
    {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
      // Internet Explorer
      try
      {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
        try
        {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
            $("#dialog").dialog("open");
            $("#dialogContent").html("Your browser does not support AJAX!");
          return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
    {
        if (xmlHttp.readyState == 4) 
        {
            if (xmlHttp.status == 200) 
            {
                document.getElementById('selectedIds').value=xmlHttp.responseText;
            }
        }
    }
    //document.getElementById('selectedIds').value = replaceAll(ids, ',', ',');
    var rooter = document.getElementById('root').value;
    xmlHttp.open("POST", rooter + "/setCheckedIds.do", true);
    
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", ids.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send('selectedIds=' + ids);*/
    
    var root = $("#root").val();
    $.ajax({
            url: root + "/setCheckedIds.do",
            data : {selectedIds: ids},
            /* 1.4 jQ versijoje tik 
             success: function(data, status, request){
                //$("#selectedIds").val(data);
              alert("Data Loaded: " + request.responseText);
            }*/
            complete: function(request, status){
                $("#selectedIds").val(request.responseText);
            }
    });
}

function replaceAll(string, oldVal, newVal)
{
    var array = string.split(oldVal);
    var ret = "";
    for (var i = 0; i < array.length; i++)
    {
        if (array[i] != '')
        {
            ret += array[i];
            ret += newVal;
        }
    }
    return ret;
}

function getObjInnerText(obj)
{
    if (obj.innerText) 
    { // IE;
        return obj.innerText;
    }
    else
    {
        if (obj.textContent) //FF
        {
            return obj.textContent;
        }
        else
            return "";
    }
} 

function URLencode(sStr)
{
    return escape(sStr)
           .replace(/\+/g, '%2B')
           .replace(/\"/g,'%22')
           .replace(/\'/g, '%27');
}

function encodeQuotes(str){
    return str.replace(/\+/g, '%2B')
                .replace(/\"/g,'%22')
                .replace(/\'/g, '%27');
}

function submit_order(id){
    // pries submit pakeiciam hidden elemento reiksme, kad Action'as suprastu, jog tai uzsakymas.
    var x= $("[name='orderStr']");
    var ids = '';
    
    for (i = 0; i < x.length; i++){
        if (x[i].value == 'false'){
            x[i].value = 'true';
        }
    }
    
    ids = $("#selectedIds").val();
    
    if((ids.length <= 2) && ('list' == id)){ // jei nera pazymetu id'u ir esame pilname aprase, tada meta klaida
        ShowRecs();
    } else {
        if (id == 'list'){
            $("#selectedIdsOrder").val(ids);
        } else {
            $("#selectedIdsOrder").val(id)
        }
        $("#detailsForm").submit();
    }
}
function saveOneFromList(actionUrl, id) {
    var ids = $("#selectedIds").val();
    $("#selectedIds").val(ids + "," + id);
    catalogAction(actionUrl);
}

/*function saveList(id){
    //checkSelectedIds(id);
    // pries submit pakeiciam hidden elemento reiksme, kad Action'as suprastu, jog tai reiksmiu issaugojimas.
    var x = $("[name='saveMyList']");
    var order = $("[name='orderStr']");
    var ids = '';
    for (i = 0; i < x.length; i++){
        if (x[i].value == 'false'){
            x[i].value = 'true';
        }
    }
    for (j = 0; j < order.length; j++){
        if (order[j].value == 'true'){
            order[j].value = 'false'; // uzdeda false, jei pries tai buvo paspaustas uzsakymo mygtukas
        }                             // kad action'as reaguotu tinkamai
    }
    
    ids = $("#selectedIds").val();
        
    if((ids.length <= 2) && ('list' == id)){ // jei nera pazymetu id'u ir esame pilname aprase, tada meta klaida
        ShowRecs();
    } else {   
        $("#selectedIdsOrder").val(ids);
        $("#detailsForm").submit();
    }
}*/

function catalogAction(actionUrl) {
    var ids = $("#selectedIds").val();
    var biDetailed = $("#biRecordId");
    if(ids.length <= 2) {   // bandom ziureti sarase
        if (biDetailed.length > 0) {
            var params = "biIds=" + biDetailed.val();    // detali perziura
            window.location = actionUrl + params;
        } else {
            message(message1);
        }
    } else {
        var params = "biIds=" + ids;
        window.location = actionUrl + params;
    }
}

/*function removeElemFromList(id){
    checkSelectedIds(id);
    // pries submit pakeiciam hidden elemento reiksme, kad Action'as suprastu, jog tai reiksmiu issaugojimas.
    var x = $("[name='removeFromList']");
    for (i = 0; i < x.length; i++){
        if (x[i].value == 'false'){
            x[i].value = 'true';
        }
    }
    $("#selectedIdsOrder").val($("#selectedIds").val());
    $("#detailsForm").submit();
}*/

function select_this(name, value) {
    /* 2010-03-15 DS. pastebeta kad nebenaudojama. Dar palauksiu
    forminputs = document.getElementsByTagName('input');

    for (i = 0; i < forminputs.length; i++) {
        var regex = new RegExp(name, "i");      
        if (regex.test(forminputs[i].getAttribute('name'))) {
            
            if (value == forminputs[i].getAttribute('value')) {
                forminputs[i].checked = true;
                break;
            } else {
                forminputs[i].checked = false;
            }
        }
    }*/
}

function select_all(name, value) {
    forminputs = $("input");
    
    for (i = 0; i < forminputs.length; i++) {
        var regex = new RegExp(name, "i");      
        if (regex.test(forminputs[i].getAttribute('name'))) {
            if (value == '1') {
                forminputs[i].checked = true;
            } else {
                forminputs[i].checked = false;
            }
        }
    }
    
    if (value == '1'){
        var allIds = $("#allIds").val();
        var currentPage = $("#hidCurrentPage").val();
        var pageSize = $("#hidPageSize").val();
        
        var allIdsArray = allIds.split(',');
        var selectedIds = $("#selectedIds").val();
        
        var i=0;
        for (i=(parseInt(currentPage)*parseInt(pageSize))-parseInt(pageSize);
             i < parseInt(currentPage)*parseInt(pageSize); i++){
            selectedIds += allIdsArray[i];
            selectedIds += ',';
        }
        checkItems(allIds);
    }
    else {
        checkItems("none");
    }
}

function setCheckedItems(name, id){
    var bi001searchId = $("#bi001searchId").val();
    
    if (bi001searchId != 'false'){
        id = bi001searchId;
    }
    
    if (document.getElementById(name).checked){
        if ($("#selectedIds").val().indexOf(id) == -1){
            s = new String($("#selectedIds").val());
            s += id + ",";
            $("#selectedIds").val(s);
            checkItems(id);
        }
    } else {
        if ($("#selectedIds").val().indexOf(id) != -1){
            s = new String($("#selectedIds").val());
            s = s.replace(id + ",", ',');
            $("#selectedIds").val(s);
            checkItems(id);
        }
    }
}

/** Puslapiavimas rezultatų sąrašui */
function listChangePage(psl, catalog){
    var rooter = $("#root").val();
    var type = 'type';
    var pageSize = $("#hidPageSize").val();
    var currentPage = $("#hidCurrentPage").val();
    var resource = $("#resId").val();
    var cql = "";
    if($("#CQLQuery").length != 0){
        cql = $("#CQLQuery").val();
        //cql = URLencode(cql);
    }
    
    if (psl == 'totalPages'){
        psl = $("#totalPag").val();
    }
    if (pageSize == '1'){
        type = $("#marcFullType").val();
    }
    window.location = rooter + '/changeResultsPage.do?pageNo='+psl+'&pageSizeCh=' 
    + pageSize + '&currentRealPage=' + currentPage + '&marcFullType=' + type + 
    '&doBackSearch=1' + '&CQLQuery=' + cql + '&catalog=' + catalog + 
    '&doNotHistory=1' + '&resId=' + resource;
}

/** Puslapiavimas rezultatams peržiūrint detalius įrašus */
function changePage(psl){
    var root = $("#root").val();
    var resource = $("#resId").val();
    var cql = "";
    var type = "full";
    if($("#CQLQuery").length != 0) {
        cql = $("#CQLQuery").val();
    }
    type = $("#marcFullType").val();
    window.location = root + '/changePage.do?pageNo=' + psl + '&marcFullType=' + type + 
        '&CQLQuery=' + cql + '&resId=' + resource;
}


function getIds(){
    var pageSize = $("#hidPageSize").val();
    
    if (pageSize == 1){
        $("#marcFullTypeA").val($("#marcFullType").val());
    } else {
        // virsutinio selectedIdsLaukasV lauko reiksme reik paimt tik tada, kai rodoma virsutine navigacijos eilute.
        $("#selectedIdsLaukasV").val($("#selectedIds").val());
    }
    $("#selectedIdsLaukasA").val($("#selectedIds").val());
}

function orderLoadLink(biId, recNum, catalog){
    var rooter = $("#root").val();
    var resource = $("#resId").val();
    var cql = "";
    if($("#CQLQuery").length != 0){
        cql = $("#CQLQuery").val();
    }
    window.location=rooter + '/showRecordDetails.do?recordNum=' + recNum
        + '&biId=' + biId + '&CQLQuery=' + cql +'&resId=' + resource;
}

function showListOrOne(type, catalog){
    var rooter = $("#root").val();
    var size = $("#defaultPageSize").val();
    var resource = $("#resId").val();
    var cql = "";
    if($("#CQLQuery").length != 0) {
        cql = $("#CQLQuery").val();
        //cql = URLencode(cql);
    }
        
    if (catalog == 'true' && cql == "" && $("#CQLQueryCatalog") != null){
        cql = $("#CQLQueryCatalog").val();
    }
    
    if (type == 'list'){
        window.location = rooter + '/changePageSize.do?pageSize=' + size + 
            '&doBackSearch=1' + '&CQLQuery=' + cql + '&catalog=' + catalog +
            '&doNotHistory=1&resId=' + resource;
    }
    if (type == 'one'){
        window.location = rooter + '/changePageSize.do?pageSize=1&doBackSearch=1'
            + '&CQLQuery=' + cql + '&catalog=' + catalog + 
            '&doNotHistory=1&resId=' + resource;
    }
}

function specifyParametres(){
    var rooter = $("#root").val();
    window.location = rooter + '/specifyParametres.do';
}

function showMarcOrFull(type, catalog, biId){
    var rooter = $("#root").val();
    var pageNum = $("#fullRecNumber").val();
    //var biId = document.getElementById('fullRecId').value;
    var bi001search = $("#bi001search").val();
    var resource = $("#resId").val();
    var cql = "";
    
    var marcAction;
    if ($("#plainFullRecord").length == 0){
        marcAction = '/recordMarcForm.do';
    } else {
        marcAction = '/recordMarcFormRelated.do';
    }
    if($("#CQLQuery").length != 0){
        cql = $("#CQLQuery").val();
        //cql = URLencode(cql);
    }
    
    if ((type == 'marc') || (type == 'full')){
        if (bi001search == 'false'){
            window.location=rooter + marcAction + '?pageNo=' + pageNum + 
                '&marcFullType=' + type + '&biId=' + biId + '&doBackSearch=1' + 
                '&pSize=1' + '&CQLQuery=' + cql + '&catalog=' + catalog + 
                '&doNotHistory=1&resId=' + resource;
        }
        else {
            window.location = rooter + marcAction + '?pageNo=' + pageNum + 
                '&marcFullType=' + type + '&biId=' + biId + '&BI001=' + 
                bi001search + '&doBackSearch=1' + '&pSize=1' + '&CQLQuery='
                + cql +'&catalog=' + catalog+'&doNotHistory=1&resId=' + resource;
        }
    }

}

function openPart(field001, type){
    var rooter = $("#root").val();
    var resource = $("#resId").val();
    field001 = URLencode(field001);
    
    if (type == 'marcFieldGroupe4'){
        window.location=rooter + '/simpleSearch.do?BI001=' + field001 + 
        '&pageSize=1&marcFullType=marc&order=true&resId=' + resource;
    } else {
        window.location=rooter + '/biSearchAction.do?BI001=' + field001 + 
        '&resId=' + resource;
    }
}

function searchForAuthor(field001, text){
    var rooter = $("#root").val();
    var filter = $("#saveFilters").val();
    var resource = $("#resId").val();
    
    if (field001 != "") {
        text = "";
        field001 = URLencode(field001);
    }
    
    window.location = rooter + '/simpleSearch.do?@creator=' + text + 
        '&creator001=' + field001 + '&@creator.relation=RELATION_EXACT&doSearch=1&doCheck=1&searchSource=1&saveFilters=' 
        + filter + '&saveParameters=false&mainFilterArea=true&resId=' + resource;
}

function searchForAuthorGroup(field001, text){
    var rooter = $("#root").val();
    var filter = $("#saveFilters").val();
    var resource = $("#resId").val();
    
    if (field001 != ""){
        text = "";
        field001 = URLencode(field001);
    }
    
    window.location = rooter + '/simpleSearch.do?@authorsGroup=' + text + 
        '&authorsGroup001=' + field001 + '&@authorsGroup.relation=RELATION_EXACT&doSearch=1&doCheck=1&searchSource=1&saveFilters='
        + filter + '&saveParameters=false&mainFilterArea=true&resId=' + resource;
}

function searchForAboutPerson(field001, text){
    var rooter = $("#root").val();
    var filter = $("#saveFilters").val();
    var resource = $("#resId").val();
    
    if (field001 != ""){
        text = "";
        field001 = URLencode(field001);
    }
    
    window.location = rooter + '/simpleSearch.do?@about.person=' + text + 
    '&@about.person001=' + field001 + 
    '&@about.person.relation=RELATION_EXACT&doSearch=1&doCheck=1&searchSource=1&saveFilters='
    + filter + '&saveParameters=false&mainFilterArea=true&resId=' + resource;
}

function searchForSubject(field001, text){
    var rooter = $("#root").val();
    var filter = $("#saveFilters").val();
    var resource = $("#resId").val();
    
    if (field001 != ""){
        text = "";
        field001 = URLencode(field001);
    }
    
    window.location=rooter + '/simpleSearch.do?@subject=' + text + 
        '&subject001=' + field001 + '&@subject.relation=RELATION_EXACT&doSearch=1&doCheck=1&searchSource=1&saveFilters='
        + filter + '&saveParameters=false&mainFilterArea=true&resId=' + resource; // + '&textsToFind-10=' + textsTofind;
}

function searchForUDK(fieldUDK){
    var rooter = $("#root").val();
    var filter = $("#saveFilters").val();
    var resource = $("#resId").val();
    window.location=rooter + '/simpleSearch.do?@udk=' + fieldUDK + '&resId=' + 
        resource + '&doSearch=1&doCheck=1&searchSource=1&idsDidFind=&saveFilters='
        + filter + '&saveParameters=false&mainFilterArea=true';
}

function searchByColection(catalog){
    var rooter = $("#root").val();
    var resource = $("#resId").val();
    // kadangi kolekcija yra filtras tai juos saugom
    //var filter = document.getElementById('saveFilters').value;
    var filter = true;
    window.location=rooter + '/simpleSearch.do?filter.area2=' + catalog 
        + '&doSearch=1&doCheck=1&searchSource=1&idsDidFind=&saveFilters=' + filter
        + '&saveParameters=false&mainFilterArea=true&resId=' + resource;
}

function searchByAI001(field001){
    var rooter = $("#root").val();
    var filter = $("#saveFilters").val();
    var resource = $("#resId").val();
    field001 = URLencode(field001);
    
    window.location=rooter + '/simpleSearch.do?AI001=' + field001
    + '&doSearch=1&saveFilters=' + filter
    + '&saveParameters=false&mainFilterArea=true&resId=' + resource;
}

function searchRubrikas(field001, rtype){
    var rooter = $("#root").val();
    var filter = $("#saveFilters").val();
    var resource = $("#resId").val();
    field001 = URLencode(field001);
    
    window.location=rooter + '/aiSearchForm.do?AI001=' + field001
        + '&doSearch=1&saveFilters=' + filter + '&saveParameters=false&rtype='
        + rtype + '&paieskosTipas=2&mainFilterArea=true&resId=' + resource;
}

function searchByCreatorText(text){
    var rooter = $("#root").val();
    var filter = $("#saveFilters").val();
    window.location=rooter + '/simpleSearch.do?@creator=' + text
        + '&@creator.relation=RELATION_EXACT&doSearch=1&doCheck=1&searchSource=1&saveFilters='
        + filter + '&saveParameters=false&mainFilterArea=true';
}

function searchTTT(text, id, textsTofind){
    var rooter = $("#root").val();
    var searchType = $("#paieskosSarTipas").options[document.getElementById("paieskosSarTipas").selectedIndex].value;
    
    if (textsTofind == 'nebenaudojamasParametras'){
        text = getObjInnerText(document.getElementById(id));
        //text = URLencode(text);
        //text = encodeURI(text);
        textsTofind = text;
    }
    
    if (id < 0){
        id = "";
        textsTofind = "";
    }
    
    if (searchType == 0){
        window.location=rooter + '/simpleSearch.do?@creator=' + text
            + '&@creator.relation=RELATION_EXACT&doSearch=1&doCheck=1&searchSource=1&idsDidFind-0='
            + id + '&textsToFind-0=' + textsTofind+'&mainFilterArea=true';
    }
    
    if (searchType == 1){
        window.location=rooter + '/simpleSearch.do?@authorsGroup=' + text + '&@authorsGroup.relation=RELATION_EXACT&doSearch=1&doCheck=1&searchSource=1&idsDidFind-1=' + id + '&textsToFind-1=' + textsTofind+'&mainFilterArea=true';
    }
    
    if (searchType == 2){
        window.location=rooter + '/simpleSearch.do?@title=' + text + '&@title.relation=RELATION_EXACT&doSearch=1&doCheck=1&searchSource=1&idsDidFind=&mainFilterArea=true';
    }
    
    if (searchType == 3){
        window.location=rooter + '/simpleSearch.do?@series=' + text + '&@series.relation=RELATION_EXACT&doSearch=1&doCheck=1&searchSource=1&idsDidFind=&mainFilterArea=true';
    }
    
    if (searchType == 4){
        window.location=rooter + '/simpleSearch.do?@publisher=' + text + '&@publisher.relation=RELATION_EXACT&doSearch=1&doCheck=1&searchSource=1&idsDidFind=&mainFilterArea=true';
    }
    
    if (searchType == 5){
        window.location=rooter + '/simpleSearch.do?@udk=' + text + '&doSearch=1&doCheck=1&searchSource=1&idsDidFind=&mainFilterArea=true';
    }
    
    if ((searchType == 6) || (searchType == 7) || (searchType == 8) || (searchType == 9) || (searchType == 10)){
        window.location=rooter + '/simpleSearch.do?@subject=' + text + '&@subject.relation=RELATION_EXACT&doSearch=1&doCheck=1&searchSource=1&idsDidFind-10='+ id + '&textsToFind-10=' + textsTofind+'&mainFilterArea=true';
    }
}

function showSelected(type){
    var rooter = $("#root").val();
    var size = $("#defaultPageSize").val();
    
    if (document.getElementById('selectedIds').value != ","
        || document.getElementById('selectedIds').value != ""){
        if (type == 0){
            window.location=rooter + '/simpleSearch.do?showSelected=selected&gotoPage=1&pageSize=' + size;
        } else if (type == 1){
            window.location=rooter + '/simpleSearch.do?showSelected=all&gotoPage=1&pageSize=' + size;
        }
    }
}

function setSortBy(catalog){
    var selectValue = $("#sortBySelect").val();
    var submitButton = $("#submitButton");
    var sort = $("[name='sortBy']");
    var search = $("[name='doSearch']");
    for (j = 0; j < sort.length; j++){
        sort[j].value = selectValue;
    }
    for (k = 0; k < search.length; k++){
        search[k].value = '1';
    }
    if ('false' == catalog){
        if (null == submitButton){
            $("#simpleSearch").submit();
        } else { 
            submitButton.click();
        }
    } else {
        var x = $("[name='sortMyList']");
        for (i = 0; i < x.length; i++){
            if (x[i].value == 'false'){
                x[i].value = 'true';
            }
        }
        $("#detailsForm").submit();
     }
}

// Jei atidarytas pilnas aprašas ar unimarc, patikrinam, ar pažymėtų id sąraše yra atidaryto įrašo id. Jei ne, įdeda.
// Tam, kad nebūtų būtina pažymėti tą atidarytą įrašą.
function checkSelectedIds(id){
    if (id != "list"){
        var idai = $("#selectedIds").val();
        if (idai.indexOf(id) == -1){
            idai = idai + id + ",";
            checkItems(id);
        }
    }
}

function ShowRecs(){
    //alert('<bean:message key="searchRezRelated.jsp.NoSelected" />');
    $("#dialog").dialog("open");
    $("#dialogContent").html(message1);
}   
function removeFilters(){
    if (document.getElementById('removeFltr').checked){
        document.getElementById('saveFilters').value = 'true';
    }
    else{
        document.getElementById('saveFilters').value = 'true';
        document.getElementById('removeFltr').disabled = 'false';
    }
}

function hidePopup(mouseover, obj){
    if (0 == mouseover){
        obj.style.display = "none";
    } else {
        obj.style.display = "block";
    }
}

// Langelio atidarymas paspaudus ant nuorodos
function displayPopup(theme_popup, popup){
    var sObject = $("#" + theme_popup);
    var popUpTable = $("#hidDiv_" + theme_popup);
    
    var poshoriz = sObject.offsetLeft;
    var posvert = sObject.offsetTop;
    var pObject = sObject;
    
    while (pObject = pObject .offsetParent){
        poshoriz += pObject .offsetLeft;
        posvert += pObject .offsetTop;
    }

    $("#" + popup).html($("#hidDiv_" + theme_popup).html());
    /*document.getElementById(popup).style.top = posvert + 15 + "px";
    document.getElementById(popup).style.left = poshoriz +"px";*/
    document.getElementById(popup).style.display = "block";
}

// </Popup>

function getAllParts(){
    var rooter = $("#root").val();
    var tevo_id = $("#biRecordId").val();
    var resource = $("#resId").val();
    
    window.location=rooter + '/simpleSearch.do?tevo_id=' + tevo_id
        + '&doSearch=1&clearAllFilters=1&resId=' + resource;
}

function myPrint(printObj){
    /*var cover = document.getElementById("cover"); // salina virseli
    if (null != cover)
        printObj.removeChild(cover);
    */
    var html = printObj.innerHTML;
    var head = document.getElementsByTagName("head")[0].innerHTML;
    OpenWindow=window.open("", "Print", "height=auto, width=auto,toolbar=no,scrollbars=yes,menubar=yes");
    OpenWindow.document.write("<html>");
    OpenWindow.document.write("<head>");
    OpenWindow.document.write(head);
    OpenWindow.document.write("</head>");
    OpenWindow.document.write("<body>");
    OpenWindow.document.write(html);
    OpenWindow.document.write("</body>");
    OpenWindow.document.write("</html>");
    OpenWindow.document.close();
    OpenWindow.print();
}

function searchArticles(leidinyje, sourceId){
    var rooter = $("#root").val();
    window.location = rooter + '/simpleSearch.do?@sourceId=' + leidinyje
        + '&source_id=' + sourceId
        + '&doCheck=1&doSearch=1&searchSource=1&filter.area.c9=1';
}

function groupBy(catalog) {
    var selectedValue = $("#grupavimas").val();
    var rooter = $("#root").val();
    var cql = $("#mainCqlQuery").val();
    var resource = $("#resId").val();
    cql = encodeURIComponent(cql);
    if (catalog == 'true'){ 
        window.location = rooter + '/searchRezGroupBy.do?groupBy=' + selectedValue 
        + '&catalog=' + catalog + '&doNotHistory=1' + '&mainCqlQuery=' + cql +
        '&resId=' + resource;
    }
    else {
        window.location = rooter + '/searchRezGroupBy.do?groupBy=' + 
            selectedValue + '&catalog='+catalog+'&doSearch=1' + '&mainCqlQuery='
            + cql + '&resId=' + resource;
    }
}

function selectGroup(group) {
    var root = $("#root").val();
    var cql = $("#mainCqlQuery").val();
    var selectedGroupNo = $("#grupavimas").val();
    var resource = $("#resId").val();
    
    cql = encodeURIComponent(cql);
    window.location=root + '/selectGroup.do?group=' + group + '&mainCqlQuery=' +
        cql + '&groupBy=' +  selectedGroupNo + '&resId=' + resource;
}

function searchByGroup(group) {
    var root = $("#root").val();
    var cql = $("#mainCqlQuery").val();
    var resource = $("#resId").val();
    
    cql = encodeURIComponent(cql);
    window.location=root + '/byGroup.do?group=' + group + '&mainCqlQuery=' +
        cql + '&resId=' + resource;
}

function showFrbrList(){
    var root = $("#root").val();
    var cql = $("#hidCQLQuery").val();
    
    window.location = rooter + '/frbrSearch.do?doSearch=1&CQLQuery=' + cql;
}

function paimtiKorteles(id, path) {
    checkSelectedIds(id);

    var sbiids = document.getElementById('selectedIds').value;
    var url = "";

    // Jei esam detaliame, tai ir ims is detalaus. Is saraso nebe.
    if (id != "list") {
        sbiids = "," + id + ",";
    }

    if (sbiids != ",") {
        var tmpStr = sbiids.substr(0, 1);
        if ("," == tmpStr) {
            sbiids = sbiids.substr(1, sbiids.length - 2);
        } else
            sbiids = sbiids.substr(0, sbiids.length - 1);
    } else {
        sbiids = "";
    }

    id = document.ISBD_form.elements["sarasasISBD"].options[document.ISBD_form.elements["sarasasISBD"].selectedIndex].value;
    url = path + "/gamyba/korteles?prg=8&sid=";
    url = url + id;
    url = url + "&sch=";
    url = url + document.ISBD_form.p_sch.value;
    if (sbiids == "") {
        ShowRecs()
    } else
        window.top.location = url + "&" + "idai=" + sbiids;
}

function LeidinioGamyba(id, path) {
    checkSelectedIds(id);

    var sbiids = document.getElementById('selectedIds').value;
    var url = "";

    if (sbiids != ",") {
        var tmpStr = sbiids.substr(0, 1);
        if ("," == tmpStr) {
            sbiids = sbiids.substr(1, sbiids.length - 2);
        } else
            sbiids = sbiids.substr(0, sbiids.length - 1);
    } else {
        sbiids = "";
    }

    id = document.Leidinis_form.elements["leidiniai"].options[document.Leidinis_form.elements["leidiniai"].selectedIndex].value;

    url = path + "/gamyba/leidinys?sid=" + id + "&sch=" + document.ISBD_form.p_sch.value;
    if (sbiids == "") {
        ShowRecs()
    } else
        window.top.location = url + "&" + "idai=" + sbiids;
}

/**
 * E-knygos parsiuntimas
 * @param fileUrl knygos URL'as
 */
function downloadEbook(fileUrl) {
	viewEbookPrompt(fileUrl);
}

/**
 * E-knygos peržiūros pranešimas
 */
function viewEbookPrompt(fileUrl) {
	openEBookDialog(ebookDownloadMessage + " <a target='_blank' href='http://www.adobe.com/products/digitaleditions'>http://www.adobe.com/products/digitaleditions</a>", fileUrl);
	//alert(ebookDownloadMessage + 'http://www.adobe.com/products/digitaleditions');
}
