
//document.body.style.display='none';


function getStyle(oElm, strCssRule)
	{
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle)
		{
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
		}
	else if(oElm.currentStyle)
		{
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1)
			{
			return p1.toUpperCase();
			});
		strValue = oElm.currentStyle[strCssRule];
		}
	strValue=''+strValue;
	return strValue;
	}

function disableSelectionPointer(target)
  {
  if (typeof target.onselectstart!="undefined") //IE route
	{
	select_func = target.onselectstart;
	target.onselectstart=function(){return false}
	}
  else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	{
	select_func = target.style.MozUserSelect;
	target.style.MozUserSelect="none"
	}
  else //All other route (ie: Opera)
	{
	select_func = target.onmousedown;
	target.onmousedown=function(){return false}
	}

  select_curs = target.style.cursor;
  target.style.cursor = "pointer"
  }



function McInit ()
	{
	
	//document.body.style.display='none';
	var onglets=[];
	var boutons=[];
	var now=new Date();
	var log='Starting '+now+'\n';
	var elems=getOnglets(document.body);
	log+='Getonglets in '+((new Date())-now)+'\n';
	
	for (var i=0;i<elems.length;i++)
		{
		//alert(i+'/'+elems.length);
		onglets.push(new McOnglets(elems[i]));
		//elems[i].style.display='inline';
		}
	
	log+='Menu created in '+((new Date())-now)+'\n';
	
	var bts=getBoutons(document.body);
	var pms=getPlusMoins(document.body);
	//alert(elems.length);
	log+='GetBoutons in '+((new Date())-now)+'\n';
	
	//alert('bts0 '+bts[0]+'bts1 '+bts[1]);
	for (var j=0;j<bts.length;j++)
		{
		//alert('BOUCLE BOUTONS '+j+'/'+bts.length);
		boutons.push(new McBouton(bts[j]));
		//elems[i].style.display='inline';
		}
	
	for (var j=0;j<pms.length;j++)
		{
		//alert('BOUCLE BOUTONS '+j+'/'+bts.length);
		boutons.push(new McPlusMoins(pms[j]));
		//elems[i].style.display='inline';
		}
	
	log+='Bouton created in '+((new Date())-now)+'\n';
	
	if ((navigator.userAgent.match(/MSIE/)) || (navigator.userAgent.match(/Opera/)))
		{
		var tmp=''+window.location;
		tmp=tmp.replace(/\/[^\/]*$/,'')+'/';
		var reguri=new RegExp(tmp);
		var divs=document.getElementsByTagName('DIV');
		for (var j=0;j<divs.length;j++)
			{
			if ((divs[j].getAttribute('pngfix')) && (divs[j].getAttribute('pngfix')>0))
				{
				var src=getStyle(divs[j],'background-image').replace(/^url\(/,'').replace(/\)$/,'');
				divs[j].style.backgroundImage='none';
				divs[j].style.filter='filter : progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+src.replace(reguri,'')+', sizingMethod="scale");';
				}
			}
		var divs=document.getElementsByTagName('SPAN');
		for (var j=0;j<divs.length;j++)
			{
			if ((divs[j].getAttribute('pngfix')) && (divs[j].getAttribute('pngfix')>0))
				{
				var src=getStyle(divs[j],'background-image').replace(/^url\(/,'').replace(/\)$/,'');
				divs[j].style.backgroundImage='none';
				divs[j].style.filter='filter : progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+src.replace(reguri,'')+', sizingMethod="crop");';
				}
			}
		}
	
	document.body.style.display='';
	//alert(log);
	}

function getOnglets (base)
	{
	var elems=[];
	if ((navigator.userAgent.match(/MSIE/)) || (navigator.userAgent.match(/Opera/)))
		{
		var tmp=document.getElementsByTagName('UL');
		for (var i=0;i<tmp.length;i++)
			{
			if (tmp[i].getAttribute('name')=='McOnglets')
				{
				elems.push(tmp[i]);
				}
			}
		}
	else
		{
		elems=document.getElementsByName('McOnglets');
		}
	return elems;
	}

