var timerID = null;
var timerRunning = false;

function MakeArray(size){
  this.length = size;
   for(var i = 1; i <= size; i++){ this[i] = ""; }
   return this;
}

function stopclock(){ if(timerRunning) clearTimeout(timerID); timerRunning = false; }

function showdate(){
  var now = new Date();
  var year = now.getFullYear();
  var month = now.getMonth() + 1;
  var date = now.getDate();
  var day = now.getDay();
  var thisDay = new MakeArray(17);
  thisDay[0]="Sonntag";
  thisDay[1]="Montag";
  thisDay[2]="Dienstag";
  thisDay[3]="Mittwoch";
  thisDay[4]="Donnerstag";
  thisDay[5]="Freitag";
  thisDay[6]="Samstag";
  thisDay[10]="So";
  thisDay[11]="Mo";
  thisDay[12]="Di";
  thisDay[13]="Mi";
  thisDay[14]="Do";
  thisDay[15]="Fr";
  thisDay[16]="Sa";
  
  var dateValue = (datetimeShort == 'true') ? thisDay[day+10] + ', ' : thisDay[day] + ', ' ;
  dateValue += ((date < 10) ? '0' : '') + date + '.';
  dateValue += ((month < 10) ? '0' : '') + month + '.' + year;
  document.getElementById('showDate').innerHTML = dateValue;

}

function showtime () {
  var now = new Date();
  var hours = now.getHours();
  var minutes = now.getMinutes();
  var seconds = now.getSeconds();
   
  var timeValue = ((hours < 10) ? '0' : ' ') + hours;
  timeValue += ((minutes < 10) ? ':0' : ':') + minutes;
  timeValue += ((seconds < 10) ? ':0' : ':') + seconds;
  
  document.getElementById('showTime').innerHTML = timeValue;
  timerID = setTimeout("showtime()",1000);
  timerRunning = true;
}


function startclock(){
  stopclock();
  showtime();
  if(datetimeDate=='true')showdate();
}
