﻿var preloadImg = new Image();
var prevSelectedThumbnail = 0;
var preloadAltImgs = new Array(0);
var preloadBigImgs = new Array(0);
var preloadVariantImgs = new Array(0);
var zoomSizeX = 350;
var zoomSizeY = 350;

if(!Control) var Control = {};
Control._DetailController = Class.create();

Control._DetailController.prototype = {
	initialize: function( jsonText , traduc ) {
		this.initDetailPage( jsonText , traduc );
	},
	
	initDetailPage:function(jsonText){
		if( typeof jsonText.error != 'undefined' && jsonText.error == '1' ) {
			window.location = "/404";
		}

		this.jsonText = jsonText;
		this.traduc = traduc;
		this.curSize = -1;
		this.curHoverSize = -1;
		this.changePrice = -1;
		this.formulaire = new Array();
		this.PushButton = null;
		this.hideButton = null;
		this.carrousselValue = null;
		this.carLeft = null;
		this.carRight = null;
		this.bouge = null;

		this.ASINS = jsonText.asins;
		this.AltImages = new Array(this.ASINS.length);
//		this.AltThumbImages = new Array( this.ASINS.length );
		this.AltThumbImages = new Array();
		this.AltZoomImages = new Array( this.ASINS.length );
		this.sizeLabels = jsonText.sizes;
        this.conversionLabels = jsonText.conversions;
        this.selectionTexts = jsonText.selectionTexts;
        this.imageLivr = jsonText.imageLivr;
		this.mySC = new Array(this.sizeLabels.length);
		this.choices=jsonText.choices;
		this.zoom = jsonText.zoom;
		this.derCons = jsonText.tabDerCons;

		if( document.getElementsByClassName('imageThumbnail').length > 0 ){
			var imageThumbnail = document.getElementsByClassName('imageThumbnail');
			for( i = 0 ; i < imageThumbnail.length ; i++ ){
				this.AltThumbImages.push( imageThumbnail[i].src );
			}
				this.displayThumbImages( imageThumbnail );
				this.altImagesPreload( this.AltThumbImages );
				this.bigImagesPreload(this.AltThumbImages);
		}
		
		/*if( this.ASINS.length != 0 ){
			for(var i=0;i<this.ASINS.length;i++){
				this.AltImages[i] = this.ASINS[i].altviews_images;
				this.AltThumbImages[i]= this.ASINS[i].altviews_thumbImages;
				this.AltZoomImages[i] = this.ASINS[i].altviews_zoomImages;

				this.bigImagesPreload(this.AltZoomImages[i]);
				this.altImagesPreload(this.AltImages[i]);
				this.displayThumbImages(this.AltThumbImages[i]);
			}
		}*/
		this.setObjectJSON();
		this.displayDefaultPage();
		this.gestionOnglet();
		if( jsonText.shopType == 5 )
			this.dernieresCons();
	},
	
	setObjectJSON: function() {
		if (this.choices.length==0){
			this.mySC = null;
		}else{
			for(var i=0;i<this.choices.length;i++){
				var x = new Object();
				x.asin = this.choices[i].asin;
				x.listprice = this.choices[i].listPrice;
                x.catalogprice = this.choices[i].catalogPrice;
				x.price = this.choices[i].buyingPrice;
				x.avail = this.choices[i].avail;
				x.yousave = this.choices[i].yousave;
				x.stock = this.choices[i].stock;
				x.fidelityPoints = this.choices[i].fidelityPoints;
				if (this.choices[i].size==-1)
					this.choices[i].size=0;
				this.mySC[this.choices[i].size] = x;
			}
		}
	},
	
	displayDefaultPage : function(){
		var divPlusQue;
		var classDivPlusQue;
		var idDivPlusQue;

		divPlusQue = document.createElement('div');
		classDivPlusQue = document.createAttribute('class');
		classDivPlusQue.nodeValue = 'picker';
		idDivPlusQue = document.createAttribute('id');
		idDivPlusQue.nodeValue = 'sizebox';

		divPlusQue.setAttributeNode( classDivPlusQue );
		divPlusQue.setAttributeNode( idDivPlusQue );

		//divPlusQue.appendChild( this.displayTotalStock() )
		$('size').appendChild( divPlusQue );
		$('quantitybox').appendChild( this.displayTotalStock() )
		
		/*if( this.traduc.descriptionFiche != null )
			$('fiche_description').innerHTML = this.traduc.descriptionFiche;*/
		
		this.displayTailles();
	},
	
	displayTotalStock : function(){
		var spanPlusQue;
		var classSpanPlusQue;
		var idSpanPlusQue;
		var texteNodePlusQue
		
		spanPlusQue = document.createElement('span');
		idSpanPlusQue = document.createAttribute('id');
		idSpanPlusQue.nodeValue = 'sizetext';
		
		classSpanPlusQue = document.createAttribute('class');
		classSpanPlusQue.nodeValue = 'fiche_stock_texte';
		
		spanPlusQue.setAttributeNode( idSpanPlusQue );
		spanPlusQue.setAttributeNode( classSpanPlusQue );
		
		spanPlusQue.innerHTML = this.jsonText.dispo;

		return spanPlusQue;
	},
	
	variantImagesPreload: function(imgList){

		for( var count=0 ; count < preloadVariantImgs.length ; count++ ){
           preloadVariantImgs[count] = null;
        }
        if( typeof( imgList ) != "undefined" ){
           preloadVariantImgs = new Array( imgList.length );
           for(var i=0; i<imgList.length; i++){
              preloadVariantImgs[i] = new Image();
              preloadVariantImgs[i].src = imgList[i];
           }

        }
	},

    altImagesPreload: function( imgList ){
		for( var count=0; count<preloadAltImgs.length; count++ ){
			preloadAltImgs[count] = null;
		}
        if( typeof( imgList ) != "undefined" ){
			preloadAltImgs = new Array( imgList.length );
				for( var i=0 ; i < imgList.length ; i++ ){
					preloadAltImgs[i] = new Image();
					preloadAltImgs[i].src = imgList[i].replace( '51x51' , '350x350' );
				}
				
			this.displayMainImage();
		}
    },
	
	bigImagesPreload: function( imgList ){
		for( var count=0; count<preloadAltImgs.length; count++ ){
			preloadBigImgs[count] = null;
		}
        if( typeof( imgList ) != "undefined" ){
			preloadBigImgs = new Array( imgList.length );
				for( var i=0 ; i < imgList.length ; i++ ){
					//$('imgPath').src = thumbList[0].replace( '51x51' , '85x85' );
					preloadBigImgs[i] = new Image();
					preloadBigImgs[i].src = imgList[i].replace( '51x51' , '1600x1600' );
				}
				
			this.displayBigImage( preloadBigImgs[0].src );
		}
    },
	
	//displayMainImage: function( mainImage ){
	displayMainImage: function(){
		imageMain = $( 'mImage' );
		/*imageMain = document.createElement('img');
		idImageMain = document.createAttribute('id');
		idImageMain.nodeValue = 'mImage';
		imageMain.setAttributeNode( idImageMain );
		imageMain.src = mainImage;
		$('mainImageID').appendChild(imageMain);*/
		this.bouge = this.pos.bind( this )
		Event.observe( imageMain , 'mousemove' , this.bouge )
		Event.observe( imageMain , 'mouseover' , this.bouge )
		Event.observe( $('over') , 'mousemove' , this.bouge );
		Event.observe( imageMain , 'mouseout' , this.restore.bind( this ) )
		Event.observe( $('over') , 'mouseout' , this.restore.bind( this ) )
	},
	
	displayBigImage: function( bigImage ){
		divBig = document.createElement('div');
		idDivBig = document.createAttribute('id');
		idDivBig.nodeValue = 'big';
		divBig.setAttributeNode( idDivBig );
		imageBig = document.createElement('img');
		idImageBig = document.createAttribute('id');
		idImageBig.nodeValue = 'bImage';
		imageBig.setAttributeNode( idImageBig );
		imageBig.src = bigImage;
		divBig.appendChild(imageBig);
		$('detailLeft').appendChild(divBig);
	},
	
	displayThumbImages : function( thumbList ){
		var divImage;
		var attributClass;
		var thumbImage;
		var classname = 'productThumbnail';
		var classname2 = 'cadre3 cadre_vip';
		var imageThumb = thumbList[0];
		/*if( typeof $('imgPath') != 'undefined' ){
			alert('toto');
			$('imgPath').src = imageThumb.src.replace( '51x51' , '85x85' );
		}*/
		for( var i = 0 ; i < thumbList.length ; i++ ){
			/*divImage = document.createElement('div');
			attributClass = document.createAttribute('class');
			attributClass.nodeValue = classname;
			divImage.setAttributeNode( attributClass );
			thumbImage = document.createElement( 'img' );
			thumbImage.src = thumbList[i];
			attributClass2 = document.createAttribute('class');
			attributClass2.nodeValue = classname2;
			thumbImage.setAttributeNode( attributClass2 );
			attributid = document.createAttribute('id');
			attributid.nodeValue = i;
			thumbImage.setAttributeNode( attributid );
			divImage.appendChild(thumbImage);
			$('altviewbox').appendChild( divImage );*/
			Event.observe( thumbList[i] , 'mouseover' , this.updateMainImage.bind( this ) );
		}
	},
	
	updateMainImage: function( e ){
		var image  = Event.element(e);
		$("mImage").src = preloadAltImgs[image.id].src;
		$("bImage").src = preloadBigImgs[image.id].src;
	}, 

	pos: function( event ) {
		$("detailLeftContent").style.display = "none";
		var myPos = Position.cumulativeOffset( $( "mImage" ) );
		var posBig = Position.cumulativeOffset( $( "big" ) );
		var scroll = Position.realOffset( $( "mImage" ) );
		var cLeft = myPos[0];
		var cRight = cLeft + $("mImage").width;
		var cTop = myPos[1];
		var cBottom = cTop + $("mImage").height;
		var ex = event.clientX;
		var ey = event.clientY;

		var widthCadreBig = parseFloat( $('big').getStyle('width') );
		//var widthImageBig = $('bImage').width == 0 ? parseFloat( $('bImage').getStyle('width') ) : $('bImage').width;
		var widthImageBig = 1600;
		var widthImageMoy = $('mImage').width;

		var scaleX = (ex - myPos[0])+scroll[0];
		var scaleY = (ey - myPos[1])+scroll[1];

		ratio = widthImageMoy/widthImageBig;
	
		if( ex < cLeft || ex > cRight || ( ey+scroll[1] ) < cTop || ( ey+scroll[1] ) > cBottom || this.zoom == 0 ) {
			this.restore();
			showMouseMessage( this.traduc.zoomIndisponible );
			Event.observe( $('mImage') , 'mouseout' , hideMouseMessage )
			return;
		}

		$("over").style.width = (ratio*widthCadreBig)+"px";
		$("over").style.height = (ratio*widthCadreBig)+"px";

		$("over").style.left = (scaleX-parseInt( ratio*widthCadreBig )/2 )+'px';
		$("over").style.top = (scaleY-( ratio*widthCadreBig )/2 )+'px';

		$("big").style.display = "inline";
		$("big").firstChild.style.left = (widthCadreBig/2)-(scaleX/ratio)+'px';
		$("big").firstChild.style.top  = (widthCadreBig/2)-(scaleY/ratio)+"px";
		$("over").style.display = "block";

	},

	restore : function(){
		$('over').style.display='none';
		$('detailLeftContent').style.display='inline';
		$('big').style.display='none';
	},

	displayTailles : function(){
		var swatchSize;
		var swatchSizeId;
		var swatchSizeString;
		var idSwatchSizeString;
		var classSwatchSizeString;
		var textNode;
		var ddaa;
		var idDdaa;
		var classDdaa;
		var choisirTaille;
		var	h = 0;

		if( this.mySC != null ){
			while( typeof( this.mySC[h] ) == 'undefined' ){
				h++;
			}
			ddaa = document.createElement( 'div' );
			idDdaa = document.createAttribute('id');
			classDdaa = document.createAttribute('class');
			idDdaa.nodeValue = 'ddaa';
			classDdaa.nodeValue = 'fiche_selection_texte';
			ddaa.setAttributeNode(idDdaa);
			ddaa.setAttributeNode(classDdaa);
			
			if( $('td_hplus') != null ){
				Event.observe( $('td_hplus') , 'click' , this.ajoute.bind( this ) );
				Event.observe( $('td_hminus') , 'click' , this.enleve.bind( this ) );
			}
			
			if( this.jsonText.pwyw == 1 ){
				Event.observe( $('td_hminusPwyw') , 'click' , this.decreasePrice.bind( this ) );
				Event.observe( $('td_hplusPwyw') , 'click' , this.increasePrice.bind( this ) );
				Event.observe( $('mypriceinput') , 'change' , this.functionChangePrice.bind( this ) );
			}
			if( this.choices.length > 1 ){
					choisirTaille = document.createTextNode( this.traduc.choisirtaille );
					$('addToCartNote').childNodes[0].innerHTML = this.traduc.pourajouter;
					Event.observe( $('addToCartBtn') , 'mouseover' , this.showAlertMessage.bind( this ) );
					this.hideButton = this.hideAlert.bind( this );
					Event.observe( $('addToCartBtn') , 'mouseout' , this.hideButton );
			}else{
				choisirTaille = document.createTextNode( this.traduc.selection+' : '+this.mySC[h].avail );
				this.clickSize( h )
			}
			ddaa.appendChild( choisirTaille );
			$('sizebox').appendChild(ddaa);
			if( this.jsonText.pwyw == 1 ){
				Event.observe( $('addToCartBtn') , 'mouseover' , this.showAlertMessage.bind( this ) );
				this.hideButton = this.hideAlert.bind( this );
				Event.observe( $('addToCartBtn') , 'mouseout' , this.hideButton );	
			}
		}

		if( this.jsonText.cadeau == 'false' ){
			this.updateBuyBox(h);
		}else{
			$('ddmp').innerHTML = '0 &euro;';
			$('buyboxprice').style.display = 'none';
			$('livraison48').style.display = 'none';
		}
		if( this.jsonText.tailleUnique == 'false' ){
			swatchSize = document.createElement('div');
			swatchSizeId = document.createAttribute('id');
			swatchSizeId.nodeValue = 'swatchSize';
			swatchSize.setAttributeNode( swatchSizeId );
			$('sizebox').appendChild( swatchSize );
		}

		if ( this.sizeLabels && this.sizeLabels.length > 0 && this.jsonText.tailleUnique == 'false' && this.mySC != null ){
			for( var i=0 ; i < this.sizeLabels.length ; i++ ){

				swatchSizeString = document.createElement( 'span' );
				idSwatchSizeString = document.createAttribute( 'id' );
				idSwatchSizeString.nodeValue = 'size'+i;
				swatchSizeString.setAttributeNode( idSwatchSizeString );
				classSwatchSizeString = document.createAttribute( 'class' );
				classSwatchSizeString.nodeValue = this.drawSize(i);
				swatchSizeString.setAttributeNode( classSwatchSizeString );
				
				/*if( i == 0 ){
					swatchSizeString.style.border = "#ccc solid 1px";
				}*/
				swatchSizeString.innerHTML = this.sizeLabels[i];

				Event.observe( swatchSizeString , 'click' , this.clickSize.bind( this , i ) );
				Event.observe( swatchSizeString , 'mouseover' , this.hoverSize.bind( this, swatchSizeString , i , null) );
				Event.observe( swatchSizeString , 'mouseout' , this.hoverSize.bind( this , swatchSizeString , -1 , i ) );
				$("swatchSize").appendChild( swatchSizeString );
			}

			this.updateWidth();
		}
		if( $('aFidelityPoints') != null ){
			Event.observe( $('aFidelityPoints') , 'mouseover' , showImgMsg.bind( this , '> Cliquez pous plus d\'info' ) );
			Event.observe( $('aFidelityPoints') , 'mouseout' , hideImgMsg.bindAsEventListener( this ) );
			Event.observe( $('aFidelityPoints') , 'click' , this.popupPointsFidelite.bind( this ) );
		}
		
		if( typeof( $('popupChono') ) != 'undefined' )
			Event.observe( $('popupChono') , 'click' , function(e){ $('opacDiv').style.display = 'block'; $('expedition_chrono_about').style.display = 'block'; } );

		if( typeof( $('lePlusBrandalley') ) != 'undefined' )
			Event.observe( $('lePlusBrandalley') , 'click' , this.popupPlusBrandalley.bind( this ) );

	},

	updateWidth : function(){
		maxlength = parseInt( this.jsonText.maxlen );

		if( this.jsonText.shopType != 5 ){
			maxLen = 4;
			width = "46px";
			maxLen2 = 6;
			width2 = "66px";
			maxLen3 = 8;
			width3 = "76px";
			fontSize2 = "10px";
			padding2 = "0px";
			height2 = "auto";
			margin2 = "0px;";
		}else{
			maxLen = 3;
			width = "50px";
			maxLen2 = 6;
			width2 = "80px";
			maxLen3 = 9;
			width3 = "110px";
			fontSize2 = "default";
			padding2 = "default";
			height2 = "default";
			margin2 = "default";		
		}

		if( ( maxlength > maxLen || maxlength > maxLen2 || maxlength > maxLen3 ) && this.jsonText.tailleUnique == 'false' ){

			var swatch = new Array(5);
			swatch[0] = document.getElementsByClassName('swatchTextActive');
			swatch[1] = document.getElementsByClassName('swatchTextAvail');
			swatch[2] = document.getElementsByClassName('swatchTextUnavail');
			swatch[3] = document.getElementsByClassName('swatchTextHover');
			swatch[4] = document.getElementsByClassName('swatchTextActiveUnavail');

            for( var i=0; i < 5; i++ ) {
				var s = swatch[i];
				for( var nb=0 ; nb < s.length ; nb++ ){
					if ( maxlength > maxLen3 ) {
						s[nb].style.width = width3;
                        if ( fontSize2 != 'default' ) {
							s[nb].style.fontSize = fontSize2;
						}
                        if( padding2 != 'default' ) {
							s[nb].style.padding = padding2;
						}
                        if(height2 != 'default') {
							s[nb].style.height = height2;
                        }
                        if( margin2 != 'default' ) {
							s[nb].style.margin = margin2;
                        }
					} else if ( maxlength > maxLen2 ) {
						s[nb].style.width = width2;
					} else {
						s[nb].style.width = width;
                    }
				}
			}
		}
	},
	
	drawSize: function( i ) {
		var isAvailable = this.checkSizeAvailable(i);
		if( isAvailable ){
			if( this.curSize == i ) {
				myClass = 'swatchTextActive';
			}else if(this.curHoverSize == i) {
				myClass = 'swatchTextHover';
			}else {
				myClass = 'swatchTextAvail';
			}
		}else {
			if(this.curSize == i) {
				myClass = 'swatchTextUnavail';
			}else if(this.curHoverSize == i) {
				myClass = 'swatchTextUnavail';
			}else {
				myClass = 'swatchTextUnavail';
			}
		}
		return myClass;
	},
	
	hoverSize: function( objectElement , i , objectI) {
		this.curHoverSize = i;
		
		if( i != -1 )
			showMouseMessage(this.conversionLabels[i]);
		else
			hideMouseMessage();
		
		this.updateQuanranteHuitHeure();
		
		
		i = objectI != null ? objectI : i;
		this.updateTextDdaa( i );
		this.updateDrawSize( objectElement , i );
	},
	
	clickSize: function( i ) {
		var isAvailable = this.checkSizeAvailable(i);
		
		if( this.curSize != -1 && isAvailable ){
			if( this.curSize != i )
				$('addToCartNote').style.visibility = 'hidden';

			classObjectElement = document.createAttribute('class');
			classObjectElement.nodeValue = 'swatchTextAvail';
			$( 'size'+this.curSize ).setAttributeNode(classObjectElement);
		}
		if( isAvailable && this.curSize != i ) {
			$('sizetext').style.display = 'none';
			Event.stopObserving( $('addToCartBtn'), 'click', this.PushButton );	
			this.curSize = i;
			//this.updateDetailBox();
			this.updateBuyBox(i);
			this.updateQuanranteHuitHeure();

			if( $('SelectUKquantite') != null )
				this.changeSelectQuantity();
				
			this.PushButton = this.addToCartFunction.bind( this );
			Event.observe( $('addToCartBtn') , 'click' , this.PushButton );
		}
		
	},
	
	updateQuanranteHuitHeure: function(){
		if( $('livraison48') != null ){
			if( this.curHoverSize == -1 ){
				if( this.jsonText.livraison48 == 'true' ){
					$('livraison48').style.visibility = 'visible';
				}else{
					if( this.curSize == -1 )
						$('livraison48').style.visibility = 'hidden';
					else{
						if( this.imageLivr[this.curSize] == 'oui' ){
							$('livraison48').style.visibility = 'visible';
						}else{
							$('livraison48').style.visibility = 'hidden';
						}
					}
				}
			}else{
				var isAvailable = this.checkSizeAvailable( this.curHoverSize );
				var visibility = $('livraison48').getStyle('visibility');
				if( isAvailable ){
					if( this.imageLivr[this.curHoverSize] == 'oui' ){
						$('livraison48').style.visibility = 'visible';
					}else{
						$('livraison48').style.visibility = 'hidden';
					}
				}
			}
		}
	},
	
	updateTextDdaa : function( i ){
		var isAvailable = this.checkSizeAvailable(i);
		var ddaa = $('ddaa');
		var newText;

		if( isAvailable )
			this.updateBuyBox(i);

		if( ddaa.hasChildNodes() )
			ddaa.removeChild( ddaa.firstChild );
		
		
		if( this.curSize != -1 && this.curHoverSize  == -1 ){
			newText = this.traduc.selection+' : '+this.mySC[this.curSize].avail;
		}else if( this.curHoverSize  != -1 && isAvailable ){
			newText = this.traduc.selection+' : '+this.mySC[i].avail;
		}else if( this.curSize  == -1 && this.curHoverSize == -1 ){
			newText = this.traduc.choisirtaille;
		}else
			newText = this.traduc.stocknul;

		ddaa.innerHTML = newText;
	},
	
	updateDrawSize: function( objectElement , i ) {

		var isAvailable = this.checkSizeAvailable(i);
		if( isAvailable && this.curSize == i ){
			myClass = 'swatchTextActive';
		}else if( isAvailable && this.curHoverSize == -1 ){
			myClass = 'swatchTextAvail';
		}else if( isAvailable && this.curHoverSize == i ){
			myClass = 'swatchTextHover';
		}else{
			myClass = 'swatchTextUnavail';
		}

		objectElement.removeAttribute('class');;
		classObjectElement = document.createAttribute('class');
		classObjectElement.nodeValue = myClass;
		objectElement.setAttributeNode(classObjectElement);

	},
	
	updateBuyBox : function(i){
		if( this.curHoverSize == -1 ){
			if( this.mySC != null ){
				var h = 0;
				while( typeof( this.mySC[h] ) == 'undefined' ){
					h++;
				}
			}else
				h = i;

			i = this.curSize != -1 ? this.curSize : ( this.mySC != null && typeof( this.mySC[0] ) != 'undefined' ) ? 0 : h;
		}
		

		if( this.jsonText.cadeau == 'false' ){
			priceRange = this.getPriceRange();
			
			$("ddmp").innerHTML =  priceRange;
			if( this.mySC != null && typeof( this.mySC[i] ) != 'undefined' ){
				if( this.mySC[i].listprice != this.mySC[i].price ){
					$('buyboxprice').style.display = 'block';
					$("ddlp").innerHTML = traduc.devise1+formatPrice(this.mySC[i].listprice)+' '+traduc.devise2;
					 if ($("ddcp") != null){
                        if( ( this.mySC[i].catalogprice != this.mySC[i].listprice ) && this.mySC[i].catalogprice != this.mySC[i].price  && ( parseFloat(this.mySC[i].catalogprice) > parseFloat(this.mySC[i].price) ) ) { //TGX&& this.jsonText.soldes == 1 ){
							$("ddcp").innerHTML = this.traduc.devise1+formatPrice( this.mySC[i].catalogprice )+' '+this.traduc.devise2;
                            if (this.jsonText.soldes == 1 || this.jsonText.troisprix == 1)
                                $("ddcp").parentNode.style.display = 'block';
						} else {
                            $("ddcp").parentNode.style.display = 'none';
                        }
					}
				}else{
					$('buyboxprice').style.display = 'none';
					if( typeof( $('portOffert') ) != 'undefined' )
						$('portOffert').style.display = 'block';
				}
				if( $('discount') == 'undefined' )
					$('discount').innerHTML = '(-'+this.calculDiscount( this.mySC[i].price, this.mySC[i].listprice )+'%)';

			}else{
				if( this.jsonText.catalogprice != this.jsonText.listprice ){
					$('buyboxprice').style.display = 'block';
					$("ddlp").innerHTML = traduc.devise1+formatPrice(this.jsonText.listprice)+' '+traduc.devise2;
					 if ($("ddcp") != null){
						if( ( ( this.mySC != null && this.mySC[i].catalogprice != this.mySC[i].listprice ) && this.jsonText.catalogprice != this.jsonText.buyingprice ) && ( parseFloat(this.jsonText.catalogprice) > parseFloat(this.jsonText.buyingprice)  ) ) { //TGX && this.jsonText.soldes == 1 ){
							$("ddcp").innerHTML = this.traduc.devise1+formatPrice( this.jsonText.catalogprice )+' '+this.traduc.devise2;
                            if (this.jsonText.soldes == 1 || this.jsonText.troisprix == 1)
                                $("ddcp").parentNode.style.display = 'block';
						} else {
                            $("ddcp").parentNode.style.display = 'none';
                        }
					}
				}else{
					$('buyboxprice').style.display = 'none';
					if( typeof( $('portOffert') ) != 'undefined' )
						$('portOffert').style.display = 'block';
				}
				if( $('discount') == 'undefined' )
					$('discount').innerHTML = '(-'+this.calculDiscount( this.jsonText.buyingprice, this.jsonText.listprice )+'%)';

				$('quantitybox').style.display = 'none';
				$('addToCartBtn').style.display = 'none';
				//$('addToCartNote').style.display = 'none';
				var elP = document.createElement('p');
				var id = document.createAttribute('id');
				id.nodeValue = 'pIndispo';
				elP.setAttributeNode(id);
				elP.innerHTML = this.jsonText.dispo;
				$('marge').appendChild( elP );
				if( $('my_module_div') != null ){
					$('my_module_div').style.display = 'none';
				}
			}
			
			if( this.jsonText.pwyw == 1 ){
				$('chooseyourprice').style.display = 'block';
				$('chooseyourpriceTitle').style.display = 'block';
				$('ddmp').style.display = 'none';
				if( this.changePrice == -1 )
					$('mypriceinput').value = priceRange;
			}

			/*if( this.jsonText.soldes == 1 ){
				if( $('ddcpp') != null )
					$('ddcpp').style.display = 'block';
			}*/
		}else{
			this.ajoute(null);
		}
	},
	
	calculDiscount : function( sellingPrice , buyingPrice ){
	
		var bp = parseFloat(buyingPrice.replace(',','')) * 10;
		var sp = parseFloat(sellingPrice) * 10;
		var calcul;
		var fin;
		calcul = sp / bp;
		fin = calcul * 100;
		
		/*if( (100-Math.ceil(fin)) <= 25)
			$('gratisShipping').style.visibility='visible';*/
			
		return Math.ceil(100-Math.ceil(fin));
	},
	
	getPriceRange : function() {
		var subsetBuyingPrice = new Array();
		var mySizeIndex = -1;
		var result;
		if( this.curHoverSize != -1 ) {
			mySizeIndex = this.curHoverSize;
		} else if( this.curSize != -1 ) {
			mySizeIndex = this.curSize;
		}

		for( var i = 0; i < this.choices.length; i++ ) {
			if( (typeof this.choices[i].size == 'undefined' || this.choices[i].size == mySizeIndex || mySizeIndex == -1) ) {
				if( typeof this.choices[i].buyingPrice != 'undefined' )
					subsetBuyingPrice[subsetBuyingPrice.length] = this.choices[i].buyingPrice;
			}
		}

		if( subsetBuyingPrice.length > 0 ) {
			var curMin = subsetBuyingPrice[0];
			var curMax = subsetBuyingPrice[0];
			for( var i = 0; i < subsetBuyingPrice.length; i++ ) {
				if( subsetBuyingPrice[i] > curMax ) {
					curMax = subsetBuyingPrice[i];
				} else if( subsetBuyingPrice[i] < curMin ) {
					curMin = subsetBuyingPrice[i];
				}
			}
			if( curMin != curMax ) {
				if( this.jsonText.pwyw == 0 ){
					result = this.traduc.apartir+' '+this.traduc.devise1+formatPrice(curMin)+' '+this.traduc.devise2;
					if( $('aFidelityPoints') != null ){
						$('fidelityPoints').parentNode.style.visibility = 'hidden';
					}
				}else
					result = formatPrice(curMax);
			} else {
				if( this.jsonText.pwyw == 0 ){
					if( $('aFidelityPoints') != null ){
						$('aFidelityPoints').style.visibility = 'visible';
					}
				
					result = this.traduc.devise1+formatPrice(curMin)+' '+this.traduc.devise2;
					if( $('aFidelityPoints') != null && mySizeIndex != -1 ){
						$('fidelityPoints').innerHTML = this.mySC[mySizeIndex].fidelityPoints;
					}
				}else
					result = formatPrice(curMin);
			}
		} else {
            var p = this.jsonText.catalogprice;
            if (typeof this.jsonText.buyingprice != 'undefined') p = this.jsonText.buyingprice;
			if( this.jsonText.pwyw == 0 )
				result = this.traduc.devise1+formatPrice(p)+' '+this.traduc.devise2;
			else
				result = formatPrice( p );
		}
		return result;
	},
	
	ajoute : function( objectElement ){

		var addedASIN = this.getChosenAsin();
		var addedStock = this.getStock();
		
		if( addedStock != null  && this.jsonText.cadeau == 'false' )
			var addedStock = addedStock > 12 ? 12 : addedStock;
		else
			var addedStock = 12;

		nb = document.forms['addtocartform'].elements['quantite'].value;
		
		if( objectElement != null )
			nb++;

		if ( nb > addedStock ) {
			nb = addedStock;
		}
		
		if( this.jsonText.cadeau == 'true' && addedASIN  != null ){
			var regm = new RegExp("(\\d+\\.?\\d*)","gi");
			var price = ( regm.exec(addedASIN.tailleSelect)[0] );
			var tot = price * nb;
			$('ddmp').innerHTML = ''+tot+' &euro;';
		}

		document.forms['addtocartform'].elements['quantite'].value = nb;
	},

	enleve : function() {
		var addedASIN = this.getChosenAsin();
		if( this.PushButton != null )
			Event.observe( $('addToCartBtn') , 'click' , this.PushButton );

		nb = document.forms['addtocartform'].elements['quantite'].value;
		nb--;
		if ( nb < 1 ){
			nb = 1;
		}
	
		if( this.jsonText.cadeau == 'true' && addedASIN  != null ){
			var regm = new RegExp("(\\d+\\.?\\d*)","gi");
			var price = ( regm.exec(addedASIN.tailleSelect)[0] );
			var tot = price * nb;
			$('ddmp').innerHTML = ''+tot+' &euro;';
		}
	
		document.forms['addtocartform'].elements['quantite'].value = nb;
	},

	increasePrice : function(){
		nb = $('mypriceinput').value;

		if( isNaN( nb ) )
			nb = 0;
			
		nb++;
		this.changePrice = 0;
		$('mypriceinput').value = formatPrice( nb );
	},
	
	decreasePrice : function( name,id ){
		nb = $('mypriceinput').value;

		if( isNaN( nb ) )
			nb = 0;

		nb--;
		
		this.changePrice = 0;
		if ( nb < 1 ){
			nb = 1;
		}
		
		$('mypriceinput').value = formatPrice( nb );
		
	},
	
	functionChangePrice : function(){
		this.changePrice = 0;
		Event.stopObserving( $('mypriceinput') , 'change' , this.functionChangePrice );
	},
	
	changeSelectQuantity : function (){
		var select = $('SelectUKquantite');

		if( typeof( select ) != 'undefined' && select.firstChild  != null ){
			while( select.hasChildNodes() ){
				select.removeChild(select.firstChild);
			}

			var addedStock = this.getStock();
			if( addedStock != null )
				var addedStock = addedStock > 12 ? 12 : addedStock;
			else
				var addedStock = 12;

			for ( i=0 ; i < addedStock ; i++ ){
				var option = document.createElement( 'option' );
				var value = document.createAttribute( 'value' );
				var textOption = document.createTextNode( i+1 )
				value.nodeValue = i+1;
				option.setAttributeNode( value );
				option.appendChild( textOption );
				select.appendChild( option );
			}
		}
	},
	
	checkSizeAvailable: function(index) {
		return this.isAvailable(index);
	},

	isAvailable: function( sizeIndex ) {
        var ret = false;
        try {
			ret = this.mySC[sizeIndex] == null ? false : true;
        } catch(e) {}
			return ret;
    },
	
	getChosenAsin:function(){
		var addedASIN=null;
		
		if ( this.curSize != -1 && this.mySC[this.curSize] ){
			addedASIN=this.mySC[this.curSize].asin;

			if( this.jsonText.cadeau  == 'true' ){
				addedASIN = {
								"skuProd" : this.mySC[this.curSize].asin,
								"tailleSelect" : this.sizeLabels[this.curSize]
							}
			}

		}
		
		return addedASIN;
	},

	getStock:function(){
		var addedStock = null;
		if ( this.curSize != -1 && this.mySC[this.curSize] )
			addedStock = this.mySC[this.curSize].stock;
		return addedStock;
	},

getChampsCusto:function(){
		var erreur = false;
		var nb = this.formulaire['nb'];
		
		try{
			for (i=1; i<=nb; i++ ) { 
				if( this.formulaire['custo'+i] == null || this.formulaire['custo'+i] == '' ){
					var txtNom = document.createTextNode('Veuillez renseigner le champ');
					$('idErreurEmail'+i).appendChild(txtNom);
					$('idErreurEmail'+i).style.display = 'block';
					erreur = true;
				}
			}
			custo = 'custo|'+nb ;
			if(erreur == true){
				throw erreur;
			}

			var formulaire = $('formPopupCC').elements;
			for( i = 0 ; i < formulaire.length ; i++ ){				
				createInputHidden(formulaire[i].name, this);
			}
			switch_visibility('none','opacDiv');
			$('idParentCC').parentNode.removeChild($('idParentCC'));
			
		
			miseAuPanier( document.location , null , this.traduc.idRayon,custo );

		}catch(e){
		}
	},
	getChampsChequesCadeau:function(){
		var erreur = false;
		try{
			var errorMail = erreurmail( this );
			if( errorMail != true ){
				var txtEmail = document.createTextNode(errorMail);
				$('idErreurEmail').appendChild(txtEmail);
				$('idErreurEmail').style.display = 'block';
				erreur = true;
			}

			if( erreurDate( this ) != true ){
				var txtDate = document.createTextNode(erreurDate( this ));
				$('idErreurDate').appendChild(txtDate);
				$('idErreurDate').style.display = 'block';
				erreur = true;
			}
			if( this.formulaire['nomCC'] == null || this.formulaire['nomCC'] == '' ){
				var txtNom = document.createTextNode('Veuillez entrer un nom');
				$('idErreurNom').appendChild(txtNom);
				$('idErreurNom').style.display = 'block';
				erreur = true;
			}

			if( this.formulaire['prenomCC'] == null || this.formulaire['prenomCC'] == '' ){
				var txtPrenom = document.createTextNode('Veuillez entrer un prénom');
				$('idErreurPrenom').appendChild(txtPrenom);
				$('idErreurPrenom').style.display = 'block';
				erreur = true;
			}

			if(erreur == true){
				throw erreur;
			}

			var formulaire = $('formPopupCC').elements;
			for( i = 0 ; i < formulaire.length ; i++ ){
				createInputHidden(formulaire[i].name, this);
			}
			switch_visibility('none','opacDiv');
			$('idParentCC').parentNode.removeChild($('idParentCC'));

			miseAuPanier( document.location , 49 , this.traduc.idRayon );

		}catch(e){
		}
	},
	
	hideAlert : function(){
		$('addToCartNote').style.visibility = 'hidden';
	},
	
	showAlertMessage: function(){
        var alertmsg2 = "";
        var alertmsg = "";
		
		if (this.curSize == -1 && this.sizeLabels.length != 0) {
			$('addToCartNote').style.visibility = 'visible';
			/*if( typeof( cadeau ) == 'undefined' ) {
				alertmsg2= traduc.pourajouter;
			} else {
				var newPrix = 0;
				alertmsg2 = ""+newPrix+" &euro;";
			}*/
		}else if ( pwyw == 1 ) {
			var mypriceinput = document.getElementById('mypriceinput');
            if ( mypriceinput != null ) {
				var value = mypriceinput.value;
				var cvalue = parseFloat(value);

                if ( isNaN(cvalue) || cvalue < 1 ) {
					//alertmsg = 'Please check your price';
					$('addToCartNote').childNodes[0].innerHTML = 'Please check your price';
					$('addToCartNote').style.visibility = 'visible';
                } else {
					var input = document.getElementById('myprice');
                    if ( input != null ) {
						input.value = formatPrice(cvalue);
                        mypriceinput.value = formatPrice(cvalue);
					}
				}
			}
		}

		var cursorId;
		cursorId = "addToCartBtn";
		showMouseMessage( alertmsg );
		$(cursorId).style.cursor = "pointer";
	},
	
	gestionOnglet: function(){
		var tabOnglets = document.getElementsByClassName('cadreOnglets');
		var test;
		var widthLast;
		var widthNew;

		for( i = 0 ; i < tabOnglets.length ; i++ ){
			var regm = new RegExp("([a-z])+","gi");
			test = regm.exec( tabOnglets[i].firstChild.data );
			Event.observe( tabOnglets[i] , 'click' , this.moveOnglet.bind( this , tabOnglets[i] , test[0] , tabOnglets ) );
		}
		if( this.jsonText.cadeau == 'true' ){
			widthLast = tabOnglets[i-1].getStyle('width');
			widthNew = $('fakeOne').getStyle('width');
			newWidth = parseInt( widthLast.replace('px','') ) + parseInt( widthNew.replace('px','') );
			tabOnglets[i-1].style.display = 'none';
			$('fakeOne').style.width = newWidth+'px'
		}
	},
	
	moveOnglet:function( obectElement ,  nomId , tabOnglets ){
		
		for( i = 0 ; i < tabOnglets.length ; i++ ){
			var regm = new RegExp("([a-z])+","gi");
			test = regm.exec( tabOnglets[i].firstChild.data );
			if( this.jsonText.shopType == 5 ){
				tabOnglets[i].style.background = '#DDD';
				tabOnglets[i].style.borderBottom = '1px solid #ccc';
			}else{
				tabOnglets[i].style.background = '#EEE';
				tabOnglets[i].style.borderBottom = '1px solid #ccc';
			}
			if( this.jsonText.shopType == 5 )
				tabOnglets[i].style.lineHeight = '23px';
			else
				tabOnglets[i].style.lineHeight = '25px';
			if( $('cadre'+test[0]) != null )
				$('cadre'+test[0]).style.display = 'none';
		}
		if( jsonText.shopType == 5 ){
			obectElement.style.background = 'white';
			obectElement.style.borderBottom = 'none';
		}else{
			obectElement.style.background = 'white';
			obectElement.style.borderBottom = 'none';
		}
		if( this.jsonText.shopType == 5 )
			obectElement.style.lineHeight = '24px';
		else
			obectElement.style.lineHeight = '26px';
		$('cadre'+nomId).style.display = 'block';
		
	},

	addToCartFunction:function() {
		if (pwyw == 0) {
			Event.stopObserving( $('addToCartBtn'), 'click', this.PushButton );
			Event.stopObserving( $('addToCartBtn'), 'mouseout', this.hideButton );
		}
     	var addedASIN = this.getChosenAsin();
		if( addedASIN != null ) {
			if (pwyw == 1) {
				var mypriceinput = document.getElementById('mypriceinput');
				if (mypriceinput != null) {
					var value = mypriceinput.value;
					var cvalue = parseFloat(value);

					if (isNaN(cvalue) || cvalue < 1) {
						return;
					}
				}
			}
			if( this.jsonText.cadeau == 'true' ){
				addedASIN = addedASIN.skuProd;
			}
			document.addtocartform.skuproduct.value=addedASIN;
			
			if ( this.jsonText.customizable == 1 ) {				
				popupCusto( this );				
			}				
			else if( this.jsonText.cadeau == 'true' ){
				popupCC( this );
			}else{
				miseAuPanier( document.location,null, traduc.idRayon);
			}
		}
	},
	
	popupPointsFidelite : function(){
		var divFid;
		var idFid;
		var h1Fid;
		var fermerFid;
		var classFermer;
		var div2Fid;
		var classTexte;
		
		
		divFid = document.createElement('div');
		idFid = document.createAttribute('id');
		idFid.nodeValue = 'divPopupFidelite';
		divFid.setAttributeNode(idFid);
		
		h1Fid = document.createElement('h1');
		h1Fid.innerHTML = 'Gagnez 10&euro; tous les 200&euro; d&acute;achat';
		
		fermerFid = document.createElement('div');
		
		classFermer = document.createAttribute('class');
		classFermer.nodeValue = 'classFermer ';
		fermerFid.setAttributeNode(classFermer );
		fermerFid.innerHTML = 'Fermer <img src="http://media.brandalley.com/cvsmedia/v3/www2/pix/arrows/sup_article.png" align="absmiddle"/>';
		fermerFid.style.cursor = 'pointer';
	
		div2Fid = document.createElement('div');
		classTexte = document.createAttribute('class');
		classTexte.nodeValue = 'classTexte ';
		div2Fid.setAttributeNode( classTexte );
		
		div2Fid.innerHTML = '<p>Entr&eacute;e gratuite dans notre programme de fidélité <span class="bold">apr&egrave;s votre premi&egrave;re commande</span>.</p><p class="espace"> 1&euro; d&acute;achat* = 1 point pour chaque commande d&egrave;s votre deuxi&egrave;me commande. <br />200 points consolid&eacute;s = 10&euro; offerts.</p> <p class="petit">* Ne sont pas comptabilis&eacute;s dans le cumul des points : les articles sold&eacute;s, retourn&eacute;s ou annul&eacute;s, les articles pr&eacute;sents dans les ventes affichant des remises suppl&eacute;mentaires comme les soldes, les commandes ayant b&eacute;n&eacute;fici&eacute; d&acute;un coupon de r&eacute;duction ou d&acute;un ch&egrave;que-cadeau ou d&acute;un bon d&acute;achat, les commandes annul&eacute;es ou retourn&eacute;es, les frais de port.</p> <p>Pour en savoir plus, rendez-vous dans MON COMPTE, rubrique &laquo; Programme de Fid&eacute;lit&eacute; &raquo;</p>'
		
		divFid.appendChild(fermerFid);
		divFid.appendChild(h1Fid);
		divFid.appendChild(div2Fid);
		
		$('page-content').appendChild(divFid);
		
		//Event.stopObserving( $('aFidelityPoints') , 'click', this.popupFid );
		
		$('opacDiv').style.display = "block";
		
		Event.observe( fermerFid , 'click' , this.destroyPopup.bind( this , divFid  ) );
	},
	
	popupPlusBrandalley : function(){
		var divMain;
		var idMain;
		var imgMain;
		var pMain;
		var fermer;
		var classFermer;
		
		fermer = document.createElement('div');
		
		classFermer = document.createAttribute('class');
		classFermer.nodeValue = 'classFermer ';
		fermer.setAttributeNode(classFermer );
		fermer.innerHTML = 'Fermer <img src="http://media.brandalley.com/cvsmedia/v3/www2/pix/arrows/sup_article.png" align="absmiddle"/>';
		fermer.style.cursor = 'pointer';
		
		divMain = document.createElement('div');
		idMain = document.createAttribute('id');
		idMain.nodeValue = 'idMain';
		divMain.setAttributeNode( idMain );
		
		imgMain = document.createElement('img');
		imgMain.src = 'http://media.brandalley.com/shops/3/aide/leplusbrandalley.gif';
		
		pMain = document.createElement('p');
		pMain.innerHTML = 'Brandalley s&acute;engage à exp&eacute;dier votre commande dans la limite du d&eacute;lai pr&eacute;visionnel affich&eacute; lors de l&acute;enregistrement de la commande. Dans le cas o&ugrave; ce d&eacute;lai ne serait pas respect&eacute;, Brandalley s&acute;engage à vous rembourser 1€ par jour de retard, sous forme de coupon de r&eacute;duction et dans la limite de 10&euro;. Ce coupon vous sera remis sur simple demande aupr&egrave;s de notre Service Client.'

		divMain.appendChild(  fermer );
		divMain.appendChild(  imgMain );
		divMain.appendChild(  pMain );
		$('page-content').appendChild( divMain );
		
		$('opacDiv').style.display = "block";
		
		Event.observe( fermer , 'click' , this.destroyPopup.bind( this , divMain ) );
		
	},
	
	destroyPopup : function( objectElement  ){
		$('opacDiv').style.display = "none";
		objectElement.parentNode.removeChild( objectElement );
	},
	
	dernieresCons :function(){
		var image;
		var classImg;
		var titleImg;
		var totalWidth = 0;
		for( var i = 0 ; i < this.derCons.length ; i++ ){
			image = document.createElement( 'img' );
			image.src = this.derCons[i].src;
			classImg = document.createAttribute('class');
			titleImg = document.createAttribute('title');
			titleImg.nodeValue = this.derCons[i].titleUK;
			classImg.nodeValue = 'classImgDerCons';
			image.setAttributeNode(classImg);
			image.setAttributeNode(titleImg);
			$('cadreDijavouImg').appendChild( image );
			Event.observe( image , 'click' , this.derConsLocation.bind( this , this.derCons[i].href ) );

			if( i >= 6 )
				totalWidth += image.width+10;
		}

		if( i > 6 ){
			leftPos = this.carrousselValue == null ? $('cadreDijavouImg').getStyle('left') : this.carrousselValue;
			this.carLeft = carrousselLeft.bind( this ,  parseFloat( leftPos ) , this , totalWidth);
			this.carRight = carrousselRight.bind( this ,  parseFloat( leftPos ) , this ,totalWidth );
			Event.observe( $('imgFlLeft') , 'mouseover' , this.carLeft );
			Event.observe( $('imgFlRight') , 'mouseover' , this.carRight );
		}
	},

	derConsLocation : function( href ){
		document.location = href;
	}

}

