//
// Pour la date et l'heure du serveur et non du client, il faut inégrer ce javascript dans une page PHP
//

//--------------------------------------------------------------------------------------------------------
// Definition
//--------------------------------------------------------------------------------------------------------

var imgPath     = "/clock/images";  // path to images (digits)
var imgExt		= "png";  // extension of images
var borderColor = "#F5F5F5";  // border color
var borderWidth = "0";  // border width (pixels); set to 0 for no border
var bgColor = "#F5F5F5";  // background color
var displayDate = false;  // set to true to display date

//--------------------------------------------------------------------------------------------------------
// Build clock
//--------------------------------------------------------------------------------------------------------

if (displayDate == true) {
	document.write('<table border="0" cellspacing="0" cellpadding="' + borderWidth + '"><tr><td bgcolor="' + borderColor + '">');
	document.write('<table border="0" cellspacing="0" cellpadding="1" width="135" bgcolor="' + bgColor + '">');
}

// Affichage de la date
if (displayDate == true) {
	document.write('<tr align=center>');
	document.write('<td nowrap>');
	document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="wd">');
	document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="d1">');
	document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="d2">');
	document.write('<img src="' + imgPath + '/c.' + imgExt + '">');
	document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="m1">');
	document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="m2">');
	document.write('<img src="' + imgPath + '/c.' + imgExt + '">');
	document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="y1">');
	document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="y2">');
	document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="y3">');
	document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="y4">');
	document.write('</td></tr>');
}
//

// Affichage de l'heure
if (displayDate == true) {
	document.write('<tr align=center><td nowrap>');
}

document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="hr1">');
document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="hr2">');
document.write('<img src="' + imgPath + '/c.' + imgExt + '">');
document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="mn1">');
document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="mn2">');
document.write('<img src="' + imgPath + '/nix.' + imgExt + '">');
document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="se1" width=8 height=10>');
document.write('<img src="' + imgPath + '/8.' + imgExt + '" name="se2" width=8 height=10>');

if (displayDate == true) {
	document.write('</td></tr></table></td></tr></table>');
}
//

//--------------------------------------------------------------------------------------------------------
// Functions
//--------------------------------------------------------------------------------------------------------

var dg0 = new Image();  dg0.src = imgPath + '/0.' + imgExt;
var dg1 = new Image();  dg1.src = imgPath + '/1.' + imgExt;
var dg2 = new Image();  dg2.src = imgPath + '/2.' + imgExt;
var dg3 = new Image();  dg3.src = imgPath + '/3.' + imgExt;
var dg4 = new Image();  dg4.src = imgPath + '/4.' + imgExt;
var dg5 = new Image();  dg5.src = imgPath + '/5.' + imgExt;
var dg6 = new Image();  dg6.src = imgPath + '/6.' + imgExt;
var dg7 = new Image();  dg7.src = imgPath + '/7.' + imgExt;
var dg8 = new Image();  dg8.src = imgPath + '/8.' + imgExt;
var dg9 = new Image();  dg9.src = imgPath + '/9.' + imgExt;
var dk0 = new Image();  dk0.src = imgPath + '/0.' + imgExt;
var dk1 = new Image();  dk1.src = imgPath + '/1.' + imgExt;
var dk2 = new Image();  dk2.src = imgPath + '/2.' + imgExt;
var dk3 = new Image();  dk3.src = imgPath + '/3.' + imgExt;
var dk4 = new Image();  dk4.src = imgPath + '/4.' + imgExt;
var dk5 = new Image();  dk5.src = imgPath + '/5.' + imgExt;
var dk6 = new Image();  dk6.src = imgPath + '/6.' + imgExt;
var dk7 = new Image();  dk7.src = imgPath + '/7.' + imgExt;
var dk8 = new Image();  dk8.src = imgPath + '/8.' + imgExt;
var dk9 = new Image();  dk9.src = imgPath + '/9.' + imgExt;

function viewTime() {
  var d = new Date();
  //var d= new Date(<%=year(now)%>,<%=month(now)-1%>,<%=day(now)%>,<%=hour(now)%>,<%=minute(now)%>,<%=second(now)%>);
  //var d = new Date(<? echo date('Y',time());?>,<? echo date('m',time())-1;?>,<? echo date('d',time());?>,<? echo date('H',time())?>,<? echo date('i',time());?>,<? echo date('s',time());?>);
  var weekday = d.getDay();
  var day = d.getDate() + 100;
  var month = d.getMonth() + 101;
  var year = d.getYear();
  if(year < 1900) year += 1900;
  var date = '' + day + month + year;

  if (displayDate == true) {
	  document.wd.src = imgPath + '/wd' + weekday + '.' + imgExt;
	  document.d1.src = imgPath + '/' + date.substr(1, 1) + '.' + imgExt;
	  document.d2.src = imgPath + '/' + date.substr(2, 1) + '.' + imgExt;
	  document.m1.src = imgPath + '/' + date.substr(4, 1) + '.' + imgExt;
	  document.m2.src = imgPath + '/' + date.substr(5, 1) + '.' + imgExt;
	  document.y1.src = imgPath + '/' + date.substr(6, 1) + '.' + imgExt;
	  document.y2.src = imgPath + '/' + date.substr(7, 1) + '.' + imgExt;
	  document.y3.src = imgPath + '/' + date.substr(8, 1) + '.' + imgExt;
	  document.y4.src = imgPath + '/' + date.substr(9, 1) + '.' + imgExt;
  }

  var hr = d.getHours() + 100;
  var mn = d.getMinutes() + 100;
  var se = d.getSeconds() + 100;
  var time = '' + hr + mn + se;

  document.hr1.src = imgPath + '/' + time.substr(1, 1) + '.' + imgExt;
  document.hr2.src = imgPath + '/' + time.substr(2, 1) + '.' + imgExt;
  document.mn1.src = imgPath + '/' + time.substr(4, 1) + '.' + imgExt;
  document.mn2.src = imgPath + '/' + time.substr(5, 1) + '.' + imgExt;
  document.se1.src = imgPath + '/' + time.substr(7, 1) + '.' + imgExt;
  document.se2.src = imgPath + '/' + time.substr(8, 1) + '.' + imgExt;
}

var interval = setInterval('viewTime()', 1000);
