<!-- 

//This script performs browser local time manipulations

// Unfortunately we can't extract the Locale specific month names from Javascript and
// the main browsers seem to use English anyway despite your Regional Setting.

var months = new Array ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var months_vn = new Array ("1","2","3","4","5","6","7","8","9","10","11","12");


///////////////////////////////////////////////////////////////////////////////////////
//
// Returns the CST equivalent time for the specified UTC time string
//
function CSTTime(UTC_str)
{
  // Create a time object with UTC as "local" time and adjust to equivalent CST time

  when_CST = new Date(UTC_str);
  
  // Australia: + 9.5 * 60; Norway: + 2.0 * 60 in the summer time; Hanoi: + 7.0 * 60

  when_CST.setMinutes(when_CST.getMinutes() + 0.0 * 60);
  
  return when_CST;
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Returns a local time string for the given UTC time
//
function localTimeStr(UTC_str, separator)
{
  // Initialise the local time using the provided UTC time (we will use this to return true local time)

  when_LCL = new Date(UTC_str + " UTC");

  // Create another time object with UTC as "local" time and adjust to equivalent CST time

  when_CST = CSTTime(UTC_str);                          

  // Only show the date in the local time if it differs from the CST date

  var LCL_str = ((when_CST.getDay() == when_LCL.getDay()) ? "" : (when_LCL.getDate() + separator + months[when_LCL.getMonth()] + separator));

  // Construct local (date and) time string

  LCL_str += ((when_LCL.getHours() < 10) ? "0" : "") + when_LCL.getHours();
  LCL_str += ((when_LCL.getMinutes() < 10) ? ":0" : ":") + when_LCL.getMinutes();

  return LCL_str;
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Returns a CST time string for the given UTC time
//
function CSTTimeStr(UTC_str, separator, showSeconds)
{
	// Create a time object with UTC as "local" time and adjust to equivalent CST time

	when_CST = CSTTime(UTC_str);                          

	// Construct CST date and time string

	var weekday = when_CST.getDay();
	var weekday_str;
	var mday = when_CST.getDate();
	var mday_str;

	if (weekday == 0) { weekday_str = "Chủ Nhật";
	} else if (weekday == 1) { weekday_str = "Thứ Hai";
	} else if (weekday == 2) { weekday_str = "Thứ Ba";
	} else if (weekday == 3) { weekday_str = "Thứ Tư";
	} else if (weekday == 4) { weekday_str = "Thứ Năm";
	} else if (weekday == 5) { weekday_str = "Thứ Sáu";
	} else if (weekday == 6) { weekday_str = "Thứ Bảy";
	}
	if (mday == 1 || mday == 21) { mday_str = "st";
	} else if (mday == 2 || mday == 22) { mday_str = "nd";
	} else if (mday == 3 || mday == 23) { mday_str = "rd";
	} else { mday_str = "th";
	}

	//var CST_str = weekday_str + ", " + when_CST.getDate() + mday_str + separator + months_[when_CST.getMonth()] + separator;
	var CST_str = ((when_CST.getHours() < 10) ? "0" : "") + when_CST.getHours()
	CST_str += ((when_CST.getMinutes() < 10) ? ":0" : ":") + when_CST.getMinutes();
	if (showSeconds)
	{
	 CST_str += ((when_CST.getSeconds() < 10) ? ":0" : ":") + when_CST.getSeconds();
	}

	return CST_str;
}

///////////////////////////////////////////////////////////////////////////////////////
//
// Output a combined CST and Local ttime string to the HTML document
//
function writeCombinedTime(UTC_str, separator)
{
  document.write(CSTTimeStr(UTC_str,"&nbsp;", false) + "&nbsp;CST" + separator + "<font color=#FF6600>" + localTimeStr(UTC_str,"&nbsp;") + "</font>");
}

var timerID = null;
var timerRunning = false;

function startTimer()
{
	// Stop the clock (in case it's running), then make it go.
	stopTimer();

	// Locate base objects
	if (document.getElementById) {	
		timerObject = document.getElementById("timerbox");
		runClock();
	}else {
		//document.write("Timer Failed!");
		return true;
	} 
}

function stopTimer()
{
  //stop the clock
  if(timerRunning)
  {
    clearTimeout(timerID);
    timerRunning = false;
  }
} 

function runClock()
{
  // Get the current time

  var date = new Date();

  // Adjust this to fake UTC as local to utilise our CST routines

  date.setMinutes(date.getMinutes() + date.getTimezoneOffset());

  // Get the local time and turn into a UTC string that our time routines expect

  var local = new Date();

  LCLstr  = local.getUTCDate() + " " + months[local.getUTCMonth()] + " " + local.getUTCFullYear() + " ";
  LCLstr += local.getUTCHours() + ":" + local.getUTCMinutes();

  if (document.body.innerHTML) {
     // Display CST followed by local time in the timerObject
     timerObject.innerHTML = CSTTimeStr(date, " ", true) + " GMT [" + localTimeStr(LCLstr, " ") + "]";
  } else {
     // Display CST followed by local time in status bar of browser
     // Note that this display is similar to the time formats used on the web site 
     window.defaultStatus = CSTTimeStr(date, " ", true) + " GMT [" + localTimeStr(LCLstr, " ") + "]";
  }
   
  // Set status of the windows
  //window.defaultStatus = "Cộng Đồng Du Học Sinh Việt Nam Tại Na Uy";

  // Notice how setTimeout() calls its own calling function, runClock().;

  timerID = setTimeout("runClock()",1000);
  timerRunning = true;
}

//-->

