
// --------- --------- ---------
// Javascript Real-time Clock+Date
// Created By Darksider
// darksider@swedger.com
// http://www.swedger.com
// --------- --------- ---------
// This script is OPEN-SOURCE,
// and as such can be downloaded,
// modified, and re-distributed
// by ANYONE. Though if you do,
// PLEASE LEAVE THIS AND ALL OTHER
// COMMENT BLOCKS INTACT!!
// --------- --------- ---------
function realtimeclock(lang) {

	lang = typeof(lang) != 'undefined' ? lang : "fr";

	var timestamp=new Date();
	// - - - FIRST SORT THE TIME - - -
	
	monthCaptions = {
		"fr":["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"], 
		"en":["January","February","March","April","May","June","July","August","September","October","November","December"]
	}
	var months = monthCaptions[lang];
	
	var showPeriod = (lang=="en");
	var hour=timestamp.getHours();// hours passed today(0-23)
	var mins=timestamp.getMinutes();// minutes past the hour(0-59)
	var secs=timestamp.getSeconds();// seconds past the minute(0-59)
	var period; // variable to contain "am/pm" string
	if (showPeriod) {
	if(hour==0) {hour=12;}// turns 0 into 1 (0 is returned for 12 midday and 12 midnight)
	if(hour>12) {hour=(hour-12);period=" pm";} else {period=" am";}// if hour is more than 12, deduct 12 and make the period PM - otherwise make period AM	
	} else {
		period = "";
	}
	if(mins<10) {mins="0"+mins;}// add a trailing zero the the minutes variable if the minutes are less than 10
	if(secs<10) {secs="0"+secs;}// also add a trailing zero to the seconds variable if seconds < 10
	var curTime=hour+":"+mins+":"+secs+period;// build out curTime string with the 4 blocks(hours:minutes:seconds <am/pm>)
	// - - - NEXT SORT THE DATE - - -
	var date=timestamp.getDate();// current date (0-30/31 or 28/29 for February[1])
	var month=timestamp.getMonth();// current month (0-11)
	var year=timestamp.getFullYear();// full year (4-digits)
	date=(date); // add 1 to the date, because they start at 0 (1st day)
	month=(month+1);// also add 1 because 0 = January
	// - - - MAKE MONTH TEXTUAL - - -
	month=months[month-1];
	var curDate = "";
	if (lang == "fr")
		curDate=date+" "+month+" "+year;// build out curDate string with the 3 blocks(date/month/year)
	else {
		curDate=month+" "+date+" "+year;// build out curDate string with the 3 blocks(month/date/year)
	}
	// - - - THEN PRINT DATE+TIME - - -
	if (document.getElementById("clock")) {
		document.getElementById("clock").firstChild.nodeValue=curDate+" "+curTime;
	}
	if (document.getElementById("current-year")) {
		document.getElementById("current-year").firstChild.nodeValue=year;
	}
}
