function BuddyList(id) {

	//this.buddySubMenuContainer;
	//this.buddySubmenueventItemClickable;
	//this.msgSubmenueventItemClickable
	this.buddyAreaContainer;
	this._buddyMain;			//contenitore dei contenitori di questa sezione
	
	this.id=id;				// id dell'utente a cui la BuddyList appartiene
	this.users=new Array();
	//var lista;
	//this.lista = lista;
	this.relation=0;			//relazione esistente tra uid & oid : viene ricavata quando visito un profilo cosi da essere disponibile per tutte le possibili interazione tra uid e oid
	this.blacklistFirst=1;
	this.buddyFirst=1;
	
	this.action='';			//conterra idetificativo azione che si vuol e compiere...sara utile in totCheck() per capire quali messaggi mettere nei dialog
	this.actionUrl='';			//identifica la url associata all'azione ....
	this.buddyNotifContainer='layer5_content';	//contenitore della notifica esistenza invito buddy pendente dall'utente che avevamo invitato in buddy
	
	this.currentBuddy_inv='';	//fid ultimo invito risposto (serve per aggiornare l'icona nell'event box
	this.currentBuddy_ok='';
	this.currentBuddy_nok='';
	this.currentOther='';
	
	this.onlineurl='/profile/getuserpart2?str=';
this.lastOtherCheck=''; //conterra il valore dell'ultimo check della relazione tra uid & oid (usato quando devo eliminare un _notifica.event['buddy_inv'] per un utente che metto in black list 

	this.inviteAnswerRead=function(tex,o){
		ans=JSON.parse(tex);
		if (ans.status == 200) {
			msg=ans.msg;
			//alert('llllllllllllll'+tex);
			if (msg == 'ok'){
				sync('buddy_ok');
			}	
			else {
				sync('buddy_nok');
			}	
		}	
		else {
			h=ans.errormsg;
			alert('Ci sono dei problemi tecnici, operazione non eseguita');
		}
	}
		
	this.listbuddy=function(tex,o){
		var h='';
		var str='';
		var r=0;
		var ans = JSON.parse(tex);
		//f=ans.dati; //(id,alias)
		h='Nessun utente in buddylist';
		if (ans.dati) {
			if (ans.dati.length > 0){
				h='';
				for (r=0;r<ans.dati.length;r++){
					str+=ans.dati[r].id+',';
				}
				str=str.substr(0,str.length-1);
				url=this.onlineurl+str;
//////////////////////////////////////////////////////////////////////////////////////////
					$.getJSON(url,function(ans){
					usrs = new Array();
					usrs=ans.usrs;
					var counter=0;
					var cont='<div id="conten_online" >';
					var opencont=0;
					for (r=0;r<usrs.length;r++){
						
						//userthumb=userstamp(usrs[r],_user.thumbContainer);
						if (counter == 0) {
							cont+='<div id="riga_profilo" name="riga_profilo">';
							//alert('riga!');
							opencont=1;
						}	
						userthumb=_nav.userthumb3(usrs[r]);
						//alert(userthumb);
						cont+=userthumb;
						if (counter == 2) {
							cont+='</div>';
							counter=0;
							opencont=0;
						}
						else	counter++;	
						//alert(counter);
					}
					if (opencont == 1) cont+='</div>';
					cont+='</div>';
						//h='<div id="blacklist"><a class="rosso" >Black List >></a></div>'+cont;
						h=cont;
						var id='#'+_buddy.buddyAreaContainer;
						$(id).empty().append(h);	
						$(id).show;
					if (_user.clkonOnlineThumbFirst) {
						bindevent('clkonSearchThumb');
						_buddy.clkonOnlineThumbFirst=0;
					}
					});
//////////////////////////////////////////////////////////////////////////////////////////				
			}
			else {
						//h='<div id="blacklist"><a class="rosso" >Black List >></a></div>'+h;
						h=''+h;
						var id='#'+_buddy.buddyAreaContainer;
						$(id).empty().append(h);	
						$(id).show;
			}	
		
		}	
		//h+='<br><a id="blacklist">black list</a>';
		/*
		if (_buddy.blacklistFirst) {
			_buddy.blacklistFirst=0;
			$('#blacklist').livequery(function(){
				$(this).unbind('click').click(function(){
					var ur='/usermanager/listfriend2?what=black';
					updtElem(ur,_buddy,'listblack',_container);
				});
			});
		}*/
	}
	this.listblack=function(tex,o){
		var h='';
		var str='';
		var r=0;
		var ans = JSON.parse(tex);
		//f=ans.dati; //(id,alias)
		h='Nessun utente in blacklist';
		if (ans.dati) {
			if (ans.dati.length > 0){
				h='';
				for (r=0;r<ans.dati.length;r++){
					str+=ans.dati[r].id+',';
				}
				str=str.substr(0,str.length-1);
				url=this.onlineurl+str;
//////////////////////////////////////////////////////////////////////////////////////////
					$.getJSON(url,function(ans){
					usrs = new Array();
					usrs =ans.usrs;
					var counter=0;
					var cont='<div id="conten_online" >';
					var opencont=0;
					for (r=0;r<usrs.length;r++){
						
						//userthumb=userstamp(usrs[r],_user.thumbContainer);
						if (counter == 0) {
							cont+='<div id="riga_profilo" name="riga_profilo">';
							//alert('riga!');
							opencont=1;
						}	
						userthumb=_nav.userthumb3(usrs[r]);
						//alert(userthumb);
						cont+=userthumb;
						if (counter == 2) {
							cont+='</div>';
							counter=0;
							opencont=0;
						}
						else	counter++;	
						//alert(counter);
					}
					if (opencont == 1) cont+='</div>';
					cont+='</div>';
					h=cont;
						var id='#'+_buddy.buddyAreaContainer;
						$(id).empty().append(h);	
						$(id).show;
					if (_user.clkonOnlineThumbFirst) {
						bindevent('clkonSearchThumb');
						_buddy.clkonOnlineThumbFirst=0;
					}
					});
//////////////////////////////////////////////////////////////////////////////////////////				
			}
			else {
						var id='#'+_buddy.buddyAreaContainer;
						$(id).empty().append(h);	
						$(id).show;
			}	
		}
		//h+='<br><a id="blacklist">black list</a>';
	}
	
	this.listblack_back=function(tex,o){
		var h='';
		//alert(tex);
		ans = JSON.parse(tex);
		
		ans.dati; //(id,alias)
		h='Nessun utente in blacklist';
		if (ans.dati) 
			if (ans.dati.length > 0) {
				h='';
				for (r=0;r<ans.dati.length;r++){
					h+='<a>'+ans.dati[r].alias+'</a><br>';
				}
			}		
		id='#'+_buddy.buddyAreaContainer;
		$(id).empty().append(h);	
	}

	this.visu=function(msg){
		alert(msg);
	}	
	
	this.pendantBuddy=function(){
		var h='hai gia un invito pendente dall\'utente'+other
		+'<br><br>'
		+'<a id=pend_now>Visualizza invito di '+utente+' </a>'
		+'<a id=pend_after>Visualizzero gli inviti in un altro momento</a>';
		$('#'+this.buddyNotifContainer).empty().append(h).parent().show();
		$('#'+this.buddyNotifContainer+' > a').click(function(event){
			alert('un click sulla ancora');
		});	
		//$('#menucontent > input[@name="profilo"]').livequery(function(){
		//				$(this).trigger('click');});
	}	
	
	/*
	handle the servlet answer to buddy invite
		possible output	-invito ok
						-invito already send
						-invito nn spedito perchè c'è stato un errore
	*/
	this.inviteAnswer=function(tex,o){
		var ans=JSON.parse(tex);
		var h='';
		if (ans.status == 200) {
			var msg=ans.msg;
			if (msg == 'ok'){
				//alert ('Bene hai un nuovo amico:'+_buddy.currentOther);
				h='Bene hai un nuovo amico:'+_buddy.currentOther;
			}	
			else if (msg=='refute') {
				h='Rifiutata amicizia a:'+_buddy.currentOther;
			}
			else if (msg=='blacklist') {
				//alert('Purtroppo non e\' stato possibile aggiungerti nella buddy list perche\' ora sei in black list per l\'utente '+_buddy.currentOther);
				h='Purtroppo non e\' stato possibile aggiungerti nella buddy list perche\' ora sei in black list per l\'utente '+_buddy.currentOther;
			}
			//else if 	
		}
		else {
			alert(ans.errormsg);
		}
		sync('buddy_inv');
		$('#'+_nav.userthumbMenuContainer).parent().hide(); //QUESTA RIGA DOVREBBE POTERSI CANCELLARE
		//$('#'+this.buddyNotifContainer).empty().append(h).parent().show();
	}	

	this.inviteBuddy=function(tex,o){
		var h;
		var ans=JSON.parse(tex);
		if (ans.status == 200) {
			msg=ans.msg;
			if (msg == 'ok'){
				h='Abbiamo inoltrato il tuo invito a <b>'+_nav.other+'</b>....appena dara\' una risposta ti aggiorneremo';
			}	
			else {
				h='Problemi nell\'invio dell\'invito';
			}	
		}	
		else {
			h=ans.errormsg;
		}
		$('#'+_buddy.buddyNotifContainer).empty().append(h);
	}

	this.stopBlack=function(tex,o){
		var h;
		var ans=JSON.parse(tex);
		if (ans.status == 200) {
			//alert('Utente rimosso dalla black list');
			h='Utente rimosso dalla black list';
			//alert(_nav.mainMode);
			if ((_nav.mainMode=='my') && (_nav.currentAction=='black')) menucontent_switch('black');
			
		}
		else {
			alert('Ci sono stati dei problemi tecnici, operazione non condotta a buon fine');	
			h='Ci sono stati dei problemi tecnici, operazione non condotta a buon fine';
		}	
		$('#'+_buddy.buddyNotifContainer).empty().append(h);
	}
	this.stopBuddy=function(tex,o){
		var ans=JSON.parse(tex);
		var h;
		if (ans.status == 200) {
			//alert('Utente rimosso dalla buddy list');
			h='Utente rimosso dalla buddy list';
			if ((_nav.mainMode=='my') && (_nav.currentAction=='buddy')) menucontent_switch('buddy');
		}
		else {
			alert('Ci sono stati dei problemi tecnici, operazione non condotta a buon fine');	
			h='Ci sono stati dei problemi tecnici, operazione non condotta a buon fine';
		}	
		$('#'+_buddy.buddyNotifContainer).empty().append(h);
	}
		
	/*
	manages the action of putting a user (oid id) in black list for user logged-in (uid)
	a seconda di quello che diranno lato prodotto qui potrei anche innescare una gestione del risultato fornito dal server
	*/
	this.putInBlack=function(tex,o){
	var h;
		var ans=JSON.parse(tex);
		if (ans.status == 200) {
			msg=ans.msg;
			if (msg == 'ok'){
					h='Utente immesso in black list';
					if (_buddy.lastOtherCheck == -6){
						for (r=0;r<_notifica.events['buddy_inv'].length;r++){
							if (_chisono.oid == _notifica.events['buddy_inv'][r].oid) _buddy.currentBuddy_inv=_notifica.events['buddy_inv'][r].fid;
						}
						//alert ('oid:'+_chisono.oid+' buddy_inf-fid:'+_buddy.currentBuddy_inv);
						sync('buddy_inv'); //pero devo impostare il current buddy_inv da cancellare
					}
					if ((_nav.mainMode=='my') && (_nav.currentAction=='buddy')) menucontent_switch('buddy');
			}
			else h='Problemi nella inserzione dell utente in black list';
		}
		else {
			h=ans.errormsg;
		}
		$('#'+_buddy.buddyNotifContainer).empty().append(h);
	}

	this.confirmAction=function(msg){
		var h=msg
		+'<br><input type="button" id=buddyconf class=Bottone value="Conferma"/> <input type=button id=deleteconf class="Bottone" value="Annulla"/>';
		$('#'+this.buddyNotifContainer).empty().append(h).parent().show();
		$('#'+this.buddyNotifContainer+' > input').click(function(event){
			
			if ($(this).attr('id')=='buddyconf') {
				if (_buddy.action=='buddy') updtElem(_buddy.actionUrl,_buddy,'inviteBuddy','');
				if (_buddy.action=='black') updtElem(_buddy.actionUrl,_buddy,'putInBlack','');
				if (_buddy.action=='stopblack') updtElem(_buddy.actionUrl,_buddy,'stopBlack','');
				if (_buddy.action=='stopbuddy') updtElem(_buddy.actionUrl,_buddy,'stopBuddy','');
			}	
			else if ($(this).attr('id')=='deleteconf') {
				h='Operazione Annullata!';
				$('#'+_buddy.buddyNotifContainer).empty().append(h);
			}	
			else alert('un click sulla ancora');
		});
	}
	
	/*
	attraverso il check della relation between uid & oid => taking the value of _buddy.action display messages in dialog box...
	*/
	this.totCheck=function(tex,o){
		var msg='';
		var ans=JSON.parse(tex);
		//alert('L'+tex);
		if (ans.status == 200) {
			//fare uso di _buddy.actionUrl
			var rel=ans.rel;
			//alert(rel);
			//ci saranno relazioni che implicano dialog di notifica	_this.prompt(msg)
			//			relazioni che implicano dialog di conferma	_this.dialog(msg)
			var other=ans.other;
			this.lastOtherCheck=ans.rel;
			if (this.action=='buddy'){
				switch (rel){
					case -2:
						msg='gli utenti sono gia buddy';
						this.visu(msg);
						break;
					case -3:
						//msg='L\'utente '+other+' e\' gia stato invitato in buddy';
						msg='Hai gia\' inviato una richiesta di amicizia all\'utente '+other;
						this.visu(msg);
						break;
					case -5:
						msg='Sei nella black list di '+other+', non puoi invitarlo';
						this.visu(msg);
						break;
					case -7:
					case -4:
						msg='Situazione incoerente, errore!';
						this.visu(msg);
						break;
					case -6:		//qui si dovrebbero recuperare i dati necessari a gestire l'invito di oid
						this.pendantBuddy(other);
						// c'è gia un invito pendente di oid per uid...visualizzare un (accetta/rifiuta/'più tardi')
						break;
					case -8:
						msg=other+' risulta essere nella tua black list, confermi lo spostamento in buddylist?';
						this.confirmAction(msg);
						break;
					case -1:
						this.error();	
						break;
					case 0:
						//msg='Vuoi invitare <b>'+other+'</b> ad essere tuo buddy friend ?';
						msg='Invita <b>'+other+'</b> a diventare tuo amico';
						this.confirmAction(msg);
						break;
					default:
						alert('default');	
				}
			}
			if (this.action=='black'){
				switch (rel){
					case 0:
						msg='Vuoi aggiungere '+other+' nella tua black list ?';
						this.confirmAction(msg);
						break;
					case -1:
						this.error();	
						break;
					case -2:
						msg='L\'utente '+other+' risulta presente nella tua buddylist, confermi lo spostamento in blacklist?!';
						this.confirmAction(msg);
						break;
					case -3:
						msg='L\'utente '+other+' era stato invitato in buddylist...annulli l\'invito e lo aggiungi alla black list?';
						this.confirmAction(msg);
						break;
					case -5:
						msg='Vuoi aggiungere '+other+', nella tua black list?';
						this.confirmAction(msg);
						break;
					case -6:
						msg='Hai un invito in buddy list dall\'utente '+other+', confermi lo spostamento in blacklist?!';
						//TODO TODOTODOTODO Se l'utente conferma....DEVO CANCELLARE IL RELATIVO EVENTO
						this.confirmAction(msg);
						break;
					case -8:
						msg=other+' risulta gia essere nella tua black list';
						this.visu(msg);
						break;
				}
			}
			if (this.action=='stopblack'){
				switch (rel){
					case -8:
						msg='Vuoi toglieere '+other+' dalla tua black list ?';
						this.confirmAction(msg);
						break;
				}
			}	
			if (this.action=='stopbuddy'){
				switch (rel){
					case -3:
						msg='Vuoi toglieere '+other+' dalla tua buddy list ?';
						this.confirmAction(msg);
						break;
					case -2:
						msg='Vuoi toglieere '+other+' dalla tua buddy list ?';
						this.confirmAction(msg);
						break;
				}
			}	
			
		}	
		else {
			this.error('totCheck');
		}		
	}
	this.error=function(err){
		alert('sono in error');
		switch (err){
			default:
			case 'totCharck':
				alert('Problemi tecnici, riprovare tra qualche minuto. Grazie');
			break;	
		}	
	}		

}
