﻿// JScript File
var timerID = null;
var timerRunning = false;

function StopClock() {
	if(timerRunning)
		clearTimeout(timerID);
	timerRunning = false;
}

function StartClock() {
	StopClock();
	DisplayTime();
}

function DisplayTime() {
    var theDate = new Date();
	weekday = getWeekDayName(theDate.getDay());
	month = getMonthName(theDate.getMonth());
	day = theDate.getDate();
	year = theDate.getFullYear();
	hour = theDate.getHours();
	minute = AddLeadingZero(theDate.getMinutes());
	second = AddLeadingZero(theDate.getSeconds());
	if (hour > 11)
	    ampm = "PM";
	else
	    ampm = "AM";
	hour = (hour == 0) ? 12 : hour;
	hour = (hour > 12) ? hour - 12 : hour;

	document.aspnetForm.currentdatetime.value = weekday + ", " + month + " " + day + ", " + year + " " + hour + ":" + minute + ":" + second + " " + ampm;
	timerID = setTimeout("DisplayTime()",1000);
	timerRunning = true;
}

function AddLeadingZero(num) {
	if (num < 10)
		num = "0" + num;
	return num;
}

function getMonthName(month) {
    // create array to hold name of each month
    var ar = new Array(12)
    ar[0] = "January"
    ar[1] = "February"
    ar[2] = "March"
    ar[3] = "April"
    ar[4] = "May"
    ar[5] = "June"
    ar[6] = "July"
    ar[7] = "August"
    ar[8] = "September"
    ar[9] = "October"
    ar[10] = "November"
    ar[11] = "December"

    // return name of specified month (parameter)
    return ar[month]
}

function getWeekDayName(day) {
    var weekDay = new Array(7)
    weekDay[0] = "Sunday"
    weekDay[1] = "Monday"
    weekDay[2] = "Tuesday"
    weekDay[3] = "Wednesday"
    weekDay[4] = "Thursday"
    weekDay[5] = "Friday"
    weekDay[6] = "Saturday"
    
    return weekDay[day];
}

window.onload = WindowLoad;
window.onresize = WindowResize;

function WindowLoad() {
    ResizeContentTable();
    StartClock();
}

function WindowResize() {
    ResizeContentTable();
}

function ResizeContentTable() {
    //var width = GetWindowWidth();
    //var content_width = document.getElementById("ContentTable").offsetWidth;
    //var left = (width - content_width)/2;
    //document.getElementById("ContentTable").style.left = left + "px";
    document.getElementById("ContentTable").style.height = GetWindowHeight() + "px";
}

function GetWindowWidth() {
  var myWidth = 0;
  var myHeight = 0;
  if (typeof(window.innerWidth) == 'number')
    myWidth = window.innerWidth;
  else if (document.documentElement && document.documentElement.clientWidth)
    myWidth = document.documentElement.clientWidth;
  else if (document.body && document.body.clientWidth)
    myWidth = document.body.clientWidth;
  return myWidth;
}

function GetWindowHeight() {
  var myHeight = 0;
  if (typeof(window.innerHeight) == 'number')
    myHeight = window.innerHeight;
  else if (document.documentElement && document.documentElement.clientHeight)
    myHeight = document.documentElement.clientHeight;
  else if (document.body && document.body.clientHeight)
    myHeight = document.body.clientHeight;
  return myHeight;
}

function GetRealLeft(el) {
    xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function GetRealTop(el) {
    yPos = el.offsetTop;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}