
var BienSelectionObjects = new Array;

var BienSelectionObject = null;

function BienSelection(object_id)
{
	this.objectId = object_id;
	
	this.contentContainer = $(object_id+'_container');
	
	this.init = function()
	{
		BienSelectionObjects[this.objectId] = this;
		BienSelectionObject = this;
	}
	
	this.actionAddBien = function(bien_id)
	{
		AjaxScriptAsync('SelectionItemAddBien', {object_id:this.objectId, bien_id:bien_id}, 'get');		
	}
	
	this.onAjaxAddBienCompleted = function(result)
	{
		if(result == 'exists')
		{
			alert('Vous avez déja sélectionné ce bien !');
		}
		else if(result == 'ok')
			this.actionRefreshContent();
	}
	
	this.actionRemoveBien = function(bien_id)
	{
		AjaxScriptAsync('SelectionItemRemoveBien', {object_id:this.objectId, bien_id:bien_id}, 'get');
	}
	
	this.onAjaxRemoveBienCompleted = function()
	{
		this.actionRefreshContent();
	}
	
	this.actionRefreshContent = function()
	{
		this.dropContent();
		
		AjaxScriptAsync('SelectionItemBuildContent', {object_id:this.objectId}, 'get');
	}
	
	this.setContent = function(content)
	{
		this.contentContainer.innerHTML = content;
	}
	
	this.dropContent = function()
	{
		this.contentContainer.innerHTML = '';
	}
	
	this.init();
}