var Registration = function(){}
Registration.REGISTRATION_COOKIE = "wpniuser";
Registration.PLUCK_COOKIE = "hd";
Registration.FACEBOOK_UID_COOKIE= "fbuid";
Registration.FACEBOOK_NAME_COOKIE= "fbuname";
Registration.prototype.getEditProfileLink = function( txt )
{
  return '<a href="/ac2/wp-dyn?node=admin/registration/manage&destination=manage&nextstep=gather">'+txt+'</a>';
}
Registration.prototype.getSignInLink = function( txt )
{
  return '<a href="/ac2/wp-dyn?node=admin/registration/register&destination=login&nextstep=gather&application=reg30-globalnav&applicationURL=http://www.washingtonpost.com">'+txt+'</a>';
}
Registration.prototype.getSignOutLink = function( txt )
{
  return '<a href="/ac2/wp-dyn?node=admin/registration/login&destination=logout&nextstep=confirm">'+txt+'</a>';
}
Registration.prototype.getRegisterLink = function( txt )
{
  return '<a href="/ac2/wp-dyn?node=admin/registration/register&destination=register&nextstep=gather&application=reg30-globalnav&applicationURL=http://www.washingtonpost.com">'+txt+'</a>';
}
Registration.prototype.isSignedIn = function()
{
  if( typeof this.signedIn == 'undefined' )
  {
    this.signedIn = ( document.cookie.indexOf( Registration.REGISTRATION_COOKIE ) != -1 );
  }
  return this.signedIn;
}
Registration.prototype.isFBUser = function()
{
  if( typeof this.FBUser == 'undefined' )
  {
   this.FBUser = ( document.cookie.indexOf( Registration.FACEBOOK_UID_COOKIE ) != -1 );
  }
  return this.FBUser;
}
Registration.prototype.getPluckUserName = function()
{
   if (document.cookie.indexOf(Registration.REGISTRATION_COOKIE) != -1)
    {
      var start = (document.cookie.indexOf(Registration.REGISTRATION_COOKIE) + Registration.REGISTRATION_COOKIE.length + 1
);
      var end = (document.cookie.indexOf(";",start)) == -1 ? document.cookie.length : document.cookie.indexOf(";",start);

      this.pluckusername = document.cookie.substring(start,end);
      if( this.pluckusername.indexOf( "@" ) != -1 ) 
           this.pluckusername = this.pluckusername.substring(0,this.pluckusername.indexOf("@"));
    
  }
  return this.pluckusername;

}
Registration.prototype.getUserName = function()
{
  if( typeof this.username == 'undefined' )
  {
    
    if (document.cookie.indexOf(Registration.REGISTRATION_COOKIE) != -1)
    {
      var start = (document.cookie.indexOf(Registration.REGISTRATION_COOKIE) + Registration.REGISTRATION_COOKIE.length + 1);
      var end = (document.cookie.indexOf(";",start)) == -1 ? document.cookie.length : document.cookie.indexOf(";",start);
      this.username = document.cookie.substring(start,end);
      if( this.username.indexOf( "@" ) != -1 ) this.username = this.username.substring(0,this.username.indexOf("@"));
    }
  }
       if (document.cookie.indexOf(Registration.FACEBOOK_UID_COOKIE) != -1)
    {
      var start = (document.cookie.indexOf(Registration.FACEBOOK_NAME_COOKIE) + Registration.FACEBOOK_NAME_COOKIE.length + 1);
      var end = (document.cookie.indexOf(";",start)) == -1 ? document.cookie.length : document.cookie.indexOf(";",start);
      this.username = document.cookie.substring(start,end);
     }

    if (document.cookie.indexOf(Registration.PLUCK_COOKIE) != -1)
    {
        this.username = '<a href="http://www.washingtonpost.com/wp-srv/community/mypost/index.html?newspaperUserId='+Registration.prototype.getPluckUserName()+'">'+this.username+'</a>'; }

    return this.username;
}
Registration.prototype.getRawUserName = function()
{
  if( typeof this.username == 'undefined' )
  {
    if (document.cookie.indexOf(Registration.REGISTRATION_COOKIE) != -1)
    {
      var start = (document.cookie.indexOf(Registration.REGISTRATION_COOKIE) + Registration.REGISTRATION_COOKIE.length + 1);
      var end = (document.cookie.indexOf(";",start)) == -1 ? document.cookie.length : document.cookie.indexOf(";",start);
      this.username = document.cookie.substring(start,end);
    }
    if (document.cookie.indexOf(Registration.FACEBOOK_UID_COOKIE) != -1)
        {
          var start = (document.cookie.indexOf(Registration.FACEBOOK_NAME_COOKIE) + Registration.FACEBOOK_NAME_COOKIE.length + 1);
          var end = (document.cookie.indexOf(";",start)) == -1 ? document.cookie.length : document.cookie.indexOf(";",start);
          this.username = document.cookie.substring(start,end);
     }
  }
    return this.username
}
