// JavaScript Document
/***********************************************
* Local Time script- © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
/*----------------------------------------------
* ITA-ENG Time scrip - GigartDesign (http://gigartdesign.com)
* Based on the original script by Dynamic Drive, this version only works 
* with ASP pages, returning an Italian/English date/time format
* based on the local computer time setting. 

* To switch between ITA/ENG change "eng" to "ita" when inserting following
* code into the <body> tag of  your .asp page:
	<span id="timebox"></span>
	<script type="text/javascript">
	new showLocalTime("timebox", 0, "ita")
	</script>
-----------------------------------------------*/

var weekdaystxt=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
var weekgiornitxt=["Domenica", "Luned&iacute;", "Marted&iacute;", "Mercoled&iacute;", "Gioved&iacute;", "Venerd&iacute;", "Sabato"]

function showLocalTime(container, offsetMinutes, displayversion){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.displayversion=displayversion
var servertimestring=Date();
this.localtime=this.serverdate=new Date(servertimestring)
this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to local time
this.updateTime()
this.updateContainer()
}

showLocalTime.prototype.updateTime=function(){
var thisobj=this
this.localtime.setSeconds(this.localtime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

showLocalTime.prototype.updateContainer=function(){
var thisobj=this
if (this.displayversion=="ita"){
//this.container.innerHTML=this.localtime.toLocaleString()
var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()
//---GMT
var hourGMT=this.localtime.getHours()-1
//---Date
var date=this.localtime.getDate()
var month=this.localtime.getMonth()+1
var year=this.localtime.getYear()
if (year<2000){
year=year+1900
}
var dayofweek=weekgiornitxt[this.localtime.getDay()]
this.container.innerHTML=dayofweek+", "+date+"/"+month+"/"+year+" "+hour+":"+formatField(minutes)+":"+formatField(seconds)
}
else{
var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()
var ampm=(hour>=12)? "PM" : "AM"
//---GMT
var hourGMT=this.localtime.getHours()
hourGMT = hour-1
var ampmGMT=(hourGMT>=12)? "PM" : "AM"
//---Date
var date=this.localtime.getDate()
var month=this.localtime.getMonth()+1
var year=this.localtime.getYear()
if (year<2000){
year=year+1900
}
var dayofweek=weekdaystxt[this.localtime.getDay()]
this.container.innerHTML=dayofweek+", "+month+"/"+date+"/"+year+" "+formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" | GMT "+formatField(hourGMT, 1)+":"+formatField(minutes)+" "+ampmGMT
}
setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
}

function formatField(num, isHour){
if (typeof isHour!="undefined"){ //if this is the hour field
var hour=(num>12)? num-12 : num
return (hour==0)? 12 : hour
}
return (num<=9)? "0"+num : num//if this is minute or sec field
}

