var isOpera = (navigator.userAgent.indexOf('Opera') != -1)? true : false;
var isIE = (document.all && !isOpera && navigator.platform == "Win32")? true : false;
var isIE6 = (navigator.userAgent.indexOf('MSIE 6') != -1)? true : false ;
var isIE7 = (navigator.userAgent.indexOf('MSIE 7') != -1)? true : false ;
	
Event.observe(window, 'load',PI_init);
var MyBasket;
var Debugger;
var myScrollBasket;
var myScrollContent;
var offsetHeight;
var offsetWidth;
var scrollTop;
function PI_init(){
	
 	if($("navLeft") && !$("AWL_help")){
		navig = new Nav();
	}

/*	VBZ: Mise en commentaire pour l'instant
	if($("inputSearch")){
		div = document.createElement("div");
		div.id="rechercheAuto";
		$("container").appendChild(div);
		
		new Ajax.Autocompleter(
		"inputSearch", 
		"rechercheAuto", 
		"/ajax_template/search.htm",
		{paramName: 'search',minChars: 3,method: 'get' }
		);
	}

	if($("inputSearchRecette")){
		div = document.createElement("div");
		div.id="rechercheAuto";
		$("container").appendChild(div);
		
		new Ajax.Autocompleter(
		"inputSearchRecette", 
		"rechercheAuto", 
		"/ajax_template/search.htm",
		{paramName: 'search',minChars: 3,method: 'get' }
		);
	}
*/
 	
	PI_loadNav();
	PI_loadInputFocus();
	PI_ContentScroll();

	$$('div.PI_boxProduct').each(function(e){
		if(e.id) this["d"+e.id] = new SubsDraggable(e.id, {dragelement:PI_getDragElement});
	});
	
	$$('div.PI_boxProductList').each(function(e){
		if(e.id){
			this["d"+e.id] = new SubsDraggable(e.id, {dragelement:PI_getDragElement});
		}
	});
	
	$$('div.PI_boxProductDetail').each(function(e){
		if(e.id) this["d"+e.id] = new SubsDraggable(e.id, {dragelement:PI_getDragElement});
	});
	
	if(document.getElementById("plan")==null)
		MyBasket = new Basket('basketDetail');
	
	Event.observe(document, "mousemove", PI_eventMouseMove);	
	
	//PI_loadLay('deliveryLay');
}

function PI_loadNav(){
	var tabNavTop = $$('#navTop a').each(
		function(e) {
			if(PI_getImgStat(e) != 1){
				Event.observe(e, 'mouseover',PI_swapImg.bind(this,e));
				Event.observe(e, 'mouseout',PI_swapImg.bind(this,e));
			}
		}
	)
}

var tab
var inputValue = "";
function PI_loadInputFocus(){
	$$("#footer input.PI_inp").each( function(e) { PI_addEventInputFocus(e); });
	$$("#header input.PI_inp").each( function(e) { PI_addEventInputFocus(e); });
	
	$$("#contentRight input.PI_inp").each( function(e) { PI_addEventInputFocus(e); });
	$$(".PI_infoLay input.PI_inp").each( function(e) { PI_addEventInputFocus(e); });
	
	
}
function PI_addEventInputFocus(e){
	Event.observe(e, 'focus',PI_focusInput.bindAsEventListener(this,e));
	Event.observe(e, 'blur',PI_blurInput.bindAsEventListener(this,e));
}
function PI_focusInput(e,obj){
	if(obj.value == obj.alt){
		obj.value = "";
	}
	if(obj.id == "inputDelivery"){
		obj.maxLength = 5;
	}
}
function PI_blurInput(e,obj){
	if(obj.id == "inputDelivery"){
		obj.maxLength = 100;
	}
	if(obj.value == ""){
		obj.value = obj.alt;
	}
}

function PI_getImgStat(obj){
	obj = obj.getElementsByTagName('img')[0];
	var ch = obj.src;
	var fin=ch.substring(ch.length-5,ch.length-4);
	return fin;
}

