/* ================================================ */
/* === GENERIC FUNCTIONS ========================== */
/* ================================================ */

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

/* ================================================ */
/* === SPECIFIC FUNCTIONS ========================= */
/* ================================================ */


function showResourcesTab1() {
	MM_showHideLayers("RessourcesTab1","","show","RessourcesTab2","","hide");
	var tabLink1 = document.getElementById("tabLink1");
	var tabLink2 = document.getElementById("tabLink2");
	tabLink1.className = "Active";
	tabLink2.className = "";
}

function showResourcesTab2() {
	MM_showHideLayers("RessourcesTab1","","hide","RessourcesTab2","","show");
	var tabLink1 = document.getElementById("tabLink1");
	var tabLink2 = document.getElementById("tabLink2");
	tabLink1.className = "";
	tabLink2.className = "Active";
}

/* ================================================ */
/* === HOMEPAGE - FICHES ========================== */
/* ================================================ */

var dhtmlgoodies_slideSpeed = 20;	// Higher value = faster
var dhtmlgoodies_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);

	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			dhtmlgoodies_activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}



function initShowHideDivs() 
{ 
   var divs = document.getElementsByTagName('DIV'); 
   var divCounter = 1; 
   for(var no=0;no<divs.length;no++){ 
      if(divs[no].className=='dhtmlgoodies_question'){ 
         divs[no].onclick = showHideContent; 
         divs[no].id = 'dhtmlgoodies_q'+divCounter; 
         var answer = divs[no].nextSibling; 
         while(answer && answer.tagName!='DIV'){ 
            answer = answer.nextSibling; 
         } 
         answer.id = 'dhtmlgoodies_a'+divCounter;    
         contentDiv = answer.getElementsByTagName('DIV')[0]; 
         contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';     
         contentDiv.className='dhtmlgoodies_answer_content'; 
         contentDiv.id = 'dhtmlgoodies_ac' + divCounter; 
         answer.style.display='none'; 
         answer.style.height='1px'; 
         divCounter++; 
      }       
   }    
} 
window.onload = initShowHideDivs;

function submitSondage()
{
	c=0;
	for (i=1;i<=5;i++)
	{
		r=document.sondageform.reponse[i-1];
		if (r) if (r.checked) c=i;
	}
	if (c==0)
	{
		alert('Merci de choisir une réponse');
	}
	else
	{
		document.sondageform.submit();
	}
}
