function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function daysElapsed(date1,date2) {
	var difference = Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0) - Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0);
	alert(difference);
	return difference/1000/60/60/24;
}

var MONTH_NAMES=new Array("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre","Gen","Feb","Mar","Apr","Mag","Giu","Lug","Ago","Set","Ott","Nov","Dic");
//var DAY_NAMES=new Array();
var DAY_NAMES=new Array("Domenica","Lunedi","Martedi","Mercoledi","Giovedi","Venerdi","Sabato","Dom","Lun","Mar","Mer","Gio","Ven","Sab");
function LZ(x) {return(x<0||x>9?"":"0")+x}

function loadcombo(backHistory,back) {
	var oggi = new Date() - 86400000;
	var giorno;
	var select = document.forms['af1'].s;
	for (i = 0; i < backHistory; i++)
	{
		giorno = new Date(oggi-(i*86400000));
		select.options[i+1] = new Option(formatDate(giorno,"EE d MMM y"), formatDate(giorno,"yMMdd"));
		if (window.location.pathname.split("/")[4] != null) {
			if (window.location.pathname.split("/")[4].split(".")[0] == formatDate(giorno,"yMMdd")) {
				//alert(window.location.pathname.split("/")[4].split(".")[0]);
				select.selectedIndex = i+1;
				back = 1;
			}
		}
	}

	if (back == 0) {
		select.selectedIndex = "archivio";
	}
}

function ePchangeDate() {
	g = document.forms['af1'].s.value;
	if (g > 0) {
		window.location.href="/" + window.location.pathname.split("/")[1] + "/" + window.location.pathname.split("/")[2].split("_")[0] + "/" + g.substr(0,4) + "/" + g + ".shtml"
	} else {
		window.location.href="/" + window.location.pathname.split("/")[1] + "/" + window.location.pathname.split("/")[2] + "_1.shtml";
	}
}

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["NNN"]=MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
	}
	return result;
}


