var isIE6 = (navigator.userAgent.indexOf('MSIE 6') != -1)? true : false;
var isIE7 = (navigator.userAgent.indexOf('MSIE 7') != -1)? true : false;

var IE6Hack = Class.create({
	
	initialize: function () {
		this.IE6 = (navigator.appVersion.indexOf("MSIE 6")!=-1) ?true :false;
	},
	
	pngFix: function (pixGifUrl) {
		if (this.IE6) {
			for (var i=0;i<document.images.length;i++) {
				var imgs = document.images[i];
				this.pngFixItem(pixGifUrl,imgs);
				imgs.style.visibility = "visible";
			}
		}
	},
	
	pngFixItem: function (pixGifUrl,img) {
		if (this.IE6) {
			if (img.src.substring(img.src.length-3,img.src.length)=="png") {
				img.style.height = img.style.width = "";
				img.style.height = img.offsetHeight + "px"; img.style.width = img.offsetWidth + "px";
				img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + img.src + ",sizingMethod='scale')";
				img.src = pixGifUrl;
			}
		}
	},
	
	pngFixRoll: function (img) {
		if (this.IE6) {
			Event.observe(img,"mouseover",this.pngRoll.bindAsEventListener(this,0,1));
			Event.observe(img,"mouseout",this.pngRoll.bindAsEventListener(this,1,0));
		}
	},
	
	pngRoll: function (e,toReplace,replaceBy) {
		Event.element(e).style.filter = Event.element(e).style.filter.replace("-"+toReplace+".png","-"+replaceBy+".png");
	},
	
	fixLayerWithFrame: function (o,frameName,params) {
		if(this.IE6&&$(frameName)){
			$(frameName).parentNode.removeChild($(frameName));
		}
		
		if (this.IE6&&!$(frameName)) {
			var create = document.createElement('iframe');
			var e = o.appendChild(create);
			e.id = frameName;
			Element.setStyle(e,{
				position: 'absolute',
				top: (params.top) ?params.top+'px' :o.offsetTop+'px',
				left: (params.left) ?params.left+'px' :o.offsetLeft+'px',
				width: (params.width) ?params.width+'px' :o.offsetWidth+'px',
				height: (params.height) ?params.height+'px' :o.offsetHeight+'px',
				filter: 'alpha(opacity=0);',
				border: '10px',
				zIndex: -20
			});			
		}
	}

});

var urlPixGif = '/static/images/pix.gif';
var myIE6Hack = new IE6Hack();

var popInfosCloseTime = 2000;
var subMenuInit = -1;
// MENU DROITE  ///////////////////////////////////////////////////////////////////



function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


// MENU TOP SWAP IMAGES ///////////////////////////////////////////////////////////////////////////

<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//-->


// MENU TOP & LAYERS ///////////////////////////////////////////////////////////////////



var w3c = document.getElementById ? true : false;
var iex = document.all ? true : false;
var ns4 = document.layers ? true : false;

function fixNetscape(){
	if(origWidth != window.innerWidth || origHeight != window.innerHeight){
		window.location.reload();
	}	
}
if(ns4){
	origWidth = window.innerWidth;
	origHeight = window.innerHeight;
	window.onresize = fixNetscape;
}
function newImage(src){
	img = new Image();
	img.src = src;
	return img;
}
function imageSwap(img,obj,div){
	if(ns4 && div != null){
		document.layers[div].document.images[img].src = obj.src;
	}else{
		document.images[img].src = obj.src;
	}
}
function getStyle(name, nest){
	nest = nest ? 'document.'+nest+'.' : '';
	return w3c ? document.getElementById(name).style : iex ? document.all[name].style : ns4 ? eval(nest+'document.'+name) : false;
}

// ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

Menus = new Object();
var curMenu = null;

