/* _____________________________________________________________________________

  (B.I.T.S.) Better Innovative Technical Services Pty/Ltd
  Copyright (C) 1996-2006, All rights reserved.

  Project:       Live Bid Online
  Files(s):      livebidonline.js
  Classes:       N/A
  Author:        John Vander Reest

  Description
  N/A

  Notes
  N/A

  Change History
  ______________________________________________________________________________
  REL | DATE/TIME           | WHO | DETAILS
  1.0 | 02/08/2007 17:06:00 | Jvr | Initial Release
  ______________________________________________________________________________

*/

/* Declare global variables, Functions and  Classes for jslint.js */
/* global Ajax, Class, Element, Event, $ */
 
/*
 * consts
 */
var DefaultStatusMessage = "";
var LiveBidURL = "livebidonline.php";

var LiveBidLed = "led";
var LiveBidButton = "buttonbid";
var LiveBidTabImage = "tabimage";
var LiveBidTabPurchases = "tabpurchases";


/*
 * LiveBidOnline State:
 */
var asNone = 0;
var asAuctionStarted = 1;
var asAuctionFinished = 2;
var asLotReady = 3;
var asLotOpened = 4;
var asLotClosed = 5;
var asRoomBid = 6;
var asAbsenteeBid = 7;
var asWebBid = 8;
var asSelling = 9;
var asPassing = 10;
var asStatusMessage = 10;

var LiveBidState = [
  /*  0 */ "asNone",
  /*  1 */ "asAuctionStarted",
  /*  2 */ "asAuctionFinished",
  /*  3 */ "asLotReady",
  /*  4 */ "asLotOpened",
  /*  5 */ "asLotClosed",
  /*  6 */ "asRoomBid",
  /*  7 */ "asAbsenteeBid",
  /*  8 */ "asWebBid",
  /*  9 */ "asSelling",
  /* 10 */ "asPassing",
  /* 10 */ "asStatusMessage"
];


/*
 * LiveBidOnline State Led CSS:
 */
var LiveBidLedCSS = [
  /*  0 */ "lednone",
  /*  1 */ "lednone",
  /*  2 */ "lednone",
  /*  3 */ "ledblue",
  /*  4 */ "ledgreen",
  /*  5 */ "ledred",
  /*  6 */ "ledgreen",
  /*  7 */ "ledgreen",
  /*  8 */ "ledgreen",
  /*  9 */ "ledorange",
  /* 10 */ "ledpurple",
  /* 11 */ "lednone"
];


/*
 * LiveBidOnline State Color:
 */
var LiveBidColor = [
  /*  0 */ "#666",
  /*  1 */ "#0C3",
  /*  2 */ "#f66",
  /*  3 */ "#33C",
  /*  4 */ "#393",
  /*  5 */ "#C33",
  /*  6 */ "#393",
  /*  7 */ "#393",
  /*  8 */ "#393",
  /*  9 */ "#f63",
  /* 10 */ "#c3c",
  /* 11 */ "#666"
];


/*
 * LiveBidOnline Status Message:
 */
var LiveBidStatusMessage = [
  /*  0 */ "N/A",
  /*  1 */ "Auction Starting ...",
  /*  2 */ "Auction Finished",
  /*  3 */ "Please Wait ...",
  /*  4 */ "Lot Open<br/> <i>Bid Now, be quick !</i>",
  /*  5 */ "Lot Closed",
  /*  6 */ "Room Bidder",
  /*  7 */ "Absentee Bidder",
  /*  8 */ "Internet Bidder",
  /*  9 */ "Lot Selling ...<br/><i>Hurry, it's going !</i>",
  /* 10 */ "Passing Lot in ...<br/><i>Bid Now, don't wait !</i>",
  /* 11 */ "Status Message"
];



/*
 * CRC-8 table values
 */
