﻿    // *****************************************************************
    function GetDay(intDay) {
        var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
                         "Thursday", "Friday", "Saturday");
        return DayArray[intDay];
    }

    // *****************************************************************
    function GetMonth(intMonth) {
        var MonthArray = new Array("January", "February", "March",
                               "April", "May", "June",
                               "July", "August", "September",
                               "October", "November", "December");
        return MonthArray[intMonth];
    }

    // *****************************************************************
    function getDateTimeDOWStr(date) {
		try {
	        var year = date.getYear();
			var curHour = date.getHours();
			var curAMPM = 'AM';
			var curTime = '';
			
			if (curHour >= 12) {
				curHour -= 12;
				curAMPM = 'PM';
			}
			
			if (curHour == 0) curHour = 12
			
			curTime = curHour + curAMPM;
			
	        if (year < 1000) year += 1900;
	        var todayStr = GetDay(date.getDay()) + ', ';
	        todayStr += GetMonth(date.getMonth()) + ' ' + date.getDate();
	        todayStr += ', ' + year + ' - ' + curTime;
	        return todayStr;
		} catch (e) {
			if (_ui.DebugFlag) {
				debugUpdate('getDateTimeDOWStr',e);
			}		
		}
    }
	
    // *****************************************************************
    function getTime(date) {
	
			var curHour = date.getHours();
			var curMin = date.getMinutes();

			var curAMPM = 'AM'
			if (curHour >= 12) {
				curHour -= 12;
				curAMPM = 'PM';
			}
			
			if (curHour == 0) curHour = 12
			curTime = curHour + ':' + curMin + curAMPM;			
			
			return curTime;
	}
	
	// *****************************************************************
    function getCurrentDate() {
		// find the form we need to update
		var curDateTime = new Date();

		// get current hour
		var hour = curDateTime.getHours();

		// get current date
		var month = curDateTime.getMonth() + 1;
		var year = curDateTime.getYear();
		var day = curDateTime.getDate();

		// convert date by casting
		if (day < 10) day = "" + day;
		if (month < 10) month = "" + month;
		if (year < 1000) year += 1900;

		var currentDate = { };
		
		currentDate.day = day - 0;
		currentDate.month = month - 0;
		currentDate.year = year - 0;
		currentDate.hour = hour - 0;
			
		return currentDate;
	}
	
	// *****************************************************************
    function checkDate(m,d,y,h) {
		
		try {
			var myDate = getCurrentDate();
		
			// check boundaries, input date must be
			//   1 <= month <= 12
			//   1 <= day <= 31
			//   2001 <= year <= current year
			//   0 <= time <= 24
			//   input date < now
		
			// check date logic by using date object
			// Javascript consider months in the range 0 - 11
			// type casting to make sure vars contain ints
			var month = (m - 0) - 1;
			y = y - 0;
			d = d - 0;
			h = h - 0;

			// create a date object
			var source_date = new Date(y,month,d);
			
			// error in year
			if(y != source_date.getFullYear())
			{
				return false;
			}

			if(month != source_date.getMonth())
			{
				return false;
			}

			// error in day
			if(d != source_date.getDate())
			{
				return false;
			}

			// error in time format
			if( h <= 0 && h > 24) 
			{
				return false;
			}
							
			// date is greater than now
			if (y <= myDate.year && y > 2001)   
			{
				if (m >= myDate.month && d >= myDate.day && h >= myDate.hour) {
					return false;				
				} else {
					return true;
									
				}
			} else {
				return false;
			}
			
		} catch (e) {
			if (_ui.DebugFlag) {
				debugUpdate('checkDate',e);
			}		
						
			return false;
		}
	
		return true;
	}
