
  function escapePlus(str) {
    return str.replace(/\+/g, "%2B");
  }
  function getVar(name)  {
        get_string = frames['search'].location.href;
        return_value = '';
        do { //This loop is made to catch all instances of any get variable.
            name_index = get_string.indexOf(name + '=');
            if(name_index != -1) {
                get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
                end_of_value = get_string.indexOf('&');
                if(end_of_value != -1)
                    value = get_string.substr(0, end_of_value);
                else
                    value = get_string;
                if(return_value == '' || value == '')
                    return_value += value;
                else
                   return_value += ', ' + value;
            }
        } while(name_index != -1)
        //Restores all the blank spaces.
        space = return_value.indexOf('+');
        while(space != -1)
        {
            return_value = return_value.substr(0, space) + ' ' +
            return_value.substr(space + 1, return_value.length);
            space = return_value.indexOf('+');
         }
         alert("return_value : " + return_value);
        return(return_value);
  }
  function re(){
  }
  function setHelpPosition() {
    var width = (document.body.clientWidth - document.getElementById("Table_01").clientWidth);
    if (width % 2 == 1) {
      width = (width + 1) / 2;
    } else {
      width = width / 2;
    }
    var helpDiv = document.getElementById("helpDiv");
    helpDiv.style["right"] = width + 1 + "px";
    helpDiv.style["marginTop"] = document.getElementById("site_header").clientHeight + document.getElementById("site_header_panel").clientHeight + "px";
  }

  function showHelp() {
    var helpDiv = document.getElementById("helpDiv");
    helpDiv.style["visibility"] = "visible";
    helpDiv.style["display"] = "block";
  }

  function setDocHeight() {
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
      var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
      if (ieversion < 8) {
        document.getElementById("stretcher").style["height"] = document.documentElement.clientHeight - 186 + "px";
      }
    }
  }

  function submit_media_bib1form(frompageValue,pageValue,dbnameValue,bib1idValue,bib1fieldValue,termValue,directionValue) {
    mywindow = null;
    if( bib1idValue == "2023" ) {
      mywindow = window.open("media.jsp?dbname="+dbnameValue+"&bib1id="+bib1idValue+"&bib1field="+bib1fieldValue+"&term="+escapePlus(escape(termValue)),"media_url");
    } else {
      mywindow = window.open("media.jsp?dbname="+dbnameValue+"&bib1id="+bib1idValue+"&bib1field="+bib1fieldValue+"&term="+escapePlus(escape(termValue)),"media","height=400,width=400,scrollbars=yes,resizable=yes,menubar=no,status=no,toolbar=no");
    }
    mywindow.focus(); 
  }
function show_help(page, url, lang,event) {
    var child = document.getElementById("help_"+page);
    var pars = "page="+page+"&lang="+lang;
    $.get(url+'?'+pars, function(data) {
      $('#help_'+page).html(data);
    });
    if(child.hasChildNodes()) {
      child.style.display="block";
      child.style.visibility="visible";
      child.style.top=(event.clientY + 15) + "px";
      child.style.width=child.offsetWidth +"px";
      child.style.left=(event.clientX - child.offsetWidth - 15) + "px";
      var myiframe = document.getElementById("myiframe");
      myiframe.style.width = child.offsetWidth +'px';
      myiframe.style.height = child.offsetHeight +'px';
      myiframe.style.top = child.offsetTop+'px';
      myiframe.style.left = child.offsetLeft+'px';    
      myiframe.style.display="block";
      myiframe.style.visibility="visible";
    }


}

function hide_help(page) {
  var child = document.getElementById('help_'+page);
  if( child.style.visibility=="visible" ) {
    child.style.visibility="hidden";
    child.style.display="none";
    var myiframe = document.getElementById("myiframe");
    myiframe.style.visibility="hidden";
    myiframe.style.display="none";
  }
}

