
//Affiche le panel droit de l'etape
function dspRightPanText(stepname)
{
	if(stepname!="TpStepSearchPhoto"){
	$('creation_tablo_droite').innerHTML = $(stepname+'-rightpan').innerHTML;
	}
	
}

function dbg(msg)
{
	$('infos').innerHTML += " <br />"+msg+'<br />';
}

// set or get the current display style of the div
function dsp(d,v){
		
	if(v==undefined){
		return d.style.display;
	}else{
		
		d.style.display=v;

	}
}

// set or get the height of a div.
function sh(d,v){
	// if you are getting the height then display must be block to return the absolute height
	if(v==undefined){
		
		if(dsp(d)!='none' && dsp(d)!=''){
			//alert('return offsetheight dsp = '+dsp(d)+' offsetheight = '+d.offsetHeight);
			return d.offsetHeight;
		}
		//maxh
		viz = d.style.visibility;
		d.style.visibility = 'hidden';
		o = dsp(d);
		dsp(d,'block');
		r = parseInt(d.offsetHeight);
		dsp(d,o);
		d.style.visibility = viz;
		return r;
	}else{
		d.style.height=v;
	}
}
/*
* Variable 'S' defines the speed of the accordian
* Variable 'T' defines the refresh rate of the accordian
*/
s=7;
t=10;

var lCollapseOkPx = 20;
//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
function ct(d){
	
	/*
	d.style.opacity = (v/d.maxh);
	d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
	*/
	d = $(d);
	
	//TODO corriger le bug 
	//ICI si lCollapseOkPx > 20  = pas de bug, sous FF, 
	//Le test normal est sh(d) > 3, et sous FF il est toujours superieur a 3 ( ce qui provoque le bug )
	if(sh(d)>lCollapseOkPx){
		
	v = Math.round(sh(d)/d.s);
	v = (v<1) ? 1 :v ;
	v = (sh(d)-v);
	v = Math.ceil( v );
	sh(d,v+'px');
	d.style.opacity = (v/d.maxh);
	d.style.filter  = 'alpha(opacity='+(v*100/d.maxh)+');';
		
	}else{
		//dbg(' fin ct de '+d.id);
		sh(d,0);
		dsp(d,'none');
		clearInterval(d.t);
		// reduction finie ici
	}
}

//Expand Timer is triggered as a setInterval to increase the height of the div exponentially.
function et(d){
	//alert('et');
	//alert( d.maxh );
	
	d = $(d);
	if(sh(d)<d.maxh){
	//alert( "d.maxh = "+d.maxh);
	v = Math.round((d.maxh-sh(d))/d.s);
	v = (v<1) ? 1 :v ;
	v = (sh(d)+v);
	sh(d,v+'px');
	//dbg("opacity setting opacity = "+(v/d.maxh)+" et filter = "+(v*100/d.maxh));
	d.style.opacity = (v/d.maxh);
	d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
		
	}else{
		//alert( "d.maxh = "+d.maxh+" et sh(d) = "+sh(d));
		sh(d,d.maxh);
		clearInterval(d.t);
		d.style.opacity = 1;
		d.style.filter  = 'alpha(opacity=100);';
		//d.t = '';
		isReady = 1;
	}
}

// Collapse Initializer
function cl(d){
	if(dsp(d)=='block'){
		clearInterval(d.t);
		d.t=setInterval('ct("'+d.id+'");',t);
		//dbg("interval collapse "+t );
	}
}

//Expand Initializer
function ex(d){
	if(dsp(d)=='none'){
		
		dsp(d,'block');
		d.style.height='0px';
		if( typeof d.t != "undefined" )
		{
		clearInterval(d.t);
		}
		d.t=setInterval('et("'+d.id+'");',t);
		//alert(d.t.toString());
	}
}

// Removes Classname from the given div.
function cc(n,v){
	s=n.className.split(/\s+/);
	for(p=0;p<s.length;p++){
		if(s[p]==v+n.tc){
			s.splice(p,1);
			n.className=s.join(' ');
			break;
		}
	}
}
//Accordian Initializer
function Accordian(d,s,tc){
  
  $('container-selector').show();
  $('container-selector-loading').hide();
	
	l=$(d).getElementsByTagName('div');
	
	c=[];
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='content'){c.push(h);}
		
	}
	sel=null;
	//then search through headers
	
	for(i=0;i<l.length;i++){
		
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='header'){
			d=$(h.substr(0,h.indexOf('-'))+'-content');
			
			d.style.display='none';
			d.style.overflow='hidden';
			d.maxh=sh(d);
			d.s=(s==undefined)? 7 : s;
			//dbg('Set e.s pour '+d.id+' avec la valeur '+d.s );
			h=$(h);
			h.tc=tc;
			h.c=c;
			
			// set the onclick function for each header.
			h.onclick = function(){
			
			// Recharge le bouton sur la requete ajax de l'étape final pour l'aperçut du prix du produit en cour de création
  			//$('montableau').style.display='block';
  			//$('resultatPrice').style.display='none';
			getCurrentProductPriceValue();
			var selectedStep = $(this.id.substring( 0, this.id.indexOf('-', 0 ) ) +"-content");
					
				if( AccordionItemExpandHandler( selectedStep ) )
				{
					
					//alert(' il y '+this.c.length+' et je suis '+this.id );
					//dbg('<hr />' );
					for(i=0;i<this.c.length;i++){
						
						cn=this.c[i];
						n=cn.substr(0,cn.indexOf('-'));
						//dbg('n-header ='+n+'-header et this.id='+this.id );
						if( (n+'-header') == this.id ){
							
							var elttemp = $(n+'-content');
							stepListObject.setCurrentStep( n );	
							ex(elttemp);
							n=$(n+'-header');
							cc(n,'__');
							n.className=n.className+' '+n.tc;
							//dbg('expansion de '+n.id+' css = '+n.className );
							
						}else{
							
							cl($(n+'-content'));
							cc($(n+'-header'),'');
							//dbg('collapse de '+n.id+' css = '+n.className );
						}
					}
					//dbg('<hr />' );
				}
				
			}
			if(h.className.match(/selected+/)!=undefined){ sel=h;}
		}
	}
	if(sel!=undefined){sel.onclick();}
}