MakeMenu = function(name,left,top,rollimg,rollout,rollover,rolldiv){
	this.name = name;
	this.left = left;
	this.top = top;
	this.timer = null;
	this.rollimg = rollimg;
	this.rollout = newImage(rollout);
	this.rollover = newImage(rollover);
	this.rolldiv = (rolldiv != null) ? rolldiv : null;
	this.obj = name+'Object';
	eval(this.obj+'=this');
}
MakeMenu.prototype.show = function(){
	clearTimeout(this.timer);
	getStyle(this.name).visibility = 'visible';
	imageSwap(this.rollimg,this.rollover,this.rolldiv);
	curMenu = this.name;
	if (this.w&&this.h) {
		PI_rescueFrame($(this.name),0,this.w,this.h);
	}
	else {
		PI_rescueFrame($(this.name),0);
	}
}
MakeMenu.prototype.hide = function(){
	this.timer = setTimeout(this.obj+'.hideIt()',50);
}
MakeMenu.prototype.hide2 = function(){
	this.timer = setTimeout(this.obj+'.hideIt()',50);
}
MakeMenu.prototype.hideIt = function(){
	getStyle(this.name).visibility = 'hidden';
	imageSwap(this.rollimg,this.rollout,this.rolldiv);
}
MakeMenu.prototype.startMenu = function(){
	var html;
	if(ns4){
		html = '<layer name="'+this.name+'" left="'+this.left+'" top="'+this.top+'" z-index="2000" visibility="hidden" ';
	}else{

		html = '<div id="'+this.name+'" style="position:relative; left:'+this.left+'px; top:'+this.top+'px; z-index:2000; visibility:hidden" ';
	}
	html += 'onMouseOver="Menus.'+this.name+'.show()" onMouseOut="Menus.'+this.name+'.hide()">';
	return html;
}
hideCur = function(){
	if(curMenu != null){
		Menus[curMenu].hideIt();
		curMenu = null;
	}
}
endMenu = function(){
	 return ns4 ? '<\/layer>' : '<\/div>';
}
createMenu = function(name,left,top,rollimg,rollout,rollover,rolldiv){
	Menus[name] = new MakeMenu(name,left,top,rollimg,rollout,rollover,rolldiv);
}
createLayer = function(name,left,top){
	Layer[name] = new MakeMenu(name,left,top);
}
// ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

Layers = new Object();
var curLayer = null;
var openZoom;

MakeLayer = function(name,left,top){
	this.name = name;
	this.left = left;
	this.top = top;
	this.timer = null;
	this.obj = name+'Object';
	eval(this.obj+'=this');
}
MakeLayer.prototype.show = function(){
	clearTimeout(this.timer);
	getStyle(this.name).visibility = 'visible';
	getStyle(this.name).display = 'block';
                
	var imgFix = $(this.name).getElementsByTagName('img');
	if (imgFix.length>0) {
		for (var i=0;i<imgFix.length;i++) {
			myIE6Hack.pngFixItem(urlPixGif,imgFix[i]);       
		}
	}
	curLayer = this.name;

	if (openZoom&&openZoom!=this) {
		openZoom.hideIt();       
	}
	openZoom = this;

	if(curLayer.indexOf('total')==-1){ // pour eviter une alerte securite sous ie6 en https pour les rollover 'total estime'
		if (this.w&&this.h) {
			PI_rescueFrame($(this.name),0,this.w,this.h);
		}
		else {
			PI_rescueFrame($(this.name),0);
		}
	}

	var nameLayer = this.name;
	Event.observe(document, "mouseup", function(){ 
		Layers[nameLayer].hide();
		Event.stopObserving(document,"mouseup");
		}
	);
}

MakeLayer.prototype.hide = function(){
	this.timer = setTimeout(this.obj+'.hideIt()',50);
}
MakeLayer.prototype.hideIt = function(){
	getStyle(this.name).visibility = 'hidden';
	getStyle(this.name).display = 'none';
}
MakeLayer.prototype.startLayer = function(w,h){
	this.w = w;
	this.h = h;
	var html;
	if(ns4){
		html = '<layer name="'+this.name+'" left="'+this.left+'" top="'+this.top+'" z-index="1000" visibility="hidden" ';
	}else{
		html = '<div id="'+this.name+'" style="position:relative; cursor:pointer; left:'+this.left+'px; top:'+this.top+'px; z-index:1000; visibility:hidden;" ';
	}
	if (this.name.indexOf('produit')!=-1) {
		html += 'onClick="Layers.'+this.name+'.hide();">';
	} else {
		html += 'onMouseOver="Layers.'+this.name+'.show()" onMouseOut="Layers.'+this.name+'.hide()">';
	}
	return html;
}
hideCur = function(){
	if(curLayer != null){
		Layers[curLayer].hideIt();
		curLayer = null;
	}
}
endLayer = function(){
	 return ns4 ? '<\/layer>' : '<\/div>';
}