function PI_swapImg(obj){
	if(!obj) return;
	obj = obj.getElementsByTagName('img')[0];
	var ch = obj.src;
	var finfin=ch.substring(ch.length-3,ch.length);
	var fin=ch.substring(ch.length-5,ch.length-4);
	ch=ch.substring(0,ch.length-5);
	if(fin == "0") obj.src=ch+"1."+finfin;
	else obj.src=ch+"0."+finfin;
}

/*** Chargement du scroll content ***/
function PI_ContentScroll(){
	if($('contentScroll')){
		if($('contentMid')) oContent = $('contentMid');
		else oContent = $('contentCenter');
		
		$('scrollTools').innerHTML += '<div id="scrollbarBg"></div>';
		$('presScrollMask').style.height = oContent.getHeight()-$('presScrollMask').offsetTop-5+"px";
		$('scrollTools').style.top = $('presScrollMask').offsetTop+"px";
		$('scrollTools').style.height = $('presScrollMask').getHeight()-5+"px";
		$('scDn').style.top = $('presScrollMask').getHeight()-13+"px";
		$('cursor').style.height = $('scrollbarBg').style.height = $('presScrollMask').getHeight()-26+"px";
	
		myScrollContent =  new Scroller ("vertical",{
			container:$("contentScroll"),
			scrollbar:$('scrollTools'),
			scrollbarBgV:$("scrollbarBg"),
			mask:$("presScrollMask"),
			scUp:$("scUp"),
			scDn:$("scDn"),
			cursorV:$("cursor")
		},10,5);
		myScrollContent.init();
	}
}

/*** Chargement du scroll Layer ***/
function PI_ContentScrollLayer(omask,oscroll,view){
	var scroll = $(oscroll);
	scroll.innerHTML += '<div id="scrollbarBg'+omask+'"></div>';
	var scUp = Element.childElements(scroll)[0];
	var scDn = Element.childElements(scroll)[1];
	var sc = Element.childElements(scroll)[2];
	var maskDiv = $(omask);
	var el = Element.down(maskDiv);

	scroll.style.top = maskDiv.offsetTop+"px";
	scroll.style.height = maskDiv.getHeight()-5+"px";
	scDn.style.top = maskDiv.getHeight()-13+"px";
	sc.style.height = $('scrollbarBg'+omask).style.height = maskDiv.getHeight()-26+"px";

	//if(el.offsetHeight<maskDiv.offsetHeight) return;

	this['myScroll'+omask] =  new Scroller ("vertical",{
		container:el,
		scrollbar:scroll,
		scrollbarBgV:$('scrollbarBg'+omask),
		mask:maskDiv,
		scUp:scUp,
		scDn:scDn,
		cursorV:sc
	},10,5);
	this['myScroll'+omask].init();
	
	if(view == false) this['myScroll'+omask].showScrollElems("vertical","hidden");

	return this['myScroll'+omask];
}

/*** Initialisation du scroll droie partie Achat ***/
function PI_initAchatRightScroll(){
	$('presScrollMaskRight').style.height = $('contentCenterRight').getHeight() - $('presScrollMaskRight').offsetTop - $$('#rightStep div.PI_detail')[0].getHeight() - 5 +"px";
	
	
	if(this['myScrollpresScrollMaskRight']) this['myScrollpresScrollMaskRight'].reload();
	
}

/*** Permet de voir les png transparent sous ie6 ***/
function PI_hackPng(){
  if (navigator.appVersion.indexOf("MSIE 6")!=-1)
    for (i = 0; i < document.images.length; i++)
      if (document.images[i].src.substring(document.images[i].src.length-3, document.images[i].src.length) == "png") 
      {
        document.images[i].style.height = document.images[i].height + "px";
        document.images[i].style.width = document.images[i].width + "px";
        document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + document.images[i].src + ",sizingMethod='scale')";
        document.images[i].src = "/img/commun/pix.gif";
      }
}

/*** Function d'ouverture de layer ***/
var tabLay = new Array();		
var timeLay;
/* MODIF IFRAME_PANIER */
var objLay;	

