// JavaScript by Emiliano Giovanni Vavassori <testina@sssup.it>.
//
// Il risultato come nel seguente esempio:
//  ``Buon giorno, gentile visitatore, sono le ore 14:30 del giorno mercoledì 02 Aprile 2003,,.

var DisplayDate = true;
var ie4=document.all
var ns4=document.layers
var ns6=document.getElementById&&!document.all
var DaysOfWeek = new Array(7);
	DaysOfWeek[0] = "domenica";
	DaysOfWeek[1] = "luned&igrave;";
	DaysOfWeek[2] = "marted&igrave;";
	DaysOfWeek[3] = "mercoled&igrave;";
	DaysOfWeek[4] = "gioved&igrave;";
	DaysOfWeek[5] = "venerd&igrave;";
	DaysOfWeek[6] = "sabato";

var MonthsOfYear = new Array(12);
	MonthsOfYear[0] = "Gennaio";
	MonthsOfYear[1] = "Febbraio";
	MonthsOfYear[2] = "Marzo";
	MonthsOfYear[3] = "Aprile";
	MonthsOfYear[4] = "Maggio";
	MonthsOfYear[5] = "Giugno";
	MonthsOfYear[6] = "Luglio";
	MonthsOfYear[7] = "Agosto";
	MonthsOfYear[8] = "Settembre";
	MonthsOfYear[9] = "Ottobre";
	MonthsOfYear[10] = "Novembre";
	MonthsOfYear[11] = "Dicembre";

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function getCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) 
		break; 
	}
	return null;
}

function setCookie (name, value) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function genDate() {
	var Digital = new Date();
	var day = Digital.getDay();
	var mday = Digital.getDate();
	var month = Digital.getMonth();
	var hours = Digital.getHours();
	var saluto = (hours < 12)?((hours < 6)?'Buona notte, ':'Buon giorno, '):((hours < 18)?'Buon pomeriggio, ':'Buona sera, ');
	var minutes = Digital.getMinutes();
	var seconds = Digital.getSeconds();
	var year = Digital.getYear();
	(year < 200)?year = year + 1900:year = Digital.getYear();

	if (hours <= 9)
		hours = '0'+hours;
	if (minutes <= 9)
		minutes = "0"+minutes;
	if (seconds <= 9)
		seconds = "0"+seconds;

	myclock = '';
	myclock += saluto;
	myclock += nome+', sono le ore '+hours+':'+minutes+':'+seconds;
	if (DisplayDate) {
		myclock += ' del giorno '+DaysOfWeek[day]+' '+mday+' '+MonthsOfYear[month]+' '+year+'.';
	} else {
		myclock += '.';
	};
	return myclock;
}

function startclock() {
	document.getElementById('clocktext').innerHTML = genDate();
	setTimeout("startclock()",1000);
}

var expireDate = new Date();
expireDate.setTime(expireDate.getTime() + (24 * 60 * 60 * 1000 * 365));

nome = (getCookie('nomeuser'))?getCookie('nomeuser'):window.prompt('Digita il tuo nome o il tuo nickname:','Emiliano');
if (nome == '' || nome == null) {nome = 'gentile visitatore'};
if (nome == 'dyno' || nome == 'Dyno' || nome == 'DYNO') {nome = 'cazzone'};
setCookie('nomeuser', nome, expireDate, '/', null, false);

// vim:sts=2:ts=2
