﻿function OnLoadDate() {
    var dateField = document.getElementById("txtDate");
    if (dateField) {
        dateField.value = getCalendarDate() + " " + getClockTime();
    }
}

function getCalendarDate() {
    var months = new Array(13);
    months[0] = "January";
    months[1] = "February";
    months[2] = "March";
    months[3] = "April";
    months[4] = "May";
    months[5] = "June";
    months[6] = "July";
    months[7] = "August";
    months[8] = "September";
    months[9] = "October";
    months[10] = "November";
    months[11] = "December";
    var now = new Date();
    var monthNumber = now.getMonth();
    var monthName = months[monthNumber];
    var monthDay = now.getDate();
    var year = now.getYear();
    if (year < 2000) {
        year += 1900;
    }
    var dateString = monthName + ' ' + monthDay + ', ' + year;
    return dateString;
}

function getClockTime(includeSeconds) {
    var now = new Date();
    var hour = now.getHours();
    var minute = now.getMinutes();
    var second = now.getSeconds();
    var ap = "am";
    if (hour > 11) { ap = "pm"; }
    if (hour > 12) { hour -= 12; }
    if (hour == 0) { hour = 12; }
    if (hour < 10) { hour = "0" + hour; }
    if (minute < 10) { minute = "0" + minute; }
    if (second < 10) { second = "0" + second; }
    var timeString = hour + ':' + minute;
    if (includeSeconds) {
        timeString += " :" + second;
    }
    timeString += " " + ap;
    return timeString;
}