var current_date  = new Date();
var chatState;

var chatStartDate = new Date();
var chatEndDate   = new Date();

var spanString;
var availString;

//*************************************************************
// Set the UTC value for the start and end dates for which we
// will allow the chat room to be active.  We will us UTC as our
// base so the chat room is active for all users relative to a
// single time across all time zones.  It will handle conversions
// between UTC and the user's time zone.
//
// Example in CDT, UTC time is 5 hours ahead.
// CST = Wed  September 20, 2006 22:00:00:000000
// UTC = Thur September 21, 2006 03:00:00:000000
//*************************************************************

chatStartDate.setUTCMonth(8 - 1);
chatStartDate.setUTCDate(16);
chatStartDate.setUTCFullYear(2008);
chatStartDate.setUTCHours(0);
chatStartDate.setUTCMinutes(0);
chatStartDate.setUTCSeconds(0);
chatStartDate.setUTCMilliseconds(0);

chatEndDate.setUTCMonth(8 - 1);
chatEndDate.setUTCDate(16);
chatEndDate.setUTCFullYear(2008);
chatEndDate.setUTCHours(3);
chatEndDate.setUTCMinutes(0);
chatEndDate.setUTCSeconds(0);
chatEndDate.setUTCMilliseconds(0);

function clockSpan()
{
spanString  = '';

spanString += ('<table border=0 cellpadding=0 cellspacing=3 width="100%">');
spanString += ('<tr>');
spanString += ('<td align= "center" valign="top">');

spanString += ('<table border=0 cellpadding=0 cellspacing=0 width="100%">');

spanString += ('<tr>');

spanString += ('<td align= "center" valign="top">');
spanString += ('<font face="Verdana" size="2">');
spanString += current_date.toLocaleString();
spanString += ('</font>');
spanString += ('</td>');

spanString += ('</tr>');
spanString += ('</table>');

spanString += ('</td>');
spanString += ('</tr>');
spanString += ('</table>');
}

//*************************************************************
// Print the time that the chat room will be available
//*************************************************************
function chatAvailSpan()
{
document.writeln('<p>');
document.writeln('<table border="0" cellspacing="0" cellpadding="0" width="100%">');
document.writeln('<tr>');
document.writeln('	<td bgcolor="#ffffff" nowrap>');
document.writeln('		<b><font face="Verdana" color="#000000" size="2">Availablity:</font></b>');
document.writeln('	</td>');
document.writeln('</tr>');
document.writeln('<tr>');
document.writeln('	<td bgcolor="#AD0707" width="100%"><img src="images/common/redline.gif"></td>');
document.writeln('</tr>');
document.writeln('<tr>');
document.writeln('	<td width="100%">');
document.writeln('	<font face="Verdana" size="2">');
document.writeln('<p align="left">');
document.writeln('The chat room will be available between ');
document.writeln(chatStartDate.toLocaleString() + ' and ');
//document.writeln('&nbsp;and&nbsp;');
document.writeln(chatEndDate.toLocaleString() + '.');					
document.writeln('</p>');	
document.writeln('	<p></p>');
document.writeln('	</font>	');				
document.writeln('	</td>');
document.writeln('</tr>');
document.writeln('</table>');
}

//*************************************************************
// Get the current time for print
//*************************************************************
function handleClock()
{
  // get the current date
  current_date = new Date();

  // determin screen area to push
  if ( (chatStartDate <= current_date) & (current_date < chatEndDate) )
  {
    // refresh the page to open the chat
 	if (chatState != 1)
	{
	  window.location.reload()
    }
  }

  // get clock
  clockSpan();

  // write the data to a predefined area on the screen  
  if (document.all)
    document.all.clock.innerHTML=spanString
  else if (document.getElementById)
    document.getElementById("clock").innerHTML=spanString
  else
    document.write(spanString)
}

//*************************************************************
// Start the clock
//*************************************************************
function startChat()
{
  // get the current date
  current_date = new Date();

  // determin initial chat state
  if ( (chatStartDate <= current_date) & (current_date < chatEndDate) )
  {
    chatState = 1;
  }
  else
  {
    chatState = 0;
  } 

  // update the clock and chat states
  if (document.all || document.getElementById)
    setInterval("handleClock()",1000)
}

//*************************************************************
// Puts up some nice text when the chat room is closed
//*************************************************************
function noChat()
{
document.writeln('<table border=0 cellpadding=0 cellspacing=3 width="100%"');
document.writeln('<tr>');
document.writeln('<td align="center" valign="middle">');
document.writeln('<img src="./images/common/nochat.jpg" border=0>');
document.writeln('</td>');
document.writeln('</tr>');
document.writeln('<tr>');
document.writeln('<td align="center" valign="middle">');
//document.writeln('<p>');
document.writeln('<font face="Verdana" size="2">');
document.writeln('<b>The Emperor commands you make contact with him.</b>');
document.writeln('</font>');
document.writeln('</td>');
document.writeln('</tr>');
document.writeln('</table>');
}

