// [lea - 01/03/2010]
var g_nb_experiences = 10;

// JavaScript Document
var PullDown = {};
var liste="deroule"
window.onload=init
function init()
	{
		outlineout()			// sort les outline des liens survolés
		if($('slide'))
			{
				 PullDown.panel = Rico.SlidingPanel.top( $('outer_panel'), $('inner_panel'));// replie l'image
				 redimslide($('outer_panel'))
				 $('slide').style.display="block"
			}  
		if ($('deroule'))
			{
				$$('.colapse').each(function(e){e.style.display='none';});	// replie les sous menus (prototype)
		
		
				// calcul de la hauteur de la liste déroulante
				$('deroule').style.display="none"
				difference=$('gauche').offsetHeight - $('smenufin').offsetTop
				//if (difference < 100) difference= 100
				//difference-=50
				//alert(difference)
				$('smenufin').style.height=difference+"px"
				$('deroule').style.display="block"
				hauteurMax=difference	// place max
				// fin du calcul de la hauteur de la liste déroulante
		
				//if ($(menu)) montre(menu)		// fait apparaitre le sous menu1
				//alert(menu)
				/*if (menu) selectmenu(menu,numeros)		// fait apparaitre le sous menu1
				else if($('smenu1')) montre('smenu1') 
				else montre(null)*/
				selectmenu(menu,numeros)
				$('menu').style.visibility="visible";
			}
		roundMe()				// calques coins arrondis
		//initscroll('deroule','smenufin')	// lance scroll de la liste
	
		// [lea - 04/03/2010]
		traite_page_experiences();

		traite_page_iode_contact();
	}
	
/*	
function selectmenu(m,s){

var children = $A($("menu").childNodes);			// dl et dd
var last=null
children.each(function(child) {
	if (child.id=m) {
		montre(m,last)
		last=child
		if (s)
			{
				children = $A($(menu).childNodes.childNodes);	//ul li
				var i=0
				children.each(function(child) {
					if (i=m) child.setAttribute("class", "encours");
					i++
				})
			}
	}
})
}
*/
function selectmenu(m,s){
var message=""
var children = $A($("menu").childNodes);			// dl et dd
var last=null
//alert(children.inspect(children))

if (m)											// si sous menu à déplier au chargement
	{
		children.each(function(child) {
				if (child.tagName=='DT') {
					last=child
				}
				else if (child.id==m) {
					montre(m,last)
					if (s)
						{
							children = $A($(m).getElementsBySelector("LI"));	//ul li
							//alert(children.inspect(children))
							var i=1
							children.each(function(child) {
								if (s==i) child.addClassName("encours");
								i++
							})
						}
					}
			})
		}
	else						// pas de sous menu juste un numeros pour présélectionner
		{
			montre(null)
			children = $A($("menu").getElementsBySelector("DT"));	//ul li
			//alert(children.inspect(children))
			var i=1
			children.each(function(child) {
				if (s==i) child.addClassName("menudd");
				i++
			})
			
		}
}






function redimslide(obj)
{
	obj.style.width=($('slide').offsetWidth)+"px"
}
	
function outlineout() {
		var collection=document.getElementsByTagName("a")
		for(i=0; (obj = document.getElementsByTagName("a")[i]); i++)
			{
				if (obj.attachEvent)
					{
						obj.attachEvent("onfocus",obj.onfocus)				// no outline
						obj.onfocus=gestion
						obj.attachEvent("onmouseover",obj.onmouseover)		// affiche title
						obj.onmouseover=affiche
						obj.attachEvent("onmouseout",obj.onmouseout)		// affiche title
						obj.onmouseout=masque
					}
				else if (obj.addEventListener)
					{
							obj.addEventListener("focus",gestion,false)
							obj.addEventListener("mouseover",affiche,false)
							obj.addEventListener("mouseout",masque,false)
					}
				else 
					{
							obj.onfocus=gestion
							obj.onmouseover=affiche
							obj.onmouseout=masque
					}
			}
		// comportement expériences
		if ($("experience"))
			  {
					var collection = $A($("experience").getElementsBySelector("DT"));	//ul li
					collection.each(function(obj) {
					
						if (obj.attachEvent)
							{
								obj.attachEvent("onclick",obj.onclick)				// no outline
								obj.onclick=gestionexp
							}
						else if (obj.addEventListener)
							{
									obj.addEventListener("click",gestionexp,false)
							}
						else 
							{
									obj.onclick=gestionexp
							}
					})
			  }
	}
	
