document.write('<script type="text/javascript" src="/inc/js/moo.fx/prototype.lite.js"></script>');
document.write('<script type="text/javascript" src="/inc/js/moo.fx/moo.fx.js.v3"></script>');
document.write('<script type="text/javascript" src="/inc/js/moo.fx/moo.fx.pack.js.v3"></script>');
document.write('<script type="text/javascript" src="/inc/js/xmlhttprequest2.js"></script>');

var d = document;


/* Funzioni generali */
function myEscape(string) { return escape(string).replace('+','%2B'); };
function ieHover() {
	if(! document.all)
		return false;
		
	var elements = Array('footer-pers','footer-cont','footer-part','footer-info');
    for(var i = 0; i < elements.length; i++) {
		var element = $(elements[i]);
		if(element) {
			element.onmouseover = function () { this.className = this.className + ' hover'; }
            element.onmouseout = function () { this.className = this.className.replace(/hover/,''); }
		}
	}
}

window.onload = function() { ieHover(); }


/* Ajax */
function Ajax(address) {
	this.address = address;
	this.client = new XMLHttpRequest();
	this.data = new Array();
	this.method = 'get';
	this.onload = function(tmp) {};
	this.onerror = false;
	this.send = function() {
		var self = this;
		this.client.onreadystatechange = function() {
			if(self.client.readyState  == 4) {
				if(self.address.indexOf('/my/comnew') == -1)
					progressOff();
				if(self.client.status == 200 && self.client.responseText.indexOf('<!--error') == -1) {
					if(typeof self.onload == 'function') self.onload(self.client.responseText);
					if(self.onload == 'eval') eval(self.client.responseText);
					else { var res = $(self.onload); if(res) res.innerHTML = self.client.responseText; }
				} else {
					var st = self.client.responseText.indexOf('<!--error: ');
					if(st == -1) {
						if(self.address.indexOf('/my/comnew') == -1)
							errorOn('Errore durante il caricamento, riprova');
					} else {
						if(self.onerror)
							self.onerror(self.client.responseText.substring(st + 11,self.client.responseText.indexOf('-->',st)));
						else {
							if(self.address.indexOf('/my/comnew') == -1)
								errorOn(self.client.responseText.substring(st + 11,self.client.responseText.indexOf('-->',st)));
						}
					}
				}
			}
		};

		var c = this.data.length;
		if(c > 0) {
			var args = this.data[0];
			for(var i=1;i<c;i++) args = args + '&' + this.data[i];
		} else
			var args = false;
		if(self.address.indexOf('/my/comnew') == -1)
			progressOn();
		if(this.method == 'get') {
			this.client.open('GET', this.address + (args?'?' + args:''),true);
			this.client.setRequestHeader('If-Modified-Since','Sat, 1 Jan 2000 00:00:00 GMT');
			this.client.setRequestHeader('AJAX-Request','true');
			this.client.send(null);
		}
		if(this.method == 'post') {
			this.client.open('POST',this.address,true);
			this.client.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			this.client.setRequestHeader('AJAX-Request','true');
			this.client.send(args);
		}
	};
}

