// JavaScript Document

var timerID = null
var timerRunning = false
var days = new Array('Domenica','Lunedì','Martedì','Mercoledì','Giovedì','Venerdì','Sabato');
var months = new Array('Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','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(){
	    var span_ora = document.getElementById('ora');
		span_ora.innerHTML = timeNow();
        //document.clock.face.value = 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()
        hours = now.getHours()
        minutes = now.getMinutes()
        seconds = now.getSeconds()
        timeStr = "" + ((hours > 12) ? hours - 12 : hours)
        timeStr  += ((minutes < 10) ? ":0" : ":") + minutes
        timeStr  += ((seconds < 10) ? ":0" : ":") + seconds
        timeStr  += (hours >= 12) ? " PM  " : " AM  "
        return timeStr
}

    

function longyear(number)
{
	return (number < 1000) ? number + 1900 : number;
}

function data(){	
	// Oggi = Giorno DD Mese AAAA
	var now = new Date();
	var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
	today = (days[now.getDay()] + " " + date + " " + months[now.getMonth()] + " " + longyear(now.getYear()));
	var span_data = document.getElementById('data');
	span_data.innerHTML = today;
}