/*
FileName : dateDisplay.js
Author   : K.Ramachandran
Date	 : 13/06/2002
Version  : 1.0
*/
  
  /*
  This function to setting the current date for the user display
  */	
  function setDateFunc()
  {
        //getting the date object
   		var tDate = new Date();  
		//getting the today's date value
   		var day=tDate.getDate();
		//getting the current month value
		var month=tDate.getMonth() + 1;
		//getting the current year value
		var year=tDate.getFullYear();
		//getting the current day of the week
		var curDay=tDate.getDay();
		//variable to store the month value and day value in string 
		var monthString="",dayString="";
		//switch statement to find the month value in string corresponding to the integer value
		switch(month)
		{
		  /*
           updation : Shortened the month names into its first three letters for the date display
		   done by  : K.Ramachandran
		   date     : 30-10-2002
          */
		  case 1:
		   monthString="Jan";
		   break;
		  case 2:
		   monthString="Feb";
		   break;
		  case 3:
		   monthString="Mar";
		   break;
		  case 4:
		   monthString="Apr";
		   break;
		  case 5:
		   monthString="May";
		   break;
		  case 6:
		   monthString="Jun";
		   break;
		  case 7:
		   monthString="Jul";
		   break;
		  case 8:
		   monthString="Aug";
		   break;
		  case 9:
		   monthString="Sep";
		   break;
		  case 10:
		   monthString="Oct";
		   break;
		  case 11:
		   monthString="Nov";
		   break;
		  case 12:
		   monthString="Dec";
		   break;             
		}
		switch(curDay)
		{
		  case 0:
		   dayString="Sunday";
		   break;
		  case 1:
		   dayString="Monday";
		   break;
		  case 2:
		   dayString="Tuesday";
		   break;
		  case 3:
		   dayString="Wednesday";
		   break;
		  case 4:
		   dayString="Thursday";
		   break;
		  case 5:
		   dayString="Friday";
		   break;
		  case 6:
		   dayString="Saturday";
		   break;
		  
		 }  
		//variable to store the subscript value which is to be displayed after the date value
		var daySub="";
		//setting the date's subscript value based on its integer value
		if(day==1 || day==21)
		 daySub="st";
		else if(day==2 || day==22)
		 daySub="nd";
		else
		 daySub="th";
	    //parsing the date,month and year value to form the full date 	 
	  //  var fullDate= dayString+":"+day+"<sup>"+daySub+"</sup> "+monthString+" "+year;
	    var fullDate= dayString+": "+" "+monthString+" "+day+", "+year;
	    //displaying the current date.
	    //document.write(fullDate);
		return fullDate;
  }//end of setDateFunc function
  
/*
This function to get the current system time for the display
*/  
function clock()
{
    //if the current browser is not a netscape and internet explorer then return from the function
	if (!document.getElementById && !document.layers && !document.all) return;
	//getting a date object
	var digital = new Date();
	//getting the hours part of time
	var hours = digital.getHours();
	//getting the minutes part of time
	var minutes = digital.getMinutes();
	//getting the seconds part of time
	var seconds = digital.getSeconds();
	//getting the date part by calling the function setDateFunc()
	var fullDate=setDateFunc();
	//setting time initially as 'AM'
	var amOrPm = "AM";
	//if the hours > 11 setting the time as 'PM'
	if (hours > 11) amOrPm = "PM";
	//after 12 rotate the clock again from 1 to 12
	if (hours > 12) hours = hours - 12;
	//if hours=0 then setting hours=12
	if (hours == 0) hours = 12;
	//if minutes in single digit then adding '0' in front of the minute
	if (minutes <= 9) minutes = "0" + minutes;
	//if seconds in single digit then adding '0' in front of the second
	if (seconds <= 9) seconds = "0" + seconds;
	//storing the date value in a variable dispDate
	dispDate = fullDate;
	//storing the complete time with hours,minutes and seconds.
	dispTime=hours + ":" + minutes + ":" + seconds + " " + amOrPm;
	//if the browser is netscape with version above or equal to 5
	if (navigator.appName == 'Netscape' && parseFloat(navigator.appVersion) >=5.0  && document.getElementById != null) 
	{ 
	 //getting the 'pendule' layer and setting the date and time in that layer
	 var x=document.getElementById("pendule");
	 x.innerHTML="<table><tr><td align=center><font face=verdana,arial size=1 color=white><b>"+dispDate+"</b></font></td></tr><tr><td align=center><font face=verdana,arial size=1 color=black><b>"+dispTime+"</b></font></td></tr></table>";
	}
	//if the browser is a netscape with version less than 5
	else if (document.layers) {
	//writing the date and time value in the layer 'pendule'
	document.layers['pendule'].document.writeln("<table><tr><td align=center><font face=verdana,arial size=1 color=white><b>"+dispDate+"</b></font></td></tr><tr><td align=center><font face=verdana,arial size=1 color=#000000><b>"+dispTime+"</b></font></td></tr></table>");
	document.layers['pendule'].document.close();
	//pendule.innerHTML = "<table><tr><td><font face=verdana,arial size=1 color=white><b>"+dispDate+"</b></font></td></tr><tr><td><font face=verdana,arial size=1 color=#000000><b>"+dispTime+"</b></font></td></tr></table>";
	}
	//if the browser is a internet explorer
	else
	if (document.all)
	//setting the date and time value in the 'pendule' layer for display
	pendule.innerHTML = "<table><tr><td align=center><font face=verdana,arial size=1 color=white><b>"+dispDate+"</b></font></td></tr><tr><td align=center><font face=verdana,arial size=1 color=#000000><b>"+dispTime+"</b></font></td></tr></table>";
	//calling the clock() function for each second to show the current time
	setTimeout("clock()", 1000);
}//end of clock() function