function pagina(numpagina)
{
	document.persone.pagina.value = numpagina;
	document.persone.submit();
}
function online(num)
{
	document.persone.online.value = num;
	document.persone.pagina.value = '1';
	document.persone.submit();
}
function tutti(num)
{
	document.persone.tutti.value = num;
	document.persone.pagina.value = '1';
	document.persone.submit();
}
function reset_ricerca()
{
	document.ricerca.eta_s.value = '18';
	document.ricerca.eta_e.value = '80';
	document.ricerca.luogo.value = '';
	document.ricerca.foto.checked = false;
	document.ricerca.online.checked = false;
}

// funzioni per la chat
function register_chat()
{
	ajaxEngine.registerRequest( 'chat', '/ajax/chat.php' );
	sincro();
}
var timer;
function sincro()
{
	ajaxEngine.sendRequestAndUpdate( 'chat', 'system', { evalScripts: true,  parameters: "oper=ping" });
	timer = setTimeout("sincro()",30000);
}
function controll_chat()
{
	ajaxEngine.registerRequest( 'chat', '/ajax/chat.php' );
	ajaxEngine.registerAjaxElement('dchat');
	ajaxEngine.sendRequest( 'chat', { evalScripts: true,  parameters: "oper=controll" });
}
function msgalert(username, messaggio, foto)
{
	var d = new Date();
	$('msgalert').innerHTML = '<a class="alert" href="javascript:openChatWindow(\''+username+'\'); clearTimeout(chiudiTimer); chiudidiv(\'msgalert\');"><img class="square" src="/fotosquare/70/'+foto+'" align="left"><span id="msg_nick">' + username + '</span>:<br /><span id="messaggio">' + messaggio + '</span></a>';
	apridiv('msgalert');
}
function ding() {
	var so = new SWFObject("/sound.swf", "player", "0", "0", "8","#1D1D1D");
	so.write("sound");	
}

var i=0;
win = new Array();
var chiudiTimer;
function apridiv(iddiv){
	var div=document.getElementById(iddiv);
	div.style.top = i+"px";
	if (i<120)
	{
		i=i+2;
		moveTimer = setTimeout("apridiv('"+iddiv+"')",10);
	} else {
		chiudiTimer = setTimeout("chiudidiv('"+iddiv+"')",10000);
	}
}
function chiudidiv(iddiv){
	var div=document.getElementById(iddiv);
	div.style.top = i+"px";
	if (i>0)
	{
		i=i-2;
		moveTimer = setTimeout("chiudidiv('"+iddiv+"')",10);
	}
}
function openChatWindow(username){
	winwidth = 750;
	winheight = 600;
	winleft=(screen.width-winwidth)/2;
	wintop=(screen.height-winheight)/2;
	win[username] = window.open("/chat.php?username="+username, username, "width="+winwidth+",height="+winheight+",top="+wintop+",left="+winleft);
}
function closeChatWindow(username){
	win[username].close();
}
function now()
{
	var d = new Date();
	h = d.getHours()<1? '0'+d.getHours() : d.getHours();
	m = d.getMinutes()<1? '0'+d.getMinutes() : d.getMinutes();
	return ( h + ':' + m );
}
function invia(username,msg,num)
{
	ajaxEngine.registerAjaxElement('msg_'+num);
	ajaxEngine.sendRequest( 'chat', "oper=invia", "destinatario=" + username, "messaggio=" + msg, "num=" + num );
}

function setPointer(id, classe)
{
	//alert(id+' - '+bgcolor);
	document.getElementById(id).className = classe;
}

function DarkenPage()
{
    var errorback = document.getElementById('errorback');
    errorback.style.height = document.body.parentNode.scrollHeight + 'px';
    errorback.style.width = document.body.parentNode.scrollWidth + 'px';
    errorback.style.display = 'block';
}

function LightenPage()
{
    var errorback = document.getElementById('errorback');
    errorback.style.display = 'none';
}

function errorbox(text)
{
	DarkenPage();
	$('boxtext').innerHTML = text;
	var box = document.getElementById('errorbox');
    
    // w is a width of the newsletter panel
    w = 200;
    
    // get the x and y coordinates to center the newsletter panel
    xc = Math.round((document.body.clientWidth/2)-(w/2))
    yc = 200
    
    // show the newsletter panel
    box.style.left = xc + "px";
    box.style.top  = yc + "px";
    box.style.display = 'block';
}
function closebox()
{
	LightenPage();
	$('errorbox').style.display = 'none';
}
function delfriend(username)
{
	ajaxEngine.registerRequest( 'delfriend', '/ajax/delfriend.php' );
	ajaxEngine.sendRequestAndUpdate( 'delfriend', 'system', { evalScripts: true,  parameters: "username="+username });
}
function inlinea(stato)
{
	ajaxEngine.registerRequest( 'online', '/ajax/online.php' );
	ajaxEngine.sendRequestAndUpdate( 'online', 'system', { evalScripts: true,  parameters: "r="+Math.random()+"&online="+stato });
}