var crc8_table = [
  0x00,0x1B,0x36,0x2D,0x6C,0x77,0x5A,0x41,0xD8,0xC3,0xEE,0xF5,0xB4,0xAF,0x82,0x99,
  0xD3,0xC8,0xE5,0xFE,0xBF,0xA4,0x89,0x92,0x0B,0x10,0x3D,0x26,0x67,0x7C,0x51,0x4A,
  0xC5,0xDE,0xF3,0xE8,0xA9,0xB2,0x9F,0x84,0x1D,0x06,0x2B,0x30,0x71,0x6A,0x47,0x5C,
  0x16,0x0D,0x20,0x3B,0x7A,0x61,0x4C,0x57,0xCE,0xD5,0xF8,0xE3,0xA2,0xB9,0x94,0x8F,
  0xE9,0xF2,0xDF,0xC4,0x85,0x9E,0xB3,0xA8,0x31,0x2A,0x07,0x1C,0x5D,0x46,0x6B,0x70,
  0x3A,0x21,0x0C,0x17,0x56,0x4D,0x60,0x7B,0xE2,0xF9,0xD4,0xCF,0x8E,0x95,0xB8,0xA3,
  0x2C,0x37,0x1A,0x01,0x40,0x5B,0x76,0x6D,0xF4,0xEF,0xC2,0xD9,0x98,0x83,0xAE,0xB5,
  0xFF,0xE4,0xC9,0xD2,0x93,0x88,0xA5,0xBE,0x27,0x3C,0x11,0x0A,0x4B,0x50,0x7D,0x66,
  0xB1,0xAA,0x87,0x9C,0xDD,0xC6,0xEB,0xF0,0x69,0x72,0x5F,0x44,0x05,0x1E,0x33,0x28,
  0x62,0x79,0x54,0x4F,0x0E,0x15,0x38,0x23,0xBA,0xA1,0x8C,0x97,0xD6,0xCD,0xE0,0xFB,
  0x74,0x6F,0x42,0x59,0x18,0x03,0x2E,0x35,0xAC,0xB7,0x9A,0x81,0xC0,0xDB,0xF6,0xED,
  0xA7,0xBC,0x91,0x8A,0xCB,0xD0,0xFD,0xE6,0x7F,0x64,0x49,0x52,0x13,0x08,0x25,0x3E,
  0x58,0x43,0x6E,0x75,0x34,0x2F,0x02,0x19,0x80,0x9B,0xB6,0xAD,0xEC,0xF7,0xDA,0xC1,
  0x8B,0x90,0xBD,0xA6,0xE7,0xFC,0xD1,0xCA,0x53,0x48,0x65,0x7E,0x3F,0x24,0x09,0x12,
  0x9D,0x86,0xAB,0xB0,0xF1,0xEA,0xC7,0xDC,0x45,0x5E,0x73,0x68,0x29,0x32,0x1F,0x04,
  0x4E,0x55,0x78,0x63,0x22,0x39,0x14,0x0F,0x96,0x8D,0xA0,0xBB,0xFA,0xE1,0xCC,0xD7
  ];

/*
 * By default the crc paramater should be set to 0x00
 *
 * Calculate the crc8 value for the supplied string
 */
function strCRC8(str) {
  var size = str.length;
  var index = 0;
  var crc = 0;
  var cc = 0;

  for (index = 0; index < size; index++) {
    cc = str.charCodeAt(index);

    crc = crc8_table[(crc^cc)&0xFF];
  }

  return crc;
}



/*
 * TimerExecuter: redefinition of PeriodicalExecuter (uses milliseconds NOT seconds)
 */ 
var TimerExecuter = Class.create();
TimerExecuter.prototype = {
  initialize: function(callback, frequency) {
    this.callback = callback;
    this.frequency = frequency;
    this.currentlyExecuting = false;

    this.registerCallback();
  },

  registerCallback: function() {
    this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency);
  },

  stop: function() {
    if (!this.timer) {
      return;
    }
    
    clearInterval(this.timer);
    this.timer = null;
  },

  onTimerEvent: function() {
    if (!this.currentlyExecuting) {
      try {
        this.currentlyExecuting = true;
        this.callback(this);
      } finally {
        this.currentlyExecuting = false;
      }
    }
  },
  
  changeFrequency: function(frequency) {
    if (this.frequency !== frequency) {
      this.stop();
      this.frequency = frequency;
      this.registerCallback();
    }
  }
};  // TimerExecuter





/*
 * LiveBidOnline class defintion
 */
var LiveBidOnline = Class.create();

