<!--
// .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
// Código del contador de CO2 by Guillermo BT
// gbt@gbt.es (19feb2008)
// .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..

dirImg=	"img/";

var timerID= null;
var timerActivo= false;


// .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
// Precarga de los digitos para el contador
// .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..

var arNum= new Array();
for (var b=0; b<=9; b++) {
  arNum[b]= new Image();
  arNum[b].src = dirImg + b + ".jpg";
}

function PararReloj () {
  if (timerActivo)
    clearTimeout (timerID);
}

function ActivarReloj () {
  PararReloj();
  Reloj();
}


function Reloj () {
  var fecha= new Date();
  var horas= fecha.getHours();
  var minutos= fecha.getMinutes();
  var segundos= fecha.getSeconds();

  //Valor a las 23:59h 26,42312 Tons)
  //Nuevo factor= 26,42312 / 86400= 0,000305823
  segundosTranscurridos=	horas * 3600 + minutos * 60 + segundos;
  factor=					0.000305823;  //factor=					0.0012669;
  co2Consumido=				parseFloat(segundosTranscurridos * factor);

  pEntera=					ParteEntera(co2Consumido);
  pDecimal=					ParteDecimal(co2Consumido);
  pDecimal5=				String(pDecimal).substring(0, 5);		//Sólo queremos 5 dígitos

  //statusTxt= 	segundosTranscurridos + " CO2:  ("+pEntera+";"+pDecimal5+")";

  // Actualizar cantidad cada N segundos
  if ((segundosTranscurridos % 1) == 0) {

	  cuantosEnteros=	pEntera.length;

	  var arCifras= new Array();
	  //Todo a cero por defecto
	  for (k=0; k<=7; k++) {
		arCifras[k]= 0;
	  }


	  if (cuantosEnteros < 1) {
	  	pEntera= "000"
	  }
	  if (cuantosEnteros == 1) {
	  	pEntera= "00" + pEntera;
	  }
	  if (cuantosEnteros == 2) {
	  	pEntera= "0" + pEntera;
	  }

	  for (t=0; t < (pEntera.length); t++) {
	  	arCifras[7-t]= 	pEntera.charAt(t);
	  }
	  for (r=0; r<5; r++) {
	  	arCifras[r]= 	pDecimal5.charAt(r);
	  }

	  if (document.unidades) {
		  document.unidades.src=  arNum[parseInt(arCifras[5])].src;
		  document.decenas.src=   arNum[parseInt(arCifras[6])].src;
		  document.centenas.src=  arNum[parseInt(arCifras[7])].src;

		  document.decimal_1.src= arNum[parseInt(arCifras[0])].src;
		  document.decimal_2.src= arNum[parseInt(arCifras[1])].src;
		  document.decimal_3.src= arNum[parseInt(arCifras[2])].src;
		  document.decimal_4.src= arNum[parseInt(arCifras[3])].src;
		  document.decimal_5.src= arNum[parseInt(arCifras[4])].src;
	  }
  }

  timerID= setTimeout("Reloj()",1000);
  timerActivo= true;
}

function RedondeoDecimal(numero, numDecimales) {
  return Math.round(numero*Math.pow(10,numDecimales))/Math.pow(10,numDecimales);
}

function ParteDecimal (numero) {
	var txNum=	String(numero);
	var arPartes=	txNum.split(".");
	resul = String(arPartes[1]);
	return (resul);
}

function ParteEntera (numero) {
	var txNum=	String(numero);
	var arPartes=	txNum.split(".");
	resul = String(arPartes[0]);
	return (resul);
}


// .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
// Codigo para la ventana emergente
// .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
