var TID = null
var timerRunning = false

function stopclock(){
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function startclock(h,i,s,lnk){
     // Make sure the clock is stopped
    stopclock()
    var now = new Date()
    var second = now.getSeconds()
    var os = second-s;
    if(os < 0) os = 60+os;
    showtime(h,i,s,lnk,os)
}

function showtime(h,i,s,lnk,os){
    var now = new Date()
    var hours = now.getHours()
    var minutes = now.getMinutes()
    var seconds = now.getSeconds()
    var time = "" + ((hours > 12) ? hours - 12 : hours)
    time  += ((minutes < 10) ? ":0" : ":") + minutes
    time  += ((seconds < 10) ? ":0" : ":") + seconds
    time  += (hours >= 12) ? " pm" : " am"

    var s = seconds-os;
    if(s < 0) s = 60-os+seconds;
    if(s==0){
    	s=0;i++;
    	if(i==60){
    		i=0;h++;
    		if(h==24){
    			h=0;
    			var RefWindow = window.open(lnk,'_self');
    			}
    		}
    	}
    var timeL = "" + ((h > 12) ? h - 12 : h)
    timeL  += ((i < 10) ? ":0" : ":") + i
    timeL  += ((s < 10) ? ":0" : ":") + s
    timeL  += (h >= 12) ? " pm" : " am"

    var time1 = "" + time +""    
    var time2 = "" + timeL +""
    var test = "link: [" +lnk+ "]   sec-os: " +os+ ""
//    window.status = "" + time1 +" il tempo conta"
    document.clock.face.value = time1
    document.clock.faceL.value = time2
    document.clock.faceTest.value = test
    TID = setTimeout("showtime("+h+","+i+","+s+",'"+lnk+"',"+os+")",1000)
    timerRunning = true
}

function Doit(h,i,s,lnk) {
	startclock(h,i,s,lnk)
}

function eMail(server,name,ext,over){
  document.write("<a href=\"mailto:"+name+"@"+server+"\."+ext+"\"");
  if(over!=""){
    document.write("onmouseover=\"document\."+over+"\.src='dos/img/"+over+"up.gif'\"");
    document.write("onmouseout=\"document\."+over+"\.src='dos/img/"+over+".gif'\"");
    }
  document.write(">");
}

function toggleMenu(currMenu) {
if (document.getElementById) {
  thisMenu = document.getElementById(currMenu).style
    if (thisMenu.display == "block") {
      thisMenu.display = "none"
      }
    else {
      thisMenu.display = "block"
      }
    return false
    }
  else {
    return true
  }
}