function PI_loadLay(obj,type){
	var container = ($("containerpop"))? $("containerpop") : $("container");
	objLay = $(obj);
	if(!objLay) return;
	
	if(obj == 'basketFull'&&objLay.offsetHeight==0&&objLay.offsetWidth==0){
	}
	else{
		offsetHeight = objLay.offsetHeight;
		offsetWidth = objLay.offsetWidth;
	}
	
	if(!$('maskLay')){
		var divmask = document.createElement("div");
		container.appendChild(divmask);
		divmask.id="maskLay";
		divmask.style.visibility = "visible";
		divmask.style.display = "block";
			
   }

	Event.observe($("maskLay"), 'click',this.PI_nothing.bind());
	
	/* MODIF IFRAME_PANIER */
	if($('WIDGET_PANIER') != null)
	{
		objLay.style.top = "40px";
		objLay.style.left = "3px";
		objLay.style.width = "241px";
		objLay.style.height = "230px";
		objLay.style.display = "block";
		objLay.style.visibility = "visible";
	}
	else
	{
		objLay.style.top = (container.getHeight()/2)-(offsetHeight/2)+"px";
		objLay.style.left = (container.getWidth()/2)-(offsetWidth/2)+"px";
		objLay.style.display = "block";
		objLay.style.visibility = "visible";
	}
	if(type == "delivery"){
		PI_loadDeliveryLay(objLay);
	}
	if(type == "log"){
		objLay.style.top = 32+"px";
		objLay.style.left = 585+"px";
	}
	if(type == "TIMER"){
		clearTimeout(timeLay);
		timeLay = setTimeout("PI_removeTimerLay('"+obj+"')",2000);

	}
	PI_rescueFrame(objLay,0);
	
	if($('presScrollMaskLay'))$('presScrollMaskLay').scrollTop=scrollTop;
	
	tabLay.push(objLay);
}
function PI_nothing(){

}
function PI_removeTimerLay(obj){
	clearTimeout(timeLay);
	objLay = $(obj);

	if(!objLay) return;

	for(var i=0;i<tabLay.length;i++){
		if(objLay == tabLay[i]){
			objLay.style.visibility = "hidden";
			PI_removeRescueFrame(objLay);
			tabLay.splice(i,1);
			return;
		}
	}
}

function PI_removeLayObj(obj){
	if(!isLayAjax) PI_removeMask();
	
	for(var i=0;i<tabLay.length;i++){
		objLay = tabLay[i];

		if(Element.descendantOf(obj,objLay) || obj.id == objLay.id){
			if(objLay.id){
				$$("#"+objLay.id+' .PI_txtError').each(function(e){
					e.innerHTML = "";
				});
				$$("#"+objLay.id+' .PI_error').each(function(e){
					e.innerHTML = "";
				});
				
				$$("#"+objLay.id+' .PI_inp').each(function(e){
					e.removeClassName('PI_inpError');
				});
			}
			//objLay.style.visibility = "hidden";
			objLay.style.display = "none";
			PI_removeRescueFrame(objLay);
			tabLay.splice(i,1);
			break;
		}
	}
}


function PI_removeLay(){
	if(!isLayAjax) PI_removeMask();
		
	if(objLay.id){
		$$("#"+objLay.id+' .PI_txtError').each(function(e){
			e.innerHTML = "";
		});
		$$("#"+objLay.id+' .PI_error').each(function(e){
			e.innerHTML = "";
		});
		
		$$("#"+objLay.id+' .PI_inp').each(function(e){
			e.removeClassName('PI_inpError');
		});
	}
	//objLay.style.visibility = "hidden";
	objLay.style.display = "none";
	PI_removeRescueFrame(objLay);
	
}

function PI_removeMask(){
	var container = ($("containerpop"))? $("containerpop") : $("container");
	if($('maskLay')){
	//	container.removeChild($('maskLay'));
	$('maskLay').remove();
	}
}