createLayer = function(name,left,top){
	Layers[name] = new MakeLayer(name,left,top);
}
// ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

var Pops = new Object();
var curPop = null;

MakePop = function(name,left,top){
	this.name = name;
	this.left = left;
	this.top = top;
	this.timer = null;
	this.obj = name+'Object';
	eval(this.obj+'=this');
}
MakePop.prototype.show = function(){
	clearTimeout(this.timer);
	var getId = this.name.split('_');
	var o = scrollNodes[getId[1]-1];
	getStyle(this.name).top = (o.offsetTop+o.offsetHeight-30) + 'px';
	getStyle(this.name).left = (o.offsetLeft-30-$('scMask').scrollLeft) + 'px';
	getStyle(this.name).visibility = 'visible';
	curPop = this.name;

}
MakePop.prototype.hide = function(){
	this.timer = setTimeout(this.obj+'.hideIt()',50);

}
MakePop.prototype.hideIt = function(){
	getStyle(this.name).visibility = 'hidden';
}
MakePop.prototype.startLayer = function(w,h){
	this.w = w;
	this.h = h;
	var html;
	if(ns4){
		html = '<layer name="'+this.name+'" left="'+this.left+'" top="'+this.top+'" z-index="1000" visibility="hidden" ';
	}else{
		html = '<div id="'+this.name+'" style="position:relative; left:'+this.left+'px; top:'+this.top+'px; z-index:1000; visibility:hidden" ';
	}
	html += 'onMouseOver="Pops.'+this.name+'.show()" onMouseOut="Pops.'+this.name+'.hide()">';
	return html;
}
hideCur = function(){
	if(curPop != null){
		Pops[curPop].hideIt();
		curPop = null;
	}
}
endPop = function(){
	 return ns4 ? '<\/layer>' : '<\/div>';
}

createPop = function(name,left,top){
	Pops[name] = new MakePop(name,left,top);
}
// ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

// ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

function PI_rescueFrame(obj,pos,w,h){
	if(isIE6){		
		if(!$('rescueFrame'+obj.id)){
			var rescueObj = document.createElement('iframe');
			var rescueElement = obj.appendChild(rescueObj);
			rescueElement.id = 'rescueFrame';
			rescueElement.style.position = 'absolute';
			if(pos || pos == 0){
				rescueElement.style.top = pos; 
				rescueElement.style.left = pos;
			}
			else{
				rescueElement.style.top = obj.offsetTop+'px'; 
				rescueElement.style.left = obj.offsetLeft+'px';
			}
			rescueElement.style.width = (w) ?w+'px' :obj.offsetWidth+'px'; 
			rescueElement.style.height = (h) ?h+'px' :obj.offsetHeight+'px';
			
			if (rescueElement.style.height=='0px' && $('pageFicheProduit')||obj.id.indexOf('submenu')!=-1) {
				var nodes = obj.getElementsByTagName('div');
				if (nodes) {
					rescueElement.style.height = nodes[0].offsetHeight;
				}
			}
			
			//rescueElement.style.visibility = 'hidden';
			rescueElement.style.border = '10px';
			//rescueElement.style.filter = 'alpha(opacity=0);';
			rescueElement.style.zIndex = -20;
			
		}
	}
}

//~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

function openPlanning(){
	var hauteur = document.getElementById('page').offsetHeight;	
	$('colorZone').style.height = (hauteur+"px");
	$('colorZone').style.visibility='visible';
    $('colorZone').style.display='block';
	$('popUpPlanning').style.visibility='visible';
    $('popUpPlanning').style.display='block';
}
function openCalendar(type){
    $('popUpPlanning').className = "planningType"+type;
}
function hidePlanning(){
	$('colorZone').style.visibility='hidden';
    $('colorZone').style.display='none';
	$('popUpPlanning').style.visibility='hidden';
    $('popUpPlanning').style.display='none';
    $('popUpPlanning').className = "defaultPlanning";
}