//torles gombra alapra allitas
function alap(itemCount,lang,url,itemCount) {
  var dbNames = getDbNames();
  for ( i = 0; i < itemCount; i++) {
    
    //1elso combo oszlop torles
    var alap = document.getElementById('bib1ext__'+i);	
    alap.selectedIndex = i;
    //ajax-os elemek visszallitasa
    fillElement('','hu','search_term__'+i,'',dbNames,url,false);
    //logikai oszlop visszallitasa
    alap = document.getElementById('logic_'+i);
    if (itemCount-1!=i)  alap.selectedIndex = 0;

  }//for i
  search_back_process(lang,url,itemCount, 'true');
}// torles


function search_back_process(lang,url,itemCount) {
  search_back_process(lang,url,itemCount, 'false');
}

function search_back_process(lang,url,itemCount, reset) {
  //kiszedjuk a kivalasztott adatbazisokat
  var dbNames = getDbNames();
  //az aktualisan hasznalt szotar tipusu mezoket lekerjuk ajax-szal
  var i;
  for ( i = 0; i < itemCount; i++) {
    var select_elem = document.getElementById('bib1ext__'+i);
    var val = select_elem.options[select_elem.selectedIndex].value;
    if (dict_elements[val]!=null) {
      var szuloId = 'search_term__'+i;
      var dictName = val;
      if (reset=='true') {
        fillElement(dictName,lang,szuloId,"",dbNames,url,false);
      } else {
        fillElement(dictName,lang,szuloId,getDefaultValue(szuloId),dbNames,url,false);
      }
    }
  }//for x
}//doChange

function storeActDict(szuloId, bib1) {
  var tmp = new Array();
  tmp[0]=szuloId;
  tmp[1]=bib1;
  akt_dicts[szuloId] = tmp;
}

//valasztasnal van ez (AJAX)
function fillElement(currentBib1ext,lang,szulo_id,currentValue,dbNames,url,check) {
    var child = document.getElementById(szulo_id+'_gyerek');
    var checkString = '';
    if (check && isText(child)) {
      checkString = '&check=true';
    }
    var pars = 'verb=fillElement&bib1='+currentBib1ext+'&lang='+lang+'&currentValue='+currentValue+dbNames+'&szuloId='+szulo_id+checkString;
    // JQuery - prototype helyett
    $.get(url+'?'+pars, function(data) {
      $('#'+szulo_id).html(data);
    });
}

//ajax-szal kell lekerni az adatbazishoz tartozo szotarelemeket
function dbChange(lang,url) {
  //kiszedjuk a kivalasztott adatbazisokat
  var dbNames = getDbNames();
  //az aktualisan hasznalt szotar tipusu mezoket lekerjuk ajax-szal
  var x;
  for (x in akt_dicts) {
    if (akt_dicts[x]!=null && akt_dicts[x][0]!=null && akt_dicts[x][1]!=null) {
      var szuloId = akt_dicts[x][0];
      var dictName = akt_dicts[x][1];
      fillElement(dictName,lang,szuloId,getDefaultValue(szuloId),dbNames,url,false);
    }//if x. nem null
  }//for x
}//doChange

function getDefaultValue(szulo_id) {
  var select_elem = document.getElementById(szulo_id+'_gyerek');
  if (select_elem.options != null && select_elem.options.length>0) {
    return (select_elem.options[select_elem.selectedIndex].value);
  } else {
    return null;
  }
}

//combo-k valasztasanal ajaxos hivas
function valaszt(select_id, szulo_id, default_ertek, lang, url) {
  var szotar_select = document.getElementById(select_id);    
  var szotar_nev = szotar_select.options[szotar_select.selectedIndex].value;
  fillElement(szotar_nev,lang,szulo_id,default_ertek,getDbNames(),url,true);
}

function isText(child) {
  return child.getAttribute("type") == "text";

}