function PI_loadDeliveryLay(obj){
	obj.style.top = 150+"px";
	obj.style.left = 748+"px";
}

//----------------------------------------------
/** drag patch **/
var gobalObj=null;

function PI_getDragElement(element){
    var el = element.cloneNode(true);
    el.id = 'sub'+element.id;
    $('content').appendChild(el);
    gobalObj=el;
	
if (isIE6) {
		var dragHack = $$('#'+el.id+' .visu');
		for (var i=0;i<dragHack.length;i++) {
			var img = dragHack[i].getElementsByTagName('img')[0];
			if (img) {
				dragHack[i].setStyle({
					width:img.offsetWidth+'px',
					height:img.offsetHeight+'px',
					background:'url('+img.src+')'
				});
				img.style.display = 'none';
			}
		}
	}
    return el;
}

//-----------------------------------------------
// Add carte & quantity
//--

function PI_ChangeQuantity(obj,_source,move,bool){
	var valueQuant=0;
	if (bool==false){
		if(move==-1){
			Element.next(obj).value--;
			if(Element.next(obj).value<1){
				Element.next(obj).value=1;
			}
			valueQuant=Element.next(obj).value;
		}else if(move==1){
			Element.previous(obj).value++;
			valueQuant=Element.previous(obj).value;
		}
		
	}else if (bool==true){
		valueQuant=obj.value;
	}
	
	itemInfo=$(_source).down(0);
	infoTab=itemInfo.innerHTML.split("-");
	itemInfo.innerHTML=infoTab[0]+"-"+valueQuant+"-"+_source.substring(1,_source.length);
}

function PI_ChangeQuantityFull(obj,_source,move,bool,objScroll){
	//alert("qty : "+obj.value+", source : "+_source+", move : "+move+", bool : "+bool);
	if(objScroll) {
		//alert(objScroll.scrollTop);
		scrollTop=objScroll.scrollTop;
	}
		if(move == -1 || obj.value == 0){
			//alert("Obj != null");
			MyBasket.removeItem(_source);
			
		}else{
			if(obj!=null && obj.value!=null){
				//alert("Obj != null");
				if(!isNaN(obj.value)){
					MyBasket.addItemWithQty(_source,obj.value);
				}
				
			}else{
				MyBasket.addItem(_source);	
			}
		}
	
}

function PI_removeCart(_source,objScroll){
	if(objScroll) {
		//alert(objScroll.scrollTop);
		scrollTop=objScroll.scrollTop;
	}
	if(MyBasket.removeFullItem(_source)){
		//loadBasketFull(typeBasket);
	}
}

function PI_addCart(_source){
	MyBasket.add(_source);
}

function PI_addMultiCart(_source){

   	for(i=0; i<_source.length;i++)
   	{
      		PI_addCart(_source[i]);
    }
}

/* 
*	ajout d''articles en vérifiant avant le Code Postal
*	(permet d'éviter d'avoir un seul article alors qu'on commande plusieurs articles
*	si le systeme demande de confirmer le CP)
*/
function PI_addMultiCartAfterCheckCP(_source){

	var myFunction="";
   	for(i=0; i<_source.length;i++)
   	{
      		myFunction="PI_addCart('"+ _source[i] + "');"+myFunction
    }
	MyBasket.checkCPwithFunction(myFunction);
}

function PI_deleteCart(){
	   MyBasket.deleteAll();
}
function PI_deleteCartWithoutAsk(){
	   if(MyBasket!=null)MyBasket.deleteAllWhitoutAsk();
}

