﻿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( typeof( popupChek ) != 'undefined' ){
	var extended = popupChek;
}else
	var extended = insertPanier;

var _DetailController = Class.create( extended , {

	initialize: function( $super ){
		$super();
		this.timeCarLeft = null;
		this.timeCarRight = null;
		this.curSize = -1;
		this.curHoverSize = -1;
		this.changePrice = -1;
		this.hideButton = null;
		this.heightCenter2 = null;
		this.tabImage = new Array();
		this.formulaire = new Array();

		var classZoom = document.getElementsByClassName( 'mouseoverZoom' );
		for( var i = 0 ; i < classZoom.length ; i++ ){
			var newsrc = classZoom[i].src.replace( '85x85' , '350x350' );
			this.tabImage[i] = new Image();
			this.tabImage[i].src = newsrc;
			classZoom[i].observe( 'mouseover' , this.mouseoverZoom.bindAsEventListener( this , i ) );
		}

	},

	neededForGetTaillesFiche:function(){

		var sendJson = {};
		sendJson.idRayonPourFiche = idRayonPourFiche;
		sendJson.Pt = Pt;
		sendJson.url = conciergerie.encode( document.location );

    	var jsonElements = {
    						'url':'/Ajax=getTaillesFiches',
    						'myClass':this,
    						'myMethod':'getTaillesFiche()',
    						'parametres' : sendJson
    					};

    	ajaxReq = new _AjaxElements( jsonElements );
    	ajaxReq.getAjaxInformations();
	},

	getTaillesFiche:function(){
		var pere = this.json;
		var jsonText;
		var oneSize = new Array();
		var devise1 = isSet( pere.devise1 ) ? pere.devise1 : "";
		var devise2 = isSet( pere.devise2 ) ? pere.devise2 : "";
		var customizableProperties = isSet( pere.customizableProperties ) ? pere.customizableProperties : "";
		var livraison48 = 'false';

		oneSize = pere.oneSize;

		if( this.shopid == 3 ){
			if( !isSet( pere.iDontWantQuaranteHuit ) ){
				if( isSet( $('livraison48') ) ){
					$('livraison48').style.visibility = 'visible';
					livraison48 = 'true';
				}
			}else if( isSet( pere.iDontWantQuaranteHuit ) ){
				for( var z = 0 ; z < pere.imageLivraison.length ; z++ ){
					if( pere.imageLivraison[z] == 'oui' ){
						$('delaisDeLivraison').style.display = 'none';
						$('delaisDeLivraisonGeneric').style.display = 'block';
						break;
					}
				}
			}

			if( isSet( pere.iWantQuaranteHuit ) ){
				phrase48 = pere.iWantQuaranteHuit;
				texte =  $('takeIt').firstChild.data ;
				$('delaisDeLivraison').update( phrase48 );
				$('ajouterLabelIci').update( texte );
			}
		}

		this.jsonText = { 'tailleUnique' : pere.tailleUnique,
                		  'troisprix' : pere.troisprix,
                		  'sizes' : oneSize,
                		  'choices' : pere.choices,
                		  'conversions' : pere.conversions,
                		  'selectionTexts' : pere.selectionTexts,
                		  'imageLivr' : pere.imageLivraison,
                		  'listprice' : pere.listpricesAll,
                		  'catalogprice' : pere.catalogprices,
                		  'buyingprice' : pere.buyingPriceAll,
                		  'portOffert' : pere.portOffert,
                		  'dispo' : pere.totalStock,
                		  'availability': pere.stocknul,
                		  'zoom' : pere.zoom,
                		  'maxlen' : pere.maxLen,
                		  'indisponible' : pere.indisponible,
                		  'pwyw' : pere.pwyw,
                		  'soldes' : pere.soldes,
                		  'cadeau' : pere.cadeau,
                		  'livraison48' : livraison48,
                		  'displayFidelity' : pere.displayFidelity,
                		  'customizable' : pere.customizable,
                		  'customizableProperties' : customizableProperties,
                		  'tabDerCons' : isSet( pere.dernieresCons ) ? pere.dernieresCons[0] : null
				};

		this.traduc = {'choisirtaille':pere.choisirtaille,
				'pourajouter' : pere.pourajouter,
				'selection' : pere.selection,
				'devise1' : devise1,
				'devise2' : devise2,
				'apartir' : pere.apartir,
				'stocknul' : pere.stocknul,
				'idRayon' : pere.idRayon,
				'zoomIndisponible' : pere.zoomIndisponible
				};


		if( $('iAmWaiting') != null ){
			$('iAmWaiting').style.display = 'none';
		}
		$('cadreCommander').style.display = 'block';
		$('buybox').style.visibility = 'visible';

		this.initDetailPage();

	},

	initDetailPage:function(){
		this.AltThumbImages = new Array();
		this.sizeLabels = this.jsonText.sizes;
        this.conversionLabels = this.jsonText.conversions;
        this.imageLivr = is_array( this.jsonText.imageLivr ) ? this.jsonText.imageLivr : new Array( this.jsonText.imageLivr );
		this.mySC = null;
		this.choices = this.jsonText.choices;
		this.zoom = this.jsonText.zoom;
		this.derCons = this.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 );
			}
			if( isSet( $('mImage') ) ){
				this.displayThumbImages( imageThumbnail );
				this.altImagesPreload( this.AltThumbImages );
				this.bigImagesPreload(this.AltThumbImages);
			}
		}

		this.setObjectJSON();
		this.displayDefaultPage();
		this.gestionOnglet();

		this.heightCenter2 = $('center-2').getHeight();

		if( this.derCons != null )
			this.dernieresCons();
	},

	setObjectJSON: function() {
		for(var i=0;i<this.choices.length;i++){
			if( this.choices[i].avail == 0 )
				continue;

			if( !isSet( this.mySC ) )
				this.mySC = new Array(this.sizeLabels.length);

			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 );

		$('size').appendChild( divPlusQue );
		$('quantitybox').appendChild( this.displayTotalStock() );

		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(){
		imageMain = $( 'mImage' );
		imageMain.observe( 'mousemove' , this.pos.bind( this ) );
		imageMain.observe( 'mouseover' , this.pos.bind( this ) );
		$('over').observe( 'mousemove' , this.pos.bind( this ) );
		imageMain.observe( 'mouseout' , this.restore.bind( this ) );
		$('over').observe( 'mouseout' , this.restore.bind( this ) );
	},

	displayBigImage: function( bigImage ){

		var elemntsFrame = {
				'htmlelmt' : 'div',
				'txtContent' : '<img src="'+bigImage+'" id="bImage" />',
				'attributes' : { 'id' : 'big' }
			   };
		$('detailLeft').createFrame( elemntsFrame );

	},

	displayThumbImages : function( thumbList ){
		for( var i = 0 ; i < thumbList.length ; i++ ){
			thumbList[i].observe( '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( e ) {
		$("detailLeftContent").style.display = "none";

		if( this.shopid == 43 && this.zoom != 0 ) $('center-2').writeAttribute( 'style' , 'height:auto!important;height:'+this.heightCenter2+'px;min-height:'+this.heightCenter2+'px;padding:0;' );

		var myPos = $( "mImage" ).cumulativeOffset();
		var posBig = $( "big" ).cumulativeOffset();
		var scroll = $( "mImage" ).cumulativeScrollOffset();
		var cLeft = myPos[0];
		var cRight = cLeft + $("mImage").getWidth();
		var cTop = myPos[1];
		var cBottom = cTop + $("mImage").getHeight();
		var ex = e.clientX;
		var ey = e.clientY;

		var widthCadreBig = parseFloat( $('big').getStyle('width') );
		var widthImageBig = 1600;
		var widthImageMoy = $('mImage').width;

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

		ratio = widthImageMoy/widthImageBig;

		if( this.zoom == 0 ) {
			this.restore();
			$( 'mImage' ).stopObserving();
			$('over').stopObserving();
			infos = {
				'offsetfrommouse' : [ 0 , 25 ],
				'currentimageheight' : 0,
				'moveLeft' : 0,
				'nameDiv' : 'mousemessagediv',
				'contentDiv' : this.traduc.zoomIndisponible,
				'lanceur' : $('mImage')
				};
			var mouseMsg = new imageTrail( infos );
			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').hide();
		$('detailLeftContent').show();
		$('big').hide();
	},

	displayTailles : function(){
		var ddaa;
		var choisirTaille;
		var swatchSize;
		var swatchSizeString;

		var	h = 0;
		if( this.mySC != null ){
			while( !isSet( this.mySC[h] ) ){
				h++;
			}

			if( $('td_hplus') != null ){
				$('td_hplus').observe( 'click' , this.ajoute.bind( this ) );
				$('td_hminus').observe( 'click' , this.enleve.bind( this ) );
			}

			if( this.jsonText.pwyw == 1 ){
				$('td_hminusPwyw').observe( 'click' , this.decreasePrice.bind( this ) );
				$('td_hplusPwyw').observe( 'click' , this.increasePrice.bind( this ) );
				$('mypriceinput').observe( 'change' , this.functionChangePrice.bind( this ) );
			}
			if( this.choices.length > 1 ){
					choisirTaille = this.traduc.choisirtaille;
					$('paddingAddtoCartNote').update( this.traduc.pourajouter );
					$('addToCartBtn').observe( 'mouseover' , this.showAlertMessage.bind( this ) );
					$('addToCartBtn').observe( 'mouseout' , this.hideAlert.bind( this ) );
			}else{
				choisirTaille = this.traduc.selection+' : '+this.mySC[h].avail;
				this.clickSize( h );
			}

			var elemntsFrame = {
					'htmlelmt' : 'div',
					'txtContent' : choisirTaille,
					'attributes' : { 'id' : 'ddaa' , 'class' : 'fiche_selection_texte' }
				   };
			ddaa = $('sizebox').createFrame( elemntsFrame );

			if( this.jsonText.pwyw == 1 ){
				$('addToCartBtn').observe( 'mouseover' , this.showAlertMessage.bind( this ) );
				$('addToCartBtn').observe( 'mouseout' , this.hideAlert.bind( this ) );
			}
		}

		if( this.jsonText.cadeau == 'false' ){
			this.updateBuyBox(h);
		}else{
			$('ddmp').innerHTML = '0 &euro;';
			$('buyboxprice').style.display = 'none';
			$('livraison48').style.display = 'none';
		}

		if ( this.sizeLabels && this.sizeLabels.length > 0 && this.jsonText.tailleUnique == 'false' && this.mySC != null ){
			if( this.jsonText.tailleUnique == 'false' ){
				var elemntsFrame = {
						'htmlelmt' : 'div',
						'attributes' : { 'id' : 'swatchSize' }
					   };
				swatchSize = $('sizebox').createFrame( elemntsFrame );
			}

			for( var i=0 ; i < this.sizeLabels.length ; i++ ){

				var elemntsFrame = {
						'htmlelmt' : 'div',
						'txtContent' : this.sizeLabels[i],
						'attributes' : { 'id' : 'size'+i , 'class' : this.drawSize(i) }
					   };
				swatchSizeString = swatchSize.createFrame( elemntsFrame );

				swatchSizeString.observe( 'click' , this.clickSize.bind( this , i ) );
				swatchSizeString.observe( 'mouseover' , this.hoverSize.bind( this, swatchSizeString , i , null) );
				swatchSizeString.observe( 'mouseout' , this.hoverSize.bind( this , swatchSizeString , -1 , i ) );

				if( this.conversionLabels[i] != 'n'  ){
					var infos = {
							'offsetfrommouse' : [ -240 , 25 ],
							'currentimageheight' : 0,
							'nameDiv' : 'mousemessagediv',
							'contentDiv' : '<span>'+this.conversionLabels[i]+'</span>',
							'lanceur' : swatchSizeString
						};
					var mouseMsg = new imageTrail( infos );
				}

			}

			this.updateWidth();
		}
		if( $('aFidelityPoints') != null ){
			var infos = {
							'offsetfrommouse' : [ 0 , 25 ],
							'nameDiv' : 'msgimagediv',
							'contentDiv' : '> Cliquez pous plus d\'info',
							'lanceur' : 'aFidelityPoints'
						};
			var mouseMsg = new imageTrail( infos );
			$('aFidelityPoints').observe( 'click' , this.popupPointsFidelite.bind( this ) );
		}

		if( $('popupChono') != null )
			Event.observe( $('popupChono') , 'click' , function(e){ $('opacDiv').style.display = 'block'; $('expedition_chrono_about').style.display = 'block'; } );

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

	},

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

		if( this.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;
		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';
			$('addToCartBtn').stopObserving( 'click' );
			this.curSize = i;
			this.updateBuyBox(i);
			this.updateQuanranteHuitHeure();

			if( $('SelectUKquantite') != null )
				this.changeSelectQuantity();

			$('addToCartBtn').observe( 'click' , this.addToCartFunction.bind( this ) );
		}

	},

	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( 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.update( 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.writeAttribute( 'class' , myClass );
	},

	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( parseFloat( this.mySC[i].listprice ) != parseFloat( this.mySC[i].price ) ){
					$('buyboxprice').style.display = 'block';
					$("ddlp").innerHTML = this.traduc.devise1+formatPrice(this.mySC[i].listprice)+' '+this.traduc.devise2;
					 if ($("ddcp") != null){
                        if( ( parseFloat( this.mySC[i].catalogprice ) != parseFloat( this.mySC[i].listprice ) ) && parseFloat( this.mySC[i].catalogprice ) != parseFloat( 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( $('discount') != null )
					$('discount').innerHTML = '(-'+this.calculDiscount( this.mySC[i].price, this.mySC[i].listprice )+'%)';

			}else{
				if( parseFloat( this.jsonText.catalogprice ) != parseFloat( this.jsonText.listprice ) ){
					$('buyboxprice').style.display = 'block';
					$("ddlp").innerHTML = this.traduc.devise1+formatPrice( this.jsonText.listprice )+' '+this.traduc.devise2;
					 if ($("ddcp") != null){
						if( ( ( this.mySC != null && parseFloat( this.mySC[i].catalogprice ) != parseFloat( this.mySC[i].listprice ) ) && parseFloat( this.jsonText.catalogprice ) != parseFloat( 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( isSet( $('discount') ) )
					$('discount').update( '(-'+this.calculDiscount( this.jsonText.buyingprice, this.jsonText.listprice )+'%)' );

				$('quantitybox').style.display = 'none';
				$('addToCartBtn').style.display = 'none';

				var elemntsFrame = {
						'htmlelmt' : 'p',
						'txtContent' : this.jsonText.dispo,
						'attributes' : { 'id' : 'pIndispo' }
					   };
				$('marge').createFrame( elemntsFrame );

				if( $('my_module_div') != null ){
					$('my_module_div').style.display = 'none';
				}
			}

			if( this.jsonText.portOffert == 'oui' && isSet( $('portOffert') ) )
				$('portOffert').style.display = 'block';

			if( this.jsonText.pwyw == 1 ){
				$('chooseyourprice').style.display = 'block';
				$('chooseyourpriceTitle').style.display = 'block';
				$('ddmp').style.display = 'none';
				if( this.changePrice == -1 )
					$('mypriceinput').value = priceRange;
			}

		}else{
			this.ajoute(null);
		}
	},

	calculDiscount : function( sellingPrice , buyingPrice ){

		var bp = buyingPrice * 10;
		var sp = sellingPrice * 10;

		var calcul;
		var fin;
		calcul = sp / bp;
		fin = calcul * 100;

		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 ){
					result = this.traduc.devise1+formatPrice(curMin)+' '+this.traduc.devise2;
					if( $('aFidelityPoints') != null ){

						var regm = new RegExp("(\\d+)","i");
						var valueFidelity = regm.exec( curMin )[0];
						if( this.jsonText.displayFidelity == 'false' )
							$('aFidelityPoints').style.visibility = 'hidden';
						else{
							$('fidelityPoints').innerHTML = valueFidelity;
							$('aFidelityPoints').style.visibility = 'visible';
						}

					}

					if( $('aFidelityPoints') != null && mySizeIndex != -1 ){
						var valueFidelity = this.mySC[mySizeIndex].fidelityPoints;
						$('fidelityPoints').innerHTML = valueFidelity;
						if( valueFidelity != 0 ){
							$('aFidelityPoints').style.visibility = 'visible';
						}
					}

				}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 ){

        if( this.jsonText.cadeau  == 'false' && this.jsonText.customizable == 0 )
            $('addToCartBtn').observe( 'click' , this.addToCartFunction.bind( this ) );

        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.jsonText.cadeau  == 'false' && this.jsonText.customizable == 0 )
            $('addToCartBtn').observe( 'click' , this.addToCartFunction.bind( this ) );

        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 );
	},

	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'));

			this.mettreAuPanier(  null , this.traduc.idRayon,custo );

		}catch(e){
		}
	},

	hideAlert : function(){
		$('addToCartNote').style.visibility = 'hidden';
	},

	showAlertMessage: function(){
		if (this.curSize == -1 && this.sizeLabels.length != 0) {
			$('addToCartNote').style.visibility = 'visible';
		}else if ( this.jsonText.pwyw == 1 ) {
			var mypriceinput = $('mypriceinput');
            if ( mypriceinput != null ) {
				var value = mypriceinput.value;
				var cvalue = parseFloat(value);

                if ( isNaN(cvalue) || cvalue < 1 ) {
					$('paddingAddtoCartNote').update( 'Please check your price' );
					$('addToCartNote').style.visibility = 'visible';
                } else {
					var input = $('myprice');
                    if ( input != null ) {
						input.value = formatPrice(cvalue);
                        mypriceinput.value = formatPrice(cvalue);
					}
				}
			}
		}

		$('addToCartBtn').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.shopid == 43 ){
				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.shopid == 43 )
				tabOnglets[i].style.lineHeight = '23px';
			else
				tabOnglets[i].style.lineHeight = '25px';
			if( $('cadre'+test[0]) != null )
				$('cadre'+test[0]).style.display = 'none';
		}

		if( this.shopId == 43 ){

			obectElement.style.background = 'white';
			obectElement.style.borderBottom = 'none';
		}else{
			obectElement.style.background = 'white';
			obectElement.style.borderBottom = 'none';
		}
		if( this.shopId == 43 )
			obectElement.style.lineHeight = '24px';
		else
			obectElement.style.lineHeight = '26px';

		$('cadre'+nomId).style.display = 'block';

	},

	addToCartFunction:function() {
		if (this.jsonText.pwyw == 0) {
			$('addToCartBtn').stopObserving('click');
		}

     	var addedASIN = this.getChosenAsin();
		if( addedASIN != null ) {
			if ( this.jsonText.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' ){
				this.popupCC();
			}else{
				this.mettreAuPanier( null, this.traduc.idRayon );
			}
		}
	},

	popupPointsFidelite : function(){
		var divFid;
		var fermerFid;

		var elemntsFrame = {
				'htmlelmt' : 'div',
				'attributes' : { 'id' : 'divPopupFidelite' }
			   };
		divFid = $('page-content').createFrame( elemntsFrame );

		var elemntsFrame = {
				'htmlelmt' : 'div',
				'txtContent' : 'Fermer <img src="http://media.brandalley.com/cvsmedia/v3/www2/pix/arrows/sup_article.png" align="absmiddle"/>',
				'attributes' : { 'class' : 'classFermer' , 'style' : 'cursor:pointer;' }
			   };
		fermerFid = divFid.createFrame( elemntsFrame );

		divFid.insert( '<h1>Gagnez 10&euro; tous les 200&euro; d&acute;achat</h1' );

		var elemntsFrame = {
				'htmlelmt' : 'div',
				'txtContent' : '<p>Entr&eacute;e gratuite dans notre programme de fid&eacute;lit&eacute; <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>',
				'attributes' : { 'class' : 'classTexte' }
			   };
		divFid.createFrame( elemntsFrame );

		$('opacDiv').style.display = 'block';

		fermerFid.observe( 'click' , this.destroyPopup.bind( this , divFid ) );
	},

	popupPlusBrandalley : function(){
		var divMain;
		var idMain;
		var imgMain;
		var pMain;
		var fermer;
		var classFermer;
		var nameShop = this.shopId == 42 ? 'Annasand' : 'Brandalley';

		var elemntsFrame = {
				'htmlelmt' : 'div',
				'attributes' : { 'id' : 'idMain' }
			   };
		divMain = $('page-content').createFrame( elemntsFrame );

		var elemntsFrame = {
				'htmlelmt' : 'div',
				'txtContent' : 'Fermer <img src="http://media.brandalley.com/cvsmedia/v3/www2/pix/arrows/sup_article.png" align="absmiddle"/>',
				'attributes' : { 'class' : 'classFermer' , 'style' : 'cursor:pointer' }
			   };
		fermer = divMain.createFrame( elemntsFrame );

		divMain.insert( '<img src="'+this.urlimg+'/aide/leplusbrandalley.gif"/>' );
		divMain.insert( '<p>'+nameShop+' 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;, '+nameShop+' 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.</p>' );

		$('opacDiv').style.display = "block";

		fermer.observe( 'click' , this.destroyPopup.bind( this , divMain ) );

	},

	destroyPopup : function( e ){
		$('opacDiv').hide();
		e.remove();
	},

	dernieresCons :function(){
		var image;
		var classImg;
		var titleImg;
		var leftPos;
		var totalWidth = 0;

		for( var i = 0 ; i < this.derCons.href.length ; i++ ){
			var elemntsFrame = {
					'htmlelmt' : 'img',
					'attributes' : { 'class' : 'classImgDerCons' , 'title' : this.derCons.titleUK[i] , 'src' : this.derCons.src[i] }
				   };
			image = $('cadreDijavouImg').createFrame( elemntsFrame );

			image.observe( 'click' , this.derConsLocation.bind( this , changeIt( this.derCons.href[i] ) ) );

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

		if( i > 6 ){
			leftPos = $('cadreDijavouImg').getStyle('left');

			$('imgFlLeft').observe( 'mouseover' , this.carrousselLeft.bind( this ,  parseFloat( leftPos ) , totalWidth) );
			$('imgFlRight').observe( 'mouseover' , this.carrousselRight.bind( this ,  parseFloat( leftPos ) , totalWidth ) );
		}
	},

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

	carrousselLeft:function( value ,totalWidth){
		var posDiv = value-8;
		var that = this;

		$('imgFlLeft').stopObserving();
		$('imgFlRight').stopObserving();
		$('imgFlLeft').observe( 'mouseover' , this.carrousselLeft.bind( this ,  posDiv , totalWidth ) );
		$('imgFlRight').observe( 'mouseover' , this.carrousselRight.bind( this ,  posDiv , totalWidth ));

		$('imgFlLeft').observe( 'mouseout' , this.clearCarLeft.bind( this ) );

		$('cadreDijavouImg').style.left = posDiv+'px';

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

	carrousselRight:function( value ,totalWidth ){
		var that = this;
		var posDiv = value+8;
		$('imgFlLeft').stopObserving();
		$('imgFlRight').stopObserving();
		$('imgFlLeft').observe( 'mouseover' , this.carrousselLeft.bind( this ,  posDiv , totalWidth ) );
		$('imgFlRight').observe( 'mouseover' , this.carrousselRight.bind( this ,  posDiv , totalWidth ) );

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

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

	clearCarLeft:function(){
		clearTimeout( this.timeCarLeft );
	},

	clearCarRight:function(){
		clearTimeout( this.timeCarRight );
	},

	mouseoverZoom:function( e , i ){
		var elmt = e.element();
		infos = {
				'offsetfrommouse' : [ -400 , 0 ],
				'currentimageheight' : 200,
				'nameDiv' : 'trailimagecross',
				'contentDiv' : '<img id="trailImg" src="'+this.tabImage[i].src+'" border="0" class="bigarticleimg">',
				'lanceur' : elmt
				};
		var mouseMsg = new imageTrail( infos );

	}

});

function popupCusto( detailController ){

	var property = detailController.jsonText.customizableProperties;
	var properties = property.toString().split( '|');

	switch_visibility('block','opacDiv');

	var elemntsFrame = {
			'htmlelmt' : 'div',
			'txtContent' : '<p id="annuleText">Annuler</p>',
			'attributes' : { 'id' : 'idParentCC' , 'class' : 'fiche_selection_texte' }
		   };
	var divParent = $('page_container').createFrame( elemntsFrame );

	$('annuleText').observe( 'click' , closeUp.bind( this , detailController ) );

	var elemntsFrame = {
			'htmlelmt' : 'form',
			'attributes' : { 'name' : 'formPopupCC' , 'id' : 'formPopupCC' }
		   };
	var formul = divParent.createFrame( elemntsFrame );

	var elemntsFrame = {
			'htmlelmt' : 'p',
			'txtContent' : 'Si vous ne souhaitez pas &eacute;crire de message, mettez un espace dans le(s) champs ci-dessous.',
			'attributes' : { 'class' : 'pIntro' }
		   };
	formul.createFrame( elemntsFrame );

	for (i=1; i<properties.length; i++){

		var elemntsFrame = {
				'htmlelmt' : 'label',
				'txtContent' : 'Message m&eacute;daillon '+ i +' (10 caract&egrave;res maximum)'
			   };

		var labelEmail = formul.createFrame( elemntsFrame );

		if( detailController.formulaire[ 'custo'+ i] != null && detailController.formulaire[ 'custo'+ i] != '' )
			valueEmail = detailController.formulaire[ 'custo'+ i];
		else
			valueEmail = 'Tapez votre texte ici';

		var elemntsFrame = {
				'htmlelmt' : 'input',
				'attributes' : { 'name' : 'custo'+ i , 'value' : valueEmail }
			   };

		var inputEmail = labelEmail.createFrame( elemntsFrame );

		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] == '' )
			inputEmail.observe( 'focus' , valueNull );

		inputEmail.observe('keydown' , annuleEvent );
		inputEmail.observe('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);

		Event.observe(inputSub, 'click' , subPopupCusto.bind( this , detailController ) );

}

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

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

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

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

	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;
	}

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

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 createInputHidden(nameInput, detailController){
	if( typeof( document.forms['addtocartform'].elements[nameInput] ) != 'undefined' )
		document.forms['addtocartform'].elements[nameInput].value  = detailController.formulaire[nameInput];
}