function submit_media_bib1form(frompageValue,pageValue,dbnameValue,bib1idValue,bib1fieldValue,termValue,directionValue) {
  mywindow = null;
  if( bib1idValue == "2023" ) {
    mywindow = window.open("media.jsp?dbname="+dbnameValue+"&bib1id="+bib1idValue+"&bib1field="+bib1fieldValue+"&term="+escapePlus(escape(termValue)),"media_url");
  } else {
    mywindow = window.open("media.jsp?dbname="+dbnameValue+"&bib1id="+bib1idValue+"&bib1field="+bib1fieldValue+"&term="+escapePlus(escape(termValue)),"media","height=400,width=400,scrollbars=yes,resizable=yes,menubar=no,status=no,toolbar=no");
  }
  mywindow.focus();
}

function escapePlus(str) {
  return str.replace(/\+/g, "%2B");
}

function getVar(name)  {
      get_string = frames['search'].location.href;
      return_value = '';
      do { //This loop is made to catch all instances of any get variable.
          name_index = get_string.indexOf(name + '=');
          if(name_index != -1) {
              get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
              end_of_value = get_string.indexOf('&');
              if(end_of_value != -1)
                  value = get_string.substr(0, end_of_value);
              else
                  value = get_string;
              if(return_value == '' || value == '')
                  return_value += value;
              else
                 return_value += ', ' + value;
          }
      } while(name_index != -1)
      //Restores all the blank spaces.
      space = return_value.indexOf('+');
      while(space != -1)
      {
          return_value = return_value.substr(0, space) + ' ' +
          return_value.substr(space + 1, return_value.length);
          space = return_value.indexOf('+');
       }
      return(return_value);
}

function re(){
}

function switchGroup(element){
  document.getElementById("sg_0").style.color="#DDDDDD";
  document.getElementById("sg_1").style.color="#DDDDDD";
  document.getElementById("sg_2").style.color="#DDDDDD";
  element.style.color="#FAEB9B";
}

window.onunload = function() {
    var agt=navigator.userAgent.toLowerCase();
    if (agt.indexOf("opera") != -1) {
      var query = getVar("query");
      frames['search'].location.href = "includes/search.jsp";
    }
}

function setHelpPosition() {
  var width = (document.body.clientWidth - document.getElementById("Table_01").clientWidth);
  if (width % 2 == 1) {
    width = (width + 1) / 2;
  } else {
    width = width / 2;
  }
  var helpDiv = document.getElementById("helpDiv");
  helpDiv.style["right"] = width + 1 + "px";
  helpDiv.style["marginTop"] = document.getElementById("site_header").clientHeight + document.getElementById("site_header_panel").clientHeight + "px";
}

function showHelp() {
  var helpDiv = document.getElementById("helpDiv");
  helpDiv.style["visibility"] = "visible";
  helpDiv.style["display"] = "block";
}

function setDocHeight() {
  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
    var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
    if (ieversion < 8) {
      document.getElementById("stretcher").style["height"] = document.documentElement.clientHeight - 186 + "px";
    }
  }
}


//visszaadja a kivalasztott adatbazisokat, segedeljaras
function getDbNames() {
  var dbNames = '';
  if (this.document.forms["search_form"].elements["dbname"].length>1) {
    for (counter = 0; counter < this.document.forms["search_form"].elements["dbname"].length; counter++) {
      if (this.document.forms["search_form"].elements["dbname"][counter].checked) {
        dbNames = dbNames+'&dbname='+this.document.forms["search_form"].elements["dbname"][counter].value;
      }//if
    }//for counter
  } else {
    dbNames = '&dbname='+this.document.forms["search_form"].elements["dbname"].value;
  }
  return (dbNames);
}


function showOnScreenKeyboard(inputId, writeFormId) {
  if (document.getElementById("onScreenKeyboard") != null) {
    setWrite(inputId);
    setWriteForm(writeFormId);
    gatherInputs(writeFormId);
    document.getElementById("onScreenKeyboard").style["visibility"]="visible";
    document.getElementById("onScreenKeyboard").style["display"]="block";
  }
}

function hideOnScreenKeyboard() {
  if (document.getElementById("onScreenKeyboard") != null) {
    parent.document.getElementById("onScreenKeyboard").style["visibility"]="hidden";
    parent.document.getElementById("onScreenKeyboard").style["display"]="none";
    resetWrite();
    resetWriteForm();
  }
}