//~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

function openCGV(){
	var hauteur = document.getElementById('page').offsetHeight;	
	$('colorZone').style.height = (hauteur+"px");
	$('colorZone').style.visibility='visible';
    $('colorZone').style.display='block';
	$('popUpCGV').style.visibility='visible';
    $('popUpCGV').style.display='block';
}
function hideCGV(){
	$('colorZone').style.visibility='hidden';
    $('colorZone').style.display='none';
	$('popUpCGV').style.visibility='hidden';
    $('popUpCGV').style.display='none';
}

function openLostId(){
	var hauteur = document.getElementById('page').offsetHeight;	
	$('colorZone').style.height = (hauteur+"px");
	$('colorZone').style.visibility='visible';
    $('colorZone').style.display='block';
	$('popUpLostId').style.visibility='visible';
    $('popUpLostId').style.display='block';
}
function hideLostId(){
	$('colorZone').style.visibility='hidden';
    $('colorZone').style.display='none';
	$('popUpLostId').style.visibility='hidden';
    $('popUpLostId').style.display='none';
}

function openAmmount(){
	var hauteur = document.getElementById('page').offsetHeight;	
	$('colorZone').style.height = (hauteur+"px");
	$('colorZone').style.visibility='visible';
    $('colorZone').style.display='block';
	$('popUpAmmount').style.visibility='visible';
    $('popUpAmmount').style.display='block';
}
function hideAmmount(){
	$('colorZone').style.visibility='hidden';
    $('colorZone').style.display='none';
	$('popUpAmmount').style.visibility='hidden';
    $('popUpAmmount').style.display='none';
}

function openMag(){
	var hauteur = document.getElementById('page').offsetHeight;	
	$('colorZone').style.height = (hauteur+"px");
	$('colorZone').style.visibility='visible';
    $('colorZone').style.display='block';
	$('popUpMagasin').style.visibility='visible';
    $('popUpMagasin').style.display='block';
}
function hideMag(){
	$('colorZone').style.visibility='hidden';
    $('colorZone').style.display='none';
	$('popUpMagasin').style.visibility='hidden';
    $('popUpMagasin').style.display='none';
}

function openTarifs(){
	var hauteur = document.getElementById('page').offsetHeight;	
	$('colorZone').style.height = (hauteur+"px");
	$('colorZone').style.visibility='visible';
    $('colorZone').style.display='block';
	$('popUpTarifs').style.visibility='visible';
    $('popUpTarifs').style.display='block';
}
function hideTarifs(){
	$('colorZone').style.visibility='hidden';
    $('colorZone').style.display='none';
	$('popUpTarifs').style.visibility='hidden';
    $('popUpTarifs').style.display='none';
}

//~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

Event.observe(window,"load",buildSMen);
var menData = new Array();
var menActive = -1;
function buildSMen(){
	if($("menu")){
		
		var menObj = $("menu");
		var mens = $$("#menu h4");
		for(var i = 0; i<mens.length; i++){
			
			if(mens[i].parentNode.getElementsByTagName("ul")[0]){
				mens[i].parentNode.id = "menLeft"+i;
				
				var linkObj = new Object();
				var parent = $("menLeft"+i);
				linkObj.link = parent.getElementsByTagName("h4")[0].getElementsByTagName("a")[0];
				linkObj.url = parent.getElementsByTagName("h4")[0].getElementsByTagName("a")[0].href;
				linkObj.click = "javascript:showSMen("+i+");";
				linkObj.add = parent.getElementsByTagName("h4")[0].getElementsByTagName("span")[0].innerHTML;
				linkObj.sub = parent.getElementsByTagName("ul")[0];
				
				menData[i] = linkObj;
				
				linkObj.link.removeChild(parent.getElementsByTagName("h4")[0].getElementsByTagName("span")[0]);
				linkObj.link.setAttribute("href",linkObj.click);
			}
			
		}
		
		if (subMenuInit!=-1) {
			showSMen(subMenuInit);	
		}
		
	}
}

