//-------------------------------------------------------------------------------------
function menuItem( foFajl )
  {
    setCookie( "mainFile", foFajl, 60 ) ;
    top.Main.location.href = foFajl ;
  }

function menuItemTop( foFajl )
  {
    top.location.href = foFajl ;
  }

function foMenuItem( foFajl )
  {
    setCookie( "cMenuNev", getCookie( "cMenuNev" ), -60 ) ;
    self.location.replace( "fomenu.php" ) ;
    menuItem( foFajl );
  }

function alMenu( cMenuNev )
  {
    if ( getCookie( "cMenuNev" ) == cMenuNev ) 
        setCookie( "cMenuNev", getCookie( "cMenuNev" ), -60 ) ;
    else
        setCookie( "cMenuNev", cMenuNev, 60 ) ;
    self.location.replace( "fomenu.php" /* + "?lang=<? echo $lang ?>" */ ) ;
    top.Main.location.href = "ures.php" /* + "?lang=<? echo $lang ?>" */ ;
  }

//-------------------------------------------------------------------------------------
function SuperScript( s )
  {
    document.write( "<small><sup>"+s+"</sup></small>" );
  }


//-------------------------------------------------------------------------------------
function SubScript( s )
  {
    document.write( "<small><sub>"+s+"</sub></small>" );
  }

//-------------------------------------------------------------------------------------
function toCapitalCase( s ) {
  ret = "" ;
  upper = true ;
  for ( k=0; k < s.length; k++ ) {
    if ( s[k] == " " ) {
      ret += " " ;
      upper = true ;
    }
    else if ( upper ) {
      ret += s[k].toUpperCase() ;
      upper = false ;
    }
    else
      ret += s[k].toLowerCase() ;
  }
  return ret ;
}
  
//-------------------------------------------------------------------------------------
function getCookie( sId )
  {
    var sCookie = "" ;

    if ( ! document.cookie )
        return "" ;

    sCookie = document.cookie ;
    p = sCookie.indexOf( sId + "=" );

    if ( p == -1 )
        return "" ;

    p += sId.length + 1 ;
    sCookie = sCookie.substring( p ) ;

    p = sCookie.indexOf(";") ;
    if ( p == -1 )
        p = sCookie.length;

    sCookie = sCookie.substring( 0, p ) ;

    return sCookie;
  }


//-------------------------------------------------------------------------------------
function Local()
  {
    return ( document.URL.toLowerCase().search( /localhost/ ) != -1 ) ;
  }

//-------------------------------------------------------------------------------------
function setCookie( sId, sValue, nExpMinutes )
  {
    if ( nExpMinutes == 0 )
        top.document.cookie = sId + "=" + sValue + ";" ;
    else
      {
        var dNow = new Date();
        var dExp = new Date( dNow.getTime() + nExpMinutes*60*1000 );
        var PageRoot = "/" + ( Local() ? "MGE" : "" ) ;
        top.document.cookie = sId + "=" + sValue + "; expires=" + dExp.toGMTString() + "; path=" + PageRoot + " ;" ;
      }
  }


// -------------------------------------------------------------------
function trim( str )
  {
    return rtrim( ltrim( str ) ) ;
  }


// -------------------------------------------------------------------
function ltrim( str )
  {
    while( str.length > 0 && str[0] == " " )
        str = str.slice( 1 );
    return str ;
  }


// -------------------------------------------------------------------
function rtrim( str )
  {
    while( str.length > 0 && str[str.length-1] == " " )
        str = str.slice( 0, str.length-1 );
    return str ;
  }


// -------------------------------------------------------------------
function eCim( cim, str, arg )
  {
    if ( cim == str ) { str = unescape( str ) } ;
    if ( str == "" ) { str = unescape( cim ) } ;
    document.write( '<a href="mailto:' + unescape( cim ) + arg + 
        '" onMouseover="status=\'\'; return true;">' + str + '</a>' ) ;
  }

// -------------------------------------------------------------------
function Nyelv( ny )
{
    setCookie( "lang", ny, 180*24*60 ) ;
    // alert( top.document.title ) ;
    top.document.title = 
        ( ny == "hu" ? "Magyar Go Egyesület" : 
        ( ny == "en" ? "Hungarian Go Association" : 
        ( ny == "de" ? "Ungarische Go Verein" :
        "Hungarian Go Association" ))) ;
    if( top.Logo )
      {
        top.Logo.location.reload() ;
        top.Header.location.reload() ;
        top.Main.location.reload() ;
        top.Tools.location.reload() ;
        top.LastUpd.location.reload() ;
        top.Menu.location.replace("fomenu.php") ;
      }
    else
        location.reload() ;
}

// -------------------------------------------------------------------
function wait( sec )
  {
    now = new Date();
    diff = 0 ;
    while( diff < sec * 1000 )
        diff = new Date() - now ;
  }
