//*** TimeElement class definition	***//
	
	function TimeElement(id)
	{
		this.id = id;
		this.isVisible = true;
		this.parent = null;
		this.showDiv = null;
		this.hideDiv = null;
		this.children = new Array();
		this.divElement = document.getElementById(this.id);
	}
	function toggleDiv()	
	{	ouvrirDiv = document.getElementById(this.id + 'ouvrir');
		fermerDiv = document.getElementById(this.id + 'fermer');
		
		this.setElementVisibility(!(this.isVisible));
		
		if (this.isVisible) 
		{
			ouvrirDiv.className = 'cachediv'; 
			fermerDiv.className = 'menoncachediv';
		} 
		else 
		{
			ouvrirDiv.className = 'menoncachediv'; fermerDiv.className = 'cachediv';
		}
	}
	function addChild(timeElement)
	{
		this.children.push(timeElement);
		timeElement.parent = this;
	}
	function setElementVisibility(visible)
	{		
		if(this.parent==null) return;
	
//		if(this.id.indexOf("area") >= 0 || this.id.indexOf("theatre") >= 0)
	//		
		
		this.isVisible = visible;
		
		if(this.showDiv!= null)
		{			
			if(this.isVisible)
				this.showDiv.className = "cachediv";	
			else		
				this.showDiv.className = "menoncachediv";
		}		
		if(this.hideDiv!= null)
		{
			if(this.isVisible)
				this.hideDiv.className = "menoncachediv";	
			else		
				this.hideDiv.className = "cachediv";	
		}
						
		if(this.divElement!=null)
		{
			if(this.isVisible)
				this.divElement.className = "menoncachediv";
			else		
				this.divElement.className = "cachediv";
		}
	}	
	function setVisibility(visible)
	{		
		if(this.parent==null) return;

		this.setElementVisibility(visible);
			
		if(this.parent!=null)
			this.parent.updateVisibility();
	}	
	function updateVisibility()
	{		
		var visible = false;
		for(i=0; i<this.children.length; i++)
			if(this.children[i].isVisible)
			{
				visible = true;
				break;
			}

		if(this.isVisible != visible)
			this.setVisibility(visible);
	}
	TimeElement.prototype.toggleDiv = toggleDiv;	
	TimeElement.prototype.addChild = addChild;
	TimeElement.prototype.setVisibility = setVisibility;
	TimeElement.prototype.setElementVisibility = setElementVisibility;
	TimeElement.prototype.updateVisibility = updateVisibility;
	
	//*** TimeElement class definition	***//
	
	
	var rootTimeElement = new TimeElement("root");
	var daysTimeElement = new Array();
	var timesTimeElement = new Array();
	
	function selectTimes()
	{		
		window.status = "Recherche...";
		//Check filter parameters
		var selectedSounds = new Array();
		var selectedDays = new Array();
		
		var soundVersions = document.getElementsByName("soundVersions");
		var weekDays = document.getElementsByName("weekDays");

		for(var i=0; i<soundVersions.length; i++)
			if(soundVersions[i].checked)
				selectedSounds.push(soundVersions[i].value);
		
		for(var i=0; i<weekDays.length; i++)
			if(weekDays[i].checked)
				selectedDays.push(weekDays[i].value);

						
		var startTime = "" + document.getElementsByName("startTime")[0].value;		
		if(startTime.length==1)
			startTime = "0" + startTime;		
		startTime = startTime + "00";
		
		var endTime = "" + document.getElementsByName("endTime")[0].value;		
		if(endTime.length==1)
			endTime = "0" + endTime;		
		endTime = endTime + "00";
		
		
		// Show/hide time elements
		for(var i=0; i<timesTimeElement.length; i++)
		{
			arrTime = timesTimeElement[i].id.split("_");
			time = arrTime[arrTime.length-1];
			time = time.replace(/:/g, "");
			
			timesTimeElement[i].setVisibility( (time>=startTime && time<=endTime) );					
		}
		
		// Show / hide days elements
		for(var i=0; i<daysTimeElement.length; i++)
		{			
			visibleSnd = false;
			visibleDay = false;			

			//Check sound version selection
			for(j=0; j<selectedSounds.length; j++)
				if( (daysTimeElement[i].id.search("_" + selectedSounds[j] + "_") > 0) ) 
				{
					visibleSnd=true;
					break;
				}

			//Check days selection
			for(k=0; k<selectedDays.length; k++)
				if( (daysTimeElement[i].id.search("_" + selectedDays[k]) > 0) && daysTimeElement[i].isVisible) 
				{
					visibleDay=true;
					break;
				}
			
			daysTimeElement[i].setVisibility( visibleSnd && visibleDay );	
		}
		
		window.status = "";
	}