/*---------------------------------------------------------------------------------------------------
$ // Raccourci pour avoir document.getElementById
---------------------------------------------------------------------------------------------------*/
function $(id){
	return document.getElementById(id);
}

/*---------------------------------------------------------------------------------------------------
addLoadEvent // Ajoute une fonction à la liste de fonction à executé lors de l'événement onload
---------------------------------------------------------------------------------------------------*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

/*---------------------------------------------------------------------------------------------------
getElementsByClassName // Retourne tout les élément d'une certaine classe
ex1: getElementsByClassName(document, "a", "className");
ex2: getElementsByClassName(document, "*", "className2");
---------------------------------------------------------------------------------------------------*/
function getElementsByClassName(el, strTagName, strClassName){
	var arrElements = (strTagName == "*" && el.all)? el.all : el.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return (arrReturnElements)
}

/*---------------------------------------------------------------------------------------------------
equalHeight // 
---------------------------------------------------------------------------------------------------*/
function equalHeight(){
	containerElement = $('container5');
	if (!containerElement) return false;
	var els = containerElement.getElementsByTagName("*");
	var tempArray = new Array();
	for(var i=0; i< els.length; i++){	
		var el = els[i];
		if(el.className.indexOf("equalHeight_@") != -1){
			var startSubString = el.className.indexOf("equalHeight_@");
			var string = el.className.substring(startSubString);
			var param1 = string.split('@')[1];
			var param1 = param1.split(' ')[0];
			tempArray.push(param1);
			if(!tempArray[param1])tempArray[param1] = new Array();
			tempArray[param1].push(el);
		}
	}
	for(var x in tempArray){
		if(typeof(tempArray[x]) == 'object'){
			var maxHeight = 0;
			for(var y in tempArray[x]){
				var el = tempArray[x][y];
				if(el.offsetHeight > maxHeight) maxHeight = el.offsetHeight;
			}			
			for(var y in tempArray[x]){
				var el = tempArray[x][y];
				el.style.minHeight = maxHeight + "px";
				if(navigator.userAgent.indexOf('MSIE 6.0') != -1){
					el.style.height = maxHeight + "px";
				}
			}
		}
	}
}

/*---------------------------------------------------------------------------------------------------
toggleVisibility // Initialise les forms vdaemon (ajoute 
---------------------------------------------------------------------------------------------------*/
function toggleVisibility(containerElement,startAsHidden,classContainer,classHideBtn,classShowBtn,classToggleBtn,classContent,classContentSwitch){
	if (!document.getElementById) return false;
	var containers = getElementsByClassName(containerElement, "*", classContainer);
	if(containers.length <= 0)return;
	for(var i=0; i<containers.length; i++){
		var container = containers[i];
		var hideBtn   = getElementsByClassName(container, "*", classHideBtn)[0];
		var showBtn   = getElementsByClassName(container, "*", classShowBtn)[0];
		var toggleBtn = getElementsByClassName(container, "*", classToggleBtn)[0];
		var content   = getElementsByClassName(container, "*", classContent)[0];
		if(classContentSwitch != null){
			var contentSwitch = getElementsByClassName(container, "*", classContentSwitch)[0];
		}else{
			var contentSwitch = false;
		}
		
		if(startAsHidden){
			if(showBtn)showBtn.style.display = 'block';
			if(hideBtn)hideBtn.style.display = 'none';
			if(content)content.style.display = 'none';
			if(contentSwitch)contentSwitch.style.display = 'block';
		}else{
			if(showBtn)showBtn.style.display = 'none';
			if(hideBtn)hideBtn.style.display = 'block';
			if(content)content.style.display = 'block';
			if(contentSwitch)contentSwitch.style.display = 'none';
		}
		
		//showBtn
		if(showBtn){
			showBtn.hideBtn = hideBtn;
			showBtn.content = content;
			showBtn.contentSwitch = contentSwitch;
			showBtn.onclick = function(){
				this.style.display = 'none';
				this.hideBtn.style.display = 'block';
				this.content.style.display = 'block';
				if(this.contentSwitch)this.contentSwitch.style.display = 'none';
			}
		}
		
		//hideBtn
		if(hideBtn){
			hideBtn.showBtn = showBtn;
			hideBtn.content = content;
			hideBtn.contentSwitch = contentSwitch;
			hideBtn.onclick = function(){
				this.style.display = 'none';
				this.showBtn.style.display = 'block';
				this.content.style.display = 'none';
				if(this.contentSwitch)this.contentSwitch.style.display = 'block';
			}
		}
		
		//toggleBtn
		if(toggleBtn){
			toggleBtn.content = content;
			toggleBtn.contentSwitch = contentSwitch;
			toggleBtn.onclick = function(){
				if(this.content.style.display == 'none'){
					this.content.style.display = 'block';
					if(this.contentSwitch)this.contentSwitch.style.display = 'none';
				}else if(this.content.style.display == 'block'){
					this.content.style.display = 'none';
					if(this.contentSwitch)this.contentSwitch.style.display = 'block';
				}
				
			}
		}
	}
}

function initToggleVisibility(){
	document.write("\n<style>\n<!--\n");
	document.write(".toggleHideContent{display:none;}\n");
	document.write(".contentHide{display:none;}\n");
	document.write(".jsOnlyContent{display:block !important;}\n");
	document.write("-->\n</style>\n");
	addLoadEvent(prepareToggleVisibility);
}

function prepareToggleVisibility(){
	var el = document.getElementById("container5");
	toggleVisibility(el,true,"toggleHide","hideBtn","showBtn","toggleBtn","toggleHideContent");
	toggleVisibility(el,false,"toggleShow","hideBtn","showBtn","toggleBtn","toggleShowContent");
	toggleVisibility(el,false,"toggleContent","hideBtn","showBtn","toggleBtn","contentShow","contentHide");
}

function validSearch() {
	var inputSearch = document.getElementById("s");
	
	if ((!inputSearch.value=='') || (inputSearch.length>2)){
		return true;
	}
	inputSearch.focus();
	return false;
		
	//}	
}


addLoadEvent(equalHeight);
initToggleVisibility();