//var weekdaystxt=["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"]
var i = 1;
function showLocalTime(container, servermode, offsetMinutes, displayversion,server_time){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.displayversion=displayversion
this.offsetMinutes = offsetMinutes
var servertimestring=(servermode=="server-php")? server_time : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'
this.localtime=this.serverdate=new Date(servertimestring)
this.standartime = this.localtime.getTime();
this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time
this.updateTime()
this.updateContainer()
}

showLocalTime.prototype.updateTime=function(){
var thisobj=this
this.localtime.setSeconds(this.localtime.getSeconds()+1)
this.standartime = this.standartime + 1000
if (!(this.localtime.getSeconds()%10))
{
	switch (i) {
		case 1:
		{
			this.offsetMinutes = 120
			this.localtime.setTime(this.standartime+this.offsetMinutes*60*1000) //add user offset to server time
			break;
		}
		case 2:
		{
			this.offsetMinutes = 60
			this.localtime.setTime(this.standartime+this.offsetMinutes*60*1000) //add user offset to server time
			break;
		}
		case 3:
		{
			this.offsetMinutes = 0
			this.localtime.setTime(this.standartime+this.offsetMinutes*60*1000) //add user offset to server time
			break;
		}
		case 4:
		{
			this.offsetMinutes = -420
			this.localtime.setTime(this.standartime+this.offsetMinutes*60*1000) //add user offset to server time
			break;
		}
		case 5:
		{
			this.offsetMinutes = -720
			this.localtime.setTime(this.standartime+this.offsetMinutes*60*1000) //add user offset to server time
			break;
		}
		case 6:
		{
			this.offsetMinutes = 240
			this.localtime.setTime(this.standartime+this.offsetMinutes*60*1000) //add user offset to server time
			break;
		}
	}
	i = i + 1;
	if (i==7)
	{
		i = 1;
	}
	
}

setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

showLocalTime.prototype.updateContainer=function(){
var thisobj=this
if (this.displayversion=="long")
this.container.innerHTML=this.localtime.toLocaleString()

else{

var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()

var ampm=(hour>=12)? "PM" : "AM"
//var dayofweek=weekdaystxt[this.localtime.getDay()]

	switch (this.offsetMinutes){
		case 240:
			this.container.innerHTML="Sydney: "+formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)
			break;
			
		case 120:
			this.container.innerHTML="Tokyo: "+formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)
			break;
		
		case 60:
			this.container.innerHTML="Hong Kong: "+formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)
			break;
				
		case 0:
			this.container.innerHTML="Ha Noi: "+formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)
			break;
		
		case -420:
			this.container.innerHTML="Lon Don (GMT): "+formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)
			break;
			
		case -720:
			this.container.innerHTML="New York (EST): "+formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)
			break;
	}
}
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>24)? 0 : num
return (hour==0)? 12 : hour
}
return (num<=9)? "0"+num : num//if this is minute or sec field
}


/*var xmlHttp

function startTime()
{ 
xmlHttp=GetXmlHttpObject()
var url= "clock.php"
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
setTimeout("startTime()", 1000) //update container every second
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	//alert("asdf");
	document.getElementById("digital").innerHTML = xmlHttp.responseText 
 } 
}

function GetXmlHttpObject(){
	//alert("1"+window.XMLHttpRequest);
	//alert("2"+window.ActiveXObject);
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your Browser Sucks!\nIt's about time to upgrade don't you think?");
	}
}
*/