var timeCarLeft;
function carrousselLeft( value , object  ,totalWidth){
	var posDiv = value-8;

	Event.stopObserving( $('imgFlLeft') , 'mouseover' , object.carLeft );
	Event.stopObserving( $('imgFlRight') , 'mouseover' , object.carRight );
	object.carLeft = carrousselLeft.bind( this ,  posDiv , object , totalWidth );
	object.carRight = carrousselRight.bind( this ,  posDiv , object ,totalWidth );
	Event.observe( $('imgFlLeft') , 'mouseover' , object.carLeft );
	Event.observe( $('imgFlRight') , 'mouseover' , object.carRight );
	
	Event.observe( $('imgFlLeft') , 'mouseout' , clearCarLeft.bind( this ) );
		
	$('cadreDijavouImg').style.left = posDiv+'px';

	if(  posDiv > -totalWidth ){
		timeCarLeft = setTimeout( function(){carrousselLeft(posDiv,object,totalWidth);} , 1 );
	}else{
		posDiv = -totalWidth;
		$('cadreDijavouImg').style.left = posDiv+'px';
		clearTimeout( timeCarLeft );
		Event.stopObserving( $('imgFlLeft') , 'mouseover' , object.carLeft );
	}
}

var timeCarRight;
function carrousselRight( value , object ,totalWidth ){

	var posDiv = value+8;
	Event.stopObserving( $('imgFlLeft') , 'mouseover' , object.carLeft );
	Event.stopObserving( $('imgFlRight') , 'mouseover' , object.carRight );
	object.carLeft = carrousselLeft.bind( this ,  posDiv , object ,totalWidth );
	object.carRight = carrousselRight.bind( this ,  posDiv , object ,totalWidth );
	Event.observe( $('imgFlLeft') , 'mouseover' , object.carLeft );
	Event.observe( $('imgFlRight') , 'mouseover' , object.carRight );

	Event.observe( $('imgFlRight') , 'mouseout' , clearCarRight.bind( this ) );

	if(  posDiv < 0  ){
		$('cadreDijavouImg').style.left = posDiv+'px';
		timeCarRight = setTimeout( function(){ carrousselRight( posDiv , object ,totalWidth); } , 1  );
	}else{
		posDiv = 0;
		$('cadreDijavouImg').style.left = posDiv+'px';
		clearTimeout( timeCarRight );
	}
}

