function nth(x) {
if (x==1 || x==21 || x==31) return "st";
if (x==2 || x==22) return "nd";
if (x==3 || x==23) return "rd";
return "th";
}

function noZero(x) {
if (x < 10) return "0" + x;
return x;
}

function theHourNow(x) {
if (x==0 || x==24) return "Midnight";
if (x==1 || x==13) return "One";
if (x==2 || x==14) return "Two";
if (x==3 || x==15) return "Three";
if (x==4 || x==16) return "Four";
if (x==5 || x==17) return "Five";
if (x==6 || x==18) return "Six";
if (x==7 || x==19) return "Seven";
if (x==8 || x==20) return "Eight";
if (x==9 || x==21) return "Nine";
if (x==10 || x==22) return "Ten";
if (x==11 || x==23) return "Eleven";
if (x==12) return "Midday";
return x; //default
}

function theMinuteNow (x) {
if (x==1) return "1 minute ";
if (x==15) return "a quarter ";
if (x==30) return "half ";
if (x==45) return "a quarter ";
if (x==59) return "1 minute ";
if (x > 30) return (60 - x) + " minutes ";
return x + " minutes ";
}


/* Inserts the date in English in the id="todaysDate" tag */

function timeAndDate() {

var d = new Date()
var weekday = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var monthname = new Array("January","February","March","April","May","June","July","August","September","October","November","December")



var theDay   = weekday[d.getDay()];
var theDate  = d.getDate();
var theMonth = monthname[d.getMonth()];
var theYear  = d.getFullYear();

var theHours = d.getHours()
var theMinutes = d.getMinutes()
var theSeconds = d.getSeconds()

var digitalHours = theHours
   if (theHours == 0)
      digitalHours = 12
   if (theHours > 12)
      digitalHours = theHours - 12

var ampm = " am"
   if (theHours > 11)
      ampm = " pm"

var radioHours = theHours
   if (theMinutes > 30)
      radioHours = radioHours + 1

var radioApproach = "past"
   if (theMinutes > 30)
      radioApproach = "to"

var radioMinutes = theMinutes
   if (theMinutes == 15)
      radioMinutes = "a quarter"
   if (theMinutes == 30 )
      radioMinutes = "half"
   if (theMinutes > 30)
      radioMinutes = 60 - theMinutes
   if (theMinutes == 45)
      radioMinutes = "a quarter"

if (theMinutes == 0) {
   if (theHours == 0 || theHours == 12) {
      timeNOW = theHourNow(radioHours)
   }
   else {
      timeNOW = theHourNow(radioHours) + " o'clock"
   }
}
if (theMinutes > 0) {
   timeNOW = theMinuteNow(theMinutes) + radioApproach + " " + theHourNow(radioHours)
}

document.getElementById("radioDate").innerHTML = theDay + " the " + theDate + "<sup><small>" + nth(theDate) + "</small></sup>" + " of " + theMonth + ", " +theYear;

document.getElementById("radioClock").innerHTML = timeNOW

setTimeout("timeAndDate()",1000);
}
