// <?include ('include/common.inc'); ?>
  function rand(n) { return (Math.floor (Math.random () * n)); }
  function point(x,y) {this.x=x; this.y=y;}

  function getCurrPoint(e,p) {
     if (typeof e.clientX =='number') {
        p.x=e.clientX+document.body.scrollLeft-4;
        p.y=e.clientY+document.body.scrollTop-4;
     } else  { p.x=e.pageX; p.y=e.pageY; }
     return true;
  }

  function showInfoBox (e, id) {
    var p = new point (0,0);
    var src = "details.php?helyiseg=" + id + "&rnd=" + rand(100000);
    if (lang != undefined) 
      src += "&lang=" + lang;
    getCurrPoint (e, p) ;
    fr = document.getElementById("detailsFrame");
    fr.src = src;
    //window.status = fr.src;
    lay = document.getElementById("detailsLayer");
    lay.style.visibility = "visible";
    //window.alert ("PageY: " + p.y + " layerY: " + e.layerY + " innerHeight: " + window.innerHeight);
    lay.style.left = Math.min (p.x, 180);
    lay.style.top = p.y;
  }

  function hideInfoBox () {
    //window.status = '<?=$LANG_CONST[$_REQUEST["lang"]]["valasszon"]?>';
    fr = document.getElementById("detailsFrame");
    fr.src = "varjon.html";
    lay = document.getElementById("detailsLayer");
    lay.style.visibility = "hidden";
  }

  function changeStatusToAlt (a) {
    if (window.status != a.title)
      window.status = a.title;
  }


  function getRealLeft(imgElem) {
    xPos = eval(imgElem).offsetLeft;
    //window.alert (xPos);
    tempEl = eval(imgElem).offsetParent;
    while (tempEl != null) {
      xPos += tempEl.offsetLeft;
      tempEl = tempEl.offsetParent;
    }
    return xPos;
  }

  function getRealTop(imgElem) {
    //window.alert (imgElem);
    yPos = eval(imgElem).offsetTop;
    //yPos = imgElem.offsetTop;
    tempEl = eval(imgElem).offsetParent;
    //tempEl = imgElem.offsetParent;
    while (tempEl != null) {
      yPos += tempEl.offsetTop;
      tempEl = tempEl.offsetParent;
    }
    return yPos;
  }
/*
// Gets real Top value with respect to client area
	function getRealTop(elem)
	{
		var topPosition = 0;
		while (elem)
		{
			if (elem.tagName == 'BODY')
			{
				break;
			}
			topPosition += elem.offsetTop;
			elem = elem.offsetParent;
		}
		return topPosition;
	}

// Get real Left value with respect to client area
	function getRealLeft(elem)
	{
		var leftPosition = 0;
		while (elem)
		{
			if (elem.tagName == 'BODY')
			{
				break;
			}
			leftPosition += elem.offsetLeft;
			elem = elem.offsetParent;
		}
		return leftPosition;
	}
*/

 var szintNo = -1;
 function setArrowPosition (szintNo) {
   //window.alert ("Szint: " + szintNo);
   if (szintNo >= 0) {
     var eltol = 25;
     var lay = document.getElementById ('freearrow');
     var szint = document.images['SzintI_' + szintNo];
     //var szint = document.getElementById ('Szint_<?=$H->szint?>');
     lay.style.left = (getRealLeft(szint) + X - eltol) + "px";
     lay.style.top = (getRealTop(szint) + Y - eltol) + "px";
   }
 }

 function openWinLarge (url, lang) {
   window.open (url + "&lang=" + lang, "newWin", "width=980,height=650,top=20,left=20,scrollbars=yes");
 }

 function openWin (url, lang) {
   window.open (url + "&lang=" + lang, "newWin", "width=567,height=500,top=50,left=50,scrollbars=yes");
 }

  function createCookie(name,value,days) {
    if (days) {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*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 getResolution () {
    if (readCookie("res") == resolution) 
      return;
    var res = (screen && screen.width >= 1024 && screen.height >= 768) ? "hi" : "lo";
    createCookie ("res", res, 0);
    if (readCookie("res") != resolution) 
      window.location.reload();
   }