function clearCarLeft(){
	clearTimeout( timeCarLeft );
}

function clearCarRight(){
	clearTimeout( timeCarRight );
}

var ficheoffsetfrommouse = [15,-80];		// espace entre le curseur de la souris et l'image
var fichedisplayduration = 0;				// duree pendant laquelle reste présente l'image, mettre 0 pour toujours
var fichecurrentimageheight = 20;			// taille de l'image

if (document.getElementById || document.all) {
		document.write('<div id="mousemessagediv" class="cadre3 cadre_vip fiche_fond_couleur fiche_stock_texte">');
		document.write('</div>');
}

function truebody() {
		return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function showMouseMessage(txt) {

    if (txt == null || txt == "" || txt == "undefined") return;
        document.onmousemove = fichefollowmouse;
		$('mousemessagediv').innerHTML = '<span>' + txt + '</span>';
		$('mousemessagediv').style.visibility = 'visible';
}

function hideMouseMessage() {
		$('mousemessagediv').style.visibility = 'hidden';
		document.onmousemove = '';
		$('mousemessagediv').style.left = '-500px';
}

function fichefollowmouse(e) {

		var xcoord = ficheoffsetfrommouse[0];
		var ycoord = ficheoffsetfrommouse[1];

		var docwidth = document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15;
		var docheight = document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight);
		if (docwidth > 955) {
				docwidth = 955;
		}

		/* ff */
		if (typeof e != "undefined") {
				if (docwidth - e.pageX < 200) {
						xcoord = e.pageX - xcoord - 200; // Move to the left side of the cursor
				} else {
						xcoord += e.pageX;
				}
				if (docheight - e.pageY + 100 < (fichecurrentimageheight)){
				/*if (docheight - e.pageY < (fichecurrentimageheight + 110)){*/
						/*ycoord += e.pageY - Math.max(0,(110 + fichecurrentimageheight + e.pageY - docheight - truebody().scrollTop));*/
						ycoord += e.pageY - Math.max(0,(fichecurrentimageheight + e.pageY - docheight - truebody().scrollTop));
				} else {
						ycoord += e.pageY + 100;
				}
		/* ie */
		} else if (typeof window.event != "undefined") {
				if (docwidth - event.clientX < 200) {
						xcoord = event.clientX + truebody().scrollLeft - xcoord - 200; // Move to the left side of the cursor
				} else {
						xcoord += truebody().scrollLeft+event.clientX
				}
				if (docheight - event.clientY + 100 < (fichecurrentimageheight)) {
				/*if (docheight - event.clientY < (fichecurrentimageheight + 110)) {*/
						ycoord += event.clientY + truebody().scrollTop - Math.max(0,(fichecurrentimageheight + event.clientY - docheight));
						/*ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + fichecurrentimageheight + event.clientY - docheight));*/
				} else {
						ycoord += truebody().scrollTop + event.clientY + 100;
				}
		}

		var docwidth = document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15;
		var docheight = document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);
		if(ycoord < 0) {
				/*ycoord = ycoord*-1;*/
				ycoord = ycoord*-1;
		}
		$('mousemessagediv').style.left = xcoord+"px";
		$('mousemessagediv').style.top = ycoord+"px";

}

