function findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
    }
  }
  else if (obj.x)
    curleft += obj.x;
  return curleft;
}

function findPosY(obj) {
  var curtop = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  }
  else if (obj.y)
    curtop += obj.y;
  return curtop;
}

function getObj(name)
{
  if (document.getElementById) 
    return document.getElementById(name);
  else if (document.all) 
    return document.all[name];
  else if (document.layers) 
    return document.layers[name];
  else return false;
}

function findCSSClass (name) {
  name = name.toLowerCase();
  var obj = null;
  if (!document.styleSheets) return;
  for (var i = 0; i < document.styleSheets.length; i++) {
    var theRules = new Array();
    theRules = document.styleSheets[i].cssRules ? document.styleSheets[i].cssRules : document.styleSheets[i].rules;
    for (var j = 0; j < theRules.length; j++) {
      if (name == theRules[j].selectorText.toLowerCase()) {
        obj = theRules[j];
      }
    }
  }
  return obj;
}

function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight];
}

function isOverlapped (oA, oB) {
  x0 = findPosX(oA);
  x1 = x0 + oA.offsetWidth;
  y0 = findPosY(oA);
  y1 = y0 + oA.offsetHeight;
  x2 = findPosX(oB);
  x3 = x2 + oB.offsetWidth;
  y2 = findPosY(oB);
  y3 = y2 + oB.offsetHeight;
  //window.alert ("(" + x0 + " " + y0 + " " + x1 + " " + y1 + ") (" + x2 + " " + y2 + " " + x3 + " " + y3 + ") - ("+oA.offsetWidth+";"+oA.offsetHeight+")");
  return !(((x0)<(x2) && (x1)<(x2)) || ((x0)>(x3) && (x1)>(x3)) || ((y0)<(y2) && (y1)<(y2)) || ((y0)>(y3) && (y1)>(y3)));
}

function showMenu(type, i, l, offsetX, offsetY) {
  //window.alert (findPosX(l) + ";" + findPosY(l));
  lay = getObj (type + "Sub" + i);
  if (lay) {
    lay.style.top = findPosY(l) + offsetY;
    lay.style.left = findPosX(l) + offsetX;
    lay.style.visibility = "visible";
    lay.style.zIndex = 1;
    eval ("hide" + type + "Menu" + i + " = false");
    if (document.forms["evadvalaszto"] && isOverlapped (lay, document.forms["evadvalaszto"].evad)) {
      document.forms["evadvalaszto"].evad.style.visibility = 'hidden';
    }
    if (document.forms["honapvalaszto"] && isOverlapped (lay, document.forms["honapvalaszto"].honap)) {
      document.forms["honapvalaszto"].honap.style.visibility = 'hidden';
    }
  }
}

function setHideMenu (type, i) {
  hideMenu = eval ("hide" + type + "Menu" + i + " = true");
  window.setTimeout ("doHideMenu ('"+type+"',"+i+")",150);
}

function clearHideMenu (type, i) {
  eval ("hide" + type + "Menu" + i + " = false");
}

function doHideMenu(type, i) {
  //window.alert ("Hide Top Menu");
  hideMenu = eval ("hide" + type + "Menu" + i);
  if (hideMenu == true) {
    lay = getObj (type + "Sub" + i);
    if (lay) {
      lay.style.visibility = "hidden";
      lay.style.zIndex = -1;
      if (document.forms["evadvalaszto"]) {
        document.forms["evadvalaszto"].evad.style.visibility = 'visible';
      }
      if (document.forms["honapvalaszto"]) {
        document.forms["honapvalaszto"].honap.style.visibility = 'visible';
      }
    }
  }
}

function doNothing() {}

function isEmailValid (emailaddr) {
  re = /^[0-9a-zA-Z_\-\.]+@([0-9a-zA-Z_\-]+\.)+[a-zA-Z]{2,4}$/;
  return emailaddr.match(re);
}

var agt=navigator.userAgent.toLowerCase();
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

function showActiveX(content)
{
        document.write(content);
}


function getXmlHttp () {
  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)
        {
        //alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
  return xmlHttp;
}

var ajaxable = (getXmlHttp() ? true : false);

