var OnColor = "226452";
var OffColor = "eedd77";

function GetDigit( num , place ) {
	if( num.length == 2 ) {
		var numP = /^(\d)(\d)$/;
		num = num.match( numP )[ place ];
	} else {
		if( place == 1 ) {
			num = 0;
		}
	}
	return num;
}

function Clock() {
	var d = new Date();
	var h = d.getHours().toString();
	var m = d.getMinutes().toString();
	var s = d.getSeconds().toString();
	var h1 = GetDigit( h , 1 );
	var h2 = GetDigit( h , 2 );
	var m1 = GetDigit( m , 1 );
	var m2 = GetDigit( m , 2 );
	var s1 = GetDigit( s , 1 );
	var s2 = GetDigit( s , 2 );
	PaintClock( h1 , h2 , m1 , m2 , s1 , s2 );
	setTimeout( "Clock()" , 1000 );
}

function PaintClock( h1 , h2 , m1 , m2 , s1 , s2 ) {

	document.getElementById( "hp1" ).innerHTML = h1;
	document.getElementById( "hp2" ).innerHTML = h2;
	document.getElementById( "mp1" ).innerHTML = m1;
	document.getElementById( "mp2" ).innerHTML = m2;
	document.getElementById( "sp1" ).innerHTML = s1;
	document.getElementById( "sp2" ).innerHTML = s2;

	if( h1 >= 2 ) {
		document.getElementById( "h20" ).bgColor=OnColor;
	} else {
		document.getElementById( "h20" ).bgColor=OffColor;
	}
	if( h1 % 2 >= 1 ) {
		document.getElementById( "h10" ).bgColor=OnColor;
	} else {
		document.getElementById( "h10" ).bgColor=OffColor;
	}
	if( h2 >= 8 ) {
		document.getElementById( "h8" ).bgColor=OnColor;
	} else {
		document.getElementById( "h8" ).bgColor=OffColor;
	}
	if( h2 % 8 >= 4 ) {
		document.getElementById( "h4" ).bgColor=OnColor;
	} else {
		document.getElementById( "h4" ).bgColor=OffColor;
	}
	if( h2 % 4 >= 2 ) {
		document.getElementById( "h2" ).bgColor=OnColor;
	} else {
		document.getElementById( "h2" ).bgColor=OffColor;
	}
	if( h2 % 2 >= 1 ) {
		document.getElementById( "h1" ).bgColor=OnColor;
	} else {
		document.getElementById( "h1" ).bgColor=OffColor;
	}

	if( m1 >= 4 ) {
		document.getElementById( "m40" ).bgColor=OnColor;
	} else {
		document.getElementById( "m40" ).bgColor=OffColor;
	}
	if( m1 % 4 >= 2 ) {
		document.getElementById( "m20" ).bgColor=OnColor;
	} else {
		document.getElementById( "m20" ).bgColor=OffColor;
	}
	if( m1 % 2 >= 1 ) {
		document.getElementById( "m10" ).bgColor=OnColor;
	} else {
		document.getElementById( "m10" ).bgColor=OffColor;
	}


	if( m2 >= 8 ) {
		document.getElementById( "m8" ).bgColor=OnColor;
	} else {
		document.getElementById( "m8" ).bgColor=OffColor;
	}
	if( m2 % 8 >= 4 ) {
		document.getElementById( "m4" ).bgColor=OnColor;
	} else {
		document.getElementById( "m4" ).bgColor=OffColor;
	}
	if( m2 % 4 >= 2 ) {
		document.getElementById( "m2" ).bgColor=OnColor;
	} else {
		document.getElementById( "m2" ).bgColor=OffColor;
	}
	if( m2 % 2 >= 1 ) {
		document.getElementById( "m1" ).bgColor=OnColor;
	} else {
		document.getElementById( "m1" ).bgColor=OffColor;
	}
	if( s1 >= 4 ) {
		document.getElementById( "s40" ).bgColor=OnColor;
	} else {
		document.getElementById( "s40" ).bgColor=OffColor;
	}
	if( s1 % 4 >= 2 ) {
		document.getElementById( "s20" ).bgColor=OnColor;
	} else {
		document.getElementById( "s20" ).bgColor=OffColor;
	}
	if( s1 % 2 >= 1 ) {
		document.getElementById( "s10" ).bgColor=OnColor;
	} else {
		document.getElementById( "s10" ).bgColor=OffColor;
	}
	if( s2 >= 8 ) {
		document.getElementById( "s8" ).bgColor=OnColor;
	} else {
		document.getElementById( "s8" ).bgColor=OffColor;
	}
	if( s2 % 8 >= 4 ) {
		document.getElementById( "s4" ).bgColor=OnColor;
	} else {
		document.getElementById( "s4" ).bgColor=OffColor;
	}
	if( s2 % 4 >= 2 ) {
		document.getElementById( "s2" ).bgColor=OnColor;
	} else {
		document.getElementById( "s2" ).bgColor=OffColor;
	}
	if( s2 % 2 >= 1 ) {
		document.getElementById( "s1" ).bgColor=OnColor;
	} else {
		document.getElementById( "s1" ).bgColor=OffColor;
	}
}
