// lib.js -- library functions

var UserCookie = new Array(30);
var CookieValid = false
var CookieUsername = 1, CookieUser_Id = 2, CookieGroup_Id = 3, CookieContact_Id = 4, 
    CookieName = 5, CookieEmail = 6, CookiePrefs = 7, CookiePrivs = 8;

function getCookie( name )
{
  var arg = name + '=';
  if ( document.cookie && document.cookie.length != 0 )
  {
    var cstart = document.cookie.indexOf( arg );
    if ( cstart == -1 )
      return null;
    else
    {
      var tmpStr = document.cookie.substring( cstart, ( document.cookie.length + 1 ) );
      var cend = tmpStr.indexOf( ';' );
      if ( cend == -1 ) cend = tmpStr.length + 1;
      tmpStr = unescape( tmpStr.substring( arg.length, cend ) );
      return tmpStr;
    }
  }
  else
    return null;
}

function ReadCookie()
{
  CookieValid = false;
  var j=1, i=0;
  var str = getCookie( 'Marketbright_Cookie' );
  
  if ( str == null || str == "" ) return false;
  
  if ( str.indexOf( "/" ) != -1 )
  {
    while ( str.substring( i, str.length ).indexOf( "/" ) != -1 && j < 50 )
    {
      cStr = "";
      for ( var i; str.substring( i, i + 1 ) != "/"; i++ ) cStr += str.charAt(i);
      i++;
      UserCookie[j] = cStr;
      j++
    }
  }

  UserCookie[j] = str.substring( i, str.length );
  UserCookie[0] = j-1;
  CookieValid = true;

  return true;
}

function getId()
{
  ReadCookie();
  var Id = '';
  if ( CookieValid && UserCookie[CookieUser_Id] != '1' ) Id = UserCookie[CookieContact_Id];
  return Id;
}