function popupCusto( detailController ){ 

	var property = this.jsonText.customizableProperties;
	var properties = property.split( '|');
	
	switch_visibility('block','opacDiv');
	var divParent = document.createElement('div');
	var idParent = document.createAttribute("id");
	
	idParent.nodeValue = 'idParentCC';
	divParent.setAttributeNode( idParent );
	$('page_container').appendChild(divParent);
	
	var annule = document.createElement('p');
	var idAnnule = document.createAttribute('id');
	var annuleText = document.createTextNode('Annuler');
	idAnnule.nodeValue = 'annuleText';
	annule.setAttributeNode(idAnnule);
	annule.appendChild(annuleText);
	divParent.appendChild(annule);

	var formul = document.createElement('form');
	var nameForm = document.createAttribute('name');
	var idForm = document.createAttribute('id');
	nameForm.nodeValue = 'formPopupCC';
	idForm.nodeValue = 'formPopupCC';
	formul.setAttributeNode(nameForm);
	formul.setAttributeNode(idForm);

	var pIntro = document.createElement('p');
	var txtIntro = document.createTextNode('Si vous ne souhaitez pas écrire de message, mettez un espace dans le(s) champs ci-dessous.');
	var classpIntro = document.createAttribute('class');
	classpIntro.nodeValue = 'pIntro';
	pIntro.setAttributeNode(classpIntro);
	pIntro.appendChild(txtIntro);
	formul.appendChild(pIntro);
	
		for (i=1; i<properties.length; i++){
				var labelEmail = document.createElement('label');
				var txtEmail = document.createTextNode('Message médaillon '+ i +' (10 caractères maximum)');
				var inputEmail = document.createElement('input');
				var nameEmail = document.createAttribute('name');
				var valueEmail = document.createAttribute('value');
				
				nameEmail.nodeValue = 'custo'+ i;
		
				if( detailController.formulaire[ 'custo'+ i] != null && detailController.formulaire[ 'custo'+ i] != '' )
					valueEmail.nodeValue = detailController.formulaire[ 'custo'+ i];
				else
					valueEmail.nodeValue = 'Tapez votre texte ici';
				
				inputEmail.setAttributeNode( nameEmail );
				inputEmail.setAttributeNode( valueEmail );
				labelEmail.appendChild(txtEmail);
				labelEmail.appendChild(inputEmail);
				
				formul.appendChild(labelEmail);
				
				
				var erreurEmail = document.createElement('p');
				var classError = document.createAttribute('class')
				var iderreurEmail = document.createAttribute('id')
				classError.nodeValue = 'erreur';
				iderreurEmail.nodeValue = 'idErreurEmail'+i;
				erreurEmail.setAttributeNode(classError);
				erreurEmail.setAttributeNode(iderreurEmail);
				erreurEmail.style.display = 'none';
						
				formul.appendChild(erreurEmail);
				
				if( detailController.formulaire['custo'+ i] == null || detailController.formulaire['custo'+ i] == '' ) 
					Event.observe(inputEmail , 'focus' , valueNull );	
				
					Event.observe(inputEmail, 'keydown' , annuleEvent );
					Event.observe(inputEmail, 'keydown' , limitenb );
		}
			
		var inputHidden = document.createElement('input');
		var typeInputHidden = document.createAttribute('type');
		var valueInputHidden = document.createAttribute('value');	
		var nameInputHidden = document.createAttribute('name');
		typeInputHidden.nodeValue = 'hidden';
		valueInputHidden.nodeValue = i-1 ;
		nameInputHidden.nodeValue = 'nb' ;
		
		inputHidden.setAttributeNode(typeInputHidden);
		inputHidden.setAttributeNode(valueInputHidden);
		inputHidden.setAttributeNode(nameInputHidden);
		
		formul.appendChild(inputHidden);
		
		var inputSub = document.createElement('input');
		var classInputSub = document.createAttribute('class');
		var typeInputSub = document.createAttribute('type');
		var valueInputSub = document.createAttribute('value');		
		classInputSub.nodeValue = 'pSub';
		typeInputSub.nodeValue = 'button';
		valueInputSub.nodeValue = 'Valider les informations';		
		inputSub.setAttributeNode(classInputSub);
		inputSub.setAttributeNode(typeInputSub);
		inputSub.setAttributeNode(valueInputSub);
	
		formul.appendChild(inputSub);		
		
		divParent.appendChild(formul);
		Event.observe(annule, 'click' , closeUp.bind( this , detailController ) );
		Event.observe(inputSub, 'click' , subPopupCusto.bind( this , detailController ) );
		
}
function popupCC( detailController ){

	switch_visibility('block','opacDiv');
	var divParent = document.createElement('div');
	var idParent = document.createAttribute("id");
	idParent.nodeValue = 'idParentCC';
	divParent.setAttributeNode( idParent );
	$('page_container').appendChild(divParent);
	var annule = document.createElement('p');
	var idAnnule = document.createAttribute('id');
	idAnnule.nodeValue = 'annuleText';
	annule.setAttributeNode(idAnnule);
	var annuleText = document.createTextNode('Annuler');
	annule.appendChild(annuleText);
	divParent.appendChild(annule);

	var formul = document.createElement('form');
	var nameForm = document.createAttribute('name')
	var idForm = document.createAttribute('id')
	nameForm.nodeValue = 'formPopupCC';
	idForm.nodeValue = 'formPopupCC';
	formul.setAttributeNode(nameForm);
	formul.setAttributeNode(idForm);

	var labelEmail = document.createElement('label');
	var txtEmail = document.createTextNode('Adresse email du bénéficiaire');

	var inputEmail = document.createElement('input');
	var nameEmail = document.createAttribute('name');
	var valueEmail = document.createAttribute('value');
	nameEmail.nodeValue = 'emailCC';

	if( detailController.formulaire['emailCC'] != null && detailController.formulaire['emailCC'] != '' )
		valueEmail.nodeValue = detailController.formulaire['emailCC'];
	else
		valueEmail.nodeValue = 'Entrez ici l\'adresse email du bénéficiaire du chèque cadeau';

	inputEmail.setAttributeNode( nameEmail );
	inputEmail.setAttributeNode( valueEmail );
	labelEmail.appendChild(txtEmail);
	labelEmail.appendChild(inputEmail);

	var labelNom = document.createElement('label');
	var txtNom = document.createTextNode('Nom du bénéficiaire');

	var inputNom = document.createElement('input');
	var nameNom = document.createAttribute('name');
	var valueNom = document.createAttribute('value');
	nameNom.nodeValue = 'nomCC';

	if( detailController.formulaire['nomCC'] != null && detailController.formulaire['nomCC'] != '' )
		valueNom.nodeValue = detailController.formulaire['nomCC'];
	else
		valueNom.nodeValue = 'Entrez ici le nom du bénéficiaire du chèque cadeau';

	inputNom.setAttributeNode( nameNom );
	inputNom.setAttributeNode( valueNom );
	labelNom.appendChild(txtNom);
	labelNom.appendChild(inputNom);

	var labelPrenom = document.createElement('label');
	var txtPrenom = document.createTextNode('Prénom du bénéficiaire');

	var inputPrenom = document.createElement('input');
	var namePrenom = document.createAttribute('name');
	var valuePrenom = document.createAttribute('value');
	namePrenom.nodeValue = 'prenomCC';

	if( detailController.formulaire['prenomCC'] != null && detailController.formulaire['prenomCC'] != '' )
		valuePrenom.nodeValue = detailController.formulaire['prenomCC'];
	else
		valuePrenom.nodeValue = 'Entrez ici le prénom du bénéficiaire du chèque cadeau';

	inputPrenom.setAttributeNode( namePrenom );
	inputPrenom.setAttributeNode( valuePrenom );
	labelPrenom.appendChild(txtPrenom);
	labelPrenom.appendChild(inputPrenom);

	var labelTextarea = document.createElement('label');
	var txtTextarea = document.createTextNode('Votre texte (255 caractères maximum)');

	var textarea = document.createElement('textarea');
	var nameTextarea = document.createAttribute('name');
	var id = document.createAttribute('id');
	nameTextarea.nodeValue = 'texteCC';
	id.nodeValue = 'textarea';

	if( detailController.formulaire['texteCC'] != null && detailController.formulaire['texteCC'] != '' )
		var textPresArea =  document.createTextNode( detailController.formulaire['texteCC'] );
	else
		var textPresArea =  document.createTextNode('Tapez votre texte ici. Il sera affiché sur le mail destiné au bénéficiaire');

	textarea.setAttributeNode( nameTextarea );
	textarea.setAttributeNode( id );
	textarea.appendChild( textPresArea );
	labelTextarea.appendChild(txtTextarea);
	labelTextarea.appendChild(textarea);

	var erreurEmail = document.createElement('p');
	var classError = document.createAttribute('class')
	var iderreurEmail = document.createAttribute('id')
	classError.nodeValue = 'erreur';
	iderreurEmail.nodeValue = 'idErreurEmail';
	erreurEmail.setAttributeNode(classError);
	erreurEmail.setAttributeNode(iderreurEmail);
	erreurEmail.style.display = 'none';

	var erreurNom = document.createElement('p');
	var classError = document.createAttribute('class')
	var iderreurNom = document.createAttribute('id')
	classError.nodeValue = 'erreur';
	iderreurNom.nodeValue = 'idErreurNom';
	erreurNom.setAttributeNode(classError);
	erreurNom.setAttributeNode(iderreurNom);
	erreurNom.style.display = 'none';

	var erreurPrenom = document.createElement('p');
	var classError = document.createAttribute('class')
	var iderreurPrenom = document.createAttribute('id')
	classError.nodeValue = 'erreur';
	iderreurPrenom.nodeValue = 'idErreurPrenom';
	erreurPrenom.setAttributeNode(classError);
	erreurPrenom.setAttributeNode(iderreurPrenom);
	erreurPrenom.style.display = 'none';

	formul.appendChild(labelEmail);
	formul.appendChild(erreurEmail);
	formul.appendChild(labelNom);
	formul.appendChild(erreurNom);
	formul.appendChild(labelPrenom);
	formul.appendChild(erreurPrenom);
	formul.appendChild(labelTextarea);

	/*var pTexteDate = document.createElement('p');
	var classTexteDate = document.createAttribute('class');
	classTexteDate.nodeValue = 'pTexteDate';
	pTexteDate.setAttributeNode(classTexteDate);
	var texteDate = document.createTextNode('Le chèque-cadeau sera expédié par email dès validation de la commande.');
	var insBR = document.createElement('br');
	var clic = document.createTextNode(' Si vous souhaitez l’adresser un autre jour, ');
	var spanDate = document.createElement('span');
	var classSpan = document.createAttribute('class');
	classSpan.nodeValue = 'pSpan';
	spanDate.setAttributeNode(classSpan);
	var textSpan = document.createTextNode('cliquez ici');

	pTexteDate.appendChild(texteDate);
	pTexteDate.appendChild(insBR);
	pTexteDate.appendChild(clic);
	spanDate.appendChild( textSpan )
	pTexteDate.appendChild(spanDate);

	formul.appendChild(pTexteDate);*/
	//formul.appendChild(presDate);
	formul.appendChild(createDate( detailController ));

	var inputSub = document.createElement('input');
	var classInputSub = document.createAttribute('class');
	var typeInputSub = document.createAttribute('type');
	var valueInputSub = document.createAttribute('value');
	classInputSub.nodeValue = 'pSub';
	typeInputSub.nodeValue = 'button';
	valueInputSub.nodeValue = 'Valider les informations';
	inputSub.setAttributeNode(classInputSub);
	inputSub.setAttributeNode(typeInputSub);
	inputSub.setAttributeNode(valueInputSub);

	formul.appendChild(inputSub);

	divParent.appendChild(formul);
	Event.observe(annule, 'click' , closeUp.bind( this , detailController ) );

	if( detailController.formulaire['emailCC'] == null || detailController.formulaire['emailCC'] == '' )
		Event.observe(inputEmail, 'focus' , valueNull );

	if( detailController.formulaire['nomCC'] == null || detailController.formulaire['nomCC'] == '' )
		Event.observe(inputNom, 'focus' , valueNull );

	if( detailController.formulaire['prenomCC'] == null || detailController.formulaire['prenomCC'] == '' )
		Event.observe(inputPrenom, 'focus' , valueNull );

	if( detailController.formulaire['texteCC'] == null || detailController.formulaire['texteCC'] == '' )
		Event.observe(textarea, 'focus' , valueNull );

	Event.observe(textarea, 'keydown' , limite );
	Event.observe(inputEmail, 'keydown' , annuleEvent );
	Event.observe(inputNom, 'keydown' , annuleEvent );
	Event.observe(inputPrenom, 'keydown' , annuleEvent );
	Event.observe(textarea, 'keydown' , annuleEvent );
	//Event.observe(spanDate, 'click' , afficheDate );
	Event.observe(inputSub, 'click' , subPopup.bind( this , detailController ) );


}