function showSMen(id){
	if(menActive != -1){
		hideSMen(menActive);
	}
	var obj = menData[id];
	obj.link.setAttribute("href",obj.url);
	var add = document.createElement("span");
	var addText = document.createTextNode(obj.add);
	add.appendChild(addText);
	obj.link.appendChild(add);
	obj.sub.style.display = "block";
	
	menActive = id;
}

function hideSMen(id){
	
	var obj = menData[id];
	obj.link.setAttribute("href",obj.click);
	obj.link.removeChild(obj.link.getElementsByTagName("span")[0]);
	obj.sub.style.display = "none";
	
	menActive = -1;
}

function loadListProduit(id,element){			
	new Ajax.Request(
		"/ListeProduits/"+id, {
		method: 'GET',
		parameters: 'from=ok',
		onComplete: function(response) {
			 
			$('navigajax').innerHTML = response.responseText;
			
	       (function() {
			  $$('.chemin script').each(
			    function(o){
			      myJs = ("<script>"+o.innerHTML+"</script>");
			
			      myJs = myJs.replace("<!--",""); 
			      myJs = myJs.replace("//-->",""); 
				
			      myJs.evalScripts();
			    }
			  );
			  
			  	var myTmp ="<script>Tapestry.init({\"linkZone\":[";
				$$('#items form').each(
				function(o){ 
					myTmp = myTmp + "\[\""+o.readAttribute("id")+"\", \"shoppingCartZone\", \""+o.readAttribute("action")+"\"\],";
				});
				myTmp = myTmp.substr(0,myTmp.length-1);
				myTmp = myTmp +"]});</script>";
				
				myTmp.evalScripts();
			}).delay(0.5, this);

	        
			$('contenu').parentNode.parentNode.id = "pageListingProduit";
			//$$('#contenu script').each(function(o){ eval(o.innerHTML); });			
			//$$('.chemin script').each(function(o){ console.log(("<script>"+o.innerHTML+"</script>").evalScripts()); });
			
			var id = 0;
			$$('#contenu .item').each(
				function(o){ 
					id++;
					createLayer('produit'+id, -62, -121);
					
					var div = document.createElement("div");
					div.id = "produit"+id;
					div.style.zIndex =  1000;
					div.style.left =  -62+"px";
					div.style.top =  -121+"px";
					div.style.position =  "relative";
					div.style.cursor =  "pointer";
					div.style.visibility =  "hidden";
			
					div.innerHTML = "<div class='popUpProduit'>" + o.down().nextSibling.innerHTML + "</div>";
					
					o.down().nextSibling.innerHTML = "";
					o.removeChild(o.down().nextSibling);
					o.insertBefore(div,o.down().nextSibling);
					
				}
			);
			loadPng();
			//Pour ajouter le rechargement ajax sur la pagination
			$$(".paginationPrev a, .paginationNext a").each(function (o){
				o.observe('click', reloadFromPagination);
			});
		}
		}
	)
}

function stripJSComment(text){
	text = text.replace("<!-- //",""); 
	text = text.replace("// -->",""); 
	return text;
}

//Pour forcer IE a aller recharger la page, et pas la prendre du cache!!!
Ajax.Request.prototype.setRequestHeaders =
Ajax.Request.prototype.setRequestHeaders.wrap(
  function(original) {
    this.transport.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
    original();
  }
);

//Pagination
Event.observe(window, 'load', function(event) {
	$$(".paginationPrev a, .paginationNext a").each(function (o){
		o.observe('click', reloadFromPagination);
	});
});

