// lytframe ablak nyitasa javascriptbol
// belinkelessel is lehet pl.: http://www.gurubarlang.hu/?docid=archives&frameId=id
var timeoutID = null;
function loadLytebox(hrefId) {
  if (!hrefId) hrefId = getFrameId();
  if (!hrefId) return;
  if (typeof myLytebox != 'undefined') {
    var link = document.getElementById(hrefId);
    //ha itt akarjuk parameterezni, akkor igy kell:
    /*var link = document.createElement(hrefId);
    link.href = "/page.php";
    link.rel = "lyteframe";
    link.title = "http://DwFAQ.info";
    link.rev = "width: 770px; height: 687px; scrolling: no;";*/
    myLytebox.start(link, false, true);
  } else {
    if (timeoutID) {clearTimeout(timeoutID)}
    timeoutID = setTimeout("loadLytebox('" + hrefId + "'), 100");
  }
}

function getFrameId() {
  var hash = window.location.search.substring(1);
  if (hash.length > 1) {
    var itms = hash.split("&");
    var vals = new Array(); 
    var i;
    for (i = 0; i < itms.length; i++) { 
      vals[i] = itms[i].split("=");
    }
    for (i = 0; i < vals.length; i++) {
      if (vals[i][0] == "frameId") {
        return vals[i][1];
      }
    }
  }
}

function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all ? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto";
    var docHt = getDocHeight(iframeWin.document);
    if (docHt) iframeEl.style.height = docHt + 20 + "px";
  }
}

function change(id, newClass) {
  identity = document.getElementById(id);
  if (identity) identity.className=newClass;  
}

function setArchIcon(id, name, color) {
  id.src='images/' + name + '.jpg';
  id.style.border='1px solid ' + color;
}

function setArchRow(id, style) {
  id.getElementsByTagName('td')[1].style.borderBottom = style;
}

function getKeyword() {
  var hash = window.location.search.substring(1);
  if (hash.length > 1) {
    var itms = hash.split("&");
    var vals = new Array(); 
    var i;
    for (i = 0; i < itms.length; i++) { 
      vals[i] = itms[i].split("=");
    }
    for (i = 0; i < vals.length; i++) {
      if (vals[i][0] == "word") {
        var word = vals[i][1];
      } 
    }
  }
  if (word) highlightSearchTerms(word);
}

function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) {
  searchTerm = unescape(searchTerm);
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color: #000000; background-color: #e9bc21;'>";
    highlightEndTag = "</font>";
  }
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  return newText;
}

function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag) {
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("A kereső funkció szövegkiemelése nem használható ezen a lapon!");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}

function createCookie(name, value, expInMin) {
  if (expInMin) {
    var date = new Date();
    date.setTime(date.getTime() + (expInMin * 1000));
    var expires = "; expires=" + date.toGMTString();
  }
  else var expires = "";
  document.cookie = name + "="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name) {
  createCookie(name, "", -1);
}

function setDisplay(blockId) {
  if (document.getElementById(blockId).style.display == 'none') document.getElementById(blockId).style.display = 'block';
  else document.getElementById(blockId).style.display = 'none';
}

function detectIEVersion() {
  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
   var ieversion = new Number(RegExp.$1);
   if (ieversion >= 9)
    return 9;
   else if (ieversion >= 8)
    return 8;
   else if (ieversion >= 7)
    return 7;
   else if (ieversion >= 6)
    return 6;
   else if (ieversion >= 5)
    return 5;
  } else {
    return 999;
  }
}

function scrollIntoLink(obj) {
  var ieVer = detectIEVersion();
  if (ieVer <= 7) {
    window.scrollBy(0, 50);
    return;
  } else {
    obj.scrollIntoView();
  }
}