function formatDate(date, ext) {
	if(date == '0000-00-00 00:00:00')
		return(document.write('mai'));

	months = ['gennaio','febbraio','marzo','aprile','maggio','giugno','luglio','agosto','settembre','ottobre','novembre','dicembre'];
	function pad(string) {
		string = String(string);
		if(string.length < 2)
			return '0' + string;
		return string;
	}
	var p = /^(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)$/; var pr = p.exec(date);
	var parsed = new Date(pr[1],pr[2]-1,pr[3],pr[4],pr[5],pr[6]);
	var diff = parseInt((dates[0].valueOf() - parsed.valueOf()) / 1000);
	if(diff == 0) var r = 'ora';
	else if(diff < 60) var r = diff + (ext?' second' + (diff==1?'o':'i') + ' fa':' sec');
	else if(diff < 1800) { diff = parseInt(diff/60); var r = diff + (ext?' minut' + (diff==1?'o':'i') + ' fa':' min'); }
	else if(diff < 3600) { var r = ext?'&frac12; ora fa':'&frac12; h'; }
	else if(diff < 14400) { diff = parseInt(diff/3600); half = (diff % 3600 > 1800)?(ext?' e &frac12;':'&frac12;'):''; var r = ext?(diff + (diff==1?' ora':' ore') + half + ' fa'):(diff + half + 'h'); }
	else if(parsed > dates[2]) { var r = ((parsed > dates[1])?(ext?'oggi':''):'ieri') + (ext?' alle':'') + ' ' + pad(parsed.getHours()) + ':' + pad(parsed.getMinutes()); }
	else { var d = parsed.getDate(); var r = (ext?(d==1||d==8|d==11?'l\'':'il ') + d:d) + ' ' + months[parsed.getMonth()] + (diff>15552000?' ' + (parsed.getYear()<1000?parsed.getYear()+1900:parsed.getYear()):'') + (ext?' alle':'') + ' ' + pad(parsed.getHours()) + ':' + pad(parsed.getMinutes()); }
	document.write(r);
}

var showPreferences = null;
function preferences() {
	if(! $('preferences')) {
		var preferences = d.createElement('div');
		preferences.id = 'preferences';
		var c = '<h2 class="center" style="padding: 10px">Imposta le tue preferenze</h2>' + 
			'<b>Lista amici</b>' + 
			', <a href="javascript:setPreference(\'friendlist\',\'online\');"' + (document.cookie.indexOf('friendlist%3Donline')!=-1?' class="bold"':'') + '>separata online/offline</a>' + 
			', <a href="javascript:setPreference(\'friendlist\',\'joined\');"' + (document.cookie.indexOf('friendlist%3Djoined')!=-1?' class="bold"':'') + '>unico elenco</a>' + 
			'.<br />' +
			'<b>Visualizza foto casuali</b> di ' + 
			'<a href="javascript:setPreference(\'randw\',\'b\');"' + (document.cookie.indexOf('randw%3Db')!=-1?' class="bold"':'') + '>tutti</a>' +
			', solo <a href="javascript:setPreference(\'randw\',\'f\');"' + (document.cookie.indexOf('randw%3Df')!=-1?' class="bold"':'') + '>ragazze</a>' +
			' o solo <a href="javascript:setPreference(\'randw\',\'m\');"' + (document.cookie.indexOf('randw%3Dm')!=-1?' class="bold"':'') + '>ragazzi</a>' +
			'.<br />' + 
			'<b>Suoni</b> (attenzione, possono rallentare e creare problemi)' +
			', <a href="javascript:setPreference(\'sounds\',\'1\');"' + (document.cookie.indexOf('sounds%3D1')!=-1?' class="bold"':'') + '>attivato</a>' +
			', <a href="javascript:setPreference(\'sounds\',\'0\');"' + (document.cookie.indexOf('sounds%3D0')!=-1?' class="bold"':'') + '>disattivato</a>' +
			(document.cookie.indexOf('sounds%3D2')!=-1?', <span class="bold">in attesa di verifica compatibilità</span>':'') + 
			'.<br />' + 
			'<b>Lista utenti</b>' + 
			', <a href="javascript:setPreference(\'list\',\'big\');"' + (document.cookie.indexOf('list%3Dbig')!=-1?' class="bold"':'') + '>estesa</a>' +
			', <a href="javascript:setPreference(\'list\',\'row\');"' + (document.cookie.indexOf('list%3Drow')!=-1?' class="bold"':'') + '>ridotta</a>' + 
			'.<br /><br />';
		preferences.innerHTML = c;
		$('layout').insertBefore(preferences,$('sep'));
		showPreferences = new fx.Height('preferences', { duration: 500 });
		showPreferences.hide();
	}
	if(showFriends) showFriends.hide();
	if(showSearch) showSearch.hide();
	showPreferences.toggle();
}

function setPreference(name,value) {
		var request = new Ajax('/my/preferences');
		request.data.push(name + '=' + value);
		if(setPreference.arguments[2])
			request.onload = false;
		else
			request.onload = 'eval';
		request.send();
}