function gestionexp(e)
	{
		//alert("gestion")
		if (!e) var e=window.event
		var obj = e.target ? e.target : e.srcElement
		montrexp(obj)
	}
function affiche(e)
	{
		if (!e) var e=window.event
		var obj = e.target ? e.target : e.srcElement
//message=(obj.getAttribute("title"))?obj.getAttribute("title"):(obj.getAttribute("alt"))?obj.getAttribute("alt"):""
		if (document.getElementById("message")) {
		document.getElementById("message").innerHTML=obj.getAttribute("title")
		document.getElementById("message").style.visibility="visible"
		}
	} 
function masque(e)
	{
		if (!e) var e=window.event
		var obj = e.target ? e.target : e.srcElement
		if (document.getElementById("message")) document.getElementById("message").style.visibility="hidden"
	} 

function gestion(e)
	{
		if (!e) var e=window.event
		var obj = e.target ? e.target : e.srcElement
		if (obj.blur) obj.blur()
		//document.getElementById("message").innerHTML=obj.getAttribute("title")
	} 

function roundMe() {
        $$('.roundme').each(function(e){Rico.Corner.round(e,{corners:"bottom"})});
        $$('.roundmefull').each(function(e){Rico.Corner.round(e,{blend:true})});
   }
   
  //$($('someElement').parentNode).hide()
function montre(id,parent) {
	// replie tous les sous menus
     $$('.colapse').each(function(e){e.style.display='none';});
     if (parent) $$('.menudd').each(function(e){e.className='';});
	avant=$('smenufin').offsetTop		// releve position
	if (id) {
		$(id).style.display='block';
		}	// deplie ss menu selectionne
	if (parent)
		{ 
		parent.className="menudd"
		}
	apres=$('smenufin').offsetTop		// relever nouvelle position
	hauteur=apres-avant				// déplacement
	result=hauteurMax-hauteur
	if (result < 10) result=0
	$('smenufin').style.height = (result) +"px" // ajuste derniere liste
	//alert($('smenufin').style.height)
	//alert(hauteurMax+" "+hauteur+" "+(hauteurMax-hauteur))
	initscroll('deroule','smenufin')	// relance le scroll de la liste
}
dernier=0

function cachexp()
	{
		    $$('#experience dd').each(function(e){e.style.display='none';
		});

	}

function montrexp(obj) {
	// replie tous les sous menus
    /* $$('#experience dd').each(function(e){//e.style.display='none';
			new Effect.SlideUp(e);	
		});*/
	cachexp()
	var pos=0
	var i=1
	children = $A($("experience").getElementsBySelector("DT"));	//ul li
	/*alert(children.inspect(children))
	alert(obj.inspect(obj))*/
	children.each(function(child) {

if (child==obj)
		{
			
			pos=i;
		}
	else
		{
		child.className=""
		}

		i++
	})
	i=1
	if (pos!=dernier)
		{
			dernier=pos
			children = $A($("experience").getElementsBySelector("DD"));	//ul li
			children.each(function(child) {
			if (i==pos) {
				child.className="ddencours"
				child.style.display="block";
				obj.className="expencours"
			}
			else
				{
				child.className=""
				}
			i++
			})	
		}
	else	
		{
				obj.className=""
				dernier=0
		}
}

// gestion formulaire
bImpossible=false;
function VerifForm(it)
{
	for (var i in it)
	{
		if (it.login.value == "")
		{
			bImpossible=true;
		}
		if (it.pwd.value == "")
		{
			bImpossible=true;
		}
	}
	if (bImpossible== true)
	{
		Message= "Les champs doivent être impérativement remplis" ;
		alert(Message);
		return;
	}
	it.submit()
	return;
}

LE = "Le " 

TOOLONG=" est trop long"

function VerifTaille(it,t)
{
	if (it.value.length > t)
	{
		Message= LE ;
		Message+= it.title ; 
		Message+= TOOLONG ;
		alert(Message);
		bImpossible=true;
		it.value="";
		return;
	}
	bImpossible=false;
	return;
}

// [Lea - 2010/02/26]
//================================================================================
// change_img_src
//================================================================================
function change_img_src(img_id, img_src)
{
var img = null;

	img = document.getElementById(img_id);
	img.src = img_src;
}