function reloadFromPagination(event){
	var link = event.element().up().readAttribute("href");
	if(link && event){
		event.stop();
		link = link + "&dummy=" + new Date().getTime();
	    new Ajax.Request(link, {
			method: 'GET',
			requestHeaders  : {'X-Requested-With' : ''},
			onCreate:function(){
				$(document.body).setStyle({"cursor" : "progress"});			
			},
	        onSuccess: function(response) {
	        	
	        	rText = response.responseText;
				rText = rText.replace("<!-- //",""); 
				rText = rText.replace("// -->",""); 
				
				//rText = rText.replace("<!--",""); 
				//rText = rText.replace("-->",""); 
				//console.log(rText);
			
				var divTmp = new Element('div');
				
				divTmp.innerHTML = rText;
				
				$(document.body).setStyle({"cursor" : "auto"});
			
				$("contenu").innerHTML = divTmp.down("[id=contenu]").innerHTML;
	
				var id = 0;
				$$('#contenu .item').each(
					function(o){ 
						id++;
						createLayer('produit'+id, -62, -121);
						
						var div = document.createElement("div");
						div.id = "produit"+id;
						div.style.zIndex =  1000;
						div.style.left =  -62+"px";
						div.style.top =  -121+"px";
						div.style.position =  "relative";
						div.style.cursor =  "pointer";
						div.style.visibility =  "hidden";
				
						div.innerHTML = "<div class='popUpProduit'>" + o.down().nextSibling.innerHTML + "</div>";
						
						o.down().nextSibling.innerHTML = "";
						o.removeChild(o.down().nextSibling);
						o.insertBefore(div,o.down().nextSibling);
						
						o.down(".ajouter input").writeAttribute("value", "");
					}
				);
				loadPng();
				
				//Pour ajouter le rechargement ajax sur la pagination
				$$(".paginationPrev a, .paginationNext a").each(function (o){
					o.observe('click', reloadFromPagination);
				});
				
				//pour l'ajout au panier
				var myTmp ="<script>Tapestry.init({\"linkZone\":[";
				$$('#items form').each(
					function(o){
						myTmp = myTmp + "\[\""+o.readAttribute("id")+"\", \"shoppingCartZone\", \""+o.readAttribute("action")+"\"\],";
					}
				);
				myTmp = myTmp.substr(0,myTmp.length-1);
				myTmp = myTmp +"]});</script>";
				myTmp.evalScripts.bind(myTmp).defer();
				
				divTmp.evalScripts.bind(divTmp).defer();
			}
	    });
	}
    
}

//Form Trier Par, Filtrer par
function safeOnChange2(myForm){
	$(myForm).request({
		requestHeaders  : {'X-Requested-With' : ''},
		onCreate:function(){
			$(document.body).setStyle({"cursor" : "progress"});			
		},
		onSuccess: function(response) {
			
			rText = response.responseText;
			rText = rText.replace("<!-- //",""); 
			rText = rText.replace("// -->","");  
						
			var divTmp = new Element('div');	
			divTmp.innerHTML = rText;
			
			$("contenu").innerHTML = divTmp.down("[id=contenu]").innerHTML;

			$(document.body).setStyle({"cursor" : "auto"});
			
			var id = 0;
			$$('#contenu .item').each(
				function(o){ 
					id++;
					createLayer('produit'+id, -62, -121);
					
					var div = document.createElement("div");
					div.id = "produit"+id;
					div.style.zIndex =  1000;
					div.style.left =  -62+"px";
					div.style.top =  -121+"px";
					div.style.position =  "relative";
					div.style.cursor =  "pointer";
					div.style.visibility =  "hidden";
			
					div.innerHTML = "<div class='popUpProduit'>" + o.down().nextSibling.innerHTML + "</div>";
					
					o.down().nextSibling.innerHTML = "";
					o.removeChild(o.down().nextSibling);
					o.insertBefore(div,o.down().nextSibling);
					
					o.down(".ajouter input").writeAttribute("value", "");
				}
			);
			loadPng();
			
			//Pour ajouter le rechargement ajax sur la pagination
			$$(".paginationPrev a, .paginationNext a").each(function (o){
				o.observe('click', reloadFromPagination);
			});
			
			//pour l'ajout au panier
			var myTmp ="<script>Tapestry.init({\"linkZone\":[";
			$$('#items form').each(
				function(o){
					myTmp = myTmp + "\[\""+o.readAttribute("id")+"\", \"shoppingCartZone\", \""+o.readAttribute("action")+"\"\],";
				}
			);
			myTmp = myTmp.substr(0,myTmp.length-1);
			myTmp = myTmp +"]});</script>";
			myTmp.evalScripts.bind(myTmp).defer();
			
			divTmp.evalScripts.bind(divTmp).defer();
			
		}
	});
}



//Liens droite
Event.observe(window, 'load', function(event) {
	$$(".loadWithAjax").each(function (o){
        o.observe('click', reloadFromMenu);
	});
});