/* Blog */
function deleteBlog(id) {
	var request = new Ajax('/my/blogdel');
	request.data.push('id=' + id);
	request.onload = function(content) {
		window.location.reload(false);
	}
	request.send();
}

function voteBlog(id) {
	var request = new Ajax('/my/blogvote');
	request.data.push('id=' + id);
	request.onload = 'eval';
	request.send();
}

function segnalaBlog(id) {
	var request = new Ajax('/segnala/post');
	request.data.push('id=' + id);
	request.onload = 'eval';
	request.send();
}

function blogCommenti(id,userid) {
	if($('blogcom' + id))
		new fx.Height('blogcom' + id, { duration: 500, onComplete: function() { $('blogcom' + id).parentNode.removeChild($('blogcom' + id)); } }).toggle();
		
	else {
		var div = document.createElement('div');
		div.id = 'blogcom' + id;
		div.style.height = '0px';
		$('blog' + id).appendChild(div);

		var request = new Ajax('/my/blogcomlist');
		request.data.push('postid=' + id);
		request.data.push('userid=' + userid);
		request.onload = function(text) {
			$('blogcom' + id).innerHTML = text;
			new fx.Height('blogcom' + id, { duration: 500 }).toggle();
		}
		request.send();
	}
}

function deleteBlogComment(id) {
	var request = new Ajax('/my/blogcomdel');
	request.data.push('id=' + id);
	request.onload = function(content) {
		$('commento' + id).parentNode.removeChild($('commento' + id));
	}
	request.send();
}

function showBlogReplyForm(id) {
	if($('replyBlog' + id)) {
		new fx.Height('replyBlog' + id, { duration: 500, onComplete: function() { $('replyBlog' + id).parentNode.removeChild($('replyBlog' + id)); } }).toggle();
	}
	else {
		addForm($('blog' + id),false,'Blog' + id,'blog' + id);
		new fx.Height('replyBlog' + id, { duration: 500, onComplete: function() { $('replyBlog' + id).getElementsByTagName('textarea')[0].focus(); } }).toggle();
	}
}


/* Commenti */
function doComment(form) {
	if(form.text.value.length < 1) {
		errorOn('Non è possibile inviare commenti vuoti');
		return false;
	}
	var request = new Ajax('/my/comadd');
	request.data.push('to=' + form.to.value);
	request.data.push('text=' + myEscape(form.text.value));
	request.method = 'post';
	request.onload = function(text) {
		if(text.indexOf('<!--success-->') !== -1) {
			form.innerHTML = text;
			new fx.Height(form.id, { duration: 500 }).customTo(22);
		}
	};
	request.send();
	return false;
}

function deleteComment(id,tbl) {
	var request = new Ajax('/my/comdel');
	request.data.push('id=' + id);
	request.data.push('tbl=' + tbl);
	request.onload = function(content) {
		$('commento' + id).parentNode.removeChild($('commento' + id));
	}
	request.send();
}

function deleteAllComments() {
	if(! confirm('Sei sicuro di voler cancellare tutti i commenti ricevuti?'))
		return false;
	if(! confirm('Sei assolutamente sicuro di voler cancellare DEFINITIVAMENTE tutti i commenti ricevuti?\nQuesta azione NON può essere annullata!'))
		return false;
	var pass = prompt('Per confermare la scelta di cancellare tutti i commenti ricevuti, inserisci la tua password:');
	if(pass === false)
		return false;

	var request = new Ajax('/my/comdelall');
	request.data.push('pass=' + escape(pass));
	request.onload = function(text) {
		window.location.reload(true);
	}
	request.send();
}

function historyComment(id,userid) {
	if(! $('history' + id)) {
		var hist = d.createElement('div');
		hist.className = 'history';
		hist.id = 'history' + id;
		$('content' + id).appendChild(hist);
		var request = new Ajax('/my/comcron');
		request.data.push('id=' + userid);
		request.onload = function(text) {
			$('history' + id).innerHTML = text;
		}
		request.send();
	} else
		$('content' + id).removeChild($('history' + id));
}