function getBoutons (base)
	{
	var elems=[];
	elems=document.getElementsByName('McBouton');
	
	//alert(elems.length);
	return elems;
	}

function getPlusMoins (base)
	{
	var elems=[];
	elems=document.getElementsByName('McPlusMoins');
	
	//alert(elems.length);
	return elems;
	}

function McOnglets (ul)
	{
	//ul.style.display='none';
	disableSelectionPointer(ul);
	ul.ctrl=this;
	var tmp=''+window.location;
	//alert(tmp);
	tmp=tmp.replace(/\/[0-9a-zA-Z_.?=-]*$/,'');
	//alert('REG='+tmp);
	this.elem	= ul;
	
	this.li		= [];
	this.nbLi	= 0;
	
	this.vars={};
	this.vars.ie=false;
	this.vars.pngfix=false;
	this.vars.actif=0;
	
	this.regExp={};
	this.regExp.uri=new RegExp([tmp]);
	
	if (navigator.userAgent.match(/MSIE/))
		{
		this.vars.ie=true;
		this.vars.pngfix=true;
		}

	if (navigator.userAgent.match(/MSIE 7/))
		{
		this.vars.pngfix=false;
		}

	//alert('OK');
	this.state = {};
	this.state.actif=false;
	
	if (this.elem.getAttribute('actif')>0)
		{
		this.vars.actif=1;
		}
		
	var n=0;
	for (var li=ul.firstChild;li;li=li.nextSibling)
		{
		if (li.tagName=='LI')
			{
			//alert(li+'\n'+li.innerHTML);
			this.li.push(new McOnglet(this,li,this.nbLi));
			/*if (this.vars.ie)
				{
				var src=getStyle(li,'background-image').replace(/^url\(/,'').replace(/\)$/,'');
				//alert(tmp+'/'+src.replace(this.regExp.uri,''));
				li.style.backgroundImage='none';
				li.style.filter='filter : progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+src.replace(this.regExp.uri,'')+', sizingMethod="scale");'
				}*/
			this.nbLi++;
			}
		}
		
	if (this.nbLi>1)
		{
		this.li[0].className='first';
		this.li[this.nbLi-1].className='last';
		
		if (this.li[0].ctrl.vars.actif)
			this.li[0].className+=' actif';
		if (this.li[this.nbLi-1].ctrl.vars.actif)
			this.li[this.nbLi-1].className+=' actif';
		
		//alert(this.li[0].ctrl.test);
		}
	else if (this.nbLi==1)
		{
		var lf=document.createElement('li');
		lf.className='fin';
		lf.style.width='10px';
		this.elem.appendChild(lf);
		}
	else
		{
		
		}
	
	if (this.vars.pngfix)
		{
		for (var j=0;j<this.nbLi;j++)
			{
			var src=getStyle(this.li[j],'background-image').replace(/^url\(/,'').replace(/\)$/,'');
			//alert('SRC = +\n'+src+"\n"+tmp+'/\n'+src.replace(this.regExp.uri,'').replace(/^["/]*/,''));
			this.li[j].style.backgroundImage='none';
			this.li[j].style.filter='filter : progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+src.replace(this.regExp.uri,'').replace(/^["/]*/,'')+', sizingMethod="scale");'
			}
		
		}
	//ul.style.display='';
	}

