this.focus();
function logout(){
	msgs.location.href="logout.php";
}

function trim(stringa){    while (stringa.substring(0,1) == ' '){        stringa = stringa.substring(1, stringa.length);    }    while (stringa.substring(stringa.length-1, stringa.length) == ' '){        stringa = stringa.substring(0,stringa.length-1);    }    return stringa;}

function popArea(){
	if(document.getElementById('session').value!=""){
		location.href="index.php?cod=area";
	}else{
		window.open('login.html','area_riservata','width=400 height=150');
	}
}

function div_close(){
	if(document.getElementById('reg_search').style.display=='none')
	animatedcollapse.toggle('reg_search_form');
	else{
	animatedcollapse.toggle('reg_search');
	animatedcollapse.toggle('reg_search_form');
	}
	nascondi_id('reg_search_close');
}

function emoticon(campos,val){
	document.getElementById(campos).value = document.getElementById(campos).value+""+val+" ";
	document.getElementById(campos).focus();
}

function invia_dati(forms){
	if (window.event.keyCode==13)
	{
		alert(forms);
		if(forms=='recupero')
			controlla_campi_recupero();
		else
			controlla_campi_login();
	}
}

function controlla_campi_login_mini(){
	f=document.login_mini;
	if((f.username_mini.value=='')||(f.password_mini.value==''))
	{
		alert('Inserire Il Nickname e la Password');
		return false;
	}else{
	 f.submit();
	}
}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+"; path=/";
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function controlla_campi_login(){
	f=document.login;
	if((f.username.value=='')||(f.password.value==''))
	{
		alert('Inserire Il Nickname e la Password');
		return false;
	}else{
	 f.submit();
	}
}

function controlla_campi_recupero(){
	f=document.recupero;
	if(f.email_pwd.value=='')
	{
		alert("Inserire l'Email di registrazione\nPer recuperare la Password!");
		return false;
	}else{
	 f.submit();
	}
}

function refresh_iframe(){
	window.msgs.location.href="../messaggistica/pop_load.php?popopen="+document.getElementById('popopen').value;
}

function carica_pop(){
	sndReqpop();
	window.setInterval("sndReqpop()",19191);
	if(top.document.getElementById('msg_body')){
		sndReqUsr();
		window.setInterval("sndReqUsr()",13131);
	}
}

function carica_chat(){
	if(top.document.getElementById('msgs')){
	window.setInterval("sndReqPub(0)",713);
	window.setTimeout("sndReqPub(1)",2000);
	}
}

var pagina_old;
function vis_frame(pagina){
	if(document.getElementById('reg_id').style.display=='none'){
		animatedcollapse.toggle('reg_id');
		nascondi_id('reg_id_close');
		top.search_id.location.href=pagina;
	}else{
		if(pagina_old==pagina){
			animatedcollapse.toggle('reg_id');
			nascondi_id('reg_id_close');
		}else{
			//document.getElementById('search_id').src=pagina;
			top.search_id.location.href=pagina;
		}
	}
	pagina_old=pagina;
}

function carica_light(file_name){
	myLightWindow = new lightwindow();
	myLightWindow.activateWindow({
	href: file_name, 
	title: ''
	});
}

function open_wind_msg(pagina,pname,w,h){
	window.open(pagina,pname,'width='+w+',height='+h+',scrollbars=1,resizable=1');
}

var blocco_pop = "";
function open_wind_new(pagina){
	//se nn ha mai visto la finestra di scelta
	blocco_pop = getCookie("blocco_pop");
	//alert(blocco_pop);
	//if((blocco_pop=="0")||(blocco_pop==""))
	{
		//var test = window.open(null,"","width=100,height=100");
		var test = window.open(pagina,"","width=500,height=550,scrollbars=1,resizable=1");
		try{
			//test.close();
			test.focus();
			//window.open(pagina,"","width=500,height=550,scrollbars=1,resizable=1");
		}catch(e){
			//alert("prima: "+intval);
			clearInterval(intval);
			intval="";
			//if(intval=="")
			if(confirm("E' stato rilevato il blocco delle popup!\r\nVuoi sapere come disattivarlo?")){
				myLightWindow = new lightwindow();
				myLightWindow.activateWindow({
				href: 'rilevamento_blocco_popup.php', 
				title: 'Rilevato Blocco PopUp', 
				width: '700',
				height: '350'
				});
				//carica_pop();
			}else{
				setCookie("blocco_pop","1",7);
				carica_pop();
			}
			//carica_pop();
		}
	}
	//else{
	//	window.open(pagina,"","width=500,height=550,scrollbars=1,resizable=1");
	//}
}

