//
//								          
//                                    Run Auction Countdown Javascript			          
//								          
//                                      Written by: Dwayne Reilander 			          
//                                                  For: Regal Auctions Ltd.			         
//                                               Date: March 23, 2003				          
//								          
// Synopsis: This script creates a real time countdown to Regal Auctions next sale.           
// It aquires the users local time from the users computer, converts it to the same             
// time zone as Regal Auctions (mountain time) and displays a countdown in the              
// status bar of the browser window. The countdown is in day/hour/minute format.             
// The script  also displays the name of the next auction in the "countdown",                        
// "in progress" and "has concluded" status bar messages. To update the script for          
// the next auction change the values of the "auctionStartTime", "auctionEndTime"             
// and "auctionName" variables highlighted below.                                                                     

  

function runAuctionCountdown() {

  //Declarations

  var now;
  var regalLocalTimezoneOffset;
  var auctionName;
  var auctionStartTime;
  var auctionEndTime;
  var status;
  var days;
  var hours;
  var minutes;
  var isNav;
  var dayString;
  var hourString;
  var minuteString;
  
  //instantiations

  // set the GMT or UTC tmezone offset for the Regal Auctions location (mountain time)
  regalLocalTimezoneOffset = 360;

  //set the current time
 now =  new Date();

  // adjust for time zone offset
  now.setMinutes(now.getMinutes() + (regalLocalTimezoneOffset - now.getTimezoneOffset()));

  // find out if browser is netscape
  isNav=(navigator.appName.indexOf("Netscape") != -1);


  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  // To update the auction countdown clock change the following 3 statements 
  // NOTE: hours are expressed in 24 hour time

  //set the name of the next auction
  auctionName = "21st Anniversary Sale";

  //set the start time of the next auction
  auctionStartTime  = new Date("Sep 30 2006 11:00:00");

  //set the end time of the next auction
  auctionEndTime  = new Date("Sep 30 2006 18:00:00");

  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  //select the correct message to display in the status bar
  if (now < auctionStartTime) {

    //set the number of days until the next auction
    days =  Math.floor((auctionStartTime - now) / 1000 / 60 / 60 / 24);

    //set the number of hours until the next auction
    hours = Math.floor((auctionStartTime - now) / 1000 / 60 / 60 - (24 * days));

    //set the number of minutes until the next auction
    minutes = Math.floor((auctionStartTime - now) / 1000 /60 - (24 * 60 * days) - (60 * hours));

    //set the labels to singular or plural as required
    if (days == 1) {
      dayString = "day"; 
    } else {
      dayString = "days";
    }

    if (hours == 1) {
      hourString = "hour"; 
    } else {
      hourString = "hours";
    }

    if (minutes == 1) {
      minuteString = "minute"; 
    } else {
      minuteString = "minutes";
    }

    status = "&nbsp &nbsp" + days + " " + dayString + ", " + hours + " " + hourString + " and " + minutes + " " + minuteString + " until Regal Auctions " + auctionName + " .";

  } else if ((now >= auctionStartTime) && (now < auctionEndTime)) {

    status = "Regal Auctions' " + auctionName + " is now in progress.";

  }else if ((now >= auctionEndTime) && (now.getDate() == auctionEndTime.getDate())) {

    status = "Regal Auctions' " + auctionName + " has concluded.";

  } else {

    status = "Think Auction - Think Regal";

  }
  
  // put the message in the html document
  if(isNav) {
    document.timeTag.document.write(status);
    document.timeTag.document.close();
  } else {
    timeTag.innerHTML=status;
  }


  // set the countdown to update in 1000 milliseconds
  newtime = window.setTimeout("runAuctionCountdown();", 100);
}