function reloadFromMenu(event){
	window.oldScroolY = document.viewport.getScrollOffsets()[1];
	var link = event.element().readAttribute("href");
	if(!link)
		link = event.element().up().readAttribute("href");
		
	if(location.protocol == "https:"){
		event.stop();
	    new Ajax.Request(link, {
			method: 'GET',
			evalJS: false,
			requestHeaders : {'X-Requested-With' : ''}, 
			onCreate:function(){
				$(document.body).setStyle({"cursor" : "progress"});			
			},
	        onSuccess: function(response) { 
	        	if(response.responseText){
	            	traitementResponse(response);
	        	}else{
	        		document.location = response.request.url
	        	}   
	        },
	        onFailure : function(response) {
	    		document.location = response.request.url
	    	}
	    });
	}
}

function stripAllJSComment(text){
    text = text.replace("<!-- //",""); 
    text = text.replace("// -->",""); 
    text = text.replace("//-->",""); 
    text = text.replace("<!--",""); 
    text = text.replace("-->",""); 
    return text;
}

function traitementResponse(response){
	try{
	var rText = response.responseText;
	var divTmp = new Element('div' ,{'style': 'display:none'});
	var debut = rText.indexOf("<body>");
	var fin = rText.indexOf("</body>", debut);
	
	divTmp.innerHTML = rText.substring(debut+6,fin);
	
	document.body.appendChild(divTmp);
	
	}catch(e){}
	
	if($("colonneGauche"))
		$("colonneGauche").remove();
	if($("contenu"))
		$("contenu").remove();
	if($("myNav"))
		$("myNav").remove();
	if($("recherche"))
		$("recherche").remove();
	
	var cg = null;
	var ctn = null;
	
	cg = divTmp.select("#colonneGauche,[id=colonneGauche]")[0];
	
	ctn = cg.next();
	if(ctn.readAttribute("id")!="contenu"){
		ctn = $("pageGauche").appendChild(divTmp.select("#contenu,[id=contenu]")[0]);
	}
	
	$("pageGauche").appendChild(cg);
	$("pageGauche").appendChild(ctn);
		
	$$("#pageGauche .loadWithAjax").each(function (o){
        o.observe('click', reloadFromMenu);
	});
		
	if($("pageGauche").up().readAttribute("id")=="pageAccueil"){
		$("pageGauche").up().writeAttribute("id", "pageInscription");
		$("pageGauche").up().addClassName("pageCompte");
	}	
	
	window.scrollTo(0, window.oldScroolY);
	$(document.body).setStyle({"cursor" : "auto"});
	
	if(divTmp.down("title")){
		document.title = divTmp.down("title").innerHTML+"";
	}
	try{
		var debut = rText.indexOf("body onload=\"");
		if(debut>0){
			var fin = rText.indexOf("\"",debut+13);
			var monJs = "<script>"+rText.substring(debut+13,fin)+"</script>";
			monJs.evalScripts.bind(monJs).defer();
		}
	}catch(e){}
	
	var debut = rText.indexOf("Tapestry.init({");
	var fin = rText.indexOf("});", debut);
	
	var monScript = "<script>try{"+rText.substring(debut,fin+3)+"}catch(e){}</script>";
	monScript.evalScripts.bind(monScript).defer();
	
	var arr  = divTmp.getElementsByTagName("script");
	var arr2 = $("contenu").getElementsByTagName("script");
	
	var i;
	var scriptTmp = "";
	for(i=0;i<arr.length; i++){
		scriptTmp = scriptTmp+"<script>try{";
    	scriptTmp = scriptTmp+stripAllJSComment(arr[i].innerHTML);
		scriptTmp = scriptTmp+"}catch(e){}</script>";
	}
	for(i=0;i<arr2.length; i++){
		scriptTmp = scriptTmp+"<script>try{";
    	scriptTmp = scriptTmp+stripAllJSComment(arr2[i].innerHTML);
		scriptTmp = scriptTmp+"}catch(e){}</script>";
	}
	try{
		scriptTmp.evalScripts.bind(scriptTmp).defer();
	}catch(e){}
		
	(function() {
	  document.body.removeChild(divTmp);
	}).delay(0.5, this);

}


