function buildTime(hr, mn)
{
	var formatTime = "hh:mnPA";     // Espaņol = HH:mn, Ingles = hh:mnPA, Portugues = HHhmn
	var txtTime = "";
	
	if(formatTime.length <= 0)
		formatTime = "HH:mn";
	txtTime = formatTime;

	// Hora
	if(formatTime.indexOf("HH") >= 0)
		txtTime = txtTime.replace(/HH/, (hr<10?"0":"") + hr);
	if(formatTime.indexOf("hh") >= 0)
	{
		var hrTmp = hr;
		if(hrTmp >= 13) hrTmp = hrTmp - 12;
		txtTime = txtTime.replace(/hh/, (hrTmp<10?"0":"") + hrTmp);
	}
	
	// Minute
	if(formatTime.indexOf("mn") > 0)
		txtTime = txtTime.replace(/mn/, (mn<10?"0":"") + mn);

	// PM/AM				
	if(formatTime.indexOf("PA") > 0)
	{
		var textHr = "am";
		if(hr >= 13)
			textHr = "pm";
		txtTime = txtTime.replace(/PA/, textHr);
	}
	return txtTime;
}

function buildClock()
{
	var clockcontainer = document.getElementById("clock");

	var date = new Date();
	
	var interval = 60 - parseInt(date.getSeconds());
	var hours = date.getHours();
	var minutes = date.getMinutes();
	
	var sep = "doispontos";
	
	var formatTime = buildTime(hours, minutes);

	if(hours>12) {
		hours = hours - 12;
		if(hours<10) hours = '0'+hours;
		sufix = "pm";
	} else {
		sufix = "am";
	}
		
	if(parseInt(minutes)<10) minutes = '0'+minutes;
	
	var h1 = hours.toString().substr(0,1);
	var h2 = hours.toString().substr(1,1);
	var m1 = minutes.toString().substr(0,1);
	var m2 = minutes.toString().substr(1,1);
	
	h1 = formatTime.toString().substr(0,1);
	h2 = formatTime.toString().substr(1,1);
	var sepClock = formatTime.toString().substr(2,1);
	m1 = formatTime.toString().substr(3,1);
	m2 = formatTime.toString().substr(4,1);
	
	if(sepClock == "h")	sep = "h";
	
	var HTML = ''+
	'<' + 'span class="clock-'+h1+'">'+h1+'<' + '/span>'+
	'<' + 'span class="clock-'+h2+'">'+h2+'<' + '/span>'+
	'<' + 'span class="clock-'+sep+'">' + sepClock + '<' + '/span>'+
	'<' + 'span class="clock-'+m1+'">'+m1+'<' + '/span>'+
	'<' + 'span class="clock-'+m2+'">'+m2+'<' + '/span>';

	if(formatTime.length > 5)
	{
		sufix = formatTime.toString().substr(5);
		HTML += '<' + 'span class="clock-'+sufix+'">'+sufix+'<' + '/span>';
	}
	
	clockcontainer.innerHTML = HTML;
}