function showCommentForm(to) {
	if($('replyself')) {
		new fx.Height('replyself', { duration: 500, onComplete: function() { $('replyself').parentNode.removeChild($('replyself')); } }).toggle();
	}
	else {
		addForm($('main'),$('profilocontent'),'self',to);
		new fx.Height('replyself', { duration: 500, onComplete: function() { $('replyself').getElementsByTagName('textarea')[0].focus(); } }).toggle();
	}
}

function showReplyForm(id,to) {
	if($('reply' + id)) {
		new fx.Height('reply' + id, { duration: 500, onComplete: function() { $('reply' + id).parentNode.removeChild($('reply' + id)); } }).toggle();
	}
	else {
		addForm($('content' + id),$('info' + id),id,to);
		new fx.Height('reply' + id, { duration: 500, onComplete: function() { $('reply' + id).getElementsByTagName('textarea')[0].focus(); } }).toggle();
	}
}

function showImageCommentForm(id) {
	if($('replyimage')) {
		new fx.Height( 'replyimage', { duration: 500, onComplete: function() { $('replyimage').parentNode.removeChild($('replyimage')); } }).toggle();
	}
	else {
		addForm($('biggerContainer'),$('biggerImage'),'image','image' + id);
		new fx.Height('replyimage', { duration: 500, onComplete: function() { $('replyimage').getElementsByTagName('textarea')[0].focus(); } }).toggle();
	}
}

function addForm(container,before,id,to) {
	var form = document.createElement('form');
	form.className = 'reply' + (id=='self'?' self':'');
	form.id = 'reply' + id;
	form.action = '/my/comadd';
	form.method = 'post';
	form.onsubmit = function() { return doComment(this); };
	form.style.height = '0px';
	form.innerHTML = '<textarea onfocus="if(this.value==\'inserisci il testo\')this.value=\'\';" name="text" id="text">inserisci il testo</textarea>' +
		'<input type="hidden" name="to" id="to" value="' + to +'" />' + 
		'<input type="submit" value="&nbsp;invia &raquo;&nbsp;" />';
	if(before)
		container.insertBefore(form,before);
	else
		container.appendChild(form);
}


/* Login/Logout */
function login() {
	if(! $('login')) {
		var login = d.createElement('iframe');
		login.id = 'login';
		login.style.border = '0px';
		login.style.height = '160px';
		login.style.margin = '0px';
		login.style.padding = '0px';
		login.style.width = '800px';

		login.src = '/homepage.php?' + Math.floor(Math.random()*1000000);
		if($('sep'))
			$('layout').insertBefore(login,$('sep'));
		else
			$('layout').appendChild(login);
	} else {
		$('login').parentNode.removeChild($('login'));
	}
}

function logout() {
		var request = new Ajax('/my/logout');
		request.method = 'post';
		request.onload = 'eval';
		request.send();
}


/* Ricerca utenti */
var showSearch = null;

function search() {
	if(! $('search')) {
		var searchd = d.createElement('div');
		searchd.id = 'search'; searchd.style.background = 'white';
		$('layout').insertBefore(searchd,$('sep'));

		if(search.arguments && search.arguments[0])
			var request = new Ajax('/my/search?' + search.arguments[0]);
		else
			var request = new Ajax('/my/search');

		request.onload = function(content) {
			$('search').innerHTML = content;
			showSearch = new fx.Height('search', { duration: 500 });
			showSearch.hide();
			showSearch.toggle();
		}
		request.send();
	}
	if(showFriends) showFriends.hide();
	if(showPreferences) showPreferences.hide();
	if(showSearch) showSearch.toggle();
}


/* Friendlist */
var showFriends = null;

function friends() {
	if(! $('friends')) {
		var friends = d.createElement('div');
		friends.id = 'friends'; friends.style.background = 'white';
		$('layout').insertBefore(friends,$('sep'));
		var request = new Ajax('/my/friends');
		request.onload = function(content) {
			$('friends').innerHTML = content;
			showFriends = new fx.Height('friends', { duration: 500 });
			showFriends.hide();
			showFriends.toggle();
		}
		request.send();
	}
	if(showSearch) showSearch.hide();
	if(showPreferences) showPreferences.hide();
	if(showFriends) showFriends.toggle();
}

