/*
 * time.js
 *
 * 1. Get Date
 * 2. Get Time
 * 3. Clock Update
 * 4. Clock Start
 * 5. Clock Kill
 *
 *
 *
 *
 */


// Global Variables
var int_Time_Clock_ID = 0;
var str_Time_Clock_Element = "clock";
var str_Time_Clock_Month_Format = "mmm";
var str_Time_Clock = "";
var str_Time_Clock_Month = "";
var str_Time_Clock_Day_Suffix = "th";




// 1. Get Date
function jsf_Time_getDate()
{

	// Declare, Init
	var Stamp = new Date();
	var str_Year = Stamp.getYear();
	var str_Date = "";

	// Date
	if( str_Year < 2000 ) str_Year = 1900 + str_Year;


	// Setup format
	if( str_Time_Clock_Month_Format = "mmm" )
	{

		// Get month word
		switch( Stamp.getMonth() )
		{
			case  0: str_Time_Clock_Month = "January"; break;
			case  1: str_Time_Clock_Month = "February"; break;
			case  2: str_Time_Clock_Month = "March"; break;
			case  3: str_Time_Clock_Month = "April"; break;
			case  4: str_Time_Clock_Month = "May"; break;
			case  5: str_Time_Clock_Month = "June"; break;
			case  6: str_Time_Clock_Month = "July"; break;
			case  7: str_Time_Clock_Month = "August"; break;
			case  8: str_Time_Clock_Month = "September"; break;
			case  9: str_Time_Clock_Month = "October"; break;
			case 10: str_Time_Clock_Month = "November"; break;
			case 11: str_Time_Clock_Month = "December"; break;
			default: str_Time_Clock_Month = ( tDate.getMonth() + 1 );
		}//end switch

		// Get day word
		switch( Stamp.getDate() )
		{
			case 1: str_Time_Clock_Day_Suffix = "st"; break;
			case 2: str_Time_Clock_Day_Suffix = "nd"; break;
			case 3: str_Time_Clock_Day_Suffix = "rd"; break;
			default: str_Time_Clock_Day_Suffix = "th";
		}//end switch


	}//end if
	str_Date =
		str_Time_Clock_Month + " " +
		Stamp.getDate() + str_Time_Clock_Day_Suffix + ", " +
		str_Year;


	// Return
	return( str_Date );

}//end function


function jsf_Time_Date_Display( str_ElementID )
{
	document.getElementById( str_ElementID ).innerHTML = jsf_Time_getDate();

}



// 2. Get Time
function jsf_Time_getTime()
{

	/* Declare, Init*/
	var Stamp = new Date();
	var Hours;
	var Time;
	var Mins;
	var str_Time ="";


	// Time
	Hours = Stamp.getHours();
	if (Hours >= 12) { Time = " pm"; }
	else { Time = " am"; }
	if (Hours > 12) { Hours -= 12; }
	if (Hours == 0) { Hours = 12; }
	Mins = Stamp.getMinutes();
	if (Mins < 10) { Mins = "0" + Mins; }
	str_Time = Hours + ":" + Mins + Time;

	// Return
	return( str_Time );


}//end function 1




// 3. Clock Update
function jsf_Time_Clock_Update()
{

	// Declare, Init
	var tDate = new Date();


	// Clear timeout
	if( int_Time_Clock_ID )
	{
		clearTimeout( int_Time_Clock_ID );
		int_Time_Clock_ID = 0;
	}//end if


	// Month Format
	if( str_Time_Clock_Month_Format = "mmm" )
	{
		// Define Clock's Format
		str_Time_Clock =
			str_Time_Clock_Month + " " +
			tDate.getDate() + str_Time_Clock_Day_Suffix + ", " +
			tDate.getYear() + " " +
			( tDate.getHours() < 10 ? "0" : "" ) + tDate.getHours() + ":" +
			( tDate.getMinutes() < 10 ? "0" : "" ) + tDate.getMinutes() + ":" +
			( tDate.getSeconds() < 10 ? "0" : "" ) + tDate.getSeconds();

	}//end if


	// Regular format
	else
	{
		// Define Clock with Format
		str_Time_Clock =
			tDate.getMonth() + "/" +
			tDate.getDate() + "/" +
			tDate.getYear() + " " +
			( tDate.getHours() < 10 ? "0" : "" ) + tDate.getHours() + ":" +
			( tDate.getMinutes() < 10 ? "0" : "" ) + tDate.getMinutes() + ":" +
			( tDate.getSeconds() < 10 ? "0" : "" ) + tDate.getSeconds();
	}//end else


	// Push Clock
	document.getElementById( str_Time_Clock_Element ).innerHTML = str_Time_Clock;

	// Set Timeout
	clockID =
		setTimeout
		(
			"jsf_Time_Clock_Update()",
			1000
		);

}//end function




// 4. Clock Start
function jsf_Time_Clock_Start()
{

	// Declare, Init
	var tDate = new Date();

	// Setup format
	if( str_Time_Clock_Month_Format = "mmm" )
	{

		// Get month word
		switch( tDate.getMonth() )
		{
			case  0: str_Time_Clock_Month = "January"; break;
			case  1: str_Time_Clock_Month = "February"; break;
			case  2: str_Time_Clock_Month = "March"; break;
			case  3: str_Time_Clock_Month = "April"; break;
			case  4: str_Time_Clock_Month = "May"; break;
			case  5: str_Time_Clock_Month = "June"; break;
			case  6: str_Time_Clock_Month = "July"; break;
			case  7: str_Time_Clock_Month = "August"; break;
			case  8: str_Time_Clock_Month = "September"; break;
			case  9: str_Time_Clock_Month = "October"; break;
			case 10: str_Time_Clock_Month = "November"; break;
			case 11: str_Time_Clock_Month = "December"; break;
			default: str_Time_Clock_Month = ( tDate.getMonth() + 1 );
		}//end switch

		// Get day word
		switch( tDate.getDate() )
		{
			case 1: str_Time_Clock_Day_Suffix = "st"; break;
			case 2: str_Time_Clock_Day_Suffix = "nd"; break;
			case 3: str_Time_Clock_Day_Suffix = "rd"; break;
			default: str_Time_Clock_Day_Suffix = "th";
		}//end switch


	}//end if

	// Set timeout
	clockID = setTimeout( "jsf_Time_Clock_Update()", 500 );

}//end function




// 5. Clock Kill
function jsf_Time_Clock_Kill()
{
   if( int_Time_Clock_ID )
   {
      clearTimeout( int_Time_Clock_ID );
      int_Time_Clock_ID = 0;
   }//end if
}//end function

