var timerID = null;

var start=0;
var now=null;
var finalhours=null;
var finalminutes=null;
var finalseconds=null;
var rseconds=null;
var rminutes=null;

var digit=null;

var countDown = 0;

function startclock() {
        start = new Date();
        finalseconds = start.getSeconds();
        finalminutes = start.getMinutes()+countDown;
        if (finalminutes>=60) {
			finalminutes -= 60;
			finalhours = start.getHours()+1
		} else {
			finalhours = start.getHours()
			};
}

function showtime () {
        now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds();
        var timeValue = new String("");

        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(start != 0){
        if (finalseconds >= seconds) {rseconds = finalseconds-seconds}
            else {rseconds = 60+finalseconds-seconds;
                     minutes += 1}
      }; //end if

         if (finalminutes >= minutes) {rminutes = finalminutes-minutes}
            else {rminutes = 60+finalminutes-minutes}; // end if
        
         if (rminutes <= countDown) { 
                var timeValue = "" +((rminutes < 10) ? "0" : "") + rminutes;
                timeValue += ((rseconds < 10) ? ":0" : ":") + rseconds}
         else {var timeValue = "00.00"}; // end if

	document.pictable.show.value=timeValue;
	//show.value=timeValue;

    if (timeValue =="00:00") {
          start=0
    }; // end if

        timerID = setTimeout("showtime()",1000);
} // end function

function setwatch(n){
	countDown = n;
	startclock();
	}