function showFriendCom(id) {
	if($('replyFriend')) {
		new fx.Height('replyFriend', { duration: 500, onComplete: function() { $('replyFriend').parentNode.removeChild($('replyFriend')); } }).toggle();
	} else {
		addForm($('layout'),$('main'),'Friend',id);
		new fx.Height('replyFriend', { duration: 500, onComplete: function() { $('replyFriend').getElementsByTagName('textarea')[0].focus(); } }).toggle();
	}
}

/* Direttamente dalla friendlist */
function deleteFriend(id) {
	var request = new Ajax('/my/friends');
	request.data.push('delete=' + id);
	request.onload = function(content) {
		new fx.Width('friend' + id, { duration: 800 }).toggle();
	}
	request.send();
}

/* Dai profili */
function addFriend(id) {
	var request = new Ajax('/my/friends');
	request.data.push('add=' + id);
	request.onload = function(content) {
		var link = $('friendLink');
		link.innerHTML = '<img src="/images/icons/heart_delete.png" class="icon" />rimuovi dalla friendlist';
		link.href = 'javascript:delFriend(' + id + ');';
		var f = $('friends');
		if(f)
			f.parentNode.removeChild(f);
	}
	request.send();
}

function delFriend(id) {
	var request = new Ajax('/my/friends');
	request.data.push('delete=' + id);
	request.onload = function(content) {
		var link = $('friendLink');
		link.innerHTML = '<img src="/images/icons/heart_add.png" class="icon" />aggiungi alla friendlist';
		link.href = 'javascript:addFriend(' + id + ');';
		var f = $('friends');
		if(f)
			f.parentNode.removeChild(f);
	}
	request.send();
}


/* Blacklist */
function block(id) {
	var request = new Ajax('/my/block');
	request.data.push('id=' + id);
	request.onload = function(content) {
		alert('Utente bloccato! Ora non potrà più inviarti commenti.\nSe l\'hai bloccato per sbaglio, clicca su blacklist in fondo alla pagina.');
	}
	request.send();
}

function blockByUsername(username) {
        var request = new Ajax('/my/block');
        request.data.push('username=' + myEscape(username));
        request.onload = function(content) {
		window.location.reload(false);
        }
        request.send();
	return false;
}


/* Immagini */
function deleteImage(id) {
	var request = new Ajax('/my/immagini/delete');
	request.data.push('delete=' + id);
	request.onload = function(content) {
		$('img' + id).style.height = $('img' + id).scrollHeight + 'px';
		new fx.Width('img' + id, { duration: 800 }).toggle();
	}
	request.send();
}

function setAvatar(id) {
	var request = new Ajax('/my/immagini/setavatar');
	request.data.push('avatar=' + id);
	request.onload = function() { window.location.href = '/my/immagini/?avatarset=1'; }
	request.send();
}


/* Faves */
function addFave(id) {
	var request = new Ajax('/my/favemod');
	request.data.push('add=' + id);
	request.onload = function(content) {
		if(typeof(faves) != 'undefined')
			faves[id] = true;
		var link = $('faveLink');
		link.innerHTML = '<img src="/images/icons/cancel.png" class="icon" />rimuovi fave';
		link.href = 'javascript:delFave(' + id + ');';
	}
	request.send();
}

function delFave(id) {
	var request = new Ajax('/my/favemod');
	request.data.push('delete=' + id);
	request.onload = function(content) {
		if(typeof(faves) != 'undefined')
			faves[id] = false;
		var link = $('faveLink');
		link.innerHTML = '<img src="/images/icons/add.png" class="icon" />aggiungi fave';
		link.href = 'javascript:addFave(' + id + ');';
	}
	request.send();
}


