/**
 * MyReloj v.1.0 2009-01-26
 * José Carlos Cruz Parra
 * www.programadorphpfreelance.com
 */
function MyReloj(varName,showDate,showHour)
{
	this.varName = varName;
	this.id = "reloj"+Math.round(10000*Math.random());
	this.showDate = showDate == null ? true : showDate;
	this.showHour = showHour == null ? true : showHour;
	this.time = 0;

	this.Display = function(ano,mes,dia,hora,minuto,segundo)
	{
		document.write('<span id="'+this.id+'"></span>');
		var now = new Date();
		var aux = new Date(ano==null?now.getFullYear():ano, mes==null?now.getMonth():parseInt(mes)-1, dia==null?now.getDate():dia, hora==null?now.getHours():hora, minuto==null?now.getMinutes():minuto, segundo==null?now.getSeconds():segundo);
		this.time = aux.getTime();
		this.refresh();
	}
	this.refresh = function()
	{
		var aux = new Date();
		aux.setTime(this.time);
		var date = this.showDate ? this.formatNumber(aux.getDate()) + "/" + this.formatNumber(aux.getMonth()+1) + "/" + aux.getFullYear() : "";
		var hour = this.showHour ? this.formatNumber(aux.getHours()) + ":" + this.formatNumber(aux.getMinutes()) + ":" + this.formatNumber(aux.getSeconds()) : "";
		document.getElementById(this.id).innerHTML = date+" "+hour;
		this.time += 1000;
		setTimeout(this.varName+'.refresh()', 1000);
	}
	this.formatNumber = function(n)
	{
		return n < 10 ? '0'+n : n;
	}
}