/*** Zoom produit ***/
var tZoom;
function PI_zoomProduct(o,imageUrl){ 
	if(isDragging){
	 	PI_maskZoomProduct();
		return;
	}
	
	PI_removeZoomProduct();
 	if(xMouse){
		var imgZoom = new Image; 
		imgZoom.src=imageUrl; 
		
		var divZoom = document.createElement("div");
		divZoom.id="ZoomProduct";
		divZoom.zimg = imgZoom;
		divZoom.style.visibility = "visible";
		divZoom.className = "PI_infoLay";
		var imgZoom = divZoom.appendChild(imgZoom);
		
		divZoom.style.width = "130px";
		divZoom.style.height = "130px";
		
		divZoom.style.left = xMouse+"px";
		divZoom.style.top = yMouse+"px";
		document.body.appendChild(divZoom);	
		
		
		
		Event.observe($('ZoomProduct'), 'mouseover',PI_clearZoomProduct.bind(this));
		Event.observe($('ZoomProduct'), 'mouseout',PI_maskZoomProduct.bind(this));
   }
}


function PI_maskZoomProduct(){
	tZoom = setTimeout(PI_removeZoomProduct,100);
}

function PI_removeZoomProduct(){
	clearTimeout(tZoom);
	if($('ZoomProduct')){
		document.body.removeChild($('ZoomProduct'));
	}
}
function PI_clearZoomProduct(){
	clearTimeout(tZoom);
}

var isDragging = false;
function PI_callBackInitDrag(){		 
	isDragging = true;
	 PI_removeZoomProduct()
}
function PI_callBackFinishDrag(el){		 
	isDragging = false;
}
var xMouse;
var yMouse;
function PI_eventMouseMove(e){
	xMouse = Event.pointerX(e);
	yMouse = Event.pointerY(e);
}

/*** Function Alt Image ***/

function PI_viewAlt(o,lay){
	if(o.getElementsByTagName('img')[0]){
 	$(lay).style.top = getAbsoluteTop(o.getElementsByTagName('img')[0])+o.getElementsByTagName('img')[0].height+"px";
	$(lay).style.left = getAbsoluteLeft(o.getElementsByTagName('img')[0])+o.getElementsByTagName('img')[0].width+"px";

 	if(parseInt($(lay).style.left) + $(lay).offsetWidth > document.width) $(lay).style.left -= $(lay).offsetWidth-5;
 	}
 	else {
 		$(lay).style.top = getAbsoluteTop(o)+16+"px";
 		$(lay).style.left = getAbsoluteLeft(o)+"px";
 }
 $(lay).style.visibility = "visible";
}
function PI_maskAlt(lay){
	$(lay).style.visibility = "hidden";
}

/***************************/


/*** Roll over produit mise au panier ***/
function rollPictoFiche(n){
	this["d"+$(n).id].destroy();
	
	var a = $$("#"+n+" .PI_txt")[0].getElementsByTagName('a')[0];
	var btn = $$("#"+n+" .PI_txt")[0].getElementsByTagName('a')[1];
	
	PI_swapImg(btn);
	a.className = "PI_desc PI_on";
	

}
function rolloutPictoFiche(n){
	this["d"+$(n).id] = new SubsDraggable($(n).id, {dragelement:PI_getDragElement});
	
	var a = $$("#"+n+" .PI_txt")[0].getElementsByTagName('a')[0];
	var btn = $$("#"+n+" .PI_txt")[0].getElementsByTagName('a')[1];
	
	PI_swapImg(btn);
	a.className = "PI_desc";

	
}
function rollPictoBasket(n){
	rollPictoFiche(n);
	
	if(!$('buyProduct')){
		var imgbuyProduct = new Image; 
		imgbuyProduct.src="/img/btn/achete.gif"; 
		
		var divbuyProduct = document.createElement("div");
		divbuyProduct.id="buyProduct";
		divbuyProduct.zimg = imgbuyProduct;
		divbuyProduct.style.visibility = "visible";
		divbuyProduct.className = "PI_infoAlt";
		var imgbuyProduct = divbuyProduct.appendChild(imgbuyProduct);
		divbuyProduct.style.width = "82px";
		divbuyProduct.style.height = "20px";
		
		var btn = $$("#"+n+" .PI_txt")[0].getElementsByTagName('a')[1];
		divbuyProduct.style.left = getAbsoluteLeft(btn)+20+"px";
	
		divbuyProduct.style.top = -$("presScrollMask").scrollTop+getAbsoluteTop(btn)+15+"px";
		divbuyProduct.style.paddingTop = "5px";
		divbuyProduct.style.paddingBottom = "5px";
		
		document.body.appendChild(divbuyProduct);	
		
	}
}
function rolloutPictoBasket(n){
	rolloutPictoFiche(n);
	if($('buyProduct')){
		//setTimeout("document.body.removeChild($('buyProduct'))",500);
		document.body.removeChild($('buyProduct'));
	}
}

