
var timerID = null;
var timerRunning = false;
var zone = 0;
var Lseconds = 0;
var world_time_text = "UK Time";
//document.getElementById('wt').innerHTML = world_time_text;

function stopclock(){
    	if(timerRunning)
        	clearTimeout(timerID);
    		timerRunning = false;
}

function startclock(){
    	stopclock();

    	showtime();
	showWorldclock();
}

function showtime(){
    var now = new Date();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var Lseconds = now.getSeconds();
    var timeValue = "" + ((hours > 12) ? hours - 12 : hours);
    timeValue  += "" + ((minutes < 10) ? ":0" : ":") + minutes;
    timeValue  += ((Lseconds < 10) ? ":0" : ":") + Lseconds;
    timeValue  += (hours >= 12) ? " P.M." : " A.M.";
    //document.clock.face.value = timeValue ;
	document.getElementById('face').value = timeValue;
    timerID = setTimeout("showtime()",1000);
    timerRunning = true;
}


function updateclock(moo){
	zone = moo.options[moo.selectedIndex].value;
//	document.getElementById('wt').value = moo.options[moo.selectedIndex].innerHTML;
	world_time_text = moo.options[moo.selectedIndex].innerHTML
	//document.getElementById('wt').innerHTML = world_time_text + " Time: ";
	//alert(wt);
}

function beginning_update(value){
	zone = value;
}

function showWorldclock(){
	var worldTime = new Date();
	//var offset = worldTime.getTimezoneOffset()/60;
	var hours = 0;
	
	if(zone != 0){
		hours = worldTime.getHours() + parseInt(zone);
	}else{
		hours = worldTime.getHours();
	}
	//var date = worldTime.getDate();
	//var mon = worldTime.getMonth();		
    	var minutes = worldTime.getMinutes();
    	var seconds = worldTime.getSeconds();
	
	var timeValue = "" + ((hours > 12) ? hours - 12 : hours);
    timeValue  += "" + ((minutes < 10) ? ":0" : ":") + minutes;
    timeValue  += ((seconds < 10) ? ":0" : ":") + seconds;
    timeValue  += (hours >= 12) ? " P.M." : " A.M.";
	
	/*if (hours < 0) hours+=24;
	if (hours > 23) hours-=24;

    	var timeValue = "" + ((hours > 24) ? hours - 24 : hours);
    		timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
    		timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
    		//timeValue += (hours >= 12) ? " P.M." : " A.M.";*/
	document.getElementById('test').value = timeValue;
	//document.clock.test.value = timeValue;
	timerID = setTimeout("showWorldclock()",1000);
	timerRunning = true;
}