function McOnglet (onglets,li,nbli)
	{
	li.ctrl=this;
	this.elem=li;
	this.onglets=onglets;
	//alert(onglets+'/'+onglets.state.actif);
	this.test='TEST Ok !!!';
	
	this.sep=false;
	this.a=false;
	
	this.vars={};
	this.vars.nb=nbli;
	this.vars.actif=false;
	this.vars.corps=false;
	
	this.action={};
	this.action.onclick=[];
	this.action.onunselect=[];
	this.action.onmouseover=[];
	this.action.onmouseout=[];
	
	this.regExp={};
	this.regExp.actif=/actif/g;
	
	var obj=this;
	
	for (var a=li.firstChild;a;a=a.nextSibling)
		{
		if (a.tagName=='A')
			{
			this.a=a;
			}
		}
	if (this.a)
		{
		this.action.onclick.push(function ()
			{
			if (obj.onglets.state.actif)
				{
				for (var j=0;j<obj.onglets.state.actif.action.onunselect.length;j++)
					{
					//alert('OnUnsel '+j);
					obj.onglets.state.actif.action.onunselect[j]();
					}
				}
			if (obj.onglets.vars.actif>0)
				{
				//alert(obj.onglets.vars.actif)
				obj.onglets.state.actif=obj;
				obj.vars.actif=true;
				obj.elem.className+=' actif';
				}
			});
		this.action.onunselect.push(function () 	
			{
			//alert('Desactive '+obj.elem.className+' '+obj.elem.innerHTML);
			obj.elem.className=obj.elem.className.replace(obj.regExp.actif,'');
			obj.vars.actif=false;
			//alert('Desactive');
			});
		for (var a=li.firstChild;a;a=a.nextSibling)
			{
			li.removeChild(a);
			}
		
		this.action.onmouseover.push(function ()
			{
			if (!obj.vars.actif)
				{
				obj.elem.className=obj.elem.className+' actif';
				}
			});
		
		this.action.onmouseout.push(function ()
			{
			if (!obj.vars.actif)
				obj.elem.className=obj.elem.className.replace(obj.regExp.actif,'');
			});
			
		if (this.onglets.vars.actif>0)
			{
			this.action.onclick.push(function () 
				{
				//changeOnglet(obj);
				});
			}
		
		//alert(this.a.attributes.corps.value);
		var def =this.a.getAttribute('default');
		if ((def) && (def.length>0))
			{
			this.vars.actif=true;
			this.onglets.state.actif=this;
			}
		var corps=this.a.getAttribute('corps');
		if ((corps) && (corps.length>0))
			{
			this.vars.corps=document.getElementById(corps);

			if (!this.vars.actif)
				document.getElementById(corps).style.display='none';
			else
				document.getElementById(corps).style.display='';
				
			this.action.onclick.push(function () 
				{
				document.getElementById(corps).style.display='';
				});
			
			this.action.onunselect.push(function () 
				{
				document.getElementById(corps).style.display='none';
				});
			};
		
		var hr=this.a.href;
		//alert(hr);
		if ((hr) && (hr.length>0) && !(hr.match(/#$/)))
			{
			if (hr.match(/javascript\s*:/i))
				{
				hr=hr.replace(/javascript\s*:/i,'')
				this.action.onclick.push(function () 
					{
					eval(hr);
					});
				}
			else
				{
				this.action.onclick.push(function () 
					{
					window.location=hr;
					});
				}
			}
		
		if (this.vars.nb>0)
			{
			var sep=document.createElement('DIV');
			sep.className='sep';
			sep.style.position="relative";
			sep.style.top='0px';//'-'+getStyle(this.elem,"padding-top");
			sep.style.left='-'+getStyle(this.elem,"padding-left");
			//alert(this.elem.offsetLeft+'/'+getStyle(this.elem,"padding-right"));
			this.elem.appendChild(sep);
			this.sep=sep;
			}
		
		var cont=document.createElement('DIV');
		cont.className='content';
		cont.style.fontSize=getStyle(this.elem,"font-size");
		cont.style.fontWeight=getStyle(this.elem,"font-weight");
		
		/*cont.style.marginLeft=getStyle(this.elem,"padding-left");
		cont.style.marginRight=getStyle(this.elem,"padding-right");
		this.elem.style.paddingLeft='0px';
		this.elem.style.paddingRight='0px';*/
		
		cont.style.marginLeft='1px';
		cont.style.marginRight='1px';
		cont.style.marginTop='0px';
		cont.style.marginBottom='0px';
		
		//cont.style.border='5px solid red';
		cont.style.paddingLeft='0px';
		cont.style.paddingRight='0px';
		cont.style.paddingTop=getStyle(this.elem,"padding-top");
		cont.style.paddingBottom=getStyle(this.elem,"padding-bottom");
		this.elem.style.paddingTop='0px';
		this.elem.style.paddingBottom='0px';
		
		this.elem.appendChild(cont);
		var tmp=[];
		for (c=this.a.firstChild;c;c=c.nextSibling)
			{
			tmp.push(c);
			}
		for (var i=0;i<tmp.length;i++)
			{
			cont.appendChild(tmp[i]);
			}
		}
	
	
	this.elem.onclick=function () 
		{
		for (var i=0;i<obj.action.onclick.length;i++)
			{
			//alert('OC '+i);
			obj.action.onclick[i]();
			}
		}

	this.elem.onmouseover=function () 
		{
		for (var i=0;i<obj.action.onmouseover.length;i++)
			{
			//alert('OC '+i);
			obj.action.onmouseover[i]();
			}
		}

	this.elem.onmouseout=function () 
		{
		for (var i=0;i<obj.action.onmouseout.length;i++)
			{
			//alert('OC '+i);
			obj.action.onmouseout[i]();
			}
		}
	
	return li;
	}

function changeOnglet(obj)
	{
	if (obj.onglets.state.actif)
		{
		for (var j=0;j<obj.onglets.state.actif.action.onunselect.length;j++)
			{
			//alert('OnUnsel '+j);
			obj.onglets.state.actif.action.onunselect[j]();
			}
		}
	if (obj.onglets.vars.actif>0)
		{
		obj.vars.actif=true;
		obj.onglets.state.actif=obj;
		obj.vars.corps.style.display='';
		}
	}


function McBouton (elem)
	{
	this.elem=elem;
	
	this.vars={};
	this.vars.ie=false;
	
	this.regExp={};
	
	var tmp=''+window.location;
	tmp=tmp.replace(/\/[0-9a-zA-Z_.?=-]*$/,'');
	this.regExp.uri=new RegExp([tmp]);
	
	if (navigator.userAgent.match(/MSIE/))
		{
		//alert('IE');
		this.vars.ie=true;
		}
	
	var tbl = document.createElement('TABLE');
	disableSelectionPointer(tbl);
	
	elem.ctrl=tbl;
	
	//alert(elem.style.cssText+''+elem.noDisplay);
	if (elem.noDisplay)
		tbl.style.display='none';
	//alert(this.elem+' '+this.elem.ctrl);
	
	tbl.className=elem.className;
	
	var tbo = document.createElement('TBODY');
	
	var tr0 = document.createElement('TR');
	
	var td0 = document.createElement('TD');
	var td1 = document.createElement('TD');
	var td2 = document.createElement('TD');
	
	tr0.onmouseover=function ()
		{
		tr0.className='actif';
		}
	
	tr0.onmouseout=function ()
		{
		tr0.className='';
		}
	
	td0.className='gauche';
	td1.className='milieu';
	td2.className='droite';
	
	td1.innerHTML=elem.value;
	
	tr0.appendChild(td0);
	tr0.appendChild(td1);
	tr0.appendChild(td2);
	
	tbo.appendChild(tr0);

	tbl.appendChild(tbo);
	if (elem.onclick)
		{
		tbl.onclick=function ()
			{
			elem.onclick();
			}
		}
		
	elem.parentNode.insertBefore(tbl,elem);
	elem.style.display='none';
	
	if (this.vars.ie)
		{
		var src=getStyle(td0,'background-image').replace(/^url\(/,'').replace(/\)$/,'');
		td0.style.backgroundImage='none';
		//alert(src+'\n'+src.replace(this.regExp.uri,'').replace(/^["/]*/,''));
		td0.style.filter='filter : progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+src.replace(this.regExp.uri,'').replace(/^["/]*/,'')+', sizingMethod="scale");'
		
		var src=getStyle(td1,'background-image').replace(/^url\(/,'').replace(/\)$/,'');
		td1.style.backgroundImage='none';
		td1.style.filter='filter : progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+src.replace(this.regExp.uri,'').replace(/^["/]*/,'')+', sizingMethod="scale");'
		
		var src=getStyle(td2,'background-image').replace(/^url\(/,'').replace(/\)$/,'');
		td2.style.backgroundImage='none';
		td2.style.filter='filter : progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+src.replace(this.regExp.uri,'').replace(/^["/]*/,'')+', sizingMethod="scale");'
		
		}
	return this;
	}

