﻿var timerID = null
var timerRunning = false
var mesi = new Array();
mesi[0] = "Gennaio";
mesi[1] = "Febbraio";
mesi[2] = "Marzo";
mesi[3] = "Aprile";
mesi[4] = "Maggio";
mesi[5] = "Giugno";
mesi[6] = "Luglio";
mesi[7] = "Agosto";
mesi[8] = "Settembre";
mesi[9] = "Ottobre";
mesi[10] = "Novembre";
mesi[11] = "Dicembre";
     
function stopTimer(){
        //stop the clock
        if(timerRunning) {
                clearTimeout(timerID)
                timerRunning = false
        }
}
function startTimer(){

     // Stop the clock (in case it's running), then make it go.
    stopTimer()
    runClock()
}
function runClock(){
        document.getElementById("ora").innerHTML = timeNow();
		//alert(timeNow());
        //Notice how setTimeout() calls its own calling function, runClock().
        timerID = setTimeout("runClock()",1000)
        timerRunning = true
}
function timeNow() {
        //Grabs the current time and formats it into hh:mm:ss am/pm format.
        now = new Date();
        day = now.getDate();
        month = now.getMonth();
        year = now.getFullYear();
        hours = now.getHours();
        minutes = now.getMinutes();
        seconds = now.getSeconds();
        minutes = ((minutes < 10) ? "0" : "") + minutes;
        seconds = ((seconds < 10) ? "0" : "") + seconds;
        /*timeStr = "" + ((hours > 12) ? hours - 12 : hours)
        timeStr  
        timeStr  += ((seconds < 10) ? ":0" : ":") + seconds
        timeStr  += (hours >= 12) ? " PM" : " AM"*/
        timeStr = day + " " + mesi[month] + " " + year + " ore " + hours + ":" + minutes + ":" + seconds;
        return timeStr;
}