LiveBidOnline.prototype = {

  /*
   * Pseudo constructor
   */
  initialize: function(statusid) {
    // Screen Elements
    this.client = $('client');
    this.intro = $('intro');

    // Login/Registration Details
    this.PanelLoginStatus = $('login');
    this.LabelLoginStatus = $('labellogin');
    this.LabelMyAccount = $('myaccount');
    
    this.FieldUserActivated = $('activated');
    this.LabelUserRegistered = $('labelregistered');
    this.FieldUserRegistered = $('registered');
    
    // Lot Details
    this.LabelEventID = $('eventid');
    this.LabelLotID = $('lotid');
    this.LabelLotHeading = $('lotheading');
    this.PanelLotDescription = $('lotdescription');
    this.LabelLotEstimate = $('estimate');
    this.PanelLotHistory = $('bidhistory');

    // Bidding Details
    this.LabelBidAsking = $('labelasking');
    this.FieldBidAsking = $('asking');
    this.LabelBidAmount = $('labelamount');
    this.FieldBidAmount = $('amount');
    
    this.LabelBidStatus =  $('bidstatus');
    this.LabelBidCountry = $('country');
    this.PanelBidMessage = $('message');
    
    this.PanelGutter = $('gutter');
    this.PanelFooter1 = $('footer1');
    this.PanelFooter2 = $('footer2');
    
    this.PageLotImage = $('lotimage');
    this.PagePurchases = $('purchases');
    this.TabControl = $('tabcontrol');
    this.TabImage = $(LiveBidTabImage);
    this.TabPurchases = $(LiveBidTabPurchases);
    this.ButtonBid = $(LiveBidButton);

    this.FieldResponse = $('advicevalue');

    // Other variables
    this.debugid = 0;
    this.statusid = statusid;
    this.lotid = -1;
    this.crc = 0;
    this.queueOffset = 0;
    
    this.performance = [0, 0, 0, 0, 0, 0, 0, 0];

    // Registration data
    this.rego = null;
    
    // Current call data
    this.json = null;

    // Prior call data
    this.last = null;
    
    // Set the default timer interval (very very very long)
    this.refreshInterval = 1000000;
    this.timer = null;
    
    // Initially Hide both pages

    this.PagePurchases.hide();
    this.intro.hide();
/*
    this.client.hide();
*/
    /* *** BID BUTTON *** */
    /* Assign <buttonbid> click event */
    Event.observe(
      LiveBidButton,
      'click',
      this.placeWebBid.bindAsEventListener(this)
    );

    // Assign TabImage onclick event
    Event.observe(
      LiveBidTabImage,
      "click",
      function() {
        this.TabImage.className = 'tabactive';
        this.TabPurchases.className = 'tabinactive';

        // Hide the "My Purchases" Page
        this.PagePurchases.hide();
        this.PageLotImage.show();
        
      }.bindAsEventListener(this)
    );

    // Assign TabPurchases onclick event
    Event.observe(
      LiveBidTabPurchases,
      "click",
      this.getRealized.bindAsEventListener(this)
    );
      
  },


  /*
   * isRegistered: Returns True if the user is Activated & Registered for Event
   */
  isRegistered: function() {
    var result = ((this.rego !== null) && (this.rego.registeredid !== null));
      
    return result;
  },  // isRegistered()


  /*
   * isStatusChanged: Returns True if the LiveView status has changed
   */
  isStatusChanged: function() {
    return (
      (this.json === null) ||
      (this.last === null) ||
      (this.json.statusid !== this.last.statusid) ||
      (this.json.asking !== this.last.asking)
    );
  },  // isStatusChanged


  /*
   * isEventChanged: Returns True if the LiveView Event has changed
   */
  isEventChanged: function() {
    return (
      (this.json === null) ||
      (this.last === null) ||
      (this.json.eventid !== this.last.eventid)
    );
  },  // isEventChanged


  /*
   * isLotChanged: Returns True if the LiveView Lot has changed
   */
  isLotChanged: function() {
    return (
      (this.json === null) ||
      (this.last === null) ||
      (this.json.lotid !== this.last.lotid)
    );
  },  // isLotChanged


  /*
   *
   * getBidView: Remote Method Call
   *
   * parameters:
   *   action = name of PHP server method getBidView()
   *
   * 07/02/2007 8:11:00
   * Added Queing of updates to regulate the screen refresh based on the user
   * browser response time (Throtteling)
   */
  getBidView: function() {
    return new Ajax.Request(LiveBidURL, {
      method: 'get',
      parameters: 'action=getBidView',
      onSuccess: function(transport, json) {
        // NOTE: User feedback, this is where error messages get displayed as well
        this.updateMessage(transport.responseText);

        // Process JSON object here!
        if (json !== null) {
//##JVR$('jvr').insert('testing-1'+'<br>');
          this.json = json;


          // If the statusid is blank, the intro screen should be displayed
          if ((this.json.statusid === null) || (this.json.statusid === asNone)) {
            this.client.hide();
            this.intro.show();

            // Jvr - 14/11/2007 12:59
            // Update last object to force a full refresh
            this.last = null;
          }

          // Otherwise, display the LiveBidOnline screen
          else {
            this.intro.hide();
            this.client.show();

            // Update the contents
            this.updateScreen();
            
            // Update last object for comparison next iteration
            this.last = json;
          }

        }
        else {
          this.PanelGutter.update(".");
        }
        
        // All Ok, good, then decrement the "this.queueOffset" control variable
        this.FieldResponse.update(
          new Date().getTime() -
          this.performance[this.queueOffset].getTime()
          );
        this.queueOffset--;
        
      }.bind(this)
    });

  },  // getBidView()


  /*
   * getRealized: Remote Method Call
   *
   * parameters:
   *   action = name of PHP server method getRealized()
   */
  getRealized: function() {
    // Select the Purchases Tab
    this.TabImage.className = 'tabinactive';
    this.TabPurchases.className = 'tabactive';

   // Make remote call
    return new Ajax.Request(LiveBidURL, {
      method: 'get',
      parameters: 'action=getRealized',
      onSuccess: function(transport, json) {
        // NOTE: User feedback, this is where error messages get displayed as well
        this.updateMessage(transport.responseText);
        
        // Show My Purchases" Page
        this.PageLotImage.hide();
        this.PagePurchases.show();

        // Process JSON object here!
        // If the object is not blank, then assign the data
        if ((json !== null) && (json.realized !== null)) {
          data =
            "<textarea readonly='true' enabled='true' wrap=virtual id='realized'>" +
            json.realized +
            "</textarea>";
          
          this.PagePurchases.update(data);
        }

        // Otherwise, we have no data
        else {
          this.PagePurchases.update('');
        }

      }.bind(this)
    });

  },  // getRealized()


  /*
   * placeWebBid: Remote Server Call
   *
   * parameters:
   *   action = name of PHP server method placeWebBid()
   *   bidlotid = lotid for bid being placed
   */
  placeWebBid: function(event) {
    var parameters = { action: 'placeWebBid', bidlotid: null };
    parameters.bidlotid = this.LabelLotID.innerHTML;

    return new Ajax.Request(LiveBidURL, {
      method: 'get',
      parameters: parameters,

      onSuccess: function(transport, json) {
        // NOTE: User feedback, this is where error messages get displayed as well
        this.updateMessage(transport.responseText);


        // Process JSON object here!
        if (json !== null) {
          this.json = json;

          // Update Curreny Users bidcount
          if ((this.json.history !== null) && (this.json.history.bidcount !== null)) {
            this.PanelFooter2.update(
              'Bids Placed (' + this.json.history.bidcount + ')');
          }

          // If we have data then update the screen
          if (this.json.statusid !== null) {
            this.updateScreen();
            
            // Update last object for comparison next iteration
            this.last = json;
          }
          
        }
        else {
          this.PanelGutter.update(":");
          
this.last = null;
this.rego = null;
this.getBidView();

//##JVR          alert("Error: placeWebBid() nothing to process");
        }

      }.bind(this)
    });
  },  // placeWebBid()


  /*
   * checkUserStatus: Remote Server Call
   */
  checkUserStatus: function() {
    return new Ajax.Request(LiveBidURL, {
      method: 'get',
      parameters: 'action=checkUserStatus',

      onSuccess: function(transport, json) {
        // NOTE: User feedback, this is where error messages get displayed as well
        this.updateMessage(transport.responseText);

        // Process JSON object here!
        if (json !== null) {
          this.rego = json;
          
          // Login                     
          if (this.updateLogin((this.rego.loginname !== null), this.rego.loginname)) {
            // Bidding and Registered Status            
            this.updateUserStatus(
              (this.rego.activated !== null),
              (this.rego.registeredid)
              );
                
            // Registered for current auction - Enable / Disable Bid Button
            this.updateBidButton();
          }
        }
        
        // No data was returned, user is mot logged in
        else {
          this.updateLogin(false);
        }

      }.bind(this)
    });
  },  // checkUserStatus()


  /*
   * periodicalRefresh: updates the screen periodically
   *
   * 07/02/2007 8:11:00
   * Added Queing of updates to regulate the screen refresh based on the user
   * browser response time (Throtteling)
   *
   * The "this.queueOffset" variable regulates the through-put
   */
  periodicalRefresh: function() {
    // Control the screen refresh using the Queue
    if (this.queueOffset > 0) {
      return;
    }
    else {
      // Increment the queue Offset for Throtteling
      this.queueOffset++;
      this.performance[this.queueOffset] = new Date();
      
      // Call the server for the update
      this.getBidView();
    }
  },  // periodicalRefresh()


  /*
   * updateScreen: processes the json response object passed in
   *
   * Jvr - 14/11/2005 13:59 - Added Rego/BidderID Checking on an EventID change
   */
  updateScreen: function() {
    // Update the Registration status / BidderID
    if (this.isEventChanged()) {
      this.checkUserStatus();
    }

    this.updateStatus();
    this.updateLot();
    this.updateImage(false);
    this.updateAsking();
    this.updateAmount();
    this.updateHistory();
  },  // updateScreen()



  /*
   * updateMessage
   */   
  updateMessage: function(msg) {
    var comment;
    
    if ((msg === null) || (msg === '')){
      comment = DefaultStatusMessage;
    }
    else {
      comment = msg;
    }

/*    
    var prev = this.PanelBidMessage.innerHTML;
    var data = comment + '<br />' + prev;
      this.PanelBidMessage.update(data);
*/
    var crc = strCRC8(comment);
    if (crc !== this.crc) {
//##JVR      this.PanelBidMessage.insert(comment);
      this.PanelBidMessage.update(comment);
    }
    
    // Update the Message checksum
    this.crc = crc;
  },

  
  updateStatus: function()
  {
  /*
   * updateStatus() updates the screen elements related to
   * the StatusID returned from the server
   */
   
    if ((this.json !== null) && (this.isStatusChanged())) {

      // Clear Footer2 at Auction startup and Finish
      var isValidStatus = (
        (this.json.statusid === asAuctionStarted) ||
        (this.json.statusid === asAuctionFinished)
        );
        
      if (isValidStatus) { this.PanelFooter2.update(''); }

      // Check the status of the bid button
      this.updateBidButton();


      // Bidding Status
      var style = { color: '#999' };
      style.color = LiveBidColor[this.json.statusid];

      this.LabelBidStatus.setStyle(style);
      this.LabelBidStatus.update(LiveBidStatusMessage[this.json.statusid]);

      $(LiveBidLed).className = LiveBidLedCSS[this.json.statusid];
    }
    
    else {
      // NO STATUS CHANGE
    }

    // Lot Sold
    // NOTE: Double [NOT] Equals (casting comparison)
    // has been used intentionally here!
    // DO NOT CHANGE! If you do the result becomes unpredictable and the
    // LiveBidStatusMessage[id] may be undefined (e.g. Sold to undefined)
    var isLotSold = (
      (this.json != null) &&
      (this.json.lotid != null) &&
      (this.json.history != null) &&
      (this.json.history.statusid != null) &&
      (this.json.statusid == asLotClosed)
      );

    if (isLotSold) {
      if (this.json.history.bidderid > 0) {
        this.PanelFooter2.update(
          'Lot&nbsp;&nbsp;#' + this.json.lotid + ' Sold to ' +
          LiveBidStatusMessage[this.json.history.statusid] + ' ' +
          this.json.history.bidderid);
      }
      else {
        this.PanelFooter2.update(
          'Lot&nbsp;&nbsp;#' + this.json.lotid + ' Sold to ' +
          LiveBidStatusMessage[this.json.history.statusid]);
      }
    }
  },  // updateStatus()


  /*
   * updateLot: Updates the eventid only when required
   */
  updateLot: function() {
    var tmpheading = '';

    var isValidStatus = (
      (this.json !== null) && (
        (this.last === null) ||
        (this.last.lotid === null) ||
        (this.json.lotid !== this.last.lotid)
        )
      );

    if (isValidStatus) {
      // Update EventID
      if (this.json.eventid !== null) {
        this.LabelEventID.update(this.json.eventid);
      }

      // Update LotID
      if (this.json.lotid !== null) {
        this.LabelLotID.update(this.json.lotid);
      }

      // Update Lot Heading (section)
      if (this.json.lotsectionheading !== null) {
        tmpheading = this.json.lotsectionheading;
      }

      // Update Lot Heading (code)
      if (this.json.lotcodeheading !== null) {
        tmpheading += ' - ' + this.json.lotcodeheading;
      }
      this.LabelLotHeading.update(tmpheading);


      // Update Lot Description
      if (this.json.description !== null) {
        this.PanelLotDescription.update(this.json.description);
      }

      // Update Lot Estimate
      if (this.json.estimate !== null) {
        this.LabelLotEstimate.update('$'+this.json.estimate);
      }
    }
  },  // updateLot()


  /*
   * updateHistory: Updates the history only when required
   *
   * 27/03/2008 14:11:19 - added asPassing State
   */
  updateHistory: function() {
    var isValidStatus = (
      (this.json !== null) &&
      (this.json.history !== null) &&
      (this.json.history.details !== null) && (
        (this.json.statusid === asRoomBid) ||
        (this.json.statusid === asAbsenteeBid) ||
        (this.json.statusid === asWebBid) ||
        (this.json.statusid === asSelling) ||

        // Added new State - 27/03/2008
        (this.json.statusid === asSelling) ||
        (this.json.statusid === asLotClosed)
        )
      );

    if (isValidStatus) {
      // Update only if changed
//##JVR      if ((this.last === null) || (this.last.asking !== this.json.asking)) {
      if ((this.last === null) || (this.last.bid !== this.json.bid)) {
        this.PanelLotHistory.update(this.json.history.details);
      }
    }
    else {
        this.PanelLotHistory.update('');
    }

  },  // updateHistory()


  /*
   * updateImage: Updates the eventid only when required
   */
  updateImage: function(refresh) {
    var isValidStatus = (
      (this.json !== null) && (
        (refresh === true) ||
        (this.last === null) ||
        (this.last.lotid === null) ||
        (this.json.lotid !== this.last.lotid)
        )
      );

    // Only update if status is LotReady or a full refresh is required
    if (isValidStatus) {
      if (this.json.imagename === null) {
        this.PageLotImage.update('Live<br/>Bid<br/>Online');
      }
      else {
        this.PageLotImage.update('<img src="' + this.json.imagename + '" /> ');
      }
    }
  },  // updateImage()


  /*
   * updateAsking: Updates the asking amount only when required
   *
   * 27/03/2008 17:55:23 - added check for asPassing to display asking amount
   */
  updateAsking: function() {
    var asking = 0;
    
    var isValidStatus = (
      (this.json !== null) &&
      (this.json.description !== null) &&
      (this.json.statusid > asLotReady) &&
      (this.json.statusid <= asStatusMessage) &&
      (this.json.statusid !== asLotClosed)
      );

    if (isValidStatus) {
      if (((this.json.statusid === asLotOpened) || (this.json.statusid === asPassing)) && (this.json.reserve !== null)) {
        asking = this.json.reserve;
      }
      else {
         asking = this.json.asking;
      }

      // Update asking amount
      this.FieldBidAsking.update("$" + asking);
      this.FieldBidAsking.show();
      this.LabelBidAsking.show();
    }
    else {
      this.FieldBidAsking.hide();
      this.LabelBidAsking.hide();
    }
  },  // updateAsking()


  /*
   * updateAmount: Updates the bid amount only when required
   *
   * 27/03/2008 15:06:34 - updated 'isValidStatus' to exclude asPassing
   */
  updateAmount: function() {
    var isValidStatus = (
      (this.json !== null) &&
      (this.json.bid !== null) &&
      (this.json.statusid > asLotOpened) &&
      (this.json.statusid < asPassing) &&
      (this.json.bid > 0)
      );

    // Update bid amount
    if (isValidStatus) {
      this.FieldBidAmount.update("$" + this.json.bid);
      this.FieldBidAmount.show();
      this.LabelBidAmount.show();
    }
    else {
      this.FieldBidAmount.hide();
      this.LabelBidAmount.hide();
    }


    // Update bidder country
    if ((isValidStatus) && (this.json.statusid !== asSelling) && (this.json.country !== null)) {
      this.LabelBidCountry.update(this.json.country);
      this.LabelBidCountry.show();
    }
    else {
      this.LabelBidCountry.hide();
    }

  },  // updateAmount()


  /*
   * updateBidButton: enable / disable bid button
   *
   * 27/03/2008 14:12:12 - added asPassing State
   */
  updateBidButton: function() {
    // Registered for current auction - Enable / Disable Bid Button
    var allowBidding = (
      (this.rego !== null) &&
      (this.rego.registeredid !== null) && (
        (this.json.statusid === asLotOpened) ||
        (this.json.statusid === asRoomBid) ||
        (this.json.statusid === asAbsenteeBid) ||
        (this.json.statusid === asWebBid) ||
        (this.json.statusid === asSelling) ||
        
        // New Status added - 27/03/2008
        (this.json.statusid === asPassing)
      )
    );

    this.ButtonBid.disabled = !allowBidding;
    if (allowBidding) {
      this.ButtonBid.className = 'buttonenabled';
    }
    else {
      this.ButtonBid.className = 'buttondisabled';
    }

    return (allowBidding !== null);
  }, // updateBidButton()   


  /*
   * updateLogin: upadte Login details based on if the user is logged in or not
   */
  updateLogin: function(auctionid, username) {
    if (auctionid) {
      this.PanelLoginStatus.update("Logged in As: " + username);
      this.LabelLoginStatus.update("&nbsp;&bull;&nbsp;Live Bidding Status:&nbsp;");
      this.LabelUserRegistered.update("<br/>&nbsp;&bull;&nbsp;Bidder ID:");
      this.LabelMyAccount.update(
        "<br/>&nbsp;&bull;&nbsp;Return to <a href='index.php'>MyAccount</a>");

      this.TabControl.show();
    }
    else {
      this.PanelLoginStatus.update("Not logged in");
      this.LabelLoginStatus.update("Please <a href='index.php'>click here</a> to login.");
      this.LabelUserRegistered.update("");
      this.LabelMyAccount.update("");

      this.TabControl.hide();
    }
    
    return (auctionid !== null);
  },  // updateLogin()
  
     
  /*
   * updateUserStatus: enable /disable bid button
   */
  updateUserStatus: function(activated, registeredid) {   
    if (activated) {
      this.FieldUserActivated.update("Active");
      this.FieldUserActivated.className = 'active';

      // Registered
      this.LabelUserRegistered.update("<br/>&nbsp;&bull;&nbsp;Bidder ID:&nbsp;");
      this.LabelUserRegistered.show();
    }
    else {
      this.FieldUserActivated.update("Inactive");
      this.FieldUserActivated.className = 'inactive';

      // Registered
      this.LabelUserRegistered.update("");
      this.FieldUserRegistered.hide();
    }
    
    if (registeredid !== null) {
      this.FieldUserRegistered.update(registeredid);
      this.FieldUserRegistered.className = 'active';
    }
    else {
      this.FieldUserRegistered.update("Not Registered");
      this.FieldUserRegistered.className = 'inactive';
    }
  },  // updateUserStatus()


  debugit: function(msg) {
    this.debugid++;

    $("product").update('DEBUG[' + this.debugid + '] : ' + msg);
  },


  finished: function() { alert('finished: just a place holder'); }
};  /* LiveBidOnline */



/*
 * Main entry point.
 */
window.onload=function() {
  var livebidonline = new LiveBidOnline(asNone);
  livebidonline.checkUserStatus();

  // Refresh screen first
  livebidonline.periodicalRefresh();

  // Setup data streaming
  livebidonline.timer = new TimerExecuter(
    livebidonline.periodicalRefresh.bind(livebidonline),
    650
    );
};


