
// Définition de la classe 'CarSelectorTabs'
// NB: L'ordre des méthodes est important

CarSelectorTabs.Instances = new Array();

function CarSelectorTabs(id)
{
	// Outil pour récupérer une instance par son identifiant
	CarSelectorTabs.Instances[id] = this;

	// Propriétés
	
	this.HtmlObject = document.getElementById(id);
	this.OnChanged = new Array();
	
	// Méthodes publiques
		
	this.SetSelection = function(index, styleOnly)
	{
		if (this.HtmlObject != null)
		{
			var tds = this.HtmlObject.getElementsByTagName("td");
			if (index >= 0 && index < tds.length)
				this.OnClick(tds[index], styleOnly);
		}
	}
				
	// Permet de retrouver le nom du critère associé à l'onglet en cours
	this.GetSelection = function()
	{
		if (this.HtmlObject != null)
		{
			var tabs = this.HtmlObject.getElementsByTagName("td");
			for (var i = 0; i < tabs.length; i++)
			{
				var tab = tabs[i];
				if (tab.id.indexOf("Tab__") != -1 && tab.className.indexOf("Selected") != -1)
					return tab.id.split("__")[1];
			}
		}
		return null;
	}
	
	// Récupère la propriété associée à l'onglet dont l'index est passé en paramètre
	this.GetProperty = function(index)
	{
		if (this.HtmlObject != null)
		{
			var tabs = this.HtmlObject.getElementsByTagName("td");
			for (var i = 0; i < tabs.length; i++)
				if (i == index)
					return tabs[i].id.split("__")[1];
		}
		return null;
	}

	this.OnClick = function(item, styleOnly)
	{
		// On récupère la propriété ciblée par l'onglet
		var idParts = item.id.split("__");
		var property = idParts[1];
			
		// On désélectionne tous les onglets
		$("#" + id + " td").each(function()
		{
			if ($(this).attr("class").indexOf("Separator") < 0)
				$(this).attr("class", "Enabled");
		});
		
		// On sélectionne l'élément choisi
		item.className = "Enabled Selected";
		var desc = document.getElementById("tabDesc");
		if (desc != null)
			desc.innerHTML = item.title;

		// On signale que la sélection a été modifiée
		if (!styleOnly)
			Tools_DispatchEvent(this.OnChanged, this, property);
	}
}


