var DOM = (document.getElementById) ? true:false
var IE4 = (document.all && !DOM) ? true:false
var NS4 = (document.layers) ? true:false

function darId(id) {
   if (DOM) return document.getElementById(id);
   if (IE4) return document.all[id];
   if (NS4) return document.layers[id];
}

function Fecha(idioma){
	this.f = new Date();

	if (idioma=='eng'){
		this.semana = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
		this.mes = new Array(
			"January","February","March",
			"April","May","June",
			"July","August","September",
			"October","November","December"
		);
	} else if (idioma=='nor'){
		this.semana = new Array("Diumenge","Dilluns","Dimarts","Dimecres","Dijous","Divendres","Dissabte");
		this.mes = new Array(
			"Gener","Febrer","Març",
			"Abril","Maig","Juny",
			"Juliol","Agost","Setembre",
			"Octubre","Novembre","Decembre"
		);
	} else {
		this.semana = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
		this.mes = new Array(
			"Enero","Febrero","Marzo",
			"Abril","Mayo","Junio",
			"Julio","Agosto","Septiembre",
			"Octubre","Noviembre","Diciembre"
		);
	}

	this.dNombre = this.semana[this.f.getDay()];
	this.dNumero = this.f.getDate();
	this.mNombre = this.mes[this.f.getMonth()];
	this.aCompleto = this.f.getFullYear();
	this.hora = function(objName, spanId){
		fTemp = new Date();
		hours = ( fTemp.getHours() > 9 ) ? fTemp.getHours() : "0"+fTemp.getHours();
		minutes = ( fTemp.getMinutes() > 9 ) ? fTemp.getMinutes() : "0"+fTemp.getMinutes();
		seconds = ( fTemp.getSeconds() > 9 ) ? fTemp.getSeconds() : "0"+fTemp.getSeconds();
		darId(spanId).innerHTML = hours+":"+minutes+":"+seconds;
		setTimeout(objName+".hora('"+objName+"','"+spanId+"')",1000);
	}
	this.todaLaFecha = function(){
		var une="";
		if (idioma=='eng'){
			une= "";
		} else if (idioma=='nor'){
			une= "de";
		} else {
			une= "de";
		}
		return this.dNombre+" "+this.dNumero+" "+une+" "+this.mNombre+" "+une+" "+this.aCompleto;
	}
}

function inicializador(idioma){
	miFecha = new Fecha(idioma);
	miFecha.hora("miFecha","reloj");
	darId("fecha").innerHTML = miFecha.todaLaFecha();
}