function limitenb(e){
	var zone = Event.element(e);
	var max = 10 ;
	if(zone.value.length>=max){
		zone.value=zone.value.substring(0,max);
	}
}
function limite(e){
	var zone = Event.element(e);
	var max = 255;
	if(zone.value.length>=max){
		zone.value=zone.value.substring(0,max);
	}
}

function annuleEvent(e){
	Event.stopObserving(Event.element(e), 'focus', valueNull );
}

function afficheDate(){
	$('blockDate').style.display = 'block';
	//$('idDate').style.display = 'block';
}

function valueNull(e){
	var zone = Event.element(e);
	zone.value = '';
}

function closeUp( detailController ){
	Event.observe( $('addToCartBtn'), 'click', detailController.PushButton );
	var formulaire = $('formPopupCC').elements;

	for( i = 0 ; i < formulaire.length ; i++ ){
		var expression = /(^Entrez ici l\'adresse email.+)|(^Tapez votre texte ici\..+)|(^Entrez ici le nom.+)|(^Entrez ici le prénom.+)/i;
		if( !expression.test( formulaire[i].value ) )
			detailController.formulaire[formulaire[i].name] = formulaire[i].value;
			//detailController.getChampsChequesCadeau(formulaire[i].name);
	}

	switch_visibility('none','opacDiv');
	$('idParentCC').parentNode.removeChild($('idParentCC'));
}

function createDate( detailController ){

	var temps = new Date();
	var annee = temps.getYear();
	if(annee < 999) annee+=1900;
	var mois = temps.getMonth();
	var jour = temps.getDate();

	var absolu_maintenant = temps.getTime();
	var absolu_ensuite = absolu_maintenant + (90*24*60*60*1000);
	temps.setTime(absolu_ensuite);
	var anneeAv = temps.getYear();
	if(anneeAv < 999) anneeAv+=1900;
	var moisAv = temps.getMonth() + 1;
	var moisNames = new Array( 'Janvier', 'Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre');

	var p = document.createElement('p');
	var idDate = document.createAttribute('id');
	idDate.nodeValue ='idDate';
	p.setAttributeNode(idDate);

	var selectDay = document.createElement('select');
	var nameDay = document.createAttribute('name');
	nameDay.nodeValue = 'nameDay';
	selectDay.setAttributeNode(nameDay);
	selectDay.style.width = '44px';

	var selectMois = document.createElement('select');
	var nameMois = document.createAttribute('name');
	nameMois.nodeValue = 'nameMois';
	selectMois.setAttributeNode(nameMois);
	selectMois.style.width = '44px';

	var selectYear = document.createElement('select');
	var nameYear = document.createAttribute('name');
	nameYear.nodeValue = 'nameYear';
	selectYear.setAttributeNode(nameYear);
	selectYear.style.width = '57px';

	for( h = 1 ; h <= 31 ; h++ ){

		if( (h) < 10 )
			nbrD = '0'+(h);
		else
			nbrD = h;

		option = document.createElement('option');
		value = document.createAttribute('value');
		value.nodeValue = nbrD;
		option.setAttributeNode(value);

		if( detailController.formulaire['nameDay'] != null && detailController.formulaire['nameDay'] == h ){
			sel = document.createAttribute('selected');
			sel.nodeValue = 'selected';
			option.setAttributeNode(sel);
		}else{
			if( h == jour ){
				sel = document.createAttribute('selected');
				sel.nodeValue = 'selected';
				option.setAttributeNode(sel);
			}
		}

		txtDay = document.createTextNode( nbrD );
		option.appendChild(txtDay);
		selectDay.appendChild(option);
	}
	
	for( i = mois ; i < moisNames.length ; i++ ){
		/*if( i == 11 ){
			option = document.createElement('option');
			value = document.createAttribute('value');
			value.nodeValue = i+1;
			option.setAttributeNode(value);

		if( detailController.formulaire['nameMois'] != null && detailController.formulaire['nameMois'] == i+1 ){
			sel = document.createAttribute('selected');
			sel.nodeValue = 'selected';
			option.setAttributeNode(sel);
		}

			txtMois = document.createTextNode( i+1 );
			option.appendChild(txtMois);
			selectMois.appendChild(option);
			i = 0;
		}*/

		if( (i+1) < 10 )
			nbr = '0'+(i+1);
		else
			nbr = i+1;

		option = document.createElement('option');
		value = document.createAttribute('value');
		value.nodeValue = nbr;
		option.setAttributeNode(value);
		if( detailController.formulaire['nameMois'] != null && detailController.formulaire['nameMois'] == i+1 ){
			sel = document.createAttribute('selected');
			sel.nodeValue = 'selected';
			option.setAttributeNode(sel);
		}

		txtMois = document.createTextNode( nbr );
		option.appendChild(txtMois);

		selectMois.appendChild(option);

		if( i == moisAv-1 )
			break;

	}

	for( j = annee ; j <= anneeAv ; j++ ){
		option = document.createElement('option');
		value = document.createAttribute('value');
		value.nodeValue = j;
		option.setAttributeNode(value);
		if( detailController.formulaire['nameYear'] != null && detailController.formulaire['nameYear'] == j ){
			sel = document.createAttribute('selected');
			sel.nodeValue = 'selected';
			option.setAttributeNode(sel);
		}
		txtYear = document.createTextNode( j );
		option.appendChild(txtYear);
		selectYear.appendChild(option);
	}

	var blockDate = document.createElement('p');
	var idBlockDate = document.createAttribute('id');
	idBlockDate.nodeValue ='blockDate';
	blockDate.setAttributeNode(idBlockDate);

	var presDate = document.createElement('p');
	var idPresDate = document.createAttribute('class');
	idPresDate.nodeValue ='presDate';
	presDate.setAttributeNode(idPresDate);
	var txtEmail = document.createTextNode('Date d\'expédition souhaitée : ');
	presDate.appendChild(txtEmail);

	var erreurDate = document.createElement('p');
	var classError = document.createAttribute('class')
	var iderreurDate = document.createAttribute('id')
	classError.nodeValue = 'erreur';
	iderreurDate.nodeValue = 'idErreurDate';
	erreurDate.setAttributeNode(classError);
	erreurDate.setAttributeNode(iderreurDate);
	erreurDate.style.display = 'none';


	p.appendChild(selectDay);
	p.appendChild(selectMois);
	p.appendChild(selectYear);
	blockDate.appendChild(presDate);
	blockDate.appendChild(p);
	blockDate.appendChild(erreurDate);

	/*if( ( detailController.formulaire['nameDay'] == jour && detailController.formulaire['nameMois'] == mois + 1 && detailController.formulaire['nameYear'] == annee ) || ( detailController.formulaire['nameDay'] == null && detailController.formulaire['nameMois'] == null && detailController.formulaire['nameYear'] == null ) ){
		blockDate.style.display = 'none';
	}*/

	return blockDate;
}

function subPopup( detailController ){

	var formulaire = $('formPopupCC').elements;

	var erreurTab = document.getElementsByClassName('erreur');

	for( h = 0 ; h < erreurTab.length ; h++ ){
		erreurTab[h].style.display = 'none';
		if( erreurTab[h].hasChildNodes() )
			erreurTab[h].removeChild( erreurTab[h].firstChild );
	}

	for( i = 0 ; i < formulaire.length ; i++ ){
		var expression = /(^Entrez ici l\'adresse email.+)|(^Tapez votre texte ici\..+)|(^Entrez ici le nom.+)|(^Entrez ici le prénom.+)/i;
		if( !expression.test( formulaire[i].value ) )
			detailController.formulaire[formulaire[i].name] = formulaire[i].value;
		else
			detailController.formulaire[formulaire[i].name] = '';

	}

	detailController.getChampsChequesCadeau();
}
function subPopupCusto( detailController ){

	var formulaire = $('formPopupCC').elements;

	var erreurTab = document.getElementsByClassName('erreur');

	for( h = 0 ; h < erreurTab.length ; h++ ){
		erreurTab[h].style.display = 'none';
		if( erreurTab[h].hasChildNodes() )
			erreurTab[h].removeChild( erreurTab[h].firstChild );
	}

	for( i = 0 ; i < formulaire.length ; i++ ){
		var expression = /(^Tapez votre texte ici+)/i;
		if( !expression.test( formulaire[i].value ) )
			detailController.formulaire[formulaire[i].name] = formulaire[i].value;
		else
			detailController.formulaire[formulaire[i].name] = '';
	}

	detailController.getChampsCusto();
}

function erreurDate( detailController ){

	var dateToday = new Date();

	var jourToday = dateToday.getDate();
	var moisToday = dateToday.getMonth();
	var yearToday = dateToday.getYear();
	if(yearToday < 999) yearToday+=1900;

	var absolu_maintenant = dateToday.getTime();
	var absolu_ensuite = absolu_maintenant + (90*24*60*60*1000);
	dateToday.setTime(absolu_ensuite);
	var jourMax = dateToday.getDate();
	var moisMax = dateToday.getMonth();
	var yearMax = dateToday.getYear();
	if(yearMax < 999) yearMax+=1900;

	var jourChosen = detailController.formulaire['nameDay'];
	var moisChosen = detailController.formulaire['nameMois']-1;
	var yearChosen = detailController.formulaire['nameYear'];

	var trueDate = Date.UTC( yearToday , moisToday , jourToday );
	var maxDate = Date.UTC( yearMax , moisMax , jourMax );
	var choiceDate = Date.UTC( yearChosen , moisChosen , jourChosen );


	if( choiceDate < trueDate ){
		return 'Date invalide';
	}else if( choiceDate > maxDate ){
		return 'Date maximum : '+jourMax+'/'+(moisMax+1)+'/'+yearMax;
	}else
		return true;
}

function erreurmail( detailController ){
	if( detailController.formulaire['emailCC'] != null && detailController.formulaire['emailCC'] != '' ){
		var verif = /^[a-zA-Z0-9_-]+[.]{0,1}[a-zA-Z0-9_-]{0,}@[a-zA-Z0-9-]{2,}([.][a-zA-Z]{2,3}){1,2}/;
		var testmail = verif.test(detailController.formulaire['emailCC'] );
		//var testmail = detailController.formulaire['emailCC'];
		if ( !testmail ){
			return 'Email incorrect !';
		}

	}else{
		return 'Veuillez entrer un email !';
	}

	return true;
}

function createInputHidden(nameInput, detailController){
	/*var input = document.createElement('input');
	var type = document.createAttribute('type');
	var name = document.createAttribute('name');
	var value = document.createAttribute('value');
	name.nodeValue = nameInput;
	type.nodeValue = 'hidden';
	value.nodeValue = detailController.formulaire[nameInput];
	input.setAttributeNode(name);
	input.setAttributeNode(type);
	name.nodeValue = nameInput;
	input.setAttributeNode(value);*/
	if( typeof( document.forms['addtocartform'].elements[nameInput] ) != 'undefined' )
		document.forms['addtocartform'].elements[nameInput].value  = detailController.formulaire[nameInput];
}