/* Progress */
var showProgress = null;
/*
function progressOn() {
	if(! $('progress')) {
		var progress = d.createElement('div');
		progress.id = 'progress';
		document.body.insertBefore(progress,$('navigation'));
		showProgress = new fx.Opacity('progress', { duration: 200 });
		showProgress.hide();
	}
	var progress = $('progress');
	progress.innerHTML = 'caricamento in corso, attendere prego...';
	progress.style.backgroundColor = '#cccccc';
	progress.style.color = '#ffffff';
	showProgress.clearTimer();
	showProgress.custom(0,0.9);
}

function progressOff() {
	if(showProgress) {
		showProgress.clearTimer();
		showProgress.custom(0.9,0);
	}
}
*/

/* Errori */
function errorOn(msg) {
	if(! $('progress')) {
		var progress = d.createElement('div');
		progress.id = 'progress';
		document.body.insertBefore(progress,$('layout'));
		showProgress = new fx.Opacity('progress', { duration: 400 });
		showProgress.hide();
	}
	showProgress.clearTimer();
	showProgress.hide();
	var progress = $('progress');
	progress.innerHTML = msg;
	progress.style.backgroundColor = 'red';
	progress.style.color = 'white';
	showProgress.clearTimer();
	showProgress.setOpacity(1);
	setTimeout("new fx.Opacity('progress', { duration: 3000 }).custom(1,0);",3000);
}


/* Immagini casuali */
function refreshRand(dati) {
	if(dati == false) $('rand').innerHTML = 'foto casuali temporaneamente disabilitate, ci scusiamo per l\'inconveniente';
	else {
		var ct = ''; for(i=0; i<=2; i++) {
			ct += '<a href="/utenti/' + myEscape(dati[i][1]) + '/immagini" title="' + dati[i][1]+ '">';
			ct += '<img src="/img/' + dati[i][0] + '_3.jpg" onmouseover="showRandD(\'<b>' + dati[i][1] + '</b>, ' + dati[i][2].replace('\'','\\\'') + ', ' + dati[i][3] + '\');" onmouseout="showRandD(false);" alt="' + dati[i][1] + '" />';
			ct += '</a>';
		}
		$('rand').innerHTML = ct;
	}
}

function getX(el) {
	var x = 0;
	if(el.offsetParent) {
		while(el.offsetParent) {
			x += el.offsetLeft;
			el = el.offsetParent;
		}
	} else {
		if(el.x) x += el.x;
	}
	return x;
}

function getY(el) {
	var y = 0;
	if(el.offsetParent) {
		while(el.offsetParent) {
			y += el.offsetTop;
			el = el.offsetParent;
		}
	} else {
		if(el.y) y += el.y;
	}
	return y;
}

function loadRand() {
	if(! $('randExt')) {
		var rand = d.createElement('div');
		rand.id = 'randExt';
		rand.style.left = getX($('randLink')) + $('randLink').scrollWidth - 314 + 'px';
		rand.style.top = getY($('randLink')) + $('randLink').scrollHeight + 3 + 'px';
		rand.style.visibility = 'hidden';
		rand.innerHTML = '<div id="rand"></div><div class="clearer"></div><div id="randD"></div>';
		document.body.appendChild(rand);
		showRandD(false);
	}

	var request = new Ajax('/my/rand');
	request.onload = function(json) {
		eval('var data = ' + json);
		refreshRand(data);
		if($('randExt').style.visibility == 'hidden')
			$('randExt').style.visibility = 'visible';
	}
	request.send();
}

function hideRand() {
	$('randExt').style.visibility = 'hidden';
}

function showRandD(data) {
	if(data == false) data = 'Passa con il mouse sopra una foto <a href="javascript:hideRand();">nascondi</a>';
	$('randD').innerHTML = data;
}


/* Messages */
var messages = new Array();
var lastMessage = 0;

function createMessage(content) {
	if(content.indexOf('Hai') === 0)
		tid = 'Com';
	else
		tid = lastMessage++;
	t = d.createElement('div');
	t.id = 'message' + tid;
	t.innerHTML = content;
	messages.push(t);
	$('growlerSpace').appendChild(t);
}