// Browser Detect  v2.1.6
// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
function BrowserDetect() {
        var ua = navigator.userAgent.toLowerCase();

        // browser engine name
        this.isGecko = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
        this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

        // browser name
        this.isKonqueror = (ua.indexOf('konqueror') != -1);
        this.isSafari = (ua.indexOf('safari') != - 1);
        this.isOmniweb = (ua.indexOf('omniweb') != - 1);
        this.isOpera = (ua.indexOf('opera') != -1);
        this.isIcab = (ua.indexOf('icab') != -1);
        this.isAol = (ua.indexOf('aol') != -1);
        this.isIE = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) );
        this.isMozilla = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
        this.isFirebird = (ua.indexOf('firebird/') != -1);
        this.isNS = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );

        // spoofing and compatible browsers
        this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
        this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);

        // rendering engine versions
        this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
        this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
        this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );

        // browser version
        this.versionMinor = parseFloat(navigator.appVersion);

        // correct version number
        if (this.isGecko && !this.isMozilla) {
        this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
        }
        else if (this.isMozilla) {
        this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
        }
        else if (this.isIE && this.versionMinor >= 4) {
        this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
        }
        else if (this.isKonqueror) {
        this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
        }
        else if (this.isSafari) {
        this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
        }
        else if (this.isOmniweb) {
        this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
        }
        else if (this.isOpera) {
        this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
        }
        else if (this.isIcab) {
        this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
        }

        this.versionMajor = parseInt(this.versionMinor);

        // dom support
        this.isDOM1 = (document.getElementById);
        this.isDOM2Event = (document.addEventListener && document.removeEventListener);

        // css compatibility mode
        this.mode = document.compatMode ? document.compatMode : 'BackCompat';

        // platform
        this.isWin = (ua.indexOf('win') != -1);
        this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
        this.isMac = (ua.indexOf('mac') != -1);
        this.isUnix = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
        this.isLinux = (ua.indexOf('linux') != -1);

        // specific browser shortcuts
        this.isNS4x = (this.isNS && this.versionMajor == 4);
        this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
        this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
        this.isNS4up = (this.isNS && this.versionMinor >= 4);
        this.isNS6x = (this.isNS && this.versionMajor == 6);
        this.isNS6up = (this.isNS && this.versionMajor >= 6);
        this.isNS7x = (this.isNS && this.versionMajor == 7);
        this.isNS7up = (this.isNS && this.versionMajor >= 7);

        this.isIE4x = (this.isIE && this.versionMajor == 4);
        this.isIE4up = (this.isIE && this.versionMajor >= 4);
        this.isIE5x = (this.isIE && this.versionMajor == 5);
        this.isIE55 = (this.isIE && this.versionMinor == 5.5);
        this.isIE5up = (this.isIE && this.versionMajor >= 5);
        this.isIE6x = (this.isIE && this.versionMajor == 6);
        this.isIE6up = (this.isIE && this.versionMajor >= 6);

        this.isIE4xMac = (this.isIE4x && this.isMac);
}

var browser = new BrowserDetect();

/*
Script Name: Javascript Cookie Script
Author: Public Domain, with some modifications
Script Source URI: http://techpatterns.com/downloads/javascript_cookies.php
Version 1.0.0
Last Update: 30 May 2004

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

// this function gets the cookie, if it exists
function Get_Cookie( name ) {

        var start = document.cookie.indexOf( name + "=" );
        var len = start + name.length + 1;
        if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
        {
                return null;
        }
        if ( start == -1 ) return null;
        var end = document.cookie.indexOf( ";", len );
        if ( end == -1 ) end = document.cookie.length;
        return unescape( document.cookie.substring( len, end ) );
}
/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function Set_Cookie( name, value, expires, path, domain, secure ) {
        // set time, it's in milliseconds
        var today = new Date();
        today.setTime( today.getTime() );
        // if the expires variable is set, make the correct expires time, the
        // current script below will set it for x number of days, to make it
        // for hours, delete * 24, for minutes, delete * 60 * 24
        if ( expires )
        {
                expires = expires * 1000 * 60 ; /* * 60 * 24*/
        }
        //alert( 'today ' + today.toGMTString() );// this is for testing purpose only
        var expires_date = new Date( today.getTime() + (expires) );
        //alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

        document.cookie = name + "=" +escape( value ) +
                ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
                ( ( path ) ? ";path=" + path : "" ) +
                ( ( domain ) ? ";domain=" + domain : "" ) +
                ( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
        if ( Get_Cookie( name ) ) document.cookie = name + "=" +
                        ( ( path ) ? ";path=" + path : "") +
                        ( ( domain ) ? ";domain=" + domain : "" ) +
                        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function w (txt) {
  document.write (txt);
}

function showLargeImage (url) {
  w = window.open ("","largePic","width=100,height=100,top=0,left=0,resizable=yes,scrollbars=auto");
  d = w.document;
  d.open();
  d.write ("<html><body leftmargin=0 topmargin=0><img src=\""+url+"&rnd="+Math.round(Math.random()*1000000)+"\" style=\"padding: 5px;\">");
  d.write ("<script type=\"text/javascript\">function resizeWin() { if (document.images[0].width > 0) { window.resizeTo (Math.min(screen.width, document.images[0].width + 15), Math.min(screen.height-50, document.images[0].height + 40)); } else { window.setTimeout (\"resizeWin()\", 1000); } } window.setTimeout (\"resizeWin()\", 3000); </script>");
  d.write ("</body></html>");
  d.close();
}

function emptySelect (sel) {
  if (sel.length > 0) {
    for (var i = sel.length - 1; i >= 0; i--) {
      sel.options[i] = null;
    }
  }
}