/**********************************/
function onCheckboxChange(){
	
}
function onRadiosChange(){
	
}

function PI_checkbox(obj){
	PI_swapImg(obj);

	if(PI_getImgStat(obj) == 1){
		$(obj.rel).value = 1;
	}
	else{
		$(obj.rel).value = 0;
	}
	
	onCheckboxChange($(obj.rel));
}
function PI_radiobox(obj,group){
	$$(group+' a').each(function(e){
		if(PI_getImgStat(e) == 1) PI_swapImg(e);
	});
	PI_swapImg(obj);
	$(obj.rel).value = obj.title;
	
	onRadiosChange($(obj.rel));
}

function getAbsoluteTop(objectId){
	var x = objectId;
	xTop = x.offsetTop;		 
	
	while(x.offsetParent!=null) {
		xParent = x.offsetParent;
		xTop += xParent.offsetTop-xParent.scrollTop;
		x = xParent;
	}
	return xTop;
}
function getAbsoluteLeft(objectId){
	var x = objectId;
	xLeft = x.offsetLeft;
	while(x.offsetParent!=null){
		xParent = x.offsetParent;
		xLeft += xParent.offsetLeft;
		x = xParent;
	}
	return xLeft;
}

function getAbsoluteTopContainer(objectId){
	var x = objectId;
	xTop = x.offsetTop;		 
	
	while(x.offsetParent!=null) {
		xParent = x.offsetParent;
		if(xParent.id == "container"){
			return xTop;
		}
		xTop += xParent.offsetTop-xParent.scrollTop;
		x = xParent;
	}
	return xTop;
}

function getAbsoluteLeftContainer(objectId){
	var x = objectId;
	xLeft = x.offsetLeft;
	while(x.offsetParent!=null){
		xParent = x.offsetParent;
		if(xParent.id == "container"){
			return xLeft;
		}
		xLeft += xParent.offsetLeft;
		x = xParent;
	}
	return xLeft;
}

/****** CHARGEMENT DU PANIER FULL & LISTE COURSE *******/
var typeBasket = "";
var isLayAjax = false;
var typeIdListe=1;
function loadBasketFull(type,idListe){
	typeBasket = type;
	typeIdListe=idListe;
	if(!$('basketFull')){
		var div = document.createElement("div");
		div.id="basketFull";
		div.className = "PI_layerDetail";
		$("container").appendChild(div);	
	}
	    date = new Date();
		datebidon =  date.getTime();
	if(typeBasket == "liste"){
		div.className = "PI_layerDetail PI_liste";
		var url = '/liste/componentListe/liste_course_detail.jsp?idListe='+idListe+'&d='+datebidon;
	}
	else{
	 
		var url = '/panier/componentPanier/basketFull.jsp?d='+datebidon;
	}

	var target = "basketFull";
	var myAjax = new Ajax.Request(url, {
	onComplete:this.callBackBasketFull.bind(this),
	method: 'get'});
	isLayAjax = true;
}
function callBackBasketFull(e){
	$("basketFull").update(e.responseText);
	
	PI_loadLay("basketFull");
}
function PI_closeBasketFull(){
	MyBasket.synchronize();
	PI_removeMask();
	if($('basketFull')){
		$("container").removeChild($('basketFull'));
	}
	isLayAjax = false;
}
function PI_removeBasketFull(){
	date = new Date();
	datebidon =  date.getTime();
	if(typeBasket == "liste"){
		
		var url = '/liste/componentListe/liste_course_detail.jsp?idListe='+typeIdListe+'&d='+datebidon;
	}
	else{
  	 
		var url = '/panier/componentPanier/basketFull.jsp?d='+datebidon;
	}
	var target = "basketFull";
	var myAjax = new Ajax.Request(url, {
	onComplete:this.callBackBasketFull.bind(this),
	method: 'get'});
	
	//PI_closeBasketFull()
	PI_deleteCart();
	isLayAjax = false;
}