function doMessages() {
	$('growlerSpace').style.display = 'block';
}


/* Nuovi commenti */
var checks = 0;
var lastCheck = 0;

function checkComments() {
	var request = new Ajax('/my/comnew');
	request.onload = function(text) {
		if(text == 'false')
			return false;

		var res = parseInt(text);
		if(res > 0) {
			var text = 'Hai ' + res + ' nuov' + (res==1?'o':'i') + ' comment' + (res==1?'o':'i') + ', <a href="/utenti/' + myEscape(nick) + '/commenti">leggil' + (res==1?'o':'i') + '</a>!';
			if($('messageCom')) {
				$('messageCom').innerHTML = text;
				$('commenti').style.color = '#ba4050';
				new fx.Shake('messageCom').activate();
				if(lastCheck != res)
					doBeep();
				lastCheck = res;
			} else {
				createMessage(text);
				$('commenti').style.color = '#ba4050';
				doMessages();
				doBeep();
			}
		}
	}
	request.send();
	setTimeout('checkComments();',30000 + parseInt(checks / 5) * 10000);
}


/* Suoni */
function doBeep() {
	if($('sounds')) {
		if(! $('beep')) {
			$('sounds').innerHTML = '<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" id="beep">' +
				'<embed src="/images/beep4.wav" type="audio/wave" name="beep" autostart="false" pluginspage="http://www.apple.com/it/quicktime/download/" enablejavascript="true" style="height: 0px;width: 0px">' + 
				'<param name="url" value="/images/beep4.wav" />' + 
				'<param name="autostart" value="false" />' +
				'<param name="uiMode" value="none" />' + 
				'</object>';
		}
		setTimeout('doBeepPlay();',1000);
	}
}

function doBeepPlay() {
	if($('beep').controls)
		$('beep').controls.play();
	else
		document.beep.Play();
}

function checkSounds() {
	if(navigator.plugins && navigator.plugins.length > 0) {
		for(i=0;tpl = navigator.plugins[i].name;i++) {
			if(tpl.indexOf('QuickTime') != -1) {
				setPreference('sounds',1,true);
				break;
			}
		}
	} else {
		setPreference('sounds',1,true);
	}
}


/* Messaggio di stato */
function editStatus() {
	if(! $('newStatusMsg')) {
		var text = $('statusMsg').innerText?$('statusMsg').innerText:$('statusMsg').textContent;
		var end = text.indexOf(', impostato formatDate');
		if(end == -1)
			end = text.indexOf(', impostato ora');
		if(end < 1)
			var old = 'Nessun messaggio di stato impostato';
		else
			var old = text.substr(0,end);
		$('statusMsg').innerHTML = '<form action="/" method="get" onsubmit="return updateStatus();"><input type="text" id="newStatusMsg" style="font-size: 0.9em;width: 400px;" maxlength="100" value="' + old + '" /><input type="submit" value="modifica &raquo;" /></form>';
		$('newStatusMsg').select();
	}
}

function updateStatus() {
	var request = new Ajax('/my/status');
	request.data.push('status=' + myEscape($('newStatusMsg').value));
	request.onload = function(text) {
		$('statusMsg').innerHTML = text + '<small>, impostato ora</small>';
	}
	request.send();
	return false;
}


/* Accesso all'amministrazione */
function goAdmin(loggedIn) {
	var request = new Ajax('/admin/panel');
	request.onload = 'admin';
	request.send();
}

function doAdminLogin(form) {
	var request = new Ajax('/admin/login');
	request.data.push('auth=' + escape(form.auth.value));
	request.onload = function(text) {
		var allLinks = document.getElementsByTagName('a');
		for(i = 0;a = allLinks[i];i++) {
			if(a.className.indexOf('admin') != -1)
				a.style.display = 'inline';
		}
		goAdmin();
	};
	request.send();
	return false;
}


/* Blog in esplora */
function loadBlogs(which) {
	var request = new Ajax('/my/blogs');
	request.data.push('which=' + which);
	request.onload = 'blogs';
	request.send();
}