function open_wind(p){
	var d = new Array();
	var t = window.open(p,"","width=500,height=550,scrollbars=1,resizable=1");
	try{
		t.focus();
	}catch(e){
		if(p.indexOf('|') != -1) {
			d = p.split('|');
			if(document.getElementById("nr_msg_off") && (d[1]>0)) document.getElementById("nr_msg_off").style.display='';
		}
	}
}

function open_wind_or(pagina){
	window.open(pagina,"","width=500,height=550,scrollbars=1,resizable=1");
}

function redirect_alert(pagina,msg){
	alert(msg);
	location.href=pagina;
}

function vedi_profilo(){
	nascondi('td_msg_profilo');
}

function setfocus(campo){
     f=document.getElementById(campo);
     f.focus();
}
function colora(nome){
	document.getElementById(nome).className='box3';
	try{document.getElementById(nome).select();}catch(e){};
}
function decolora(nome){
	document.getElementById(nome).className='box2';
}
function nascondi(valore,page){
	var url_p = top.messaggistica;
	alert(url_p);
	alert(valore);
	var n=url_p.document.getElementById(valore);
	alert(n);
	n.style.display=(n.style.display==''?'none':'');
}
function class_int(){
	//var n=document.getElementById(val_id);
	//alert(n+" - "+classe);
	setInterval("change_class()",1000);
}

function change_class(){
	var n=document.getElementById('foto_view_btn');
	n.className=(n.className=='box2'?'box2_over':'box2');
}

function nascondi_id(valore){
	n=document.getElementById(valore);
	n.style.display=(n.style.display==''?'none':'');
	//if(n.style.display=='') return true; else return false;
}

function colora(nome){
	document.getElementById(nome).className='box3';
	try{document.getElementById(nome).select();}catch(e){};
}

function decolora(nome){
	document.getElementById(nome).className='box2';
}

ver=parseInt(navigator.appVersion)
ie4=(ver>3  && navigator.appName!="Netscape")?1:0
ns4=(ver>3  && navigator.appName=="Netscape")?1:0
ns3=(ver==3 && navigator.appName=="Netscape")?1:0

function playSound() {
 if (ie4){ 
 	//document.all.BGSOUND_ID.src='send.mp3'; 
 	document.writeln ('<BGSOUND src="'+document.getElementById('msg_sound').value+'" loop=1;>');
 }
 if ((ns4||ns3)
  && navigator.javaEnabled()
  && navigator.mimeTypes['audio/x-midi']
  && self.document.Bach.IsReady()
 )
 {
  self.document.Bach.play()
 }
}

function valorizza_padre(id_figlio){
	if(document.getElementById(id_figlio)){
		//$(this).next(id_figlio).slideToggle(1000);
		n=document.getElementById(id_figlio);
		n.style.display=(n.style.display==''?'none':'');
	}
}

function valorizza(id_figlio,anteprima,id_gruppo){
		//alert('<?=$destinazione_gal;?>'+id_gruppo+'/mini/'+anteprima);
		window.opener.document.getElementById('id_foto').value=id_figlio;
		if((id_figlio=='')||(id_figlio==0)){
			window.opener.document.getElementById('foto_ant').src='../images/no_image.gif';
		}else{
			window.opener.document.getElementById('foto_ant').src='<?=$destinazione_gal;?>'+id_gruppo+'/mini/'+anteprima;
		}
		window.close();
}

function visualizza_figli(id_figlio){
	//$(this).next(id_figlio).slideToggle(1000);
	n=document.getElementById(id_figlio);
	n.style.display=(n.style.display==''?'none':'');
}