/****** CHARGEMENT DETAIL COMMANDE *******/
function PI_loadDetailCommande(numCmde){
	if(!$('detailCommande')){
		var div = document.createElement("div");
		div.id="detailCommande";
		div.className = "PI_layerDetail";

		$("container").appendChild(div);	
	}
	var url = '/commande/detail_commande.jsp?numCmde='+numCmde+'&openPrintPage=true';

	var target = "detailCommande";
	var myAjax = new Ajax.Request(url, {
	onComplete:this.callBackDetailCommande.bind(this),
	method: 'get'});
	isLayAjax = true;
}
function callBackDetailCommande(e){
	$("detailCommande").update(e.responseText);
	PI_loadLay("detailCommande");
}
function PI_closeDetailCommande(){
	PI_removeMask();
	if($('detailCommande')){
		$("container").removeChild($('detailCommande'));
	}
	isLayAjax = false;
}

/****** CHARGEMENT RESERVER LIVRAISON *******/
function PI_loadReserveLivraison(orderNumber){

	if(!$('reserveLivraison')){
		var div = document.createElement("div");
		div.id="reserveLivraison";
		div.className = "PI_layerDetail";

		$("container").appendChild(div);	
	}
	date = new Date();
	datebidon =  date.getTime();
	var url = '/panier/modifierCreneauLivraison.jsp?orderNumber='+orderNumber+"&d="+datebidon;

	var target = "reserveLivraison";
	var myAjax = new Ajax.Request(url, {
	onComplete:this.callBackReserveLivraison.bind(this),
	method: 'get'});
	isLayAjax = true;
}
function callBackReserveLivraison(e){
	$("reserveLivraison").update(e.responseText);
	PI_loadLay("reserveLivraison");
}
function PI_closeReserveLivraison(){
	PI_removeMask();
	if($('reserveLivraison')){
		$("container").removeChild($('reserveLivraison'));
	}
	isLayAjax = false;
}

/****** CHARGEMENT MODIFIER LIVRAISON *******/
function PI_loadModifierLivraison(){
	
	if(!$('modifLivraison')){
		var div = document.createElement("div");
		div.id="modifLivraison";
		div.className = "PI_layerDetail";

		$("container").appendChild(div);	
	}
	date = new Date();
	datebidon =  date.getTime();
	var url = '/panier/reserverCreneauLivraison.jsp?prereservation=1'+'&d='+datebidon;

	var target = "modifLivraison";
	var myAjax = new Ajax.Request(url, {
	onComplete:this.callBackModifierLivraison.bind(this),
	method: 'get'});
	isLayAjax = true;
}
function callBackModifierLivraison(e){
	$("modifLivraison").update(e.responseText);
	PI_loadLay("modifLivraison");
}
function PI_closeModifierLivraison(){
	PI_removeMask();
	if($('modifLivraison')){
		$("container").removeChild($('modifLivraison'));
	}
	isLayAjax = false;
}


/****** COMBOBOX ******/
function PI_ComboInit(el,osc){
	e = Element.childElements($(el))[0];
	Event.observe(e, 'click',PI_openCombo.bind(this,el,osc));
}
function PI_openCombo(el,osc){
	v = Element.childElements($(el))[0];
	o = Element.childElements($(el))[1];

	if(o.style.visibility == "visible"){
		Element.removeClassName(v,"PI_defaulton");
		o.style.visibility = "hidden";
		osc.showScrollElems("vertical","hidden");
		PI_removeRescueFrame(o);
	}
	else{
		Element.addClassName(v,"PI_defaulton");
		o.style.visibility = "visible";
		osc.showScrollElems("vertical","visible");
		PI_rescueFrame(o);
	}
}


