var cuser   = '';
var clogged = '';

// Find host name
var hurl  = new String(document.location.href);
var aurl  = hurl.split('/');
var chost = new String(aurl[0] + '/' + aurl[1] + '/' + aurl[2] + '/');
var http  = new String('http://' + aurl[2] + '/');

function write_usermenu()
{
 cuser   = new String(read_cookie('username'))
 clogged = new String(read_cookie('logged'));
 
 if(cuser.length > 0 && clogged == 1)
  {
   write_logged();
  }
 else 
 	{
 	 write_notlogged();
 	}
}

function write_logged()
{
 document.writeln('<br><div class="style2" align="center" style="font-size:12px;"><a href="'+http+'php/users.php?act=logout">LOGOUT</a></div>');
 document.writeln('<div class="style2" align="center" style="font-size:12px;">Logged user: '+cuser+'</div>');
}

function write_notlogged()
{
 document.writeln('<br><div class="style2" align="center" style="font-size:12px;"><a href="'+http+'php/users.php?act=login">LOGIN</a> | <a href="'+http+'register.php">REGISTER</a></div>');
}

function read_cookie(name)
{
  var stop,index;
   
  index = document.cookie.indexOf(name + "=");
  if (index == -1) return ('');
  index = document.cookie.indexOf("=", index) + 1;
  stop = document.cookie.indexOf(";", index);
  if (stop == -1) stop = document.cookie.length;
  return(unescape(document.cookie.substring(index, stop)));
}