/*
Autor: ixmael.arts
Descripción: Funciones para llevar a cabo una cuenta regresiva con el limite propuesto por el archivo XML de fecha
*/
function DateCountDown(year,month,day,hour,min,sec) {
	//atributos
	this.div;
	this.evento = new Date(year,month-1,day,hour,min,sec);
	//métodos
	this.setDiv = setDiv;
	this.Counter = Counter;
}

function setDiv(div) {
	this.div = div;
}

function Counter(futureDate) {
	if(!futureDate)futureDate = this;
	op = futureDate;
	amount = op.evento.getTime() - (new Date()).getTime();
	if(amount<0) {
		document.getElementById(op.div).innerHTML = "Ya";
	}else {
		var days = 0;
		var hours = 0;
		var mins = 0;
		var secs = 0;
		var out = "";
		
		//kill the "milliseconds" so just secs
		amount = Math.floor(amount/1000);
		
		//days
		days = Math.floor(amount/86400);
		amount = amount%86400;
		
		//hours
		hours = Math.floor(amount/3600);
		amount = amount%3600;
		
		//minutes
		mins = Math.floor(amount/60);
		amount = amount%60;
		
		//seconds
		secs = Math.floor(amount);
		
		if(days != 0) {
			out += "FALTAN  " + days +" DIA"+((days!=1)?"S":"")+", ";
		}
		if(days != 0 || hours != 0) {
			out += hours +" HORA"+((hours!=1)?"S":"")+", ";
		}
		if(days != 0 || hours != 0 || mins != 0) {
			out += mins +" MINUTO"+((mins!=1)?"S":"")+", ";
		}
		out += secs +" SEGUNDOS  PARA EL LANZAMIENTO DE PANDEMONIUM";
		document.getElementById(futureDate.div).innerHTML=out;

		setTimeout("Counter(op)",1000);
	}
}

//Aplicación general
function start() {
	var futureDate = new DateCountDown(2010,2,15,00,00,0);
	futureDate.setDiv("countbox");
	futureDate.Counter();
}