/******************/



/***** 00 - rescueFrame *****/
function PI_rescueFrame(obj,pos){
	if(isIE && !isIE7){		
		if(!$('rescueFrame'+obj.id)){
			var rescueObj = document.createElement('iframe');
			rescueObj.setAttribute("src", "javascript:void(0)");
			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 = obj.offsetWidth+'px'; 
			rescueElement.style.height = obj.offsetHeight+'px'; 
			//rescueElement.style.visibility = 'hidden';
			rescueElement.style.border = '10px';
			rescueElement.style.filter = 'alpha(opacity=0);';
			rescueElement.style.zIndex = -20;
		}
	}
}
function PI_removeRescueFrame(obj){
	if(isIE && !isIE7){
		if($('rescueFrame'+obj.id)){
			obj.removeChild($('rescueFrame'+obj.id));
		}
	}
}
/*****************************/

function PI_livraisonEdit(){
	$('infoLivraisonEdit').style.display = "block";
	$('infoLivraisonView').style.display = "none";
	
	if(this['myScrollpresScrollMaskRight']) this['myScrollpresScrollMaskRight'].reload();
	else PI_ContentScrollLayer("presScrollMaskRight","scrollRight");
}

function PI_achatStep(id){
	if($('b'+id).style.display == "block"){
		$('b'+id).style.display = "none";
		PI_initAchatRightScroll();
		return;
	}
	
	$$('#rightStep div.PI_descInfo').each(function(e){
		e.style.display = "none";
	});
	$('b'+id).style.display = "block";
	
	PI_initAchatRightScroll();
	
}

function PI_displayLay(o){
	if($(o).style.display == "block"){
		$(o).style.display = "none";
	}
	else{
		$(o).style.display = "block";
	}
}

function PI_redirect(link){
	if(!$('buyProduct')) {
		document.location.href = link;
	}
}

function PI_setInputPassword(inp1,inp2){
	if(inp2.value != ""){
		PI_hideInputPass(inp1);
		PI_viewInputPass(inp2);
		inp2.focus();
	}
	else{
		PI_hideInputPass(inp2);
		PI_viewInputPass(inp1);
	}
	Event.observe(inp1, 'focus',PI_focusInputPass.bindAsEventListener(this,inp1,inp2));
	Event.observe(inp2, 'blur',PI_blurInputPass.bindAsEventListener(this,inp1,inp2));
}

function PI_focusInputPass(e,inp1,inp2){
	PI_hideInputPass(inp1);
	PI_viewInputPass(inp2);
	inp2.focus();
}

function PI_blurInputPass(e,inp1,inp2){	
	if(inp2.value == ""){
		PI_hideInputPass(inp2);
		PI_viewInputPass(inp1);
	}
}

function PI_viewInputPass(o){
	o.style.visibility = "visible";
	o.style.top = "0px";
	if (navigator.appVersion.indexOf("MSIE 6")!=-1) o.style.position = "";
	else o.style.display = "";
}

function PI_hideInputPass(o){
	o.style.visibility = "hidden";
	o.style.top = "-500px";
	if (navigator.appVersion.indexOf("MSIE 6")!=-1) o.style.position = "absolute";
	else o.style.display = "none";
}

function PI_checkCp(e) {
	var n = Event.element(e).value;
	Event.element(e).value = (isNaN(n)) ? (isNaN(parseInt(n))) ?"" :parseInt(n) :n;
	if(Event.element(e).value.length > 5) Event.element(e).value = Event.element(e).value.substring(0,5);
}

function PI_openPopDetail(irefc)
{
	PI_openPop("/magasin/ficheProduitPopup.jsp?irefc="+irefc,570,492);
}

function PI_openPop(url,w,h)
{
	haut = screen.height/2 - h/2;
	dim = screen.width/2 - w/2;
	window.open(url,'','width='+w+',height='+h+',left='+dim+',top='+haut+',resizable=no');
}