//================================================================================
// hide_or_show_solution 
//================================================================================
function hide_or_show_solution(tr_experience_id, tr_experience_solution_id)
{
var tr_experience          = null;
var tr_experience_solution = null;
var i                      = 1;

	tr_experience          = document.getElementById(tr_experience_id);
	tr_experience_solution = document.getElementById(tr_experience_solution_id);

	if(tr_experience_solution.style.display == "none")
	{
	var tr_experience_other_solution_id = null;
	var tr_experience_other_solution    = null;

		// Affiche l'experience selectionnee
		tr_experience_solution.style.display = "table-row";

		// Cache les autres experiences
		for(i=1 ; i<(g_nb_experiences + 1) ; i++)
		{
			tr_experience_other_solution_id = "tr_experience_solution_" + i.toString();
			if(tr_experience_other_solution_id != tr_experience_solution_id)
			{
				tr_experience_other_solution = document.getElementById(tr_experience_other_solution_id);
				tr_experience_other_solution.style.display = "none";
			}
		}
	}
	else if(tr_experience_solution.style.display == "table-row")
		tr_experience_solution.style.display = "none";
}

//=======================================================
// traite_page_experiences
// Pour la page "inventif-experiences.php"
//=======================================================
function traite_page_experiences() 
{
var document_title   = "";
var doc_title_regexp = ""; 

	// Regular expression
	// . matches any character except a newline.
	doc_title_regexp = new RegExp("Exp.riences");
	//alert("doc_title_regexp = " + doc_title_regexp);
	
	document_title = document.getElementsByTagName("title")[0].innerHTML;
	//alert("document_title = " + document_title);

	if(document_title.match(doc_title_regexp))
	{
	var tr_experience_id                = ""; 
	var tr_experience_solution_id       = "";
	var tr_experience                   = null;
	var div_experiences_descr_situation = null;
	var tr_experience_solution          = null;
	var i                               = 1;

		for(i=1 ; i<(g_nb_experiences + 1) ; i++)
		{
			tr_experience_id          = "tr_experience_" + i.toString(); 
			tr_experience_solution_id = "tr_experience_solution_" + i.toString();

			tr_experience_solution = document.getElementById(tr_experience_solution_id);
			
			tr_experience_solution.style.display = "none";

			tr_experience = document.getElementById(tr_experience_id);

			if(i % 2 == 0)
			{
				tr_experience.style.backgroundColor = "#F2F5A9";
			}
			else
			{
				tr_experience.style.backgroundColor = "#E8F7BA";
			}

			ajoute_ecouteurs(tr_experience,
											 tr_experience_id, 
											 tr_experience_solution_id);
		}
	}
}

//=======================================================
// ajoute_ecouteurs
//=======================================================
function ajoute_ecouteurs(tr_experience,
													tr_experience_id, 
													tr_experience_solution_id) 
{
	if(window.addEventListener) //Mozilla
	{
		tr_experience.addEventListener("click",
				function () 
				{ 
					//alert("tr_experience_id = " + tr_experience_id);
					hide_or_show_solution(tr_experience_id, tr_experience_solution_id); 
				}, 
				false);
		//alert("MOZILLA click");
		
		tr_experience.addEventListener("mouseover", 
				function () 
				{ 
					this.style.cursor = "pointer"; 
				}, false);
		//alert("MOZILLA mouseover");

		tr_experience.onmousedown = function () 
															  { 
															    return false; 
															  };
		//alert("MOZILLA onmousedown");
	}

	else if(tr_experience.attachEvent) //IE
	{
		tr_experience.attachEvent("onclick", 
					function ()
					{ 
						hide_or_show_solution(tr_experience_id, tr_experience_solution_id); 
					});
		//alert("IE onclick");

		tr_experience.attachEvent("onmouseover", 
				function () 
				{ 
					var tr_experience = null; 
					tr_experience = document.getElementById(tr_experience_id); 
					tr_experience.style.cursor = "hand"; 
				});
		//alert("IE onmouseover");

		tr_experience.attachEvent("onselectstart", 
				function () 
				{ 
					return false; 
				});
		//alert("IE onselectstart");
	}

	else
	{
		alert("Erreur : Navigateur non supporté.");
	}
}

//=======================================================
// traite_page_iode_contact 
//=======================================================
function traite_page_iode_contact() 
{
var document_title   = "";
var doc_title_regexp = ""; 

	// Regular expression
	// . matches any character except a newline.
	doc_title_regexp = new RegExp("Contact");
	//alert("doc_title_regexp = " + doc_title_regexp);
	
	document_title = document.getElementsByTagName("title")[0].innerHTML;
	//alert("document_title = " + document_title);

	if(document_title.match(doc_title_regexp))
	{
		initOnload();
	}
}