function McPlusMoins(elem)
	{
	this.elem=elem;
	
	this.vars={};
	this.vars.ie=false;
	
	this.regExp={};
	
	var tmp=''+window.location;
	tmp=tmp.replace(/\/[0-9a-zA-Z_.-?=]*$/,'');
	this.regExp.uri=new RegExp([tmp]);
	
	if (navigator.userAgent.match(/MSIE/))
		{
		//alert('IE');
		this.vars.ie=true;
		}
	
	if (!(elem.value>=0))
		elem.value=0;
		
	var tbl = document.createElement('TABLE');
	
	elem.ctrl=tbl;
	
	//alert(elem.style.cssText+''+elem.noDisplay);
	if (elem.noDisplay)
		tbl.style.display='none';
	//alert(this.elem+' '+this.elem.ctrl);
	
	tbl.className=elem.className;
	
	var tbo = document.createElement('TBODY');
	
	var tr0 = document.createElement('TR');
	
	var td0 = document.createElement('TD');
	var td1 = document.createElement('TD');
	var td2 = document.createElement('TD');
	var td3 = document.createElement('TD');
	var td4 = document.createElement('TD');
	
	td0.onmouseover = function ()
		{
		td0.className+=' actif';
		}
	td0.onmouseout = function ()
		{
		td0.className=td0.className.replace(/actif/g,'');
		}
	td4.onmouseover = function ()
		{
		td4.className+=' actif';
		}
	td4.onmouseout = function ()
		{
		td4.className=td4.className.replace(/actif/g,'');
		}
	td1.onmouseover = function ()
		{
		td1.className+=' actif';
		td2.className+=' actif';
		td3.className+=' actif';
		}
	td1.onmouseout = function ()
		{
		td1.className=td1.className.replace(/actif/g,'');
		td2.className=td2.className.replace(/actif/g,'');
		td3.className=td3.className.replace(/actif/g,'');
		}
	td2.onmouseover = td1.onmouseover;
	td2.onmouseout = td1.onmouseout;
	
	td3.onmouseover = td1.onmouseover;
	td3.onmouseout = td1.onmouseout;
	
	td0.onclick=function ()
		{
		if (Number(elem.value)>0)
			elem.value=Number(elem.value)-1;
		else
			elem.value=0;
		td2.innerHTML=elem.value;
		}
	
	td4.onclick=function ()
		{
		elem.value=Number(elem.value)+1;
		td2.innerHTML=elem.value;
		}
	
	td2.innerHTML=elem.value;
	
	td0.className='moins';
	td1.className='valeurg';
	td2.className='valeur';
	td3.className='valeurd';
	td4.className='plus';
	
	td2.innerHTML=elem.value;
	
	tr0.appendChild(td0);
	tr0.appendChild(td1);
	tr0.appendChild(td2);
	tr0.appendChild(td3);
	tr0.appendChild(td4);
	
	tbo.appendChild(tr0);

	tbl.appendChild(tbo);
		
	elem.parentNode.insertBefore(tbl,elem);
	elem.style.display='none';
	elem.style.visibility='hidden';
	
	if (this.vars.ie)
		{
		var src=getStyle(td0,'background-image').replace(/^url\(/,'').replace(/\)$/,'');
		td0.style.backgroundImage='none';
		td0.style.filter='filter : progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+src.replace(this.regExp.uri,'')+', sizingMethod="scale");'
		
		var src=getStyle(td1,'background-image').replace(/^url\(/,'').replace(/\)$/,'');
		td1.style.backgroundImage='none';
		td1.style.filter='filter : progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+src.replace(this.regExp.uri,'')+', sizingMethod="scale");'
		
		var src=getStyle(td2,'background-image').replace(/^url\(/,'').replace(/\)$/,'');
		td2.style.backgroundImage='none';
		td2.style.filter='filter : progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+src.replace(this.regExp.uri,'')+', sizingMethod="scale");'
		
		}
	return this;
	}













