


var browser_name = null;
var browser_version = null;
var isIE6 = false;
var isSafari = false;

var photoEffectActive = true;

function stopPhotoEffect() {
	photoEffectActive = false;
}
function showMarque(nomMarque){
	if (photoEffectActive == false) {
		return;
	}
	img_marque = $('photo_marque_'+nomMarque);
	all_marques = $$('.marque_img');
	if (all_marques != null) {
		for (i = 0; i < all_marques.length; i++) {
			if (all_marques[i].id != 'photo_marque_'+nomMarque) {
				all_marques[i].style.display = 'none';
			}
		}
	}

	img_princ = document.getElementById('photo_principale');
	if (img_princ != null) {
		if (img_marque != null) {
			img_princ.style.display = 'none';
			img_marque.style.display = 'block';
		} else {
			img_princ.style.display = 'block';
		}
	}
}
function showRayon(event, elem){
	myEvent = new Event(event);
	//alert(myEvent.page.y);
	myElem = new Element(elem);
	coords = myElem.getCoordinates();
	//alert('left : '+coords.left+'\ntop : '+coords.top+'\nwidth : '+coords.width+'\nheight : '+coords.height);
	// are we still inside ?
	mouseX = myEvent.page.x;
	mouseY = myEvent.page.y;
	minX = coords.left+2;
	maxX = minX + coords.width-4;
	minY = coords.top+2;
	maxY = minY + coords.height-4;
	if (mouseX > minX && mouseX < maxX && mouseY > minY && mouseY < maxY) {
		return;
	}
	if (photoEffectActive == false) {
		return;
	}
	all_marques = $$('.marque_img');
	if (all_marques != null) {
		for (i = 0; i < all_marques.length; i++) {
			all_marques[i].style.display = 'none';
		}
	}

	img_princ = document.getElementById('photo_principale');
	if (img_princ != null) {
		img_princ.style.display = 'block';
	}
}

function supprPanier(prod,taille){
	panier = $('right-block');
	//panier.setStyles({'visibility': 'hidden'});
	var myAjax = new Ajax('/ajax_panier', {method: 'post', data: {
		type : 'suppr',
		barcode: prod,
		taille: taille
	}, onComplete: function(result) {
		panier.innerHTML = result;return;
		alert('complete ! '+result);return;
		if (drop == null) {
			drop = $('panier_table');
		}
		drop.innerHTML = result;
		drop.setStyles({'visibility': 'visible'});
	} }).request();
}

function commitPanier(prod_barcode){
	panier = $('panier_table');
	panier.setStyles({'visibility': 'hidden'});
	prod_taille = $('taille').value;
	var myAjax = new Ajax('/ajax_panier', {method: 'post', data: {
			codeProd : prod_barcode,
			taille : prod_taille
		}, onComplete: function(result) {
			//alert('complete ! '+result);
			//panier.setInnerHTML($result);
			panier.innerHTML = result;
			panier.setStyles({'visibility': 'visible'});
	} }).request();
}


function changeImage(idImage,nbImages){
	for(i = 1 ; i <= nbImages; i++){
		tmpimg = document.getElementById('img'+i);
		if (tmpimg != null) {
			tmpimg.style.display = 'none';
		}
	}
	document.getElementById('img'+idImage).style.display = 'block';
}



var sizesAssocieMessage = null;
var fxHideSizesAssocieMessage = null;
var fxShowSizesAssocieMessage = null;
var fxDragSizesAssocieMessage = null;

function displaySizesAssocieMessage(ev, sizes) {
	if (!ev) {return;}
	e = new Event(ev);
	if (sizesAssocieMessage == null) {
		sizesAssocieMessage = new Element('div', {
			'class': 'message1-tip',
			'styles': {
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'background-color': 'white',
				'padding': '5px',
				'border': 'solid 1px black',
				'font': '12px Arial, sans-serif',
				'font-weight': 'bold',
				'visibility': 'hidden',
				'opacity': '0'
			}
		}).inject(document.body);
	}
	var innerContent = 'Tailles disponibles :<br/>';
	for (var i = 0; i < sizes.length; i++) {
		num_rest = sizes[i].substring(0, 1);
		taille_name = sizes[i].substring(1);
		//alert(num_rest+' : '+taille_name);
		extraStyle = '';
		if (num_rest == 0) {
			extraStyle = ' color: red; text-decoration: line-through;';
		} else if (num_rest == 1) {
			extraStyle = ' color: orange;';
		}
		innerContent = innerContent + "<span style=\"display: block; float: left; border: solid 1px #808080; background-color: #e0e0e0; padding: 0 3px 0 3px; margin: 2px;"+extraStyle+"\">"+taille_name+"</span> ";
	}
	sizesAssocieMessage.innerHTML = innerContent;
	sizesAssocieMessage.setStyles({'width': '120px', 'height': 'auto'});
	if (fxDragSizesAssocieMessage == null) {
		fxDragSizesAssocieMessage = sizesAssocieMessage.makeDraggable(); // this returns the dragged element
	}

/*	if (fxShowSizesAssocieMessage == null) {
		fxShowSizesAssocieMessage = new Fx.Style(sizesAssocieMessage, 'opacity', {duration:0});
	}*/
	if (isIE6 == true) {
		sizesAssocieMessage.setStyles({'top': e.page.y - 40 - sizesAssocieMessage.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	} else {
		sizesAssocieMessage.setStyles({'top': e.page.y - 20 - sizesAssocieMessage.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	}
	if (fxHideSizesAssocieMessage != null) {
		fxHideSizesAssocieMessage.stop();
	}
	/*fxShowSizesAssocieMessage.stop();
	fxShowSizesAssocieMessage.start(0.8);*/
	if (fxDragSizesAssocieMessage != null) {
		fxDragSizesAssocieMessage.stop();
		if (isIE6 == false) {
			fxDragSizesAssocieMessage.start(e); // start the event manual
		}
	}
}
function hideSizesAssocieMessage(ev) {
	if (sizesAssocieMessage == null) {
		return;
	}
		if (fxHideSizesAssocieMessage == null) {
		fxHideSizesAssocieMessage = new Fx.Style(sizesAssocieMessage, 'opacity', {duration:500, onComplete: function() {
							sizesAssocieMessage.remove();
							sizesAssocieMessage = null;
							fxHideSizesAssocieMessage = null;
							fxDragSizesAssocieMessage.stop();
							fxDragSizesAssocieMessage = null;
						} });
	}
	if (fxShowSizesAssocieMessage != null) {
		fxShowSizesAssocieMessage.stop();
	}
	fxHideSizesAssocieMessage.stop();
	fxHideSizesAssocieMessage.start(0);
}

function overAssocie(ev, idImage, nbImages, sizes) {
	changeImageAss(idImage, nbImages);
	displaySizesAssocieMessage(ev, sizes);
	//alert(sizes);
}
function outAssocie(ev, nbImages) {
	hideSizesAssocieMessage(ev);
	changeImageAss(1, nbImages);
}
function changeImageAss(idImage,nbImages){
	if (idImage != 1) {
		document.getElementById('img1').style.display = 'none';
	}
	for(i = 2 ; i <= nbImages+1; i++){
		tmpimg = document.getElementById('imgAss'+i);
		if (tmpimg != null) {
			tmpimg.style.display = 'none';
		}
	}
	if (idImage == 1) {
		document.getElementById('img1').style.display = 'block';
	} else {
		document.getElementById('imgAss'+idImage).style.display = 'block';
	}
}

var basket;

window.addEvent('domready', function() {
	browser_name = new String(navigator.appName);
	browser_version = new String(navigator.appVersion);
	if (browser_version.indexOf('MSIE 6.0') != -1) {
		isIE6 = true;
	} else if (browser_version.indexOf('afari') != -1) {
		isSafari = true;
	}


	// CENTRAL13 HEADER
	header_menu_div = $('menu_header');
	if (header_menu_div != null) {
		tmp_children = header_menu_div.getChildren();
		if (tmp_children != null && tmp_children.length == 1) {
			header_menu_ul = tmp_children[0];
			if (header_menu_ul != null) {
				header_menu_li = header_menu_ul.getChildren();
				header_menu_li.each(function(el, index) {
					el.addEvent('mouseover', function(ev) {
						el.addClass('over');
					})
					el.addEvent('mouseout', function(ev) {
						el.removeClass('over');
					})
				});
			}
		}
	}

	panier_div = $('right-block');
	if (panier_div != null) {
		basket = new Basket(panier_div);
	}


	/*$$('.full').each(function(el) {el.addEvent('mouseover', displayDragDropMessage1); el.addEvent('mouseout', hideDragDropMessage1);});
	$$('.last').each(function(el) {el.addEvent('mouseover', displayDragDropMessage2); el.addEvent('mouseout', hideDragDropMessage1);});
	$$('.finished').each(function(el) {el.addEvent('mouseover', displayDragDropMessage3); el.addEvent('mouseout', hideDragDropMessage1);});*/


	var current_codeProd;
	var current_taille;
		
});

function demarreEffetPanier() {
	fxx();
	periodical = fxx.periodical(700);
}
function stopEffetPanier() {
	$clear(periodical);
	drop.setStyle('opacity', '1');
}
function tueEffetPanier() {
	$clear(periodical);
	effetPanier.stop();
	drop.setStyle('opacity', '1');
}


function clearKwicks() {
	var obj = {};
	kwicks.each(function(other, j){
		obj[j] = {'width': [other.getStyle('width').toInt(), 104]};
	});
	fx.start(obj);
	lastEntered = null;
	if (currentlyDraggedKwick != null) {
		//currentlyDraggedKwick.setStyles({'background': '#c4c4c4'});
	}
}


function chgPanierNum(prod, taille, num){
	//alert(prod+" : "+taille); return;
	panier = $('fiche_panier_main_div');
	panier.setStyles({'visibility': 'hidden'});
	var myAjax = new Ajax('/ajax_panier2', {method: 'post', data: {
		type : 'chgnum',
		prod: prod,
		taille: taille,
		num: num
	}, onComplete: function(result) {
		//alert('complete ! '+result);
		resdiv = $('fiche_panier_main_div');
		resdiv.innerHTML = result;
		resdiv.setStyles({'visibility': 'visible'});
	} }).request();
}
function panierPointClickPortOffert(val) {
	v50points = $('50points');
	v300points = $('300points');
	if (val == false) {
		setFidelite(0);
		return;
	}
	setFidelite(1);
	// val == true
	/*if (v300points != null) {
		setFidelite(1);
		if (v300points.checked == true) {
			v300points.checked = false;
			unsetRemPointsFidelite();
		}
	}*/
	if (v300points.checked == true) {
		v300points.checked = false;
	}
}
function panierPointClickRemise(val) {
	v50points = $('50points');
	v300points = $('300points');

	if (v50points != null) {
		if (v50points.checked == true) {
			v50points.checked = false;
		}
	}


	if (val == false) {
		setFidelite(0);
		//unsetRemPointsFidelite();
	} else {
		setFidelite(2);
		//setRemPointsFidelite();
	}
	// val == true
}
function setFidelite(val) {
	panier = $('fiche_panier_main_div');
	panier.setStyles({'visibility': 'hidden'});
	/*if (isSet == true) {
		boolVal = 1;
	} else {
		boolVal = 0;
	}*/
	var myAjax = new Ajax('/ajax_panier2', {method: 'post', data: {
		type : 'chgPoints',
		val: val
	}, onComplete: function(result) {
		//alert('complete ! '+result);
		resdiv = $('fiche_panier_main_div');
		resdiv.innerHTML = result;
		resdiv.setStyles({'visibility': 'visible'});
	} }).request();
}


function recapPointClickPortOffert(val) {
	v50points = $('50points');
	v300points = $('300points');
	if (val == false) {
		setFideliteRecap(0);
		return;
	}
	setFideliteRecap(1);
	// val == true
	/*if (v300points != null) {
		setFidelite(1);
		if (v300points.checked == true) {
			v300points.checked = false;
			unsetRemPointsFidelite();
		}
	}*/
	if (v300points.checked == true) {
		v300points.checked = false;
	}
}
function recapPointClickRemise(val) {
	v50points = $('50points');
	v300points = $('300points');

	if (v50points != null) {
		if (v50points.checked == true) {
			v50points.checked = false;
		}
	}


	if (val == false) {
		setFideliteRecap(0);
		//unsetRemPointsFidelite();
	} else {
		setFideliteRecap(2);
		//setRemPointsFidelite();
	}
	// val == true
}
function setFideliteRecap(val) {
	panier = $('fiche_panier_main_div');
	panier.setStyles({'visibility': 'hidden'});
	/*if (isSet == true) {
		boolVal = 1;
	} else {
		boolVal = 0;
	}*/
	var myAjax = new Ajax('/ajax_recap', {method: 'post', data: {
		val: val
	}, onComplete: function(result) {
		//alert('complete ! '+result);
		resdiv = $('fiche_panier_main_div');
		resdiv.innerHTML = result;
		resdiv.setStyles({'visibility': 'visible'});
	} }).request();
}
var slidersHahsmap = {};
var fxHashmap = {};

function link_onover(link, divname) {
	if (fxHashmap == null) {
		fxHashmap = {};
	}
	if (fxHashmap[divname] == null) {
		fxHashmap[divname] = new Fx.Style(link, 'background-color', {duration: 500});
	} else {
		effet = fxHashmap[divname];
		effet.stop();
	}
	link.setStyle('background-color', '#E0E0E0');
}
function link_onout(link, divname) {
	if (fxHashmap == null) {
		fxHashmap = {};
	}
	if (fxHashmap[divname] == null) {
		effet = fxHashmap[divname] = new Fx.Style(link, 'background-color', {duration: 500});
	} else {
		effet = fxHashmap[divname];
	}
	effet.stop();
	effet.start('#E0E0E0', '#FFFFFF');
}

function slideCmdeUp(divname) {
	if (slidersHahsmap == null) {
		slidersHahsmap = {};
	}
	if (slidersHahsmap[divname] != null) {
		slider = slidersHahsmap[divname];
	} else {
		div = $(divname);
		if (div != null) {
			div.setStyle('display', 'block');
		}
		slider = new Fx.Slide(divname);
		slidersHahsmap[divname] = slider;
		slider.hide();
	}
	slider.toggle();
}

function changeAvoirSelect(totalAmount) {
	avoirs = $$('.avoir');
	totalAvoirs = 0;
	unchecked = new Array();
	avoirs.each(function(avoir, i) {
			if (avoir == null) {
				return;
			}
			if (avoir.checked == false) {
				unchecked.push(avoir);
				return;
			}
			avoir_num = avoir.name.substring(6);
			if (avoir_num == null) {
				return;
			}
			avoir_val = $('val_'+avoir_num);
			if (avoir_val == null || avoir_val.innerHTML == null) {
				return;
			}
			totalAvoirs += parseFloat(avoir_val.innerHTML);
		});
	totalAvoirs = Math.round(totalAvoirs * 1000) / 1000;
	restant = totalAmount - totalAvoirs;
	restant = Math.round(restant * 1000) / 1000;
	reg_par = $('reglement_para');
	reglement_div = $('reglement');
	reglement_cheque_div = $('reglement-cheque');
	reglement_cheque_impossible = $('reglement-cheque-impossible');
	cartebleue = $('cartebleue');
	cheque = $('cheque');
	
	if (restant > 0) {
		unchecked.each(function(avoir, i) {
				if (avoir == null) {
					return;
				}
				avoir.disabled = false;
			});

		if (totalAvoirs != 0) {
			if (reg_par != null) {
				// Cache le paiement par cheque si avoir utilisé
				reglement_cheque_div.setStyle('display', 'none');
				reglement_cheque_impossible.setStyle('display', 'block');
				
				// Uncheck le cheque au cas ou cheke
				cheque.checked = false;
				cartebleue.checked = true;
				
				reg_par.innerHTML = 'Vous choisissez de r&eacute;gler le <u>montant restant <b>[ '+restant+' &euro; ]</b></u> par';
			}
		} else {
			if (reg_par != null) {
				// Affiche le paiement par cheque si avoir utilisé
				reglement_cheque_div.setStyle('display', 'block');
				reglement_cheque_impossible.setStyle('display', 'none');
				reg_par.innerHTML = 'Vous choisissez de r&eacute;gler votre commande par';
			}
		}
		if (reglement_div != null) {
			reglement_div.setStyle('visibility', 'visible');
		}
	} else {
		unchecked.each(function(avoir, i) {
				if (avoir == null) {
					return;
				}
				avoir.disabled = true;
			});
		if (reglement_div != null) {
			reglement_div.setStyle('visibility', 'hidden');
		}
	}
}


var dragDropMessage1 = null;
var fxHideMessage1 = null;
var fxShowMessage1 = null;
var fxDragMessage1 = null

function displayDragDropMessage1(ev) {
	if (!ev) {return;}
	e = new Event(ev);
	if (dragDropMessage1 == null) {
		dragDropMessage1 = new Element('div', {
			'class': 'message1-tip',
			'styles': {
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'background-color': 'white',
				'padding': '5px',
				'border': 'solid 1px black',
				'font': '12px Arial, sans-serif',
				'font-weight': 'bold',
				'visibility': 'hidden',
				'opacity': '0'
			}
		}).inject(document.body);
	}
	dragDropMessage1.innerHTML = 'Glisser la taille<br/>choisie jusqu\'au<br/>panier';
	if (fxDragMessage1 == null) {
		fxDragMessage1 = dragDropMessage1.makeDraggable(); // this returns the dragged element
	}

/*	if (fxShowMessage1 == null) {
		fxShowMessage1 = new Fx.Style(dragDropMessage1, 'opacity', {duration:0});
	}*/
	if (isIE6 == true) {
		dragDropMessage1.setStyles({'top': e.page.y - 40 - dragDropMessage1.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	} else {
		dragDropMessage1.setStyles({'top': e.page.y - 20 - dragDropMessage1.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	}
	if (fxHideMessage1 != null) {
		fxHideMessage1.stop();
	}
	/*fxShowMessage1.stop();
	fxShowMessage1.start(0.8);*/
	if (fxDragMessage1 != null) {
		fxDragMessage1.stop();
		if (isIE6 == false) {
			fxDragMessage1.start(e); // start the event manual
		}
	}
}
function displayDragDropMessage2(ev) {
	if (!ev) {return;}
	e = new Event(ev);
	if (dragDropMessage1 == null) {
		dragDropMessage1 = new Element('div', {
			'class': 'message1-tip',
			'styles': {
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'background-color': 'white',
				'padding': '5px',
				'border': 'solid 1px black',
				'font': '12px Arial, sans-serif',
				'font-weight': 'bold',
				'visibility': 'hidden',
				'opacity': '0'
			}
		}).inject(document.body);
	}
	dragDropMessage1.innerHTML = '<font color="orange"><u>Derni&egrave;re pi&egrave;ce<br/>en stock !!!</u></font><br/>Glisser jusqu\'au<br/>panier';
	if (fxDragMessage1 == null) {
		fxDragMessage1 = dragDropMessage1.makeDraggable(); // this returns the dragged element
	}

/*	if (fxShowMessage1 == null) {
		fxShowMessage1 = new Fx.Style(dragDropMessage1, 'opacity', {duration:0});
	}*/
	if (isIE6 == true) {
		dragDropMessage1.setStyles({'top': e.page.y - 40 - dragDropMessage1.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	} else {
		dragDropMessage1.setStyles({'top': e.page.y - 20 - dragDropMessage1.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	}
	if (fxHideMessage1 != null) {
		fxHideMessage1.stop();
	}
	/*fxShowMessage1.stop();
	fxShowMessage1.start(0.8);*/
	if (fxDragMessage1 != null) {
		fxDragMessage1.stop();
		if (isIE6 == false) {
			fxDragMessage1.start(e); // start the event manual
		}
	}
}
function displayDragDropMessage3(ev) {
	if (!ev) {return;}
	e = new Event(ev);
	if (dragDropMessage1 == null) {
		dragDropMessage1 = new Element('div', {
			'class': 'message1-tip',
			'styles': {
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'background-color': 'white',
				'padding': '5px',
				'border': 'solid 1px black',
				'font': '12px Arial, sans-serif',
				'font-weight': 'bold',
				'visibility': 'hidden',
				'opacity': '0'
			}
		}).inject(document.body);
	}
	dragDropMessage1.innerHTML = '<font color="red">Cette taille n\'est<br/>plus disponible.</font>';
	if (fxDragMessage1 == null) {
		fxDragMessage1 = dragDropMessage1.makeDraggable(); // this returns the dragged element
	}

/*	if (fxShowMessage1 == null) {
		fxShowMessage1 = new Fx.Style(dragDropMessage1, 'opacity', {duration:0});
	}*/
	if (isIE6 == true) {
		dragDropMessage1.setStyles({'top': e.page.y - 40 - dragDropMessage1.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	} else {
		dragDropMessage1.setStyles({'top': e.page.y - 20 - dragDropMessage1.getCoordinates().height, 'left': e.page.x + 10, 'visibility': 'visible', 'opacity': '0.9'});
	}
	if (fxHideMessage1 != null) {
		fxHideMessage1.stop();
	}
	/*fxShowMessage1.stop();
	fxShowMessage1.start(0.8);*/
	if (fxDragMessage1 != null) {
		fxDragMessage1.stop();
		if (isIE6 == false) {
			fxDragMessage1.start(e); // start the event manual
		}
	}
}
function hideDragDropMessage1(ev) {
	if (dragDropMessage1 == null) {
		return;
	}

	if (fxHideMessage1 == null) {
		fxHideMessage1 = new Fx.Style(dragDropMessage1, 'opacity', {duration:500, onComplete: function() {
								dragDropMessage1.remove();
								dragDropMessage1 = null;
								fxHideMessage1 = null;
								fxDragMessage1.stop();
								fxDragMessage1 = null;
							} });
	}
	if (fxShowMessage1 != null) {
		fxShowMessage1.stop();
	}
	fxHideMessage1.stop();
	fxHideMessage1.start(0);
}
function hideDragDropMessage1IE6(ev) {
	if (dragDropMessage1 == null) {
		return;
	}
	fxDragMessage1.stop();
	fxDragMessage1 = null;

	if (fxHideMessage1 == null) {
		fxHideMessage1 = new Fx.Style(dragDropMessage1, 'opacity', {duration:500, onComplete: function() {
								dragDropMessage1.remove();
								dragDropMessage1 = null;
								fxHideMessage1 = null;
							} });
	}
	if (fxShowMessage1 != null) {
		fxShowMessage1.stop();
	}
	fxHideMessage1.stop();
	fxHideMessage1.start(0);
}

function disconnect(redirect_uri) {
	var myAjax = new Ajax('/ajax_cli_disconnect', {method: 'post', data: {}, onComplete: function(result) {
			//alert(result);
			if (redirect_uri != null) {
				window.location = redirect_uri;
			} else {
				window.location = window.location;
				//window.location.reload();
			}
		} }).request();
}

function scrollToTop() {
	var scroller = new Fx.Scroll(window, {
		wait: false,
		duration: 400
	});
	scroller.toTop();
}



var stopFxMouseBool = false;
var fxImg1 = null;
var fxImg1txt = null;
var fxImg2 = null;
var fxImg2txt = null;
var fxImg3 = null;
var fxImg3txt = null;
var fxImg4 = null;
var fxImg4txt = null;

function stopFxMouse() {
	stopFxMouseBool = true;
}

function initMouseOnImg1() {
	div = $('pola_div_1');
	if (fxImg1 == null && div != null) {
		children = div.getChildren();
		if (children != null && children.length != 0 && children[0] != null) {
			childrenbis = children[0].getChildren();
			if (childrenbis != null && childrenbis.length == 3) {
				childrenbis[0].setStyle('display', 'block');
				img = childrenbis[1];
				fxImg1 = new Fx.Style(img, 'opacity', {duration:300});
				txt = childrenbis[2];
				fxImg1txt = new Fx.Style(txt, 'color', {duration:300});
			}
		}
	}
}
function fxMouseOnImg1() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg1();
	if (fxImg1 != null && fxImg1txt != null) {
		fxImg1.stop();
		fxImg1txt.stop();
		fxImg1.start(0);
		fxImg1txt.start('#ffffff');
	}
}
function fxMouseOutImg1() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg1();
	if (fxImg1 != null && fxImg1txt != null) {
		fxImg1.stop();
		fxImg1txt.stop();
		fxImg1.start(1);
		fxImg1txt.start('#808080');
	}
}

function initMouseOnImg2() {
	div = $('pola_div_2');
	if (fxImg2 == null && div != null) {
		children = div.getChildren();
		if (children != null && children.length != 0 && children[0] != null) {
			childrenbis = children[0].getChildren();
			if (childrenbis != null && childrenbis.length == 3) {
				childrenbis[0].setStyle('display', 'block');
				img = childrenbis[1];
				fxImg2 = new Fx.Style(img, 'opacity', {duration:300});
				txt = childrenbis[2];
				fxImg2txt = new Fx.Style(txt, 'color', {duration:300});
			}
		}
	}
}
function fxMouseOnImg2() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg2();
	if (fxImg2 != null && fxImg2txt != null) {
		fxImg2.stop();
		fxImg2txt.stop();
		fxImg2.start(0);
		fxImg2txt.start('#ffffff');
	}
}
function fxMouseOutImg2() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg2();
	if (fxImg2 != null && fxImg2txt != null) {
		fxImg2.stop();
		fxImg2txt.stop();
		fxImg2.start(1);
		fxImg2txt.start('#808080');
	}
}

function initMouseOnImg3() {
	div = $('pola_div_3');
	if (fxImg3 == null && div != null) {
		children = div.getChildren();
		if (children != null && children.length != 0 && children[0] != null) {
			childrenbis = children[0].getChildren();
			if (childrenbis != null && childrenbis.length == 3) {
				childrenbis[0].setStyle('display', 'block');
				img = childrenbis[1];
				fxImg3 = new Fx.Style(img, 'opacity', {duration:300});
				txt = childrenbis[2];
				fxImg3txt = new Fx.Style(txt, 'color', {duration:300});
			}
		}
	}
}
function fxMouseOnImg3() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg3();
	if (fxImg3 != null && fxImg3txt != null) {
		fxImg3.stop();
		fxImg3txt.stop();
		fxImg3.start(0);
		fxImg3txt.start('#ffffff');
	}
}
function fxMouseOutImg3() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg3();
	if (fxImg3 != null && fxImg3txt != null) {
		fxImg3.stop();
		fxImg3txt.stop();
		fxImg3.start(1);
		fxImg3txt.start('#808080');
	}
}


function initMouseOnImg4() {
	div = $('pola_div_4');
	if (fxImg4 == null && div != null) {
		children = div.getChildren();
		if (children != null && children.length != 0 && children[0] != null) {
			childrenbis = children[0].getChildren();
			if (childrenbis != null && childrenbis.length == 3) {
				childrenbis[0].setStyle('display', 'block');
				img = childrenbis[1];
				fxImg4 = new Fx.Style(img, 'opacity', {duration:300});
				txt = childrenbis[2];
				fxImg4txt = new Fx.Style(txt, 'color', {duration:300});
			}
		}
	}
}
function fxMouseOnImg4() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg4();
	if (fxImg4 != null && fxImg4txt != null) {
		fxImg4.stop();
		fxImg4txt.stop();
		fxImg4.start(0);
		fxImg4txt.start('#ffffff');
	}
}
function fxMouseOutImg4() {
	if (stopFxMouseBool == true) {
		return;
	}
	initMouseOnImg4();
	if (fxImg4 != null && fxImg4txt != null) {
		fxImg4.stop();
		fxImg4txt.stop();
		fxImg4.start(1);
		fxImg4txt.start('#808080');
	}
}

function changeFraisPort(prix) {
	var fraisport_p = $('frais_port');
	if (fraisport_p == null) {
		return;
	}
	if (prix == 0) {
		fraisport_p.innerHTML = 'Montant des frais de ports : <b>Offert</b><input name="frais_port" value="'+prix+'" type="hidden">'
	} else {
		fraisport_p.innerHTML = 'Montant des frais de ports : <b>'+prix+' &#8364;</b><input name="frais_port" value="'+prix+'" type="hidden">'
	}
}
function changeFraisPortVal(val) {
	var fraisport_p = $('frais_port');
	if (fraisport_p == null) {
		return;
	}
	fraisport_p.innerHTML = 'Montant des frais de ports : <b>'+val+' &#8364;</b><input name="frais_port" value="'+val+'" type="hidden">'
}
function getAjaxLivraison(pays_val, code_postal_val) {
	var livr_div = $('livr_div');
	if (livr_div == null) {
		return;
	}
	if (pays_val == '0') {
		livr_div.innerHTML = '<div id="livr_div2"></div>';
		changeFraisPortVal('???');
		return;
	}
	livr_div.innerHTML = '';
	var myAjax = new Ajax('/ajax_update_livraison', {method: 'post', data: {
		'pays': pays_val,
		'code_postal': code_postal_val
	}, onComplete: function(result) {
		livr_div.innerHTML = result;
	} }).request();
}
function cpChanged($cp) {
	if ($cp == null) {
		return;
	}

	var pays = '';
	var paysInput = $('pays');

	if (paysInput != null) {
		pays = paysInput.value;
	}

	getAjaxLivraison(pays, $cp);
}
function paysChanged($pays) {
	if ($pays == null) {
		return;
	}
	validPays($pays);

	var codePostalVal = '';
	var codePostalInput = $('code_postal');

	if (codePostalInput != null) {
		codePostalVal = codePostalInput.value;
	}

	getAjaxLivraison($pays, codePostalVal);
}

function changePage(url, page, taille) {
	fullurl = url+"?page="+page;
	if (taille != null) {
		fullurl = fullurl+"&taille="+taille;
	}
	window.location = fullurl;
}

function changeNbart(url, nbart, nbart_orig, page_orig, taille) {
	fullurl = url+"?nbart="+nbart;
	page_before = page_orig - 1;
	newpage_before = (page_before * nbart_orig / nbart);
	newpage_before = Math.floor(newpage_before);
	newpage = newpage_before + 1;
	//alert("page : "+page_orig+" / nbart_orig : "+nbart_orig+" / nbart : "+nbart+"\n"+Math.floor(newpage));
	if (newpage != 1) {
		fullurl = fullurl+"&page="+newpage;
	}
	if (taille != null) {
		fullurl = fullurl+"&taille="+taille;
	}
	window.location = fullurl;
}

function load_cache_images(suppImages, cat) {

	var cache_imgs = ""
	if (cat == null || cat != true) {
		cache_imgs = '<img src="/images/charte/head_homme_selected.png" class="cache_img" />\n<img src="/images/charte/MDStoreLogo.gif" alt="Logo" class="cache_img" />\n<img src="/images/charte/MDStoreLogo_pink.gif" alt="Logo" class="cache_img" />\n<img src="/images/charte/MDStoreLogo_blue.gif" alt="Logo" class="cache_img" />\n<img src="/images/charte/MDStoreLogo_orange.gif" alt="Logo" class="cache_img" />\n<img src="/images/charte/menu/icone_homme.gif" alt="Homme" class="cache_img" />\n<img src="/images/charte/menu/icone_homme_on.gif" alt="Homme" class="cache_img" />\n<img src="/images/charte/menu/icone_homme_pink.gif" alt="Homme" class="cache_img" />\n<img src="/images/charte/menu/icone_homme_blue.gif" alt="Homme" class="cache_img" />\n<img src="/images/charte/menu/icone_homme_orange.gif" alt="Homme" class="cache_img" />\n<img src="/images/charte/menu/icone_femme.gif" alt="Femme" class="cache_img" />\n<img src="/images/charte/menu/icone_femme_pink.gif" alt="Femme" class="cache_img" />\n<img src="/images/charte/menu/icone_femme_pink_on.gif" alt="Femme" class="cache_img" />\n<img src="/images/charte/menu/icone_femme_blue.gif" alt="Femme" class="cache_img" />\n<img src="/images/charte/menu/icone_femme_orange.gif" alt="Femme" class="cache_img" />\n<img src="/images/charte/menu/icone_accessoires.gif" alt="Accessoires" class="cache_img" />\n<img src="/images/charte/menu/icone_accessoires_on.gif" alt="Accessoires" class="cache_img" />\n<img src="/images/charte/menu/icone_accessoires_pink.gif" alt="Accessoires" class="cache_img" />\n<img src="/images/charte/menu/icone_accessoires_blue.gif" alt="Accessoires" class="cache_img" />\n<img src="/images/charte/menu/icone_accessoires_orange.gif" alt="Accessoires" class="cache_img" />\n<img src="/images/charte/menu/icone_basket.gif" alt="Chaussures" class="cache_img" />\n<img src="/images/charte/menu/icone_basket_on.gif" alt="Chaussures" class="cache_img" />\n<img src="/images/charte/menu/icone_basket_pink.gif" alt="Chaussures" class="cache_img" />\n<img src="/images/charte/menu/icone_basket_pink_on.gif" alt="Chaussures" class="cache_img" />\n<img src="/images/charte/menu/icone_basket_blue.gif" alt="Chaussures" class="cache_img" />\n<img src="/images/charte/menu/icone_basket_orange.gif" alt="Chaussures" class="cache_img" />\n<img src="/images/charte/menu/icone_news.gif" alt="Nouveaut&eacute;s" class="cache_img" />\n<img src="/images/charte/menu/icone_news_pink.gif" alt="Nouveaut&eacute;s" class="cache_img" />\n<img src="/images/charte/menu/icone_news_blue_on.gif" alt="Nouveaut&eacute;s" class="cache_img" />\n<img src="/images/charte/menu/icone_news_orange.gif" alt="Nouveaut&eacute;s" class="cache_img" />\n<img src="/images/charte/menu/icone_promos.gif" alt="Promotions" class="cache_img" />\n<img src="/images/charte/menu/icone_promos_pink.gif" alt="Promotions" class="cache_img" />\n<img src="/images/charte/menu/icone_promos_blue.gif" alt="Promotions" class="cache_img" />\n<img src="/images/charte/menu/icone_promos_orange_on.gif" alt="Promotions" class="cache_img" />\n<img src="/images/charte/menu/icone_panier.gif" alt="Panier" class="cache_img" />\n<img src="/images/charte/menu/icone_panier_on.gif" alt="Panier" class="cache_img" />\n<img src="/images/charte/menu/icone_panier_pink.gif" alt="Panier" class="cache_img" />\n<img src="/images/charte/menu/icone_panier_blue.gif" alt="Panier" class="cache_img" />\n<img src="/images/charte/menu/icone_panier_orange.gif" alt="Panier" class="cache_img" />\n<img src="/images/charte/menu/icone_store.gif" alt="Magasins" class="cache_img" />\n<img src="/images/charte/menu/icone_store_on.gif" alt="Magasins" class="cache_img" />\n<img src="/images/charte/menu/icone_store_pink.gif" alt="Magasins" class="cache_img" />\n<img src="/images/charte/menu/icone_store_blue.gif" alt="Magasins" class="cache_img" />\n<img src="/images/charte/menu/icone_store_orange.gif" alt="Magasins" class="cache_img" />\n<img src="/images/charte/menu/icone_aide.gif" alt="Aide" class="cache_img" />\n<img src="/images/charte/menu/icone_aide_on.gif" alt="Aide" class="cache_img" />\n<img src="/images/charte/menu/icone_aide_pink.gif" alt="Aide" class="cache_img" />\n<img src="/images/charte/menu/icone_aide_blue.gif" alt="Aide" class="cache_img" />\n<img src="/images/charte/menu/icone_aide_orange.gif" alt="Aide" class="cache_img" />\n<img src="/images/charte/menu/icone_contact.gif" alt="Contact" class="cache_img" />\n<img src="/images/charte/menu/icone_contact_on.gif" alt="Contact" class="cache_img" />\n<img src="/images/charte/menu/icone_contact_pink.gif" alt="Contact" class="cache_img" />\n<img src="/images/charte/menu/icone_contact_blue.gif" alt="Contact" class="cache_img" />\n<img src="/images/charte/menu/icone_contact_orange.gif" alt="Contact" class="cache_img" />\n<img src="/images/charte/menu/icone_compte.gif" alt="Mon compte" class="cache_img" />\n<img src="/images/charte/menu/icone_compte_on.gif" alt="Mon compte" class="cache_img" />\n<img src="/images/charte/menu/icone_compte_pink.gif" alt="Mon compte" class="cache_img" />\n<img src="/images/charte/menu/icone_compte_blue.gif" alt="Mon compte" class="cache_img" />\n<img src="/images/charte/menu/icone_compte_orange.gif" alt="Mon compte" class="cache_img" />\n<img src="/images/charte/menu/icone_parrainage.gif" alt="Parrainage" class="cache_img" />\n<img src="/images/charte/menu/icone_parrainage_on.gif" alt="Parrainage" class="cache_img" />\n<img src="/images/charte/menu/icone_parrainage_pink.gif" alt="Parrainage" class="cache_img" />\n<img src="/images/charte/menu/icone_parrainage_blue.gif" alt="Parrainage" class="cache_img" />\n<img src="/images/charte/menu/icone_parrainage_orange.gif" alt="Parrainage" class="cache_img" />\n\n<img src="/images/charte/menu/ami.gif" alt="ami" class="cache_img" />\n<img src="/images/charte/menu/ami_pink.gif" alt="ami" class="cache_img" />\n<img src="/images/charte/menu/ami_blue.gif" alt="ami" class="cache_img" />\n<img src="/images/charte/menu/ami_orange.gif" alt="ami" class="cache_img" />\n<img src="/images/charte/row.gif" alt="row" class="cache_img" />\n<img src="/images/charte/row_pink.gif" alt="row" class="cache_img" />\n<img src="/images/charte/row_blue.gif" alt="row" class="cache_img" />\n<img src="/images/charte/row_orange.gif" alt="row" class="cache_img" />\n\n<img src="/images/charte/bg-header.gif" alt="background" class="cache_img" />\n<img src="/images/charte/bg-header_pink.gif" alt="background" class="cache_img" />\n<img src="/images/charte/bg-header_blue.gif" alt="background" class="cache_img" />\n<img src="/images/charte/bg-header_orange.gif" alt="background" class="cache_img" />\n\n<img src="/images/img-cb.gif" alt="cb" class="cache_img" />\n<img src="/images/img-cb-pink.gif" alt="cb" class="cache_img" />\n<img src="/images/img-cb-blue.gif" alt="cb" class="cache_img" />\n<img src="/images/img-cb-orange.gif" alt="cb" class="cache_img" />\n\n<img src="/images/charte/onifin.gif" alt="onifin" class="cache_img" />\n<img src="/images/charte/onifin-pink.gif" alt="onifin" class="cache_img" />\n<img src="/images/charte/onifin-blue.gif" alt="onifin" class="cache_img" />\n<img src="/images/charte/onifin-orange.gif" alt="onifin" class="cache_img" />\n\n<img src="/images/charte/arrow-top.gif" alt="arrow" class="cache_img" />\n<img src="/images/charte/arrow-top-pink.gif" alt="arrow" class="cache_img" />\n<img src="/images/charte/arrow-top-blue.gif" alt="arrow" class="cache_img" />\n<img src="/images/charte/arrow-top-orange.gif" alt="arrow" class="cache_img" />\n\n<img src="/images/charte/bg-footer.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/bg-footer-femme.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/bg-footer-news.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/bg-footer-promos.gif" alt="bg" class="cache_img" />\n\n<img src="/images/charte/bg_menu_marques_top.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/bg_menu_marques.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/bg_menu_marques_bottom.jpg" alt="bg" class="cache_img" />\n\n<img src="/images/charte/panier_bottom.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_bottomleft.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_bottomright.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_left.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_right.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_top.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_topleft.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/panier_topright.jpg" alt="bg" class="cache_img" />\n\n<img src="/images/charte/pa_txt_agl_bottom_left.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_agl_bottom_right.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_agl_top_left.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_agl_top_right.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_agl_bottom_left.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_bottom.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_top.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_left.jpg" alt="bg" class="cache_img" />\n<img src="/images/charte/pa_txt_right.jpg" alt="bg" class="cache_img" />\n\n<img src="/images/catalogue/pict-epuise.gif" alt="bg" class="cache_img" />\n<img src="/images/catalogue/pict-promo.gif" alt="bg" class="cache_img" />\n<img src="/images/catalogue/pict-new.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/metalic-bottom.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/infoline.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_logo.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_left.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_right.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_top_left.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_bottom_left.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_top_right.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/aide_bottom_right.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/tab_grey_left.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/tab_grey_right.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/tab_grey_top.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/tab_white_bottom.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/tab_white_bottom_left.gif" alt="bg" class="cache_img" />\n<img src="/images/charte/tab_white_bottom_right.gif" alt="bg" class="cache_img" />\n<img src="/images/panier/panier.gif" alt="panier" class="cache_img" />\n';
	}

	if (suppImages != null) {
		suppImages.each(function(myvar, index) {
			cache_imgs += "<img src=\""+myvar+"\" alt=\"cache\" class=\"cache_img\" />\n";
		});
	}
	/*imgs_div = $('cache_imgs');
	imgs_div.innerHTML = cache_imgs;*/
}



function formatPrice(price) {
	price = Math.round(price.toFloat() * 100) / 100;
	var intVal = price.toInt();

	strInt = ''+intVal;
	strFloat = ''+price;

	if (strFloat.length == strInt.length) {
		return strFloat+'.00';
	} else if (strFloat.length == strInt.length + 1) {
		return strFloat+'00';
	} else if (strFloat.length == strInt.length + 2) {
		return strFloat+'0';
	}
	return strFloat;
}


var CatalogueElement = new Class({
	initialize: function(el) {
		this.element = el;
		this.element.setStyle('z-index', '100');

		this.panier = null;

		this.ulElem = null;
		this.liElems = [];

		this.hashLiElems = {};

		var children = el.getChildren();
		if (children == null || children.length == 0) {
			return;
		}

		this.ulElem = children[0];

		ulCoordinates = this.ulElem.getCoordinates();
		//alert(ulCoordinates.width+" - "+ulCoordinates.height);

		children = this.ulElem.getChildren();
		if (children == null || children.length == 0) {
			return;
		}
		this.liElems = children;
		this.liElems.each(function(liElem, index) {
			if (liElem.className == 'cat_separator') {
				return;
			}
			var innerSpan = liElem.getChildren()[0];
			this.hashLiElems[innerSpan.id] = new CatalogueProd(innerSpan, this);
		}.bind(this));

		this.ulElem.addEvent('mouseleave', function(event) {
			//alert(event);
			this.closeAll();
		}.bind(this));
	},

	getElement: function() {
		return this.element;
	},

	getUlElement: function() {
		return this.ulElem;
	},

	mouseEnter: function(catProd) {
		catProd.getOpened();
		this.closeAllBut(catProd.getUniqueID());
	},

	mouseLeave: function(catProd) {
		catProd.getClosed();
	},

	closeAll: function() {
		for (var i in this.hashLiElems) {
			this.hashLiElems[i].getClosed();
		}
	},

	closeAllBut: function(catProdID) {
		for (var i in this.hashLiElems) {
			if (i != catProdID) {
				this.hashLiElems[i].getClosed();
			}
		}
	},

	setPanier: function(panier) {
		this.panier = panier;
	},

	getPanier: function() {
		return this.panier;
	}
});


var CatalogueProd = new Class({
	initialize: function(el, catElement) {
		this.element = el;
		this.catElem = catElement;

		this.parent = this.element.getParent();
		/*this.parent.setStyle('z-index', '100');
		this.element.setStyle('z-index', '100');*/

		this.ulElem = this.catElem.getUlElement();

		//this.element.setStyles({'position': 'absolute', 'top': '0px', 'left': '0px', 'z-index': '100'});

		var link = this.element.getChildren()[0];
		var linkChildren = link.getChildren();
		this.photoTable = linkChildren[0];
		this.prod_design_span = linkChildren[1];
		this.prod_couleur_span = linkChildren[2];
		this.prod_prix_span = linkChildren[3];
		this.tailles_span = linkChildren[4];

		this.effect = new Fx.Style(this.tailles_span, 'opacity', {duration: 600, transition: Fx.Transitions.Expo.easeOut, onComplete: this.effectFinished.bind(this)
			});

		this.element.addEvent('mouseenter', function(event) {
			//alert(event);
			this.catElem.mouseEnter(this);
		}.bind(this));


		this.element.addEvent('mouseleave', function(event) {
			//alert(event);
			this.catElem.mouseLeave(this);
		}.bind(this));
	},

	getElement: function() {
		return this.element;
	},

	getPanier: function() {
		return this.catElem.getPanier();
	},

	getUniqueID: function() {
		return this.element.id;
	},

	getTitre: function() {
		return this.titre;
	},

	getPrix: function() {
		return this.prix;
	},

	getUlElement: function() {
		return this.ulElem;
	},

	getRelativePosition: function() {
		var posUl = this.ulElem.getPosition();
		var posLi = this.element.getPosition();
		return {'x': posLi.x - posUl.x, 'y': posLi.y - posUl.y};
		//return {'x': posLi.x, 'y': posLi.y};
	},

	showPhoto: function(num) {
		return;
		if (this.photos.length == 0) {
			return;
		}
		if (this.photos.length <= num) {
			num = 0;
		}
		for (var i = 0; i < this.photos.length; i++) {
			if (i != num) {
				this.photos[i].setStyle('display', 'none');
			}
		}
		this.photos[num].setStyle('display', 'inline');
	},

	getMainPhotoFile: function() {
		if (this.photos.length == 0) {
			return null;
		}
		var tmp_photo = this.photos[0];
		if (tmp_photo != null) {
			var tmp_src = tmp_photo.src;
			if (tmp_src != null && tmp_src.length > 0) {
				var splitted = tmp_src.split('/');
				if (splitted != null && splitted.length > 0) {
					return splitted[splitted.length - 1];
				}
			}
		}
		return null;
	},

	getOpened: function() {
		if (this.currentState == 'opened' || this.currentState == 'opening') {
			return;
		}
		if (this.tailles_span.getStyle('display') == 'none') {
			this.tailles_span.setStyles({'display': 'block', 'opacity': 0});
		}
		var thisTailleSpanHeight = this.tailles_span.getStyle('height').toInt();
		//this.tailles_span.setStyle('top', (-(thisTailleSpanHeight))+'px')
		var newTop = -10 - thisTailleSpanHeight;
		/*if (newTop < 100) {
			newTop = 100;
		}*/
		this.tailles_span.setStyle('top', newTop+'px')
		this.effect.stop();
		this.currentState = 'opening';
		this.parent.setStyles({'z-index': '102'});
		this.tailles_span.setStyle('opacity', .93);
		//this.effect.start(.98);
		this.currentState = 'opened';
	},

	getClosed: function() {
		if (this.currentState == 'closed' || this.currentState == 'closing') {
			return;
		}
		//this.tailles_span.setStyle('display', 'none');
		this.effect.stop();
		this.currentState = 'closing';
		this.parent.setStyles({'z-index': '101'});
		this.tailles_span.setStyle('opacity', 0);
		this.currentState = 'closed';
		//this.effect.start(0);
	},

	effectFinished: function() {
		if (this.currentState == 'closing' || this.currentState == 'closed') {
			this.currentState = 'closed';
			this.parent.setStyles({'z-index': '100'});
			//this.mini_pic_rollover_div.setStyle('display', 'none');
			this.showPhoto(0);
		} else if (this.currentState == 'opening' || this.currentState == 'opened') {
			this.currentState = 'opened';
		}
	},

	taillePressed: function(event, taille) {
		event = new Event(event).stop();
		var x = event.page.x;
		var y = event.page.y;

		var prod_x = x - 45;
		var prod_y = y - 70;

		var panierProd = this.generatePanierProd(taille);
		panierProd.getElement().setStyles({'position': 'absolute', 'top': prod_y+'px', 'left': prod_x+'px', 'z-index': '99999999'});

		panierProd.getElement().addEvent('emptydrop', function() {
			this.getPanier().setDroppable(null);
			this.getPanier().unBlock();
			this.getPanier().slideIn();
			disappearFx = new Fx.Styles(panierProd.getElement(), {duration: 300, transition: Fx.Transitions.linear, wait: true, onComplete: function() {
				panierProd.getElement().remove();
				panierProd = null;
			} });
			disappearFx.start({'opacity': 0});
			/*slidefx = new Fx.Styles(this, {duration: 200, transition: Fx.Transitions.linear, wait: true, onComplete: function() {
				clone.remove();
				clearKwicks();
				kwickEffectEnabled = true;
			} });
			slidefx.start({
				'top': pictopval,
				'left': picleftval
			});

			drop.removeEvents();*/
		}.bind(this));

		panierProd.inject(document.body);

		this.getPanier().setDroppable(panierProd);

		var drag = panierProd.getElement().makeDraggable({
			droppables: this.getPanier().getDroppableElement()
		}); // this returns the dragged element
	
		drag.start(event); // start the event manual

		if (this.getPanier() != null) {
			this.getPanier().blockOut();
		}
	},

	generatePanierProd: function(taille) {
		var uid = this.getUniqueID();
		var barcode = this.getTitre();
		var photo = this.getMainPhotoFile();
		var prix = this.getPrix();

		var newPanierProd = createPanierProd(uid, barcode, photo, taille, prix);
		newPanierProd.hideCloseButton();
		return newPanierProd;
	}
});


var PanierElement = new Class({
	initialize: function(el) {
		this.element = el;
		this.element.setStyle('z-index', '200');

		this.droppable = null;
		this.temporaryAdded = null;

		this.minHeight = 250;
		this.bottomHeight = 60;

		var children = el.getChildren();

		this.languette = children[0];
		this.content = children[1];

		this.marginTop = this.element.getStyle('margin-top').toInt();
		this.width = this.element.getStyle('width').toInt();
		this.height = this.element.getStyle('height').toInt();

		var languetteChildren = this.languette.getChildren();
		var qte_div = languetteChildren[0];
		var qte_div_children = qte_div.getChildren();
		this.languetteNumProds = qte_div_children[0];
		this.languetteNumProdsS = qte_div_children[1].getChildren()[0];
		var prix_div = languetteChildren[2];
		var prix_div_children = prix_div.getChildren();
		this.languettePrix = prix_div_children[0];

		var contentChildren = this.content.getChildren();
		this.realContent = contentChildren[0];
		this.panierBottom = contentChildren[1];
		this.bottomPriceSpan = this.panierBottom.getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0];

		this.prod_containers_divs = this.realContent.getChildren();
		this.panier_prods = [];
		this.prod_containers_divs.each(function(prod_container_div, i) {
				prod_div = prod_container_div.getChildren()[0];
				tmp_panier_prod = new PanierProd(prod_div);
				tmp_panier_prod.setPanier(this);
				this.panier_prods[this.panier_prods.length] = tmp_panier_prod;
			}.bind(this));

		this.parent = this.element.getParent();

		this.marginRequired = 30;

		this.fxPanier = new Fx.Style(this.element, 'top', {duration:300});

		this.hiddenRightPosition = this.element.getStyle('right').toInt();
		this.slideInTimeoutID = -1;
		this.blockedOut = false;

		this.slideOutFx = new Fx.Style(el, 'right', {duration: 200, onComplete: this.slideOutDone.bind(this)});
		this.slideInFx = new Fx.Style(el, 'right', {duration: 200, onComplete: this.slideInDone.bind(this)});

		this.slidingOut = false;
		this.slidingIn = false;

		this.languette.addEvent('mouseover', function(e) {
			ev = new Event(e);
			this.mouseEntered(ev.page.x, ev.page.y);
		}.bind(this));

		this.content.addEvent('mouseover', function(e) {
			ev = new Event(e);
			this.mouseEntered(ev.page.x, ev.page.y);
		}.bind(this));

		this.languette.addEvent('mouseout', function(e) {
			ev = new Event(e);
			if (this.checkForSlideIn(ev.page.x, ev.page.y) == true) {
				//this.slideIn();
				this.slideInWithDelay(500);
			}
		}.bind(this));

		this.content.addEvent('mouseout', function(e) {
			var ev = new Event(e);
			if (this.checkForSlideIn(ev.page.x, ev.page.y) == true) {
				//this.slideIn();
				this.slideInWithDelay(500);
			}
		}.bind(this));

		window.addEvent('windowResized', this.onWindowChanged.bind(this));
		window.addEvent('windowScrolled', this.onWindowChanged.bind(this));
	},

	getElement: function() {
		return this.element;
	},

	onWindowChanged: function() {
		var window_scroll = window.getScrollTop();

		var panierCoords = this.element.getCoordinates();
		var parentCoords = this.parent.getCoordinates();
		var panierTop = panierCoords.top;

		if (panierTop != window_scroll + this.marginRequired) {
			var requiredPos = window_scroll + this.marginRequired - this.marginTop - parentCoords.top;

			if (requiredPos + this.marginTop + this.height > parentCoords.height) {
				requiredPos = parentCoords.height - this.marginTop - this.height;
			}
			if (requiredPos < 0) {
				requiredPos = 0;
			}

			this.fxPanier.stop();
			this.fxPanier.start(requiredPos);
		}
	},

	mouseEntered: function(mouseX, mouseY) {
		if (this.slideInTimeoutID != -1) {	
			window.clearTimeout(this.slideInTimeoutID);
			this.slideInTimeoutID = -1;
		}
		this.slideOut();
	},

	mouseOut: function(mouseX, mouseY) {
	},

	slideOut: function() {
		if (this.slidingOut == true) {
			return;
		}
		this.slideOutFx.stop();
		this.slideInFx.stop();

		this.slidingIn = false;
		this.slidingOut = true;

		this.slideOutFx.start(this.getOutsideRightPos());
	},

	slideIn: function() {
		if (this.blockedOut == true) {
			return;
		}
		if (this.slidingIn == true) {
			return;
		}
		this.slideOutFx.stop();
		this.slideInFx.stop();

		this.slidingOut = false;
		this.slidingIn = true;

		this.slideInFx.start(this.getInsideRightPos());
	},

	slideInWithDelay: function(delay) {
		if ($defined(this.objectName) && this.objectName != null) {
			if (this.slideInTimeoutID != -1) {	
				window.clearTimeout(this.slideInTimeoutID);
				this.slideInTimeoutID = -1;
			}
			this.slideInTimeoutID = window.setTimeout(this.objectName+".slideIn()", delay);
		} else {
			this.slideIn();
		}
	},

	slideOutDone: function() {
		//alert('slideOutDone');
		this.slidingOut = false;
		this.slidingIn = false;
	},

	slideInDone: function() {
		if (this.slidingIn == false) {
			return;
		}

		var rightPos = this.getElement().getStyle('right').toInt();
		if (rightPos != this.getInsideRightPos()) {
			this.getElement().setStyle('right', this.getInsideRightPos()+'px');
		}

		this.slidingOut = false;
		this.slidingIn = false;
	},

	checkForSlideIn: function(mouseX, mouseY) {
		var fullwidthcont = $('fullwidth_container');
		if (fullwidthcont != null) {
			fullwidthcont_coords = fullwidthcont.getCoordinates();
			if (mouseX > fullwidthcont_coords.left + fullwidthcont_coords.width) {
				return true;
			}
		}

		thisCoords = this.getElement().getCoordinates();

		if (mouseX-2 <= thisCoords.left || mouseX+2 >= thisCoords.left + thisCoords.width || mouseY-2 <= thisCoords.top || mouseY+2 >= thisCoords.top + thisCoords.height) {
			return true;
		}
		contentCoords = this.content.getCoordinates();
		languetteCoords = this.languette.getCoordinates();

		if (mouseX-2 <= contentCoords.left && (mouseY+2 >= languetteCoords.top + languetteCoords.height || mouseY-2 <= languetteCoords.top)) {
			return true;
		}

		if (mouseY-2 <= thisCoords.top || mouseY+2 >= thisCoords.top + thisCoords.height || mouseX-2 <= thisCoords.left || mouseX+2 >= thisCoords.left + thisCoords.width) {
			return true;
		}

		return false;
	},

	getOutsideRightPos: function() {
		return 0;
	},

	getInsideRightPos: function() {
		return this.hiddenRightPosition;
	},

	blockOut: function() {
		this.blockedOut = true;
		var rightPos = this.getElement().getStyle('right').toInt();
		if (rightPos != this.getOutsideRightPos()) {
			this.slideOut();
		}
	},

	unBlock: function() {
		this.blockedOut = false;
		this.slideInWithDelay(2000);
	},

	setObjectName: function(objName) {
		this.objectName = objName;
	},

	setQuantity: function(quantity) {
		quantity = quantity.toInt();
		if (this.languetteNumProds != null) {
			this.languetteNumProds.innerHTML = quantity;
		}
		if (this.languetteNumProdsS != null) {
			if (quantity > 1) {
				this.languetteNumProdsS.setStyle('display', 'inline');
			} else {
				this.languetteNumProdsS.setStyle('display', 'none');
			}
		}
	},

	setPrice: function(price) {
		price = price.toFloat();
		price = Math.round(price * 100) / 100;
		var intPrice = Math.round(price);

		this.languettePrix.innerHTML = intPrice;
		this.bottomPriceSpan.innerHTML = formatPrice(price);
	},

	removePanierProd: function(panierProd) {
		if (panierProd == null) {
			return;
		}
		var el = panierProd.getElement();
		var parent = el.getParent();

		this.ajaxRemoveProduct(panierProd);

		if (this.panier_prods.contains(panierProd)) {
			//alert('prod found');
			this.panier_prods.remove(panierProd);
			el.remove();
		}
		if (this.prod_containers_divs.contains(parent)) {
			//alert('parent found');
			this.prod_containers_divs.remove(parent);
			parent.remove();
		}

		this.refresh();
	},

	addPanierProd: function(panierProd) {
		// Let's create our container.
		var newContainer = document.createElement('div');
		newContainer = new Element(newContainer);
		newContainer.className = 'panier_prod_container';
		panierProd.inject(newContainer);
		panierProd.showCloseButton()

		if (this.prod_containers_divs.length > 0) {
			newContainer.injectAfter(this.prod_containers_divs[this.prod_containers_divs.length - 1]);
		} else {
			newContainer.inject(this.realContent);
		}

		panierProd.setPanier(this);

		this.prod_containers_divs = this.realContent.getChildren();
		//this.prod_containers_divs[this.prod_containers_divs.length] = this.newContainer;
		this.panier_prods[this.panier_prods.length] = panierProd;
		this.refresh();

		this.ajaxAddProduct(panierProd);
	},

	addProduct: function(uniqueId, barcode, prix, taille, photo) {
		var tmp_panier_prod = createPanierProd(uniqueId, barcode, photo, taille, prix);
		this.addPanierProd(tmp_panier_prod);
	},

	addProductWithEffect: function(uniqueId, barcode, prix, taille, photo) {
		this.slideOut();
		this.addProduct(uniqueId, barcode, prix, taille, photo);
		this.slideInWithDelay(2000);
	},

	temporaryAddPanierProd: function(panierProd) {
		if (this.temporaryAdded != null) {
			return;
		}

		this.temporaryAdded = panierProd;

		var newContainer = document.createElement('div');
		newContainer = new Element(newContainer);
		newContainer.className = 'panier_prod_container';
		panierProd.getElement().setStyle('opacity', .5);
		panierProd.inject(newContainer);

		if (this.prod_containers_divs.length > 0) {
			newContainer.injectAfter(this.prod_containers_divs[this.prod_containers_divs.length - 1]);
		} else {
			newContainer.inject(this.realContent);
		}

		panierProd.setPanier(this);

		this.prod_containers_divs = this.realContent.getChildren();
		//this.prod_containers_divs[this.prod_containers_divs.length] = this.newContainer;
		this.panier_prods[this.panier_prods.length] = panierProd;

		this.temporaryAdded = panierProd;

		this.refresh();
	},

	validTemporaryAdded: function() {
		if (this.temporaryAdded == null) {
			return false;
		}
		var panierProd = this.temporaryAdded;
		this.temporaryAdded = null;

		panierProd.showCloseButton();
		panierProd.getElement().setStyle('opacity', 1);

		this.ajaxAddProduct(panierProd);

		return true;
	},

	removeTemporaryAdded: function() {
		if (this.temporaryAdded == null) {
			return;
		}
		if (this.panier_prods.length > 0) {
			var panierProd = this.panier_prods[this.panier_prods.length - 1];
			if (panierProd.getElement().getStyle('opacity') == 1) {
				// That's a double security
				this.temporaryAdded = null;
				return;
			}
			this.panier_prods.pop();
			panierProd.getElement().remove();
		}
		if (this.prod_containers_divs.length > 0) {
			var prod_container = this.prod_containers_divs.pop();
			prod_container.remove();
		}
		this.temporaryAdded = null;
		this.refresh();
	},

	refreshSize: function() {
		var newHeight = 149 * this.prod_containers_divs.length + this.bottomHeight;
		if (newHeight < this.minHeight) {
			newHeight = this.minHeight;
		}
		this.content.setStyle('height', newHeight+'px');
		
	},

	refreshQuantity: function() {
		this.setQuantity(this.prod_containers_divs.length);
	},

	refreshPrice: function() {
		var totalPrice = 0;
		this.panier_prods.each(function(panier_prod, i) {
			var prod_prix = panier_prod.getPrix();
			
			totalPrice = totalPrice + prod_prix.toFloat();
		});

		this.setPrice(totalPrice);
	},

	refresh: function() {
		this.refreshSize();
		this.refreshQuantity();
		this.refreshPrice();
	},

	setDroppable: function(obj) {
		this.removeTemporaryAdded();
		if (obj != null) {
			this.droppable = obj;
			this.content.addEvent('drop', function(dropElement, dragFX) {
				this.somethingDropped(dropElement, dragFX);
			}.bind(this));
			this.content.addEvent('over', function(dropElement, dragFX) {
				this.somethingOver(dropElement, dragFX);
			}.bind(this));

			this.content.addEvent('leave', function(dropElement, dragFX) {
				this.somethingLeave(dropElement, dragFX);
			}.bind(this));
		} else {
			this.content.removeEvents('drop');
			this.content.removeEvents('over');
			this.content.removeEvents('leave');
			this.droppable = null;
		}
	},

	getDroppableElement: function() {
		return this.content;
	},

	somethingDropped: function(dropElement, dragFX) {
		this.unBlock();
		if (this.temporaryAdded != null) {
			var res = this.validTemporaryAdded();
			if (res == true) {
				if (this.droppable != null) {
					this.droppable.getElement().remove();
					this.setDroppable(null);
					return;
				}
			}
		}
		if (this.droppable != null) {
			this.droppable.getElement().setStyles({'position': 'relative', 'top': 0, 'left': 0});
			this.addPanierProd(this.droppable);
		}
		this.setDroppable(null);

		dragFX.stop();
		dragFX.remove();
	},

	somethingOver: function(dropElement, dragFX) {
		//alert(dropElement.title);
		if (this.droppable != null) {
			var clone = this.droppable.getElement().clone();
			clone.setStyles({'position': 'relative', 'top': 0, 'left': 0});
			this.temporaryAddPanierProd(new PanierProd(clone));
		}
	},

	somethingLeave: function(dropElement, dragFX) {
		this.removeTemporaryAdded();
	},

	ajaxAddProduct: function(panierProd) {
		var myAjax = new Ajax('/ajax_panier', {method: 'post', data: {
			type: 'add',
			uid : panierProd.getProdID(),
			taille : panierProd.getTaille()
		}, onComplete: function(result) {
			//alert(result);
		} }).request();
	},

	ajaxRemoveProduct: function(panierProd) {
		var myAjax = new Ajax('/ajax_panier', {method: 'post', data: {
			type: 'suppr',
			uid : panierProd.getProdID(),
			taille : panierProd.getTaille(),
			pos: panierProd.getPosition()
		}, onComplete: function(result) {
			//alert(result);
		} }).request();
	}
});


var PanierProd = new Class({
	initialize: function(el) {
		this.element = el;

		this.parent = this.element.getParent();

		this.panier = null;

		this.prodId = this.element.title;

		var children = this.element.getChildren();
		this.title_div = children[0];
		this.title_cell = this.title_div.getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0];

		this.img_prod = children[1];
		this.bottom = children[2];

		var bottom_children = this.bottom.getChildren();
		this.tailleSpan = bottom_children[1];
		this.prixSpan = bottom_children[4].getChildren()[0];

		this.closeButton = children[3];

		this.closeButton.addEvent('click', function(event) {
			if (this.getPanier() != null) {
				var panier = this.getPanier();
				if (panier != null) {
					panier.removePanierProd(this);
				}
			}
		}.bind(this));
	},

	getElement: function() {
		return this.element;
	},

	setPanier: function(panier) {
		this.panier = panier;
	},

	getPanier: function() {
		return this.panier;
	},

	inject: function(el) {
		this.element.inject(el);
	},

	getProdID: function() {
		return this.prodId;
	},

	getTaille: function() {
		return this.tailleSpan.innerHTML;
	},

	getPrix: function() {
		return this.prixSpan.innerHTML;
	},

	showCloseButton: function() {
		this.closeButton.setStyle('display', 'block');
	},

	hideCloseButton: function() {
		this.closeButton.setStyle('display', 'none');
	},

	getPosition: function() {
		var nb_before = -1;
		var parcours_prod = this.getElement().getParent();
		if (parcours_prod.className != 'panier_prod_container') {
			return 1;
		}
		while (parcours_prod != undefined) {
			parcours_prod = parcours_prod.getPrevious();
			nb_before++;
		}

		return nb_before + 1;
	}
});

function createPanierProd(uid, barcode, img, taille, prix) {
	var newdiv = document.createElement('div');
	newdiv = new Element(newdiv);

	newdiv.title = uid;
	newdiv.className = 'panier_prod';

	newdiv.innerHTML = "<div class=\"panier_prod_title\">\n<table width=\"100%\" height=\"100%\"><tr width=\"100%\" height=\"100%\"><td width=\"100%\" height=\"100%\" align=\"center\" valign=\"center\">\n"+barcode+"</td></tr></table>\n</div>\n<img src=\"/images/photo_prods/small/"+img+"\" /><div class=\"panier_prod_bottom\">\n<b>Taille:</b> <span>"+taille+"</span><br/>\n<b>Prix:</b> <span class=\"panier_prod_prix\"><span>"+prix+"</span> &euro;</span>\n</div>\n<div class=\"panier_prod_close\"></div>";

	return new PanierProd(newdiv);
}





var PanierElement2 = new Class({
	initialize: function(el, btn_valider, il_vous_reste) {
		this.element = el;
		this.boutonValiderDiv = btn_valider;
		var boutonValiderDivChildren = this.boutonValiderDiv.getChildren();
		this.boutonValiderLink = boutonValiderDivChildren[0];
		this.boutonValiderLink.addEvent('click', function(event) {
			event = new Event(event);

			event.stop();
			document.location = '/identification';

			return false;
		}.bind(this));

		this.il_vous_reste_div = il_vous_reste;
		var resteChildren = this.il_vous_reste_div.getChildren();
		this.prixOffert = resteChildren[0].innerHTML.toFloat();
		this.spanPasOffert = resteChildren[1];
		this.spanOffert = resteChildren[2];

		this.prixRestantSpan = this.spanPasOffert.getChildren()[0];

		this.boutonValiderInactif = boutonValiderDivChildren[1];

		this.tableRows = this.element.getChildren()[0].getChildren();

		this.tableHeadRow = this.tableRows[0];
		this.tableEmptyRow = this.tableRows[1];
		this.tableFootRow = this.tableRows[this.tableRows.length - 1];
		this.tableCodePrivRow = this.tableRows[this.tableRows.length - 2];

		this.tableCodePrivTD = this.tableCodePrivRow.getChildren()[0];
		var codePrivChildren = this.tableCodePrivTD.getChildren();
		this.codePrivInput = codePrivChildren[0];
		this.codePrivVal = codePrivChildren[1];
		this.codePrivErrorDiv = codePrivChildren[2];

		var codePrivInputChildren = this.codePrivInput.getChildren();
		this.codePrivInputVal = codePrivInputChildren[1];
		this.codePrivInputButton = codePrivInputChildren[2];

		var codePrivValChildren = this.codePrivVal.getChildren();
		this.codePrivNomSpan = codePrivValChildren[0];
		this.codePrivPortOfferSpan = codePrivValChildren[1];
		this.codePrivRemiseSpan = codePrivValChildren[2];
		this.codePrivRemiseSpanVal = this.codePrivRemiseSpan.getChildren()[0];

		this.codePrivValButton = codePrivValChildren[3];

		this.codePrivInputButton.addEvent('click', function(event) {
			this.uploadCodePriv();
		}.bind(this));
		this.codePrivValButton.addEvent('click', function(event) {
			this.removeCodePriv();
		}.bind(this));

		this.tableEmptyDiv = this.tableEmptyRow.getChildren()[0].getChildren()[0];

		this.prixTotalSpan = this.tableFootRow.getChildren()[1].getChildren()[0];

		this.panier_prods = [];
		if (this.tableRows.length == 3) {
			this.isEmpty = true;
		} else {
			this.isEmpty = false;
			for (var i = 2; i < this.tableRows.length - 3; i++) {
				tmp_panier_prod = new PanierProd2(this.tableRows[i]);
				tmp_panier_prod.setPanier(this);
				this.panier_prods[this.panier_prods.length] = tmp_panier_prod;
			}
		}
	},

	getElement: function() {
		return this.element;
	},

	getBoutonValider: function() {
		return this.boutonValiderDiv;
	},

	isCodePrivSetted: function() {
		return (this.codePrivInput.getStyle('display') == 'none');
	},

	getCodePrivNom: function() {
		return this.codePrivNomSpan.innerHTML;
	},

	getCodePrivType: function() {
		if (this.codePrivPortOfferSpan.getStyle('display') != 'none') {
			return 1;
		}
		return 0;
	},

	getCodePrivPercentRem: function() {
		return this.codePrivRemiseSpanVal.innerHTML;
	},

	setPortOffert: function(is_offert) {
		if (is_offert == true) {
			this.spanPasOffert.setStyle('display', 'none');
			this.spanOffert.setStyle('display', 'inline');
		} else {
			this.spanOffert.setStyle('display', 'none');
			this.spanPasOffert.setStyle('display', 'inline');
		}
	},

	isPortOffert: function() {
		return (this.spanPasOffert.getStyle('display') == 'none');
	},

	setPrixRestant: function(prix) {
		this.prixRestantSpan.innerHTML = prix;
	},

	getPrixRestant: function() {
		return this.prixRestantSpan.innerHTML;
	},

	getPrixPortOffert: function() {
		return this.prixOffert;
	},

	updatePortOffert: function() {
		var restant = this.getPrixPortOffert() - this.getPrixTotal();
		if (restant < 0) {
			restant = 0;
		}

		this.setPrixRestant(restant);

		var a_offrir = false;
		if (restant <= 0) {
			a_offrir = true;
		}
		if (this.getCodePrivType() == 1 && this.isCodePrivSetted() == true) {
			a_offrir = true;
		}
		this.setPortOffert(a_offrir);
	},


	setPrixTotal: function(prixTotal) {
		prixTotal = prixTotal.toFloat();
		prixTotal = Math.round(prixTotal * 100) / 100;

		formattedPrice = formatPrice(prixTotal);
		if (formattedPrice != this.prixTotalSpan.innerHTML) {
			this.prixTotalSpan.innerHTML = formattedPrice;
		}
	},

	getPrixTotal: function() {
		return this.prixTotalSpan.innerHTML.toFloat();
	},

	refreshPrice: function() {
		var totalPrice = 0;
		var hasError = false;
		this.panier_prods.each(function(panierProd, i) {
			totalPrice += panierProd.getPrixTotal();
			if (panierProd.hasError()) {
				hasError = true;
			}
		});

		if (this.isCodePrivSetted() == true && this.getCodePrivType() == 0) {
			totalPrice *= (100 - this.getCodePrivPercentRem()) / 100;
		}

		this.setPrixTotal(totalPrice);
		this.setBoutonValider(!hasError);
		this.updatePortOffert();
	},

	checkIfEmpty: function() {
		if (this.panier_prods.length == 0) {
			this.isEmpty = true;
			this.tableEmptyDiv.setStyle('display', 'block');
			this.setBoutonValider(false);
		} else {
			this.isEmpty = false;
			this.tableEmptyDiv.setStyle('display', 'none');
			this.setBoutonValider(true);
		}
	},

	removePanierProd: function(panierProd) {
		var new_panier_prods = [];
		for (var i = 0; i < this.panier_prods.length; i++) {
			panierProdParcours = this.panier_prods[i];
			if (panierProdParcours != panierProd) {
				new_panier_prods[new_panier_prods.length] = panierProdParcours;
			}
		}
		this.ajaxRemoveProduct(panierProd);
		panierProd.getElement().remove();
		this.panier_prods = new_panier_prods;

		this.checkIfEmpty();
		this.refreshPrice();
	},

	ajaxSetProductQte: function(uid, taille, qte) {
		var myAjax = new Ajax('/ajax_panier', {method: 'post', data: {
			type: 'setQte',
			uid : uid,
			taille : taille,
			qte: qte
		}, onComplete: function(result) {
			//alert(result);
		} }).request();
	},

	ajaxRemoveProduct: function(panierProd) {
		this.ajaxSetProductQte(panierProd.getProdID(), panierProd.getTaille(), 0);
	},

	setBoutonValider: function(actif) {
		if (actif == true) {
			this.boutonValiderInactif.setStyle('display', 'none');
			this.boutonValiderLink.setStyle('display', 'inline');
		} else {
			this.boutonValiderLink.setStyle('display', 'none');
			this.boutonValiderInactif.setStyle('display', 'inline');
		}
	},

	uploadCodePriv: function() {
		var code = this.codePrivInputVal.value;
		this.codePrivErrorDiv.innerHTML = "";

		var myAjax = new Ajax('/ajax_code_priv', {method: 'post', data: {
			type : 'add',
			code: code
		}, onComplete: function(result) {
			var array_res = result.split('////');
			if (array_res.length == 4) {
				code = array_res[1];
				var type = array_res[2];
				var val = array_res[3];

				//alert(code+' - '+type+' - '+val);
				this.setCodePriv(code, type, val);
			} else {
				this.codePrivErrorDiv.innerHTML = "Code non valide";
			}
		}.bind(this) }).request();
	},

	setCodePriv: function(code_priv, rem_type, rem_val) {
		this.codePrivErrorDiv.innerHTML = "";
		this.codePrivNomSpan.innerHTML = code_priv;

		if (rem_type == 1) {
			this.codePrivRemiseSpan.setStyle('display', 'none');
			this.codePrivPortOfferSpan.setStyle('display', 'inline');
		} else {
			this.codePrivRemiseSpanVal.innerHTML = rem_val;
			this.codePrivPortOfferSpan.setStyle('display', 'none');
			this.codePrivRemiseSpan.setStyle('display', 'inline');
		}

		this.codePrivInput.setStyle('display', 'none');
		this.codePrivVal.setStyle('display', 'inline');
		this.refreshPrice();
	},

	removeCodePriv: function() {
		this.codePrivErrorDiv.innerHTML = "";
		this.codePrivInputVal.value = '';
		this.codePrivVal.setStyle('display', 'none');
		this.codePrivInput.setStyle('display', 'inline');
		this.codePrivNomSpan.innerHTML = '';
		this.codePrivRemiseSpanVal.innerHTML = '';
		this.ajaxRemoveCodePriv();
		this.refreshPrice();
	},

	ajaxRemoveCodePriv: function(code_priv, rem_type, rem_val) {
		var myAjax = new Ajax('/ajax_code_priv', {method: 'post', data: {
			type : 'suppr'
		}, onComplete: function(result) {
			//alert('complete ! '+result);
		} }).request();
	},

	alert_this: function() {
		alert(this.isCodePrivSetted()+' - '+this.getCodePrivNom()+' - '+this.getCodePrivType()+' - '+this.getCodePrivPercentRem());
	}
});

var PanierProd2 = new Class({
	initialize: function(el) {
		this.element = el;

		this.prodID = el.id;

		this.panier = null;

		this.columns = this.element.getChildren();

		this.imgTD = this.columns[0];
		this.infosTD = this.columns[1];
		this.prixUnitaireTD = this.columns[2];
		this.prixQteTD = this.columns[3];
		this.prixTotalTD = this.columns[4];
		this.supprTD = this.columns[5];

		this.taille = this.infosTD.getChildren()[3].innerHTML;
		
		this.prixUnitaire = this.prixUnitaireTD.getChildren()[0].innerHTML;
		this.qte_input = this.prixQteTD.getChildren()[0];
		this.prixTotalSpan = this.prixTotalTD.getChildren()[0];

		this.lastQte = this.qte_input.value.toInt();

		this.supprImg = this.supprTD.getChildren()[0];
		this.supprImg.addEvent('click', function(event) {
			this.remove();
		}.bind(this));

		this.qte_input.addEvent('keydown', this.recalculate.bind(this));
		this.qte_input.addEvent('keyup', this.recalculate.bind(this));
	},

	getElement: function() {
		return this.element;
	},

	setPanier: function(panier) {
		this.panier = panier;
	},

	getPanier: function() {
		return this.panier;
	},

	getProdID: function() {
		return this.prodID;
	},

	getTaille: function() {
		return this.taille;
	},

	setPrixTotal: function(prixTotal) {
		prixTotal = prixTotal.toFloat();
		prixTotal = Math.round(prixTotal * 100) / 100;

		formattedPrice = formatPrice(prixTotal);
		//if (formattedPrice != this.prixTotalSpan.innerHTML) {
			this.prixTotalSpan.innerHTML = formattedPrice;
			if (this.panier != null) {
				this.panier.refreshPrice();
			}
		//}
	},

	getPrixTotal: function() {
		return this.prixTotalSpan.innerHTML.toFloat();
	},

	recalculate: function() {
		var input_val = this.qte_input.value;
		input_val = input_val.trim();

		var int_val = 0;

		var isError = false;
		// Is it a correct integer ?
		if (input_val.length == 0) {
			this.qte_input.setStyle('background-color', 'orange');
			isError = true;
		} else if (''+input_val.toInt() == ''+input_val) {
			this.qte_input.setStyle('background-color', '#ffffff');
			int_val = input_val.toInt();
		} else {
			isError = true;
			this.qte_input.setStyle('background-color', '#ff0000');
		}

		var prixTotal = this.prixUnitaire * int_val;

		this.setPrixTotal(prixTotal);

		if (this.panier != null && isError == false && this.lastQte != int_val) {
			this.lastQte = int_val;
			this.panier.ajaxSetProductQte(this.getProdID(), this.getTaille(), int_val);
		}
	},

	hasError: function() {
		var input_val = this.qte_input.value;
		input_val = input_val.trim();

		var int_val = 0;

		var isError = false;
		// Is it a correct integer ?
		if (input_val.length == 0) {
			return true;
		}
		if (''+input_val.toInt() != ''+input_val) {
			return true;
		}
		return false;
	},

	remove: function() {
		if (this.panier != null) {
			this.panier.removePanierProd(this);
		}
	}
});


var IdentificationElement = new Class({
	initialize: function(el, btn_valider) {
		this.element = el;
		this.boutonValiderDiv = btn_valider;

		this.form = this.element.getChildren()[0];
		this.table = this.form.getChildren()[0];

		var boutonValiderDivChildren = this.boutonValiderDiv.getChildren();
		this.boutonValiderLink = boutonValiderDivChildren[0];
		this.boutonValiderLink.addEvent('click', function(event) {
			event = new Event(event);

			event.stop();
			this.form.submit();

			return false;
		}.bind(this));

		this.boutonValiderInactif = boutonValiderDivChildren[1];

		this.tableRows = this.table.getChildren()[0].getChildren();
		this.tableHeadRow = this.tableRows[0];
		this.tableContentRow = this.tableRows[1];

		var tableContentRowChildren = this.tableContentRow.getChildren();
		this.leftContentColumn = tableContentRowChildren[0];
		this.rightContentColumn = tableContentRowChildren[1];

		this.addrFacDiv = this.leftContentColumn.getChildren()[0];
		this.addrFacTable = this.addrFacDiv.getChildren()[0];

		this.addrFacTableRows = this.addrFacTable.getChildren()[0].getChildren();

		this.addrFacNomRow = this.addrFacTableRows[0];
		this.addrFacPrenomRow = this.addrFacTableRows[1];
		this.addrFacAdresseRow = this.addrFacTableRows[2];
		this.addrFacCpRow = this.addrFacTableRows[3];
		this.addrFacVilleRow = this.addrFacTableRows[4];
		this.addrFacPaysRow = this.addrFacTableRows[5];

		this.addrFacSpaceRow = this.addrFacTableRows[6];

		this.addrFacEmailRow = this.addrFacTableRows[7];
		this.addrFacPhoneRow = this.addrFacTableRows[8];

		this.addrLivDiv = this.rightContentColumn.getChildren()[0];
		this.addrLivTable = this.addrLivDiv.getChildren()[0];

		this.addrLivTableRows = this.addrLivTable.getChildren()[0].getChildren();

		this.addrLivRadioSameRow = this.addrLivTableRows[0];
		this.addrLivRadioDiffRow = this.addrLivTableRows[2];

		this.addrLivRadioSameButton = this.addrLivRadioSameRow.getChildren()[0].getChildren()[0];
		this.addrLivRadioDiffButton = this.addrLivRadioDiffRow.getChildren()[0].getChildren()[0];

		this.addrLivRadioSameButton.addEvent('click', function(event) {
			this.radioChange();
		}.bind(this));
		this.addrLivRadioDiffButton.addEvent('click', function(event) {
			this.radioChange();
		}.bind(this));

		if (this.addrLivRadioSameButton.checked == true) {
			this.sameAddress = true;
		} else {
			this.sameAddress = false;
		}

		this.addrLivNomRow = this.addrLivTableRows[3];
		this.addrLivPrenomRow = this.addrLivTableRows[4];
		this.addrLivAdresseRow = this.addrLivTableRows[5];
		this.addrLivCpRow = this.addrLivTableRows[6];
		this.addrLivVilleRow = this.addrLivTableRows[7];
		this.addrLivPaysRow = this.addrLivTableRows[8];

		// Nom Facturation
		var addrFacNomChildren = this.addrFacNomRow.getChildren();
		this.addrFacNomInput = addrFacNomChildren[1].getChildren()[0];
		this.addrFacNomIcoSpan = addrFacNomChildren[2].getChildren()[0];
		var addrFacNomIcoSpanChildren = this.addrFacNomIcoSpan.getChildren();
		this.addrFacNomIcoWarning = addrFacNomIcoSpanChildren[0];
		this.addrFacNomIcoOk = addrFacNomIcoSpanChildren[1];
		if (this.addrFacNomIcoWarning.getStyle('display') == 'none') {
			this.addrFacNomOK = true;
		} else {
			this.addrFacNomOK = false;
		}
		this.addrFacNomInput.addEvent('keydown', this.validFacNom.bind(this));
		this.addrFacNomInput.addEvent('keyup', this.validFacNom.bind(this));

		// Prenom Facturation
		var addrFacPrenomChildren = this.addrFacPrenomRow.getChildren();
		this.addrFacPrenomInput = addrFacPrenomChildren[1].getChildren()[0];
		this.addrFacPrenomIcoSpan = addrFacPrenomChildren[2].getChildren()[0];
		var addrFacPrenomIcoSpanChildren = this.addrFacPrenomIcoSpan.getChildren();
		this.addrFacPrenomIcoWarning = addrFacPrenomIcoSpanChildren[0];
		this.addrFacPrenomIcoOk = addrFacPrenomIcoSpanChildren[1];
		if (this.addrFacPrenomIcoWarning.getStyle('display') == 'none') {
			this.addrFacPrenomOK = true;
		} else {
			this.addrFacPrenomOK = false;
		}
		this.addrFacPrenomInput.addEvent('keydown', this.validFacPrenom.bind(this));
		this.addrFacPrenomInput.addEvent('keyup', this.validFacPrenom.bind(this));
		
		// Adresse Facturation
		var addrFacAdresseChildren = this.addrFacAdresseRow.getChildren();
		this.addrFacAdresseInput = addrFacAdresseChildren[1].getChildren()[0];
		this.addrFacAdresseIcoSpan = addrFacAdresseChildren[2].getChildren()[0];
		var addrFacAdresseIcoSpanChildren = this.addrFacAdresseIcoSpan.getChildren();
		this.addrFacAdresseIcoWarning = addrFacAdresseIcoSpanChildren[0];
		this.addrFacAdresseIcoOk = addrFacAdresseIcoSpanChildren[1];
		if (this.addrFacAdresseIcoWarning.getStyle('display') == 'none') {
			this.addrFacAdresseOK = true;
		} else {
			this.addrFacAdresseOK = false;
		}
		this.addrFacAdresseInput.addEvent('keydown', this.validFacAdresse.bind(this));
		this.addrFacAdresseInput.addEvent('keyup', this.validFacAdresse.bind(this));

		// Code Postal Facturation
		var addrFacCpChildren = this.addrFacCpRow.getChildren();
		this.addrFacCpInput = addrFacCpChildren[1].getChildren()[0];
		this.addrFacCpIcoSpan = addrFacCpChildren[2].getChildren()[0];
		var addrFacCpIcoSpanChildren = this.addrFacCpIcoSpan.getChildren();
		this.addrFacCpIcoWarning = addrFacCpIcoSpanChildren[0];
		this.addrFacCpIcoOk = addrFacCpIcoSpanChildren[1];
		if (this.addrFacCpIcoWarning.getStyle('display') == 'none') {
			this.addrFacCpOK = true;
		} else {
			this.addrFacCpOK = false;
		}
		this.addrFacCpInput.addEvent('keydown', this.validFacCp.bind(this));
		this.addrFacCpInput.addEvent('keyup', this.validFacCp.bind(this));

		// Ville Facturation
		var addrFacVilleChildren = this.addrFacVilleRow.getChildren();
		this.addrFacVilleInput = addrFacVilleChildren[1].getChildren()[0];
		this.addrFacVilleIcoSpan = addrFacVilleChildren[2].getChildren()[0];
		var addrFacVilleIcoSpanChildren = this.addrFacVilleIcoSpan.getChildren();
		this.addrFacVilleIcoWarning = addrFacVilleIcoSpanChildren[0];
		this.addrFacVilleIcoOk = addrFacVilleIcoSpanChildren[1];
		if (this.addrFacVilleIcoWarning.getStyle('display') == 'none') {
			this.addrFacVilleOK = true;
		} else {
			this.addrFacVilleOK = false;
		}
		this.addrFacVilleInput.addEvent('keydown', this.validFacVille.bind(this));
		this.addrFacVilleInput.addEvent('keyup', this.validFacVille.bind(this));

		// Pays Facturation
		var addrFacPaysChildren = this.addrFacPaysRow.getChildren();
		this.addrFacPaysSelect = addrFacPaysChildren[1].getChildren()[0];
		this.addrFacPaysIcoSpan = addrFacPaysChildren[2].getChildren()[0];
		var addrFacPaysIcoSpanChildren = this.addrFacPaysIcoSpan.getChildren();
		this.addrFacPaysIcoWarning = addrFacPaysIcoSpanChildren[0];
		this.addrFacPaysIcoOk = addrFacPaysIcoSpanChildren[1];
		if (this.addrFacPaysIcoWarning.getStyle('display') == 'none') {
			this.addrFacPaysOK = true;
		} else {
			this.addrFacPaysOK = false;
		}
		this.addrFacPaysSelect.addEvent('change', this.validFacPays.bind(this));

		// Email
		var addrFacEmailChildren = this.addrFacEmailRow.getChildren();
		this.addrFacEmailInput = addrFacEmailChildren[1].getChildren()[0];
		this.addrFacEmailIcoSpan = addrFacEmailChildren[2].getChildren()[0];
		var addrFacEmailIcoSpanChildren = this.addrFacEmailIcoSpan.getChildren();
		this.addrFacEmailIcoWarning = addrFacEmailIcoSpanChildren[0];
		this.addrFacEmailIcoOk = addrFacEmailIcoSpanChildren[1];
		if (this.addrFacEmailIcoWarning.getStyle('display') == 'none') {
			this.addrFacEmailOK = true;
		} else {
			this.addrFacEmailOK = false;
		}
		this.addrFacEmailInput.addEvent('keydown', this.validFacEmail.bind(this));
		this.addrFacEmailInput.addEvent('keyup', this.validFacEmail.bind(this));

		// Phone
		var addrFacPhoneChildren = this.addrFacPhoneRow.getChildren();
		this.addrFacPhoneInput = addrFacPhoneChildren[1].getChildren()[0];
		this.addrFacPhoneIcoSpan = addrFacPhoneChildren[2].getChildren()[0];
		var addrFacPhoneIcoSpanChildren = this.addrFacPhoneIcoSpan.getChildren();
		this.addrFacPhoneIcoWarning = addrFacPhoneIcoSpanChildren[0];
		this.addrFacPhoneIcoOk = addrFacPhoneIcoSpanChildren[1];
		if (this.addrFacPhoneIcoWarning.getStyle('display') == 'none') {
			this.addrFacPhoneOK = true;
		} else {
			this.addrFacPhoneOK = false;
		}
		this.addrFacPhoneInput.addEvent('keydown', this.validFacPhone.bind(this));
		this.addrFacPhoneInput.addEvent('keyup', this.validFacPhone.bind(this));



		/********************/


		// Nom Livraison
		var addrLivNomChildren = this.addrLivNomRow.getChildren();
		this.addrLivNomInput = addrLivNomChildren[1].getChildren()[0];
		this.addrLivNomIcoSpan = addrLivNomChildren[2].getChildren()[0];
		var addrLivNomIcoSpanChildren = this.addrLivNomIcoSpan.getChildren();
		this.addrLivNomIcoWarning = addrLivNomIcoSpanChildren[0];
		this.addrLivNomIcoOk = addrLivNomIcoSpanChildren[1];
		if (this.addrLivNomIcoWarning.getStyle('display') == 'none') {
			this.addrLivNomOK = true;
		} else {
			this.addrLivNomOK = false;
		}
		this.addrLivNomInput.addEvent('keydown', this.validLivNom.bind(this));
		this.addrLivNomInput.addEvent('keyup', this.validLivNom.bind(this));
		this.addrLivNomInput.addEvent('focus', function(event) {
			this.setSameAddress(false);
		}.bind(this));

		// Prenom Livraison
		var addrLivPrenomChildren = this.addrLivPrenomRow.getChildren();
		this.addrLivPrenomInput = addrLivPrenomChildren[1].getChildren()[0];
		this.addrLivPrenomIcoSpan = addrLivPrenomChildren[2].getChildren()[0];
		var addrLivPrenomIcoSpanChildren = this.addrLivPrenomIcoSpan.getChildren();
		this.addrLivPrenomIcoWarning = addrLivPrenomIcoSpanChildren[0];
		this.addrLivPrenomIcoOk = addrLivPrenomIcoSpanChildren[1];
		if (this.addrLivPrenomIcoWarning.getStyle('display') == 'none') {
			this.addrLivPrenomOK = true;
		} else {
			this.addrLivPrenomOK = false;
		}
		this.addrLivPrenomInput.addEvent('keydown', this.validLivPrenom.bind(this));
		this.addrLivPrenomInput.addEvent('keyup', this.validLivPrenom.bind(this));
		this.addrLivPrenomInput.addEvent('focus', function(event) {
			this.setSameAddress(false);
		}.bind(this));

		// Adresse Livraison
		var addrLivAdresseChildren = this.addrLivAdresseRow.getChildren();
		this.addrLivAdresseInput = addrLivAdresseChildren[1].getChildren()[0];
		this.addrLivAdresseIcoSpan = addrLivAdresseChildren[2].getChildren()[0];
		var addrLivAdresseIcoSpanChildren = this.addrLivAdresseIcoSpan.getChildren();
		this.addrLivAdresseIcoWarning = addrLivAdresseIcoSpanChildren[0];
		this.addrLivAdresseIcoOk = addrLivAdresseIcoSpanChildren[1];
		if (this.addrLivAdresseIcoWarning.getStyle('display') == 'none') {
			this.addrLivAdresseOK = true;
		} else {
			this.addrLivAdresseOK = false;
		}
		this.addrLivAdresseInput.addEvent('keydown', this.validLivAdresse.bind(this));
		this.addrLivAdresseInput.addEvent('keyup', this.validLivAdresse.bind(this));
		this.addrLivAdresseInput.addEvent('focus', function(event) {
			this.setSameAddress(false);
		}.bind(this));

		// Code Postal Livraison
		var addrLivCpChildren = this.addrLivCpRow.getChildren();
		this.addrLivCpInput = addrLivCpChildren[1].getChildren()[0];
		this.addrLivCpIcoSpan = addrLivCpChildren[2].getChildren()[0];
		var addrLivCpIcoSpanChildren = this.addrLivCpIcoSpan.getChildren();
		this.addrLivCpIcoWarning = addrLivCpIcoSpanChildren[0];
		this.addrLivCpIcoOk = addrLivCpIcoSpanChildren[1];
		if (this.addrLivCpIcoWarning.getStyle('display') == 'none') {
			this.addrLivCpOK = true;
		} else {
			this.addrLivCpOK = false;
		}
		this.addrLivCpInput.addEvent('keydown', this.validLivCp.bind(this));
		this.addrLivCpInput.addEvent('keyup', this.validLivCp.bind(this));
		this.addrLivCpInput.addEvent('focus', function(event) {
			this.setSameAddress(false);
		}.bind(this));

		// Ville Livraison
		var addrLivVilleChildren = this.addrLivVilleRow.getChildren();
		this.addrLivVilleInput = addrLivVilleChildren[1].getChildren()[0];
		this.addrLivVilleIcoSpan = addrLivVilleChildren[2].getChildren()[0];
		var addrLivVilleIcoSpanChildren = this.addrLivVilleIcoSpan.getChildren();
		this.addrLivVilleIcoWarning = addrLivVilleIcoSpanChildren[0];
		this.addrLivVilleIcoOk = addrLivVilleIcoSpanChildren[1];
		if (this.addrLivVilleIcoWarning.getStyle('display') == 'none') {
			this.addrLivVilleOK = true;
		} else {
			this.addrLivVilleOK = false;
		}
		this.addrLivVilleInput.addEvent('keydown', this.validLivVille.bind(this));
		this.addrLivVilleInput.addEvent('keyup', this.validLivVille.bind(this));
		this.addrLivVilleInput.addEvent('focus', function(event) {
			this.setSameAddress(false);
		}.bind(this));

		// Pays Livraison
		var addrLivPaysChildren = this.addrLivPaysRow.getChildren();
		this.addrLivPaysSelect = addrLivPaysChildren[1].getChildren()[0];
		this.addrLivPaysIcoSpan = addrLivPaysChildren[2].getChildren()[0];
		var addrLivPaysIcoSpanChildren = this.addrLivPaysIcoSpan.getChildren();
		this.addrLivPaysIcoWarning = addrLivPaysIcoSpanChildren[0];
		this.addrLivPaysIcoOk = addrLivPaysIcoSpanChildren[1];
		if (this.addrLivPaysIcoWarning.getStyle('display') == 'none') {
			this.addrLivPaysOK = true;
		} else {
			this.addrLivPaysOK = false;
		}
		this.addrLivPaysSelect.addEvent('change', this.validLivPays.bind(this));
		this.addrLivPaysSelect.addEvent('focus', function(event) {
			this.setSameAddress(false);
		}.bind(this));

		this.allOK = false;
		this.checkIfAllValid();
	},

	getElement: function() {
		return this.element;
	},

	getBoutonValider: function() {
		return this.boutonValiderDiv;
	},

	radioChange: function() {
		if (this.addrLivRadioSameButton.checked == true) {
			this.setSameAddress(true);
		} else {
			this.setSameAddress(false);
		}
	},

	setSameAddress: function(is_same) {
		if (this.sameAddress == is_same) {
			return;
		}

		if (is_same == true) {
			this.addrLivRadioSameButton.checked = true;
			this.addrLivRadioDiffButton.checked = false;
			this.addrLivDiv.className = "addr_liv_same";
		} else {
			this.addrLivRadioDiffButton.checked = true;
			this.addrLivRadioSameButton.checked = false;
			this.addrLivDiv.className = "";
		}
		this.sameAddress = is_same;
		this.checkIfAllValid();
	},

	isSameAddress: function() {
		return this.sameAddress;
	},

	validFacNom: function() {
		var nom = this.addrFacNomInput.value;
		if (nom == null) {
			nom = '';
		}
		var nom_string = new String(nom).trim();
		if (!nom_string.match('^(.+)$')) {
			this.setFacNomOK(false);
		} else {
			this.setFacNomOK(true);
		}
	},

	setFacNomOK: function(is_OK) {
		if (is_OK == this.addrFacNomOK) {
			return;
		}
		if (is_OK == true) {
			this.addrFacNomIcoWarning.setStyle('display', 'none');
			this.addrFacNomIcoOk.setStyle('display', 'inline');
		} else {
			this.addrFacNomIcoOk.setStyle('display', 'none');
			this.addrFacNomIcoWarning.setStyle('display', 'inline');
		}
		this.addrFacNomOK = is_OK;
		this.checkIfAllValid();
	},

	validFacPrenom: function() {
		var prenom = this.addrFacPrenomInput.value;
		if (prenom == null) {
			prenom = '';
		}
		var prenom_string = new String(prenom).trim();
		if (!prenom_string.match('^(.+)$')) {
			this.setFacPrenomOK(false);
		} else {
			this.setFacPrenomOK(true);
		}
	},

	setFacPrenomOK: function(is_OK) {
		if (is_OK == this.addrFacPrenomOK) {
			return;
		}
		if (is_OK == true) {
			this.addrFacPrenomIcoWarning.setStyle('display', 'none');
			this.addrFacPrenomIcoOk.setStyle('display', 'inline');
		} else {
			this.addrFacPrenomIcoOk.setStyle('display', 'none');
			this.addrFacPrenomIcoWarning.setStyle('display', 'inline');
		}
		this.addrFacPrenomOK = is_OK;
		this.checkIfAllValid();
	},

	validFacAdresse: function() {
		var adresse = this.addrFacAdresseInput.value;
		if (adresse == null) {
			adresse = '';
		}
		var adresse_string = new String(adresse).trim();
		if (!adresse_string.match('^(.+)$')) {
			this.setFacAdresseOK(false);
		} else {
			this.setFacAdresseOK(true);
		}
	},

	setFacAdresseOK: function(is_OK) {
		if (is_OK == this.addrFacAdresseOK) {
			return;
		}
		if (is_OK == true) {
			this.addrFacAdresseIcoWarning.setStyle('display', 'none');
			this.addrFacAdresseIcoOk.setStyle('display', 'inline');
		} else {
			this.addrFacAdresseIcoOk.setStyle('display', 'none');
			this.addrFacAdresseIcoWarning.setStyle('display', 'inline');
		}
		this.addrFacAdresseOK = is_OK;
		this.checkIfAllValid();
	},

	validFacCp: function() {
		var cp = this.addrFacCpInput.value;
		if (cp == null) {
			cp = '';
		}
		var cp_string = new String(cp).trim();
		if (!cp_string.match('^(.+)$')) {
			this.setFacCpOK(false);
		} else {
			this.setFacCpOK(true);
		}
	},

	setFacCpOK: function(is_OK) {
		if (is_OK == this.addrFacCpOK) {
			return;
		}
		if (is_OK == true) {
			this.addrFacCpIcoWarning.setStyle('display', 'none');
			this.addrFacCpIcoOk.setStyle('display', 'inline');
		} else {
			this.addrFacCpIcoOk.setStyle('display', 'none');
			this.addrFacCpIcoWarning.setStyle('display', 'inline');
		}
		this.addrFacCpOK = is_OK;
		this.checkIfAllValid();
	},

	validFacVille: function() {
		var ville = this.addrFacVilleInput.value;
		if (ville == null) {
			ville = '';
		}
		var ville_string = new String(ville).trim();
		if (!ville_string.match('^(.+)$')) {
			this.setFacVilleOK(false);
		} else {
			this.setFacVilleOK(true);
		}
	},

	setFacVilleOK: function(is_OK) {
		if (is_OK == this.addrFacVilleOK) {
			return;
		}
		if (is_OK == true) {
			this.addrFacVilleIcoWarning.setStyle('display', 'none');
			this.addrFacVilleIcoOk.setStyle('display', 'inline');
		} else {
			this.addrFacVilleIcoOk.setStyle('display', 'none');
			this.addrFacVilleIcoWarning.setStyle('display', 'inline');
		}
		this.addrFacVilleOK = is_OK;
		this.checkIfAllValid();
	},

	validFacPays: function() {
		var pays = this.addrFacPaysSelect.value;
		if (pays == null) {
			pays = '0';
		}
		if (pays != '0') {
			this.setFacPaysOK(true);
		} else {
			this.setFacPaysOK(false);
		}
	},

	setFacPaysOK: function(is_OK) {
		if (is_OK == this.addrFacPaysOK) {
			return;
		}
		if (is_OK == true) {
			this.addrFacPaysIcoWarning.setStyle('display', 'none');
			this.addrFacPaysIcoOk.setStyle('display', 'inline');
		} else {
			this.addrFacPaysIcoOk.setStyle('display', 'none');
			this.addrFacPaysIcoWarning.setStyle('display', 'inline');
		}
		this.addrFacPaysOK = is_OK;
		this.checkIfAllValid();
	},

	validFacEmail: function() {
		var email = this.addrFacEmailInput.value;
		if (email == null) {
			email = '';
		}
		var email_string = new String(email).trim();
		if (!email_string.match('^[a-zA-Z0-9]{1}[-_\.0-9a-zA-Z]*@[a-zA-Z0-9_-]{1}[-_\.0-9a-zA-Z]*[\.][0-9a-zA-Z]{2,}$')) {
		//if (!email_string.match('^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$')) {
			this.setFacEmailOK(false);
		} else {
			this.setFacEmailOK(true);
		}
	},

	setFacEmailOK: function(is_OK) {
		if (is_OK == this.addrFacEmailOK) {
			return;
		}
		if (is_OK == true) {
			this.addrFacEmailIcoWarning.setStyle('display', 'none');
			this.addrFacEmailIcoOk.setStyle('display', 'inline');
		} else {
			this.addrFacEmailIcoOk.setStyle('display', 'none');
			this.addrFacEmailIcoWarning.setStyle('display', 'inline');
		}
		this.addrFacEmailOK = is_OK;
		this.checkIfAllValid();
	},

	validFacPhone: function() {
		var phone = this.addrFacPhoneInput.value;
		if (phone == null) {
			phone = '';
		}
		var phone_string = new String(phone).trim();
		if (!phone_string.match('^[\+]?[ \.-]*([0-9]{1}[ \.-]*){10,}$')) {
			this.setFacPhoneOK(false);
		} else {
			this.setFacPhoneOK(true);
		}
	},

	setFacPhoneOK: function(is_OK) {
		if (is_OK == this.addrFacPhoneOK) {
			return;
		}
		if (is_OK == true) {
			this.addrFacPhoneIcoWarning.setStyle('display', 'none');
			this.addrFacPhoneIcoOk.setStyle('display', 'inline');
		} else {
			this.addrFacPhoneIcoOk.setStyle('display', 'none');
			this.addrFacPhoneIcoWarning.setStyle('display', 'inline');
		}
		this.addrFacPhoneOK = is_OK;
		this.checkIfAllValid();
	},

	validLivNom: function() {
		var nom = this.addrLivNomInput.value;
		if (nom == null) {
			nom = '';
		}
		var nom_string = new String(nom).trim();
		if (!nom_string.match('^(.+)$')) {
			this.setLivNomOK(false);
		} else {
			this.setLivNomOK(true);
		}
	},

	setLivNomOK: function(is_OK) {
		if (is_OK == this.addrLivNomOK) {
			return;
		}
		if (is_OK == true) {
			this.addrLivNomIcoWarning.setStyle('display', 'none');
			this.addrLivNomIcoOk.setStyle('display', 'inline');
		} else {
			this.addrLivNomIcoOk.setStyle('display', 'none');
			this.addrLivNomIcoWarning.setStyle('display', 'inline');
		}
		this.addrLivNomOK = is_OK;
		this.checkIfAllValid();
	},

	validLivPrenom: function() {
		var prenom = this.addrLivPrenomInput.value;
		if (prenom == null) {
			prenom = '';
		}
		var prenom_string = new String(prenom).trim();
		if (!prenom_string.match('^(.+)$')) {
			this.setLivPrenomOK(false);
		} else {
			this.setLivPrenomOK(true);
		}
	},

	setLivPrenomOK: function(is_OK) {
		if (is_OK == this.addrLivPrenomOK) {
			return;
		}
		if (is_OK == true) {
			this.addrLivPrenomIcoWarning.setStyle('display', 'none');
			this.addrLivPrenomIcoOk.setStyle('display', 'inline');
		} else {
			this.addrLivPrenomIcoOk.setStyle('display', 'none');
			this.addrLivPrenomIcoWarning.setStyle('display', 'inline');
		}
		this.addrLivPrenomOK = is_OK;
		this.checkIfAllValid();
	},

	validLivAdresse: function() {
		var adresse = this.addrLivAdresseInput.value;
		if (adresse == null) {
			adresse = '';
		}
		var adresse_string = new String(adresse).trim();
		if (!adresse_string.match('^(.+)$')) {
			this.setLivAdresseOK(false);
		} else {
			this.setLivAdresseOK(true);
		}
	},

	setLivAdresseOK: function(is_OK) {
		if (is_OK == this.addrLivAdresseOK) {
			return;
		}
		if (is_OK == true) {
			this.addrLivAdresseIcoWarning.setStyle('display', 'none');
			this.addrLivAdresseIcoOk.setStyle('display', 'inline');
		} else {
			this.addrLivAdresseIcoOk.setStyle('display', 'none');
			this.addrLivAdresseIcoWarning.setStyle('display', 'inline');
		}
		this.addrLivAdresseOK = is_OK;
		this.checkIfAllValid();
	},

	validLivCp: function() {
		var cp = this.addrLivCpInput.value;
		if (cp == null) {
			cp = '';
		}
		var cp_string = new String(cp).trim();
		if (!cp_string.match('^(.+)$')) {
			this.setLivCpOK(false);
		} else {
			this.setLivCpOK(true);
		}
	},

	setLivCpOK: function(is_OK) {
		if (is_OK == this.addrLivCpOK) {
			return;
		}
		if (is_OK == true) {
			this.addrLivCpIcoWarning.setStyle('display', 'none');
			this.addrLivCpIcoOk.setStyle('display', 'inline');
		} else {
			this.addrLivCpIcoOk.setStyle('display', 'none');
			this.addrLivCpIcoWarning.setStyle('display', 'inline');
		}
		this.addrLivCpOK = is_OK;
		this.checkIfAllValid();
	},

	validLivVille: function() {
		var ville = this.addrLivVilleInput.value;
		if (ville == null) {
			ville = '';
		}
		var ville_string = new String(ville).trim();
		if (!ville_string.match('^(.+)$')) {
			this.setLivVilleOK(false);
		} else {
			this.setLivVilleOK(true);
		}
	},

	setLivVilleOK: function(is_OK) {
		if (is_OK == this.addrLivVilleOK) {
			return;
		}
		if (is_OK == true) {
			this.addrLivVilleIcoWarning.setStyle('display', 'none');
			this.addrLivVilleIcoOk.setStyle('display', 'inline');
		} else {
			this.addrLivVilleIcoOk.setStyle('display', 'none');
			this.addrLivVilleIcoWarning.setStyle('display', 'inline');
		}
		this.addrLivVilleOK = is_OK;
		this.checkIfAllValid();
	},

	validLivPays: function() {
		var pays = this.addrLivPaysSelect.value;
		if (pays == null) {
			pays = '0';
		}
		if (pays != '0') {
			this.setLivPaysOK(true);
		} else {
			this.setLivPaysOK(false);
		}
	},

	setLivPaysOK: function(is_OK) {
		if (is_OK == this.addrLivPaysOK) {
			return;
		}
		if (is_OK == true) {
			this.addrLivPaysIcoWarning.setStyle('display', 'none');
			this.addrLivPaysIcoOk.setStyle('display', 'inline');
		} else {
			this.addrLivPaysIcoOk.setStyle('display', 'none');
			this.addrLivPaysIcoWarning.setStyle('display', 'inline');
		}
		this.addrLivPaysOK = is_OK;
		this.checkIfAllValid();
	},

	checkIfAllValid: function() {
		var isOK = false;

		var facAddressValid = false;
		if (this.addrFacNomOK == true && this.addrFacPrenomOK == true && this.addrFacAdresseOK == true && this.addrFacCpOK == true && this.addrFacVilleOK == true && this.addrFacPaysOK == true) {
			facAddressValid = true;
		}

		if (facAddressValid == true) {
			var infosSuppValid = false;
			if (this.addrFacEmailOK == true && this.addrFacPhoneOK == true) {
				infosSuppValid = true;
			}

			if (infosSuppValid == true) {
				if (this.isSameAddress()) {
					isOK = true;
				} else {
					var livAddressValid = false;
					if (this.addrLivNomOK == true && this.addrLivPrenomOK == true && this.addrLivAdresseOK == true && this.addrLivCpOK == true && this.addrLivVilleOK == true && this.addrLivPaysOK == true) {
						livAddressValid = true;
					}
					if (livAddressValid == true) {
						isOK = true;
					}
				}
			}
		}

		this.setAllValid(isOK);
	},

	setAllValid: function(is_valid) {
		if (this.allOK == is_valid) {
			return;
		}

		this.allOK = is_valid;
		this.setBoutonValider(this.allOK);
	},

	isAllValid: function() {
		return this.allOK;
	},

	setBoutonValider: function(actif) {
		if (actif == true) {
			this.boutonValiderInactif.setStyle('display', 'none');
			this.boutonValiderLink.setStyle('display', 'inline');
		} else {
			this.boutonValiderLink.setStyle('display', 'none');
			this.boutonValiderInactif.setStyle('display', 'inline');
		}
	}
});


var RecapitulatifElement = new Class({
	initialize: function(el, btn_valider) {
		this.element = el;
		this.boutonValiderDiv = btn_valider;

		this.form = this.element.getChildren()[0];

		var boutonValiderDivChildren = this.boutonValiderDiv.getChildren();
		this.boutonValiderLink = boutonValiderDivChildren[0];
		this.boutonValiderLink.addEvent('click', function(event) {
			event = new Event(event);

			event.stop();
			this.form.submit();

			return false;
		}.bind(this));

		var formChildren = this.form.getChildren();
		this.leftPart = formChildren[0];
		this.rightPart = formChildren[1];

		rightPartChildren = this.rightPart.getChildren();

		this.table = rightPartChildren[1];
		this.tableRows = this.table.getChildren()[0].getChildren();

		if (this.tableRows[this.tableRows.length - 3].className == 'panier_priv_tr') {
			this.tableProdsTotalRow = this.tableRows[this.tableRows.length - 4];
			this.tableRemiseRow = this.tableRows[this.tableRows.length - 3];
		} else {
			this.tableProdsTotalRow = this.tableRows[this.tableRows.length - 3];
			this.tableRemiseRow = null;
		}
		this.tableProdsTotal = this.tableProdsTotalRow.getChildren()[1].getChildren()[0].innerHTML;
		if (this.tableRemiseRow != null) {
			this.tableProdsTotal = this.tableProdsTotal.toFloat() + this.tableRemiseRow.getChildren()[1].getChildren()[0].innerHTML.toFloat();
		}

		this.tableLivrDatasRow = this.tableRows[this.tableRows.length - 2];
		var tableLivrCols = this.tableLivrDatasRow.getChildren();
		var tableLivrMainDatas = tableLivrCols[0];
		var tableLivrMainDatasChildren = tableLivrMainDatas.getChildren();

		this.tableLivrTransporteurSelect = tableLivrMainDatasChildren[1];
		this.tableLivrTransporteurOptions = this.tableLivrTransporteurSelect.getChildren();

		this.tableLivrDelaiContainer = tableLivrMainDatasChildren[2];
		var tmpDelaiSpans = this.tableLivrDelaiContainer.getChildren();

		this.tableLivrDelaiSpans = [];
		for (var i = 0; i < tmpDelaiSpans.length; i++) {
			this.tableLivrDelaiSpans[i] = tmpDelaiSpans[i];
		}
		this.tableLivrDelaisS = tableLivrMainDatasChildren[3];

		this.tableLivrPrixRow = tableLivrCols[1];
		this.tableLivrPrixSpans = this.tableLivrPrixRow.getChildren();

		this.tableTotalRow = this.tableRows[this.tableRows.length - 1];
		this.tableTotalSpan = this.tableTotalRow.getChildren()[1].getChildren()[0];

		this.tableLivrTransporteurSelect.addEvent('change', function(event) {
			this.transporteurChange();
		}.bind(this));
	},

	getElement: function() {
		return this.element;
	},

	getBoutonValider: function() {
		return this.boutonValiderDiv;
	},

	getProdsPrix: function() {
		return this.tableProdsTotal.toFloat();
	},

	getLivraisonPrix: function() {
		for (var i = 0; i < this.tableLivrPrixSpans.length; i++) {
			var span = this.tableLivrPrixSpans[i];
			if (span.getStyle('display') == 'inline') {
				return span.innerHTML.toFloat();
			}
		}
		return 0;
	},

	getLivraisonDelai: function() {
		for (var i = 0; i < this.tableLivrDelaiSpans.length; i++) {
			var span = this.tableLivrDelaiSpans[i];
			if (span.getStyle('display') == 'inline') {
				return span.innerHTML.toFloat();
			}
		}
		return 0;
	},

	transporteurChange: function() {
		var value = this.tableLivrTransporteurSelect.value;
		var pos = 0;
		this.tableLivrTransporteurOptions.each(function(option, i) {
			if (option.value == value) {
				pos = i;
			}
		}.bind(this));

		for (var i = 0; i < this.tableLivrDelaiSpans.length; i++) {
			var span = this.tableLivrDelaiSpans[i];
			var prix = this.tableLivrPrixSpans[i];
			if (i == pos) {
				span.setStyle('display', 'inline');
				prix.setStyle('display', 'inline');
			} else {
				span.setStyle('display', 'none');
				prix.setStyle('display', 'none');
			}
		}

		this.checkDelaiS();
		var prixTotal = this.getProdsPrix() + this.getLivraisonPrix();

		this.setPrixTotal(prixTotal);
	},

	checkDelaiS: function() {
		var delai = this.getLivraisonDelai();
		if (delai.toFloat() > 1) {
			this.tableLivrDelaisS.setStyle('display', 'inline');
		} else {
			this.tableLivrDelaisS.setStyle('display', 'none');
		}
	},

	setPrixTotal: function(prixTotal) {
		prixTotal = prixTotal.toFloat();
		prixTotal = Math.round(prixTotal * 100) / 100;

		formattedPrice = formatPrice(prixTotal);
		if (formattedPrice != this.tableTotalSpan.innerHTML) {
			this.tableTotalSpan.innerHTML = formattedPrice;
		}
	}
});

var FicheProdDatas = new Class({
	initialize: function(el) {
		this.element = el;

		this.selectedTaille = null;
		this.panier = null;

		this.img_selected = 0;

		var mainChildren = el.getChildren();

		this.real_content_div = mainChildren[0];
		var real_content_children = this.real_content_div.getChildren();
		this.fiche_prod_left = real_content_children[0];
		var fiche_prod_left_children = this.fiche_prod_left.getChildren();
		this.photo_div = fiche_prod_left_children[0];

		var list_photos = this.photo_div.getChildren()[0].getChildren()[0].getChildren()[0].getChildren()[0].getChildren();

		this.miniatures_div = fiche_prod_left_children[1].getChildren()[1];
		this.miniatures_list = this.miniatures_div.getChildren();

		this.photos = [];
		for (var count = 0; count < list_photos.length; count++) {
			this.photos[this.photos.length] = list_photos[count];
			if (count < this.miniatures_list.length || count == 0) {
				//alert(count+" - "+this.miniatures_list.length);
				//alert(list_photos[count].getChildren()[1].id);
				//var jqElem = $jq("#"+list_photos[count].getChildren()[1].id);
				//jqElem.magnify('magnifier'+(count+1));

				var jqElemID = list_photos[count].getChildren()[1].id;
				$(jqElemID).setStyle('display', 'none');
				if ($(jqElemID).complete == true) {
					var jqElem = $jq("#"+jqElemID);
					jqElem.magnify().fadeIn("fast");
					jqElem.animate({opacity: 0.01}, 0);
					jqElem.css({display: "inline", opacity: 0.01});
					jqElem.animate({opacity: 0.01}, 0);
				} else {
					$jq("#"+jqElemID).load(function() {
						//$jq(this).magnify().fadeIn("fast");
						//alert('test');
						$jq(this).magnify().fadeIn("fast");
						$jq(this).animate({opacity: 0.01}, 0);
						$jq(this).css({display: "inline", opacity: 0.01});
						$jq(this).animate({opacity: 0.01}, 0);
					});
				}
			}
		}

		this.photo_file = '';
		if (this.photos.length > 0 && this.photos[0] != null) {
			var tmp_src = this.photos[0].src;
			if (tmp_src != null && tmp_src.length > 0) {
				var splitted = tmp_src.split('/');
				if (splitted != null && splitted.length > 0) {
					this.photo_file = splitted[splitted.length - 1];
				}
			}
		}

		this.miniatures_list.addEvent('mouseleave', function(event) {
			this.showPhoto(this.img_selected);
		}.bind(this));

		this.miniatures_list.each(function(min, i) {
			var num = i;
			min.addEvent('mouseenter', function(event) {
				this.showPhoto(num);
			}.bind(this));
			min.addEvent('mouseleave', function(event) {
				//alert('leave '+num);
			}.bind(this));
			min.addEvent('click', function(event) {
				this.setPhotoSelected(i);
			}.bind(this));
		}.bind(this));

		this.infos_div = real_content_children[1];

		var infos_div_children = this.infos_div.getChildren();
		this.titre_div = infos_div_children[0].getChildren()[0];
		var titre_span_children = this.titre_div.getChildren()[0].getChildren();

		this.barcode = titre_span_children[0].innerHTML;
		this.designation = titre_span_children[1].innerHTML;
		this.couleur = titre_span_children[2].innerHTML;

		this.prixdiv = titre_span_children[4];
		this.prix = this.prixdiv.getChildren()[0].innerHTML.toFloat();

		this.infos_content_div = infos_div_children[1];

		var infos_content_div_children = this.infos_content_div.getChildren();
		this.maindesc = infos_content_div_children[0];

		this.list_tailles_span = infos_content_div_children[3];
		this.tailles = [];
		this.list_tailles_span.getChildren().each(function(span, i) {
			this.tailles[this.tailles.length] = new FicheProdTaille(span, this);
		}.bind(this));

		this.qte_select = infos_content_div_children[7];

		this.bottom_div = infos_div_children[2];
		this.bottom_div_img = this.bottom_div.getChildren()[0];

		if (this.bottom_div_img.className != 'inact') {
			this.bottom_div_img.addEvent('click', function(event) {
				event = new Event(event);
				this.buttonAddPressed();
				event.stop();
				return false;
			}.bind(this));
		}

		if (infos_div_children.length > 3) {
			var infos_assoc = infos_div_children[3];
			this.assoc_div = infos_assoc.getChildren()[1];
			this.assoc_spans = this.assoc_div.getChildren();

			this.assoc_div.addEvent('mouseleave', function(event) {
				this.showPhoto(this.img_selected);
			}.bind(this));

			this.assoc_spans.addEvent('mouseleave', function(event) {
				this.showPhoto(this.img_selected);
			}.bind(this));

			this.assoc_spans.each(function(min, i) {
				var num = this.miniatures_list.length + i;
				min.addEvent('mouseenter', function(event) {
					this.showPhoto(num);
				}.bind(this));
				min.addEvent('mouseleave', function(event) {
					//alert('leave '+num);
				}.bind(this));
			}.bind(this));
		}
	},

	getElement: function() {
		return this.element;
	},

	getProdBarCode: function() {
		return this.barcode;
	},

	getProdDesignation: function() {
		return this.designation;
	},

	getProdCouleur: function() {
		return this.couleur;
	},

	getPrix: function() {
		return this.prix;
	},

	getPhotoFile: function() {
		return this.photo_file;
	},

	getQuantity: function() {
		return this.qte_select.value;
	},

	setPhotoSelected: function(num) {
		this.img_selected = num;
		this.miniatures_list.each(function(min, i) {
			if (i == num) {
				min.addClass('selected');
			} else {
				min.removeClass('selected');
			}
		}.bind(this));
	},

	showPhoto: function(num) {
		if (num > this.photos.length + 1) {
			num = 0;
		}
		for (var i = 0; i < this.photos.length; i++) {
			if (i != num) {
				this.photos[i].setStyle('display', 'none');
			}
		}
		this.photos[num].setStyle('display', 'block');
	},

	setSelected: function(prodTaille) {
		if (prodTaille == null) {
			return;
		}
		if (this.tailles == null) {
			return;
		}
		if (prodTaille == this.selectedTaille) {
			return;
		}
		this.tailles.each(function(ptaille, i) {
			if (ptaille != prodTaille) {
				ptaille.setSelected(false);
			}
		}.bind(this));
		prodTaille.setSelected(true);
		this.selectedTaille = prodTaille;

		this.setAvailableQuantity(prodTaille.getQuantity());
	},

	setAvailableQuantity: function(num) {
		current_value = this.qte_select.value;
		if (current_value == 0) {
			current_value = 1;
		}
		if (num > 6) {
			num = 6;
		}
		// Let's empty the select
		while (this.qte_select.options.length > 0) {
			this.qte_select.removeChild((this.qte_select.options[0]));
		}
		if (num == 0) {
			newOption = document.createElement('option');
			newOption = new Element(newOption);
			newOption.value = 0;
			newOption.innerHTML = '0';
			newOption.inject(this.qte_select);
		} else {
			for (var i = 1; i <= num; i++) {
				newOption = document.createElement('option');
				newOption = new Element(newOption);
				newOption.value = i;
				newOption.innerHTML = ''+i;
				if (i == current_value || (i < current_value && i == num)) {
					newOption.selected = true;
				}
				newOption.inject(this.qte_select);
			}
		}
	},

	buttonAddPressed: function() {
		if (this.selectedTaille == null) {
			alert('Veuillez sélectionner une taille');
			return;
		}
		this.addToBasket(this.selectedTaille.getTaille(), this.getQuantity());
	},

	addToBasket: function(taille, qte) {
		addToBasket(this.getProdBarCode(), taille, qte);
	}
});

function addToBasket(barcode, taille, qte) {
	//alert(barcode+' - '+taille+' - '+qte);
	var myAjax = new Ajax('/ajax_panier', {method: 'post', data: {
		type : 'add',
		barcode: barcode,
		taille: taille
	}, onComplete: function(result) {
		//alert('complete ! '+result);
		var rb = $('right-block');
		rb.innerHTML = result;
		/*if (drop == null) {
			drop = $('panier_table');
		}
		drop.innerHTML = result;
		drop.setStyles({'visibility': 'visible'});*/
	} }).request();
}

var FicheProdTaille = new Class({
	initialize: function(el, father) {
		this.element = el;

		this.fiche_prod_datas = father;

		var elChildren = el.getChildren();
		this.taille = elChildren[0].innerHTML;
		this.quantity = elChildren[1].innerHTML.toFloat();

		if (this.quantity > 0) {
			el.addEvent('click', function(event) {
				event = new Event(event);
				this.fiche_prod_datas.setSelected(this);
				event.stop();
				return false;
			}.bind(this));
		}
	},

	getElement: function() {
		return this.element;
	},

	getTaille: function() {
		return this.taille;
	},

	getQuantity: function() {
		return this.quantity;
	},

	setSelected: function(is_selected) {
		if (is_selected == true) {
			this.getElement().addClass('selected');
		} else {
			this.getElement().removeClass('selected');
		}
	}
});

var CompteForm = new Class({
	initialize: function(el, btn_editer) {
		this.element = el;
		this.boutonEditerDiv = btn_editer;

		var boutonEditerDivChildren = this.boutonEditerDiv.getChildren();
		this.boutonEditerLink = boutonEditerDivChildren[0];
		this.boutonEditerLink.addEvent('click', function(event) {
			event = new Event(event);

			event.stop();
			this.slideAllOut();

			return false;
		}.bind(this));

		this.boutonValiderLink = boutonEditerDivChildren[1];
		this.boutonValiderLink.addEvent('click', function(event) {
			event = new Event(event);

			event.stop();
			this.validFormular();

			return false;
		}.bind(this));

		var elementChildren = this.element.getChildren();
		this.error_div = elementChildren[2];
		this.infos_pers_div = elementChildren[5];
		this.coords_div = elementChildren[7];
		this.phone_div = elementChildren[9];
		this.pwd_div = elementChildren[13];

		var infosPersChildren = this.infos_pers_div.getChildren();
		this.clientID = infosPersChildren[0].value;
		this.infosPersTable = infosPersChildren[1];
		this.infosPersTableRows = this.infosPersTable.getChildren()[0].getChildren();

		var coordsChildren = this.coords_div.getChildren();
		this.coordsTable = coordsChildren[0];
		this.coordsTableRows = this.coordsTable.getChildren()[0].getChildren();

		var phoneChildren = this.phone_div.getChildren();
		this.phoneTable = phoneChildren[0];
		this.phoneTableRows = this.phoneTable.getChildren()[0].getChildren();

		var pwdChildren = this.pwd_div.getChildren();
		this.pwdTable = pwdChildren[0];
		this.pwdTableRows = this.pwdTable.getChildren()[0].getChildren();

		//this.genrePos = 'in';
		this.prenomPos = 'in';
		this.nomPos = 'in';
		this.emailPos = 'in';
		this.adressePos = 'in';
		this.codePostalPos = 'in';
		this.villePos = 'in';
		this.paysPos = 'in';
		this.telephonePos = 'in';
		//this.portablePos = 'in';
		this.pwdPos = 'in';

		//this.genreOK = true;
		this.prenomOK = true;
		this.nomOK = true;
		this.emailOK = true;
		this.adresseOK = true;
		this.codePostalOK = true;
		this.villeOK = true;
		this.paysOK = true;
		this.telephoneOK = true;
		//this.portableOK = true;
		this.pwdOK = true;
		this.pwdConfirmOK = true;
		this.pwd_reinitialized = false;

		//this.genreGettingOut = false;
		this.prenomGettingOut = false;
		this.nomGettingOut = false;
		this.emailGettingOut = false;
		this.adresseGettingOut = false;
		this.codePostalGettingOut = false;
		this.villeGettingOut = false;
		this.paysGettingOut = false;
		this.telephoneGettingOut = false;
		//this.portableGettingOut = false;
		this.pwdGettingOut = false;

		//this.background_genre_fx = null;
		this.background_prenom_fx = null;
		this.background_nom_fx = null;
		this.background_email_fx = null;
		this.background_adresse_fx = null;
		this.background_code_postal_fx = null;
		this.background_ville_fx = null;
		this.background_pays_fx = null;
		this.background_telephone_fx = null;
		//this.background_portable_fx = null;
		this.background_pwd_fx = null;

		// GENRE
		/*this.genreRow = this.infosPersTableRows[0];
		var genreTD = this.genreRow.getChildren()[1];
		var genreTDChildren = genreTD.getChildren();
		this.genreDisplay = genreTDChildren[0];
		this.genreRequest = genreTDChildren[1];

		this.genreHommeRadio = this.genreRequest.getChildren()[0];
		this.genreFemmeRadio = this.genreRequest.getChildren()[1];

		this.genreDisplay.addEvent('mouseenter', function(event) {
			this.genreEnter();
		}.bind(this));
		this.genreDisplay.addEvent('mouseleave', function(event) {
			this.genreLeave();
		}.bind(this));
		this.genreDisplay.addEvent('click', function(event) {
			this.genreSlideOut();
		}.bind(this));*/

		// PRENOM
		this.prenomRow = this.infosPersTableRows[1];
		var prenomTD = this.prenomRow.getChildren()[1];
		var prenomTDChildren = prenomTD.getChildren();
		this.prenomDisplay = prenomTDChildren[0];
		this.prenomRequest = prenomTDChildren[1];

		var prenomRequestChildren = this.prenomRequest.getChildren();
		this.prenomInput = prenomRequestChildren[0];
		this.prenomIcoWarning = prenomRequestChildren[1].getChildren()[0];
		this.prenomIcoOk = prenomRequestChildren[1].getChildren()[1];

		this.prenomInput.addEvent('keydown', this.validPrenom.bind(this));
		this.prenomInput.addEvent('keyup', this.validPrenom.bind(this));

		/*this.prenomDisplay.addEvent('mouseenter', function(event) {
			this.prenomEnter();
		}.bind(this));
		this.prenomDisplay.addEvent('mouseleave', function(event) {
			this.prenomLeave();
		}.bind(this));
		this.prenomDisplay.addEvent('click', function(event) {
			this.prenomSlideOut();
		}.bind(this));*/

		// NOM
		this.nomRow = this.infosPersTableRows[0];
		var nomTD = this.nomRow.getChildren()[1];
		var nomTDChildren = nomTD.getChildren();
		this.nomDisplay = nomTDChildren[0];
		this.nomRequest = nomTDChildren[1];

		var nomRequestChildren = this.nomRequest.getChildren();
		this.nomInput = nomRequestChildren[0];
		this.nomIcoWarning = nomRequestChildren[1].getChildren()[0];
		this.nomIcoOk = nomRequestChildren[1].getChildren()[1];

		this.nomInput.addEvent('keydown', this.validNom.bind(this));
		this.nomInput.addEvent('keyup', this.validNom.bind(this));

		/*this.nomDisplay.addEvent('mouseenter', function(event) {
			this.nomEnter();
		}.bind(this));
		this.nomDisplay.addEvent('mouseleave', function(event) {
			this.nomLeave();
		}.bind(this));
		this.nomDisplay.addEvent('click', function(event) {
			this.nomSlideOut();
		}.bind(this));*/

		// ADRESSE
		this.adresseRow = this.coordsTableRows[0];
		var adresseTD = this.adresseRow.getChildren()[1];
		var adresseTDChildren = adresseTD.getChildren();
		this.adresseDisplay = adresseTDChildren[0];
		this.adresseRequest = adresseTDChildren[1];

		var adresseRequestChildren = this.adresseRequest.getChildren();
		this.adresseInput = adresseRequestChildren[0];
		this.adresseIcoWarning = adresseRequestChildren[1].getChildren()[0];
		this.adresseIcoOk = adresseRequestChildren[1].getChildren()[1];

		this.adresseInput.addEvent('keydown', this.validAdresse.bind(this));
		this.adresseInput.addEvent('keyup', this.validAdresse.bind(this));

		/*this.adresseDisplay.addEvent('mouseenter', function(event) {
			this.adresseEnter();
		}.bind(this));
		this.adresseDisplay.addEvent('mouseleave', function(event) {
			this.adresseLeave();
		}.bind(this));
		this.adresseDisplay.addEvent('click', function(event) {
			this.adresseSlideOut();
		}.bind(this));*/

		// CODE POSTAL
		this.codePostalRow = this.coordsTableRows[1];
		var codePostalTD = this.codePostalRow.getChildren()[1];
		var codePostalTDChildren = codePostalTD.getChildren();
		this.codePostalDisplay = codePostalTDChildren[0];
		this.codePostalRequest = codePostalTDChildren[1];

		var codePostalRequestChildren = this.codePostalRequest.getChildren();
		this.codePostalInput = codePostalRequestChildren[0];
		this.codePostalIcoWarning = codePostalRequestChildren[1].getChildren()[0];
		this.codePostalIcoOk = codePostalRequestChildren[1].getChildren()[1];

		this.codePostalInput.addEvent('keydown', this.validCodePostal.bind(this));
		this.codePostalInput.addEvent('keyup', this.validCodePostal.bind(this));

		/*this.codePostalDisplay.addEvent('mouseenter', function(event) {
			this.codePostalEnter();
		}.bind(this));
		this.codePostalDisplay.addEvent('mouseleave', function(event) {
			this.codePostalLeave();
		}.bind(this));
		this.codePostalDisplay.addEvent('click', function(event) {
			this.codePostalSlideOut();
		}.bind(this));*/

		// VILLE
		this.villeRow = this.coordsTableRows[2];
		var villeTD = this.villeRow.getChildren()[1];
		var villeTDChildren = villeTD.getChildren();
		this.villeDisplay = villeTDChildren[0];
		this.villeRequest = villeTDChildren[1];

		var villeRequestChildren = this.villeRequest.getChildren();
		this.villeInput = villeRequestChildren[0];
		this.villeIcoWarning = villeRequestChildren[1].getChildren()[0];
		this.villeIcoOk = villeRequestChildren[1].getChildren()[1];

		this.villeInput.addEvent('keydown', this.validVille.bind(this));
		this.villeInput.addEvent('keyup', this.validVille.bind(this));

		/*this.villeDisplay.addEvent('mouseenter', function(event) {
			this.villeEnter();
		}.bind(this));
		this.villeDisplay.addEvent('mouseleave', function(event) {
			this.villeLeave();
		}.bind(this));
		this.villeDisplay.addEvent('click', function(event) {
			this.villeSlideOut();
		}.bind(this));*/

		// PAYS
		this.paysRow = this.coordsTableRows[3];
		var paysTD = this.paysRow.getChildren()[1];
		var paysTDChildren = paysTD.getChildren();
		this.paysDisplay = paysTDChildren[0];
		this.paysRequest = paysTDChildren[1];

		var paysRequestChildren = this.paysRequest.getChildren();
		this.paysSelect = paysRequestChildren[0];
		this.paysIcoWarning = paysRequestChildren[1].getChildren()[0];
		this.paysIcoOk = paysRequestChildren[1].getChildren()[1];

		this.paysSelect.addEvent('change', this.validPays.bind(this));

		/*this.paysDisplay.addEvent('mouseenter', function(event) {
			this.paysEnter();
		}.bind(this));
		this.paysDisplay.addEvent('mouseleave', function(event) {
			this.paysLeave();
		}.bind(this));
		this.paysDisplay.addEvent('click', function(event) {
			this.paysSlideOut();
		}.bind(this));*/

		// EMAIL
		this.emailRow = this.phoneTableRows[0];
		var emailTD = this.emailRow.getChildren()[1];
		var emailTDChildren = emailTD.getChildren();
		this.emailDisplay = emailTDChildren[0];
		this.emailRequest = emailTDChildren[1];

		var emailRequestChildren = this.emailRequest.getChildren();
		this.emailInput = emailRequestChildren[0];
		this.emailIcoWarning = emailRequestChildren[1].getChildren()[0];
		this.emailIcoOk = emailRequestChildren[1].getChildren()[1];

		this.emailInput.addEvent('keydown', this.validEmail.bind(this));
		this.emailInput.addEvent('keyup', this.validEmail.bind(this));

		/*this.emailDisplay.addEvent('mouseenter', function(event) {
			this.emailEnter();
		}.bind(this));
		this.emailDisplay.addEvent('mouseleave', function(event) {
			this.emailLeave();
		}.bind(this));
		this.emailDisplay.addEvent('click', function(event) {
			this.emailSlideOut();
		}.bind(this));*/

		// TELEPHONE
		this.telephoneRow = this.phoneTableRows[1];
		var telephoneTD = this.telephoneRow.getChildren()[1];
		var telephoneTDChildren = telephoneTD.getChildren();
		this.telephoneDisplay = telephoneTDChildren[0];
		this.telephoneRequest = telephoneTDChildren[1];

		var telephoneRequestChildren = this.telephoneRequest.getChildren();
		this.telephoneInput = telephoneRequestChildren[0];
		this.telephoneIcoWarning = telephoneRequestChildren[1].getChildren()[0];
		this.telephoneIcoOk = telephoneRequestChildren[1].getChildren()[1];

		this.telephoneInput.addEvent('keydown', this.validTelephone.bind(this));
		this.telephoneInput.addEvent('keyup', this.validTelephone.bind(this));

		/*this.telephoneDisplay.addEvent('mouseenter', function(event) {
			this.telephoneEnter();
		}.bind(this));
		this.telephoneDisplay.addEvent('mouseleave', function(event) {
			this.telephoneLeave();
		}.bind(this));
		this.telephoneDisplay.addEvent('click', function(event) {
			this.telephoneSlideOut();
		}.bind(this));*/

		// PORTABLE
		/*this.portableRow = this.phoneTableRows[1];
		var portableTD = this.portableRow.getChildren()[1];
		var portableTDChildren = portableTD.getChildren();
		this.portableDisplay = portableTDChildren[0];
		this.portableRequest = portableTDChildren[1];

		var portableRequestChildren = this.portableRequest.getChildren();
		this.portableInput = portableRequestChildren[0];

		this.portableDisplay.addEvent('mouseenter', function(event) {
			this.portableEnter();
		}.bind(this));
		this.portableDisplay.addEvent('mouseleave', function(event) {
			this.portableLeave();
		}.bind(this));
		this.portableDisplay.addEvent('click', function(event) {
			this.portableSlideOut();
		}.bind(this));*/

		// PASSWORD
		this.pwdRow = this.pwdTableRows[0];
		var pwdTD = this.pwdRow.getChildren()[1];
		var pwdTDChildren = pwdTD.getChildren();
		this.pwdDisplay = pwdTDChildren[0];
		this.pwdRequest = pwdTDChildren[1];

		var pwdRequestChildren = this.pwdRequest.getChildren();
		this.pwdInput = pwdRequestChildren[0];
		this.pwdIcoWarning = pwdRequestChildren[1].getChildren()[0];
		this.pwdIcoOk = pwdRequestChildren[1].getChildren()[1];

		this.pwdInput.addEvent('focus', this.pwdFocus.bind(this));

		this.pwdConfirmRow = this.pwdTableRows[1];
		var pwdConfirmTDtitle = this.pwdConfirmRow.getChildren()[0];
		this.pwdConfirmTitle = pwdConfirmTDtitle.getChildren()[0];
		var pwdConfirmTDval = this.pwdConfirmRow.getChildren()[1];
		this.pwdConfirmRequest = pwdConfirmTDval.getChildren()[0];

		this.pwdInput.addEvent('focus', this.pwdFocus.bind(this));
		this.pwdInput.addEvent('keydown', this.validPwd.bind(this));
		this.pwdInput.addEvent('keyup', this.validPwd.bind(this));

		var pwdConfirmRequestChildren = this.pwdConfirmRequest.getChildren();
		this.pwdConfirmInput = pwdConfirmRequestChildren[0];
		this.pwdConfirmIcoWarning = pwdConfirmRequestChildren[1].getChildren()[0];
		this.pwdConfirmIcoOk = pwdConfirmRequestChildren[1].getChildren()[1];

		this.pwdConfirmInput.addEvent('focus', this.pwdFocus.bind(this));
		this.pwdConfirmInput.addEvent('keydown', this.validPwd.bind(this));
		this.pwdConfirmInput.addEvent('keyup', this.validPwd.bind(this));

		/*this.pwdDisplay.addEvent('mouseenter', function(event) {
			this.pwdEnter();
		}.bind(this));
		this.pwdDisplay.addEvent('mouseleave', function(event) {
			this.pwdLeave();
		}.bind(this));
		this.pwdDisplay.addEvent('click', function(event) {
			this.pwdSlideOut();
		}.bind(this));*/

	},

	getElement: function() {
		return this.element;
	},

	getClienID: function() {
		return this.clientID;
	},

	getBoutonEditer: function() {
		return this.boutonEditerDiv;
	},

	setBoutonEditer: function(actif) {
		if (actif == true) {
			this.boutonEditerInactif.setStyle('display', 'none');
			this.boutonEditerLink.setStyle('display', 'inline');
		} else {
			this.boutonEditerLink.setStyle('display', 'none');
			this.boutonEditerInactif.setStyle('display', 'inline');
		}
	},

	checkBoutonEditer: function() {
		return;
		if (/*(this.genrePos != 'in' || this.genreGettingOut == true)
			&& */(this.prenomPos != 'in' || this.prenomGettingOut == true)
			&& (this.nomPos != 'in' || this.nomGettingOut == true)
			&& (this.emailPos != 'in' || this.emailGettingOut == true)
			&& (this.adressePos != 'in' || this.adresseGettingOut == true)
			&& (this.codePostalPos != 'in' || this.codePostalGettingOut == true)
			&& (this.villePos != 'in'|| this.villeGettingOut == true)
			&& (this.paysPos != 'in'|| this.paysGettingOut == true)
			&& (this.telephonePos != 'in'|| this.telephoneGettingOut == true)
			//&& (this.portablePos != 'in'|| this.portableGettingOut == true)
			&& (this.pwdPos != 'in'|| this.pwdGettingOut == true)) {

			this.setBoutonEditer(false);
		}
	},

	getBoutonValider: function() {
		return this.boutonValiderDiv;
	},

	setBoutonValider: function(actif) {
		if (actif == true) {
			this.boutonEditerLink.setStyle('display', 'none');
			this.boutonValiderLink.setStyle('display', 'inline');
		} else {
			this.boutonValiderLink.setStyle('display', 'none');
			this.boutonEditerLink.setStyle('display', 'inline');
		}
	},

	/*genreEnter: function() {
		if (this.genrePos != 'in' || this.genreGettingOut == true) {
			return;
		}
		if (this.background_genre_fx != null) {
			this.background_genre_fx.stop();
		}
		this.genreDisplay.setStyle('background-color', '#E0E0E0');
	},

	genreLeave: function() {
		if (this.genrePos != 'in' || this.genreGettingOut == true) {
			return;
		}
		if (this.background_genre_fx == null) {
			this.background_genre_fx = new Fx.Style(this.genreDisplay, 'background-color', {duration:500});
		}
		this.background_genre_fx.stop();
		this.background_genre_fx.start('#E0E0E0', '#ffffff');
	},
	genreSlideOut: function() {
		if (this.genrePos != 'in' || this.genreGettingOut == true) {
			return;
		}
		this.genreGettingOut = true;

		var slider_genre_edit = new Fx.Slide(this.genreRequest, {duration: 200, onComplete: function() {
			this.genrePos = 'out';
			this.genreGettingOut = false;
		}.bind(this) });

		var slider_genre_val = new Fx.Slide(this.genreDisplay, {duration: 200, onComplete: function() {
			this.genreDisplay.setStyle('display', 'none');
			this.genreRequest.setStyle('display', 'block');
			slider_genre_edit.hide();
			slider_genre_edit.slideIn();
		}.bind(this) });

		slider_genre_val.slideOut('horizontal');

		this.setBoutonValider(true);
		this.checkBoutonEditer();
	},*/

	prenomEnter: function() {
		if (this.prenomPos != 'in' || this.prenomGettingOut == true) {
			return;
		}
		if (this.background_prenom_fx != null) {
			this.background_prenom_fx.stop();
		}
		this.prenomDisplay.setStyle('background-color', '#E0E0E0');
	},

	prenomLeave: function() {
		if (this.prenomPos != 'in' || this.prenomGettingOut == true) {
			return;
		}
		if (this.background_prenom_fx == null) {
			this.background_prenom_fx = new Fx.Style(this.prenomDisplay, 'background-color', {duration:500});
		}
		this.background_prenom_fx.stop();
		this.background_prenom_fx.start('#E0E0E0', '#ffffff');
	},
	prenomSlideOut: function() {
		if (this.prenomPos != 'in' || this.prenomGettingOut == true) {
			return;
		}
		this.prenomGettingOut = true;

		var slider_prenom_edit = new Fx.Slide(this.prenomRequest, {duration: 200, onComplete: function() {
			this.prenomPos = 'out';
			this.prenomGettingOut = false;
		}.bind(this) });

		var slider_prenom_val = new Fx.Slide(this.prenomDisplay, {duration: 200, onComplete: function() {
			this.prenomDisplay.setStyle('display', 'none');
			this.prenomRequest.setStyle('display', 'block');
			slider_prenom_edit.hide();
			slider_prenom_edit.slideIn();
		}.bind(this) });

		slider_prenom_val.slideOut('horizontal');

		this.setBoutonValider(true);
		this.checkBoutonEditer();
	},

	validPrenom: function() {
		var prenom = this.prenomInput.value;
		if (prenom == null) {
			prenom = '';
		}
		var prenom_string = new String(prenom).trim();
		if (!prenom_string.match('^(.+)$')) {
			this.setPrenomOK(false);
		} else {
			this.setPrenomOK(true);
		}
	},

	setPrenomOK: function(is_OK) {
		if (is_OK == this.prenomOK) {
			return;
		}
		if (is_OK == true) {
			this.prenomIcoWarning.setStyle('display', 'none');
			this.prenomIcoOk.setStyle('display', 'inline');
		} else {
			this.prenomIcoOk.setStyle('display', 'none');
			this.prenomIcoWarning.setStyle('display', 'inline');
		}
		this.prenomOK = is_OK;
		//this.checkIfAllValid();
	},

	nomEnter: function() {
		if (this.nomPos != 'in' || this.nomGettingOut == true) {
			return;
		}
		if (this.background_nom_fx != null) {
			this.background_nom_fx.stop();
		}
		this.nomDisplay.setStyle('background-color', '#E0E0E0');
	},

	nomLeave: function() {
		if (this.nomPos != 'in' || this.nomGettingOut == true) {
			return;
		}
		if (this.background_nom_fx == null) {
			this.background_nom_fx = new Fx.Style(this.nomDisplay, 'background-color', {duration:500});
		}
		this.background_nom_fx.stop();
		this.background_nom_fx.start('#E0E0E0', '#ffffff');
	},
	nomSlideOut: function() {
		if (this.nomPos != 'in' || this.nomGettingOut == true) {
			return;
		}
		this.nomGettingOut = true;

		var slider_nom_edit = new Fx.Slide(this.nomRequest, {duration: 200, onComplete: function() {
			this.nomPos = 'out';
			this.nomGettingOut = false;
		}.bind(this) });

		var slider_nom_val = new Fx.Slide(this.nomDisplay, {duration: 200, onComplete: function() {
			this.nomDisplay.setStyle('display', 'none');
			this.nomRequest.setStyle('display', 'block');
			slider_nom_edit.hide();
			slider_nom_edit.slideIn();
		}.bind(this) });

		slider_nom_val.slideOut('horizontal');

		this.setBoutonValider(true);
		this.checkBoutonEditer();
	},

	validNom: function() {
		var nom = this.nomInput.value;
		if (nom == null) {
			nom = '';
		}
		var nom_string = new String(nom).trim();
		if (!nom_string.match('^(.+)$')) {
			this.setNomOK(false);
		} else {
			this.setNomOK(true);
		}
	},

	setNomOK: function(is_OK) {
		if (is_OK == this.nomOK) {
			return;
		}
		if (is_OK == true) {
			this.nomIcoWarning.setStyle('display', 'none');
			this.nomIcoOk.setStyle('display', 'inline');
		} else {
			this.nomIcoOk.setStyle('display', 'none');
			this.nomIcoWarning.setStyle('display', 'inline');
		}
		this.nomOK = is_OK;
		//this.checkIfAllValid();
	},

	emailEnter: function() {
		if (this.emailPos != 'in' || this.emailGettingOut == true) {
			return;
		}
		if (this.background_email_fx != null) {
			this.background_email_fx.stop();
		}
		this.emailDisplay.setStyle('background-color', '#E0E0E0');
	},

	emailLeave: function() {
		if (this.emailPos != 'in' || this.emailGettingOut == true) {
			return;
		}
		if (this.background_email_fx == null) {
			this.background_email_fx = new Fx.Style(this.emailDisplay, 'background-color', {duration:500});
		}
		this.background_email_fx.stop();
		this.background_email_fx.start('#E0E0E0', '#ffffff');
	},
	emailSlideOut: function() {
		if (this.emailPos != 'in' || this.emailGettingOut == true) {
			return;
		}
		this.emailGettingOut = true;

		var slider_email_edit = new Fx.Slide(this.emailRequest, {duration: 200, onComplete: function() {
			this.emailPos = 'out';
			this.emailGettingOut = false;
		}.bind(this) });

		var slider_email_val = new Fx.Slide(this.emailDisplay, {duration: 200, onComplete: function() {
			this.emailDisplay.setStyle('display', 'none');
			this.emailRequest.setStyle('display', 'block');
			slider_email_edit.hide();
			slider_email_edit.slideIn();
		}.bind(this) });

		slider_email_val.slideOut('horizontal');

		this.setBoutonValider(true);
		this.checkBoutonEditer();
	},

	validEmail: function() {
		var email = this.emailInput.value;
		if (email == null) {
			email = '';
		}
		var email_string = new String(email).trim();
		if (!email_string.match('^[a-zA-Z0-9]{1}[-_\.0-9a-zA-Z]*@[a-zA-Z0-9_-]{1}[-_\.0-9a-zA-Z]*[\.][0-9a-zA-Z]{2,}$')) {
			this.setEmailOK(false);
		} else {
			this.setEmailOK(true);
		}
	},

	setEmailOK: function(is_OK) {
		if (is_OK == this.emailOK) {
			return;
		}
		if (is_OK == true) {
			this.emailIcoWarning.setStyle('display', 'none');
			this.emailIcoOk.setStyle('display', 'inline');
		} else {
			this.emailIcoOk.setStyle('display', 'none');
			this.emailIcoWarning.setStyle('display', 'inline');
		}
		this.emailOK = is_OK;
		//this.checkIfAllValid();
	},

	adresseEnter: function() {
		if (this.adressePos != 'in' || this.adresseGettingOut == true) {
			return;
		}
		if (this.background_adresse_fx != null) {
			this.background_adresse_fx.stop();
		}
		this.adresseDisplay.setStyle('background-color', '#E0E0E0');
	},

	adresseLeave: function() {
		if (this.adressePos != 'in' || this.adresseGettingOut == true) {
			return;
		}
		if (this.background_adresse_fx == null) {
			this.background_adresse_fx = new Fx.Style(this.adresseDisplay, 'background-color', {duration:500});
		}
		this.background_adresse_fx.stop();
		this.background_adresse_fx.start('#E0E0E0', '#ffffff');
	},
	adresseSlideOut: function() {
		if (this.adressePos != 'in' || this.adresseGettingOut == true) {
			return;
		}
		this.adresseGettingOut = true;

		var slider_adresse_edit = new Fx.Slide(this.adresseRequest, {duration: 200, onComplete: function() {
			this.adressePos = 'out';
			this.adresseGettingOut = false;
		}.bind(this) });

		var slider_adresse_val = new Fx.Slide(this.adresseDisplay, {duration: 200, onComplete: function() {
			this.adresseDisplay.setStyle('display', 'none');
			this.adresseRequest.setStyle('display', 'block');
			slider_adresse_edit.hide();
			slider_adresse_edit.slideIn();
		}.bind(this) });

		slider_adresse_val.slideOut('horizontal');

		this.setBoutonValider(true);
		this.checkBoutonEditer();
	},

	validAdresse: function() {
		var adresse = this.adresseInput.value;
		if (adresse == null) {
			adresse = '';
		}
		var adresse_string = new String(adresse).trim();
		if (!adresse_string.match('^(.+)$')) {
			this.setAdresseOK(false);
		} else {
			this.setAdresseOK(true);
		}
	},

	setAdresseOK: function(is_OK) {
		if (is_OK == this.adresseOK) {
			return;
		}
		if (is_OK == true) {
			this.adresseIcoWarning.setStyle('display', 'none');
			this.adresseIcoOk.setStyle('display', 'inline');
		} else {
			this.adresseIcoOk.setStyle('display', 'none');
			this.adresseIcoWarning.setStyle('display', 'inline');
		}
		this.adresseOK = is_OK;
		//this.checkIfAllValid();
	},

	codePostalEnter: function() {
		if (this.codePostalPos != 'in' || this.codePostalGettingOut == true) {
			return;
		}
		if (this.background_code_postal_fx != null) {
			this.background_code_postal_fx.stop();
		}
		this.codePostalDisplay.setStyle('background-color', '#E0E0E0');
	},

	codePostalLeave: function() {
		if (this.codePostalPos != 'in' || this.codePostalGettingOut == true) {
			return;
		}
		if (this.background_code_postal_fx == null) {
			this.background_code_postal_fx = new Fx.Style(this.codePostalDisplay, 'background-color', {duration:500});
		}
		this.background_code_postal_fx.stop();
		this.background_code_postal_fx.start('#E0E0E0', '#ffffff');
	},
	codePostalSlideOut: function() {
		if (this.codePostalPos != 'in' || this.codePostalGettingOut == true) {
			return;
		}
		this.codePostalGettingOut = true;

		var slider_code_postal_edit = new Fx.Slide(this.codePostalRequest, {duration: 200, onComplete: function() {
			this.codePostalPos = 'out';
			this.codePostalGettingOut = false;
		}.bind(this) });

		var slider_code_postal_val = new Fx.Slide(this.codePostalDisplay, {duration: 200, onComplete: function() {
			this.codePostalDisplay.setStyle('display', 'none');
			this.codePostalRequest.setStyle('display', 'block');
			slider_code_postal_edit.hide();
			slider_code_postal_edit.slideIn();
		}.bind(this) });

		slider_code_postal_val.slideOut('horizontal');

		this.setBoutonValider(true);
		this.checkBoutonEditer();
	},

	validCodePostal: function() {
		var codePostal = this.codePostalInput.value;
		if (codePostal == null) {
			codePostal = '';
		}
		var codePostal_string = new String(codePostal).trim();
		if (!codePostal_string.match('^(.+)$')) {
			this.setCodePostalOK(false);
		} else {
			this.setCodePostalOK(true);
		}
	},

	setCodePostalOK: function(is_OK) {
		if (is_OK == this.codePostalOK) {
			return;
		}
		if (is_OK == true) {
			this.codePostalIcoWarning.setStyle('display', 'none');
			this.codePostalIcoOk.setStyle('display', 'inline');
		} else {
			this.codePostalIcoOk.setStyle('display', 'none');
			this.codePostalIcoWarning.setStyle('display', 'inline');
		}
		this.codePostalOK = is_OK;
		//this.checkIfAllValid();
	},

	villeEnter: function() {
		if (this.villePos != 'in' || this.villeGettingOut == true) {
			return;
		}
		if (this.background_ville_fx != null) {
			this.background_ville_fx.stop();
		}
		this.villeDisplay.setStyle('background-color', '#E0E0E0');
	},

	villeLeave: function() {
		if (this.villePos != 'in' || this.villeGettingOut == true) {
			return;
		}
		if (this.background_ville_fx == null) {
			this.background_ville_fx = new Fx.Style(this.villeDisplay, 'background-color', {duration:500});
		}
		this.background_ville_fx.stop();
		this.background_ville_fx.start('#E0E0E0', '#ffffff');
	},
	villeSlideOut: function() {
		if (this.villePos != 'in' || this.villeGettingOut == true) {
			return;
		}
		this.villeGettingOut = true;

		var slider_ville_edit = new Fx.Slide(this.villeRequest, {duration: 200, onComplete: function() {
			this.villePos = 'out';
			this.villeGettingOut = false;
		}.bind(this) });

		var slider_ville_val = new Fx.Slide(this.villeDisplay, {duration: 200, onComplete: function() {
			this.villeDisplay.setStyle('display', 'none');
			this.villeRequest.setStyle('display', 'block');
			slider_ville_edit.hide();
			slider_ville_edit.slideIn();
		}.bind(this) });

		slider_ville_val.slideOut('horizontal');

		this.setBoutonValider(true);
		this.checkBoutonEditer();
	},

	validVille: function() {
		var ville = this.villeInput.value;
		if (ville == null) {
			ville = '';
		}
		var ville_string = new String(ville).trim();
		if (!ville_string.match('^(.+)$')) {
			this.setVilleOK(false);
		} else {
			this.setVilleOK(true);
		}
	},

	setVilleOK: function(is_OK) {
		if (is_OK == this.villeOK) {
			return;
		}
		if (is_OK == true) {
			this.villeIcoWarning.setStyle('display', 'none');
			this.villeIcoOk.setStyle('display', 'inline');
		} else {
			this.villeIcoOk.setStyle('display', 'none');
			this.villeIcoWarning.setStyle('display', 'inline');
		}
		this.villeOK = is_OK;
		//this.checkIfAllValid();
	},

	paysEnter: function() {
		if (this.paysPos != 'in' || this.paysGettingOut == true) {
			return;
		}
		if (this.background_pays_fx != null) {
			this.background_pays_fx.stop();
		}
		this.paysDisplay.setStyle('background-color', '#E0E0E0');
	},

	paysLeave: function() {
		if (this.paysPos != 'in' || this.paysGettingOut == true) {
			return;
		}
		if (this.background_pays_fx == null) {
			this.background_pays_fx = new Fx.Style(this.paysDisplay, 'background-color', {duration:500});
		}
		this.background_pays_fx.stop();
		this.background_pays_fx.start('#E0E0E0', '#ffffff');
	},
	paysSlideOut: function() {
		if (this.paysPos != 'in' || this.paysGettingOut == true) {
			return;
		}
		this.paysGettingOut = true;

		var slider_pays_edit = new Fx.Slide(this.paysRequest, {duration: 200, onComplete: function() {
			this.paysPos = 'out';
			this.paysGettingOut = false;
		}.bind(this) });

		var slider_pays_val = new Fx.Slide(this.paysDisplay, {duration: 200, onComplete: function() {
			this.paysDisplay.setStyle('display', 'none');
			this.paysRequest.setStyle('display', 'block');
			slider_pays_edit.hide();
			slider_pays_edit.slideIn();
		}.bind(this) });

		slider_pays_val.slideOut('horizontal');

		this.setBoutonValider(true);
		this.checkBoutonEditer();
	},

	validPays: function() {
		var pays = this.paysSelect.value;
		if (pays == null) {
			pays = '0';
		}
		if (pays != '0') {
			this.setPaysOK(true);
		} else {
			this.setPaysOK(false);
		}
	},

	setPaysOK: function(is_OK) {
		if (is_OK == this.paysOK) {
			return;
		}
		if (is_OK == true) {
			this.paysIcoWarning.setStyle('display', 'none');
			this.paysIcoOk.setStyle('display', 'inline');
		} else {
			this.paysIcoOk.setStyle('display', 'none');
			this.paysIcoWarning.setStyle('display', 'inline');
		}
		this.paysOK = is_OK;
		//this.checkIfAllValid();
	},

	telephoneEnter: function() {
		if (this.telephonePos != 'in' || this.telephoneGettingOut == true) {
			return;
		}
		if (this.background_telephone_fx != null) {
			this.background_telephone_fx.stop();
		}
		this.telephoneDisplay.setStyle('background-color', '#E0E0E0');
	},

	telephoneLeave: function() {
		if (this.telephonePos != 'in' || this.telephoneGettingOut == true) {
			return;
		}
		if (this.background_telephone_fx == null) {
			this.background_telephone_fx = new Fx.Style(this.telephoneDisplay, 'background-color', {duration:500});
		}
		this.background_telephone_fx.stop();
		this.background_telephone_fx.start('#E0E0E0', '#ffffff');
	},
	telephoneSlideOut: function() {
		if (this.telephonePos != 'in' || this.telephoneGettingOut == true) {
			return;
		}
		this.telephoneGettingOut = true;

		var slider_telephone_edit = new Fx.Slide(this.telephoneRequest, {duration: 200, onComplete: function() {
			this.telephonePos = 'out';
			this.telephoneGettingOut = false;
		}.bind(this) });

		var slider_telephone_val = new Fx.Slide(this.telephoneDisplay, {duration: 200, onComplete: function() {
			this.telephoneDisplay.setStyle('display', 'none');
			this.telephoneRequest.setStyle('display', 'block');
			slider_telephone_edit.hide();
			slider_telephone_edit.slideIn();
		}.bind(this) });

		slider_telephone_val.slideOut('horizontal');

		this.setBoutonValider(true);
		this.checkBoutonEditer();
	},

	validTelephone: function() {
		var telephone = this.telephoneInput.value;
		if (telephone == null) {
			telephone = '';
		}
		var telephone_string = new String(telephone).trim();
		if (!telephone_string.match('^[\+]?[ \.-]*([0-9]{1}[ \.-]*){10,}$')) {
			this.setTelephoneOK(false);
		} else {
			this.setTelephoneOK(true);
		}
	},

	setTelephoneOK: function(is_OK) {
		if (is_OK == this.telephoneOK) {
			return;
		}
		if (is_OK == true) {
			this.telephoneIcoWarning.setStyle('display', 'none');
			this.telephoneIcoOk.setStyle('display', 'inline');
		} else {
			this.telephoneIcoOk.setStyle('display', 'none');
			this.telephoneIcoWarning.setStyle('display', 'inline');
		}
		this.telephoneOK = is_OK;
		//this.checkIfAllValid();
	},

	/*portableEnter: function() {
		if (this.portablePos != 'in' || this.portableGettingOut == true) {
			return;
		}
		if (this.background_portable_fx != null) {
			this.background_portable_fx.stop();
		}
		this.portableDisplay.setStyle('background-color', '#E0E0E0');
	},

	portableLeave: function() {
		if (this.portablePos != 'in' || this.portableGettingOut == true) {
			return;
		}
		if (this.background_portable_fx == null) {
			this.background_portable_fx = new Fx.Style(this.portableDisplay, 'background-color', {duration:500});
		}
		this.background_portable_fx.stop();
		this.background_portable_fx.start('#E0E0E0', '#ffffff');
	},
	portableSlideOut: function() {
		if (this.portablePos != 'in' || this.portableGettingOut == true) {
			return;
		}
		this.portableGettingOut = true;

		var slider_portable_edit = new Fx.Slide(this.portableRequest, {duration: 200, onComplete: function() {
			this.portablePos = 'out';
			this.portableGettingOut = false;
		}.bind(this) });

		var slider_portable_val = new Fx.Slide(this.portableDisplay, {duration: 200, onComplete: function() {
			this.portableDisplay.setStyle('display', 'none');
			this.portableRequest.setStyle('display', 'block');
			slider_portable_edit.hide();
			slider_portable_edit.slideIn();
		}.bind(this) });

		slider_portable_val.slideOut('horizontal');

		this.setBoutonValider(true);
		this.checkBoutonEditer();
	},*/

	pwdEnter: function() {
		if (this.pwdPos != 'in' || this.pwdGettingOut == true) {
			return;
		}
		if (this.background_pwd_fx != null) {
			this.background_pwd_fx.stop();
		}
		this.pwdDisplay.setStyle('background-color', '#E0E0E0');
	},

	pwdLeave: function() {
		if (this.pwdPos != 'in' || this.pwdGettingOut == true) {
			return;
		}
		if (this.background_pwd_fx == null) {
			this.background_pwd_fx = new Fx.Style(this.pwdDisplay, 'background-color', {duration:500});
		}
		this.background_pwd_fx.stop();
		this.background_pwd_fx.start('#E0E0E0', '#ffffff');
	},
	pwdSlideOut: function() {
		if (this.pwdPos != 'in' || this.pwdGettingOut == true) {
			return;
		}
		this.pwdGettingOut = true;

		var slider_pwd_edit = new Fx.Slide(this.pwdRequest, {duration: 200, onComplete: function() {
			this.pwdPos = 'out';
			this.pwdGettingOut = false;
		}.bind(this) });

		var slider_pwd_val = new Fx.Slide(this.pwdDisplay, {duration: 200, onComplete: function() {
			this.pwdDisplay.setStyle('display', 'none');
			this.pwdRequest.setStyle('display', 'block');
			this.pwdConfirmTitle.setStyle('display', 'block');
			this.pwdConfirmRequest.setStyle('display', 'block');

			slider_pwd_edit.hide();
			slider_pwd_confirm_title.hide();
			slider_pwd_confirm_request.hide();
			slider_pwd_edit.slideIn();
			slider_pwd_confirm_title.slideIn();
			slider_pwd_confirm_request.slideIn();
		}.bind(this) });

		var slider_pwd_confirm_title = new Fx.Slide(this.pwdConfirmTitle, {duration: 200});
		var slider_pwd_confirm_request = new Fx.Slide(this.pwdConfirmRequest, {duration: 200});

		slider_pwd_val.slideOut('horizontal');

		this.setBoutonValider(true);
		this.checkBoutonEditer();
	},

	pwdFocus: function() {
		if (this.pwd_reinitialized == true) {
			return;
		}

		this.pwdInput.value = '';
		this.pwdConfirmInput.value = '';

		this.pwd_reinitialized = true;
		this.setPwdOK(false);
	},

	validPwd: function() {
		var pwd = this.pwdInput.value;
		if (pwd == null) {
			pwd = '';
		}
		var pwd_string = new String(pwd).trim();
		if (!pwd_string.match('^(.){4,}$')) {
			this.setPwdOK(false);
		} else {
			this.setPwdOK(true);
			var pwdConfirm = this.pwdConfirmInput.value;
			if (pwdConfirm == null) {
				pwdConfirm = '';
			}
			
			if (pwdConfirm == pwd) {
				this.setPwdConfirmOK(true);
			} else {
				this.setPwdConfirmOK(false);
			}
		}
	},

	setPwdOK: function(is_OK) {
		if (is_OK == this.pwdOK) {
			return;
		}
		if (is_OK == true) {
			this.pwdIcoWarning.setStyle('display', 'none');
			this.pwdIcoOk.setStyle('display', 'inline');
		} else {
			this.pwdIcoOk.setStyle('display', 'none');
			this.pwdIcoWarning.setStyle('display', 'inline');
			this.setPwdConfirmOK(false);
		}
		this.pwdOK = is_OK;
		//this.checkIfAllValid();
	},

	setPwdConfirmOK: function(is_OK) {
		if (is_OK == this.pwdConfirmOK) {
			return;
		}
		if (is_OK == true) {
			this.pwdConfirmIcoWarning.setStyle('display', 'none');
			this.pwdConfirmIcoOk.setStyle('display', 'inline');
		} else {
			this.pwdConfirmIcoOk.setStyle('display', 'none');
			this.pwdConfirmIcoWarning.setStyle('display', 'inline');
		}
		this.pwdConfirmOK = is_OK;
		//this.checkIfAllValid();
	},

	slideAllOut: function() {
		//this.genreSlideOut();
		this.prenomSlideOut();
		this.nomSlideOut();
		this.emailSlideOut();
		this.adresseSlideOut();
		this.codePostalSlideOut();
		this.villeSlideOut();
		this.paysSlideOut();
		this.telephoneSlideOut();
		//this.portableSlideOut();
		this.pwdSlideOut();

		this.setBoutonEditer(false);
	},

	validFormular: function() {
		params = {};

		params['id'] = this.getClienID();

		/*if (this.genrePos != 'in' || this.genreGettingOut == true) {
			if (this.genreOK == false) {
				alert("Genre non valide");
				return;
			}
			if (this.genreHommeRadio.checked == true) {
				params['genre'] = 'Homme';
			} else if (this.genreFemmeRadio.checked == true) {
				params['genre'] = 'Femme';
			}
		}*/
		if (this.prenomPos != 'in' || this.prenomGettingOut == true) {
			if (this.prenomOK == false) {
				alert("Veuillez saisir votre prénom");
				return;
			}
			params['prenom'] = this.prenomInput.value;
		}
		if (this.nomPos != 'in' || this.nomGettingOut == true) {
			if (this.nomOK == false) {
				alert("Veuillez saisir votre nom");
				return;
			}
			params['nom'] = this.nomInput.value;
		}
		if (this.emailPos != 'in' || this.emailGettingOut == true) {
			if (this.emailOK == false) {
				alert("email non valide");
				return;
			}
			params['email'] = this.emailInput.value;
		}
		if (this.adressePos != 'in' || this.adresseGettingOut == true) {
			if (this.adresseOK == false) {
				alert("Veuillez saisir votre adresse");
				return;
			}
			params['adresse'] = this.adresseInput.value;
		}
		if (this.codePostalPos != 'in' || this.codePostalGettingOut == true) {
			if (this.codePostalOK == false) {
				alert("Code postal non valide");
				return;
			}
			params['code_postal'] = this.codePostalInput.value;
		}
		if (this.villePos != 'in'|| this.villeGettingOut == true) {
			if (this.villeOK == false) {
				alert("Veuillez saisir votre ville");
				return;
			}
			params['ville'] = this.villeInput.value;
		}
		if (this.paysPos != 'in'|| this.paysGettingOut == true) {
			if (this.paysOK == false) {
				alert("Veuillez choisir votre pays");
				return;
			}
			params['pays'] = this.paysSelect.value;
		}
		if (this.telephonePos != 'in'|| this.telephoneGettingOut == true) {
			if (this.telephoneOK == false) {
				alert("Veuillez saisir votre numéro de téléphone");
				return;
			}
			params['telephone'] = this.telephoneInput.value;
		}
		/*if (this.portablePos != 'in'|| this.portableGettingOut == true) {
			if (this.portableOK == false) {
				alert("Numéro de portable non valide");
				return;
			}
			params['portable'] = this.portableInput.value;
		}*/
		if (this.pwd_reinitialized == true) {
			if (this.pwdOK == false) {
				alert("Mot de passe non valide");
				return;
			}
			if (this.pwdConfirmOK == false) {
				alert("Veuillez saisir 2 fois le même mot de passe");
				return;
			}
			params['pwd'] = this.pwdInput.value;
			params['pwd_confirm'] = this.pwdConfirmInput.value;
		}

		var myAjax = new Ajax('/ajax_modif_client', {method: 'post', data: params, onComplete: function(result) {
			//alert(result);
			if (result == 'OK') {
				window.location = '/compte';
			} else {
				error_msg = 'Erreur inconnue';
				if (result.length >= 4) {
					error_code = parseInt(result.substring(3, 4));
					if (error_code == 0) {
						error_msg = result.substring(5, result.length)
					} else if (error_code == 1 || error_code == 2 || error_code == 3 || error_code == 4 || error_code == 6 || error_code == 7) {
						error_msg = 'Erreur interne : '+error_code;
					} else if (error_code == 5) {
						error_msg = 'Erreur lors de la mise &agrave; jour sur le serveur';
					} else {
						error_msg = 'Erreur inconnue';
					}
				}
				errors_div = $('errors');
				errors_div.innerHTML = error_msg;
			}
		} }).request();
	}
});



var CreaCompteForm = new Class({
	initialize: function(el, btn_valider) {
		this.element = el;
		this.boutonValiderDiv = btn_valider;

		var boutonValiderDivChildren = this.boutonValiderDiv.getChildren();
		this.boutonValiderLink = boutonValiderDivChildren[0];
		this.boutonValiderLink.addEvent('click', function(event) {
			event = new Event(event);

			event.stop();
			this.validFormular();

			return false;
		}.bind(this));

		var elementChildren = this.element.getChildren();
		this.error_div = elementChildren[0];
		this.form = elementChildren[2];

		formChildren = this.form.getChildren();

		this.infos_pers_div = formChildren[2];
		this.coords_div = formChildren[4];
		this.phone_div = formChildren[6];
		this.pwd_div = formChildren[10];

		var infosPersChildren = this.infos_pers_div.getChildren();
		this.infosPersTable = infosPersChildren[0];
		this.infosPersTableRows = this.infosPersTable.getChildren()[0].getChildren();

		var coordsChildren = this.coords_div.getChildren();
		this.coordsTable = coordsChildren[0];
		this.coordsTableRows = this.coordsTable.getChildren()[0].getChildren();

		var phoneChildren = this.phone_div.getChildren();
		this.phoneTable = phoneChildren[0];
		this.phoneTableRows = this.phoneTable.getChildren()[0].getChildren();

		var pwdChildren = this.pwd_div.getChildren();
		this.pwdTable = pwdChildren[0];
		this.pwdTableRows = this.pwdTable.getChildren()[0].getChildren();

		//this.genreOK = false;
		this.prenomOK = false;
		this.nomOK = false;
		this.emailOK = false;
		this.adresseOK = false;
		this.codePostalOK = false;
		this.villeOK = false;
		this.paysOK = false;
		this.telephoneOK = false;
		//this.portableOK = false;
		this.pwdOK = false;
		this.pwdConfirmOK = false;

		// GENRE
		/*this.genreRow = this.infosPersTableRows[0];
		var genreTD = this.genreRow.getChildren()[1];
		var genreTDChildren = genreTD.getChildren();
		this.genreRequest = genreTDChildren[0];

		this.genreHommeRadio = this.genreRequest.getChildren()[0];
		this.genreFemmeRadio = this.genreRequest.getChildren()[1];*/

		// PRENOM
		this.prenomRow = this.infosPersTableRows[1];
		var prenomTD = this.prenomRow.getChildren()[1];
		var prenomTDChildren = prenomTD.getChildren();
		this.prenomRequest = prenomTDChildren[0];

		var prenomRequestChildren = this.prenomRequest.getChildren();
		this.prenomInput = prenomRequestChildren[0];
		this.prenomIcoWarning = prenomRequestChildren[1].getChildren()[0];
		this.prenomIcoOk = prenomRequestChildren[1].getChildren()[1];
		if (this.prenomIcoWarning.getStyle('display') == 'none') {
			this.prenomOK = true;
		}

		this.prenomInput.addEvent('keydown', this.validPrenom.bind(this));
		this.prenomInput.addEvent('keyup', this.validPrenom.bind(this));

		// NOM
		this.nomRow = this.infosPersTableRows[0];
		var nomTD = this.nomRow.getChildren()[1];
		var nomTDChildren = nomTD.getChildren();
		this.nomRequest = nomTDChildren[0];

		var nomRequestChildren = this.nomRequest.getChildren();
		this.nomInput = nomRequestChildren[0];
		this.nomIcoWarning = nomRequestChildren[1].getChildren()[0];
		this.nomIcoOk = nomRequestChildren[1].getChildren()[1];
		if (this.nomIcoWarning.getStyle('display') == 'none') {
			this.nomOK = true;
		}

		this.nomInput.addEvent('keydown', this.validNom.bind(this));
		this.nomInput.addEvent('keyup', this.validNom.bind(this));

		// ADRESSE
		this.adresseRow = this.coordsTableRows[0];
		var adresseTD = this.adresseRow.getChildren()[1];
		var adresseTDChildren = adresseTD.getChildren();
		this.adresseRequest = adresseTDChildren[0];

		var adresseRequestChildren = this.adresseRequest.getChildren();
		this.adresseInput = adresseRequestChildren[0];
		this.adresseIcoWarning = adresseRequestChildren[1].getChildren()[0];
		this.adresseIcoOk = adresseRequestChildren[1].getChildren()[1];
		if (this.adresseIcoWarning.getStyle('display') == 'none') {
			this.adresseOK = true;
		}

		this.adresseInput.addEvent('keydown', this.validAdresse.bind(this));
		this.adresseInput.addEvent('keyup', this.validAdresse.bind(this));

		// CODE POSTAL
		this.codePostalRow = this.coordsTableRows[1];
		var codePostalTD = this.codePostalRow.getChildren()[1];
		var codePostalTDChildren = codePostalTD.getChildren();
		this.codePostalRequest = codePostalTDChildren[0];

		var codePostalRequestChildren = this.codePostalRequest.getChildren();
		this.codePostalInput = codePostalRequestChildren[0];
		this.codePostalIcoWarning = codePostalRequestChildren[1].getChildren()[0];
		this.codePostalIcoOk = codePostalRequestChildren[1].getChildren()[1];
		if (this.codePostalIcoWarning.getStyle('display') == 'none') {
			this.codePostalOK = true;
		}

		this.codePostalInput.addEvent('keydown', this.validCodePostal.bind(this));
		this.codePostalInput.addEvent('keyup', this.validCodePostal.bind(this));

		// VILLE
		this.villeRow = this.coordsTableRows[2];
		var villeTD = this.villeRow.getChildren()[1];
		var villeTDChildren = villeTD.getChildren();
		this.villeRequest = villeTDChildren[0];

		var villeRequestChildren = this.villeRequest.getChildren();
		this.villeInput = villeRequestChildren[0];
		this.villeIcoWarning = villeRequestChildren[1].getChildren()[0];
		this.villeIcoOk = villeRequestChildren[1].getChildren()[1];
		if (this.villeIcoWarning.getStyle('display') == 'none') {
			this.villeOK = true;
		}

		this.villeInput.addEvent('keydown', this.validVille.bind(this));
		this.villeInput.addEvent('keyup', this.validVille.bind(this));

		// PAYS
		this.paysRow = this.coordsTableRows[3];
		var paysTD = this.paysRow.getChildren()[1];
		var paysTDChildren = paysTD.getChildren();
		this.paysRequest = paysTDChildren[0];

		var paysRequestChildren = this.paysRequest.getChildren();
		this.paysSelect = paysRequestChildren[0];
		this.paysIcoWarning = paysRequestChildren[1].getChildren()[0];
		this.paysIcoOk = paysRequestChildren[1].getChildren()[1];
		if (this.paysIcoWarning.getStyle('display') == 'none') {
			this.paysOK = true;
		}

		this.paysSelect.addEvent('change', this.validPays.bind(this));

		// EMAIL
		this.emailRow = this.phoneTableRows[0];
		var emailTD = this.emailRow.getChildren()[1];
		var emailTDChildren = emailTD.getChildren();
		this.emailRequest = emailTDChildren[0];

		var emailRequestChildren = this.emailRequest.getChildren();
		this.emailInput = emailRequestChildren[0];
		this.emailIcoWarning = emailRequestChildren[1].getChildren()[0];
		this.emailIcoOk = emailRequestChildren[1].getChildren()[1];
		if (this.emailIcoWarning.getStyle('display') == 'none') {
			this.emailOK = true;
		}

		this.emailInput.addEvent('keydown', this.validEmail.bind(this));
		this.emailInput.addEvent('keyup', this.validEmail.bind(this));

		// TELEPHONE
		this.telephoneRow = this.phoneTableRows[1];
		var telephoneTD = this.telephoneRow.getChildren()[1];
		var telephoneTDChildren = telephoneTD.getChildren();
		this.telephoneRequest = telephoneTDChildren[0];

		var telephoneRequestChildren = this.telephoneRequest.getChildren();
		this.telephoneInput = telephoneRequestChildren[0];
		this.telephoneIcoWarning = telephoneRequestChildren[1].getChildren()[0];
		this.telephoneIcoOk = telephoneRequestChildren[1].getChildren()[1];
		if (this.telephoneIcoWarning.getStyle('display') == 'none') {
			this.telephoneOK = true;
		}

		this.telephoneInput.addEvent('keydown', this.validTelephone.bind(this));
		this.telephoneInput.addEvent('keyup', this.validTelephone.bind(this));

		// PORTABLE
		/*this.portableRow = this.phoneTableRows[1];
		var portableTD = this.portableRow.getChildren()[1];
		var portableTDChildren = portableTD.getChildren();
		this.portableRequest = portableTDChildren[0];

		var portableRequestChildren = this.portableRequest.getChildren();
		this.portableInput = portableRequestChildren[0];*/

		// PASSWORD
		this.pwdRow = this.pwdTableRows[0];
		var pwdTD = this.pwdRow.getChildren()[1];
		var pwdTDChildren = pwdTD.getChildren();

		this.pwdInput = pwdTDChildren[0];
		this.pwdIcoWarning = pwdTDChildren[1].getChildren()[0];
		this.pwdIcoOk = pwdTDChildren[1].getChildren()[1];

		if (this.pwdIcoWarning.getStyle('display') == 'none') {
			this.pwdOK = true;
		}

		this.pwdConfirmRow = this.pwdTableRows[1];
		var pwdConfirmTDtitle = this.pwdConfirmRow.getChildren()[0];
		this.pwdConfirmTitle = pwdConfirmTDtitle.getChildren()[0];
		var pwdConfirmTDval = this.pwdConfirmRow.getChildren()[1];
		var pwdConfirmTDchildren = pwdConfirmTDval.getChildren();

		this.pwdInput.addEvent('keydown', this.validPwd.bind(this));
		this.pwdInput.addEvent('keyup', this.validPwd.bind(this));

		this.pwdConfirmInput = pwdConfirmTDchildren[0];
		this.pwdConfirmIcoWarning = pwdConfirmTDchildren[1].getChildren()[0];
		this.pwdConfirmIcoOk = pwdConfirmTDchildren[1].getChildren()[1];
		if (this.pwdConfirmIcoWarning.getStyle('display') == 'none') {
			this.pwdConfirmOK = true;
		}

		this.pwdConfirmInput.addEvent('keydown', this.validPwd.bind(this));
		this.pwdConfirmInput.addEvent('keyup', this.validPwd.bind(this));

	},

	getElement: function() {
		return this.element;
	},

	getClienID: function() {
		return this.clientID;
	},

	getBoutonValider: function() {
		return this.boutonValiderDiv;
	},

	setBoutonValider: function(actif) {
		if (actif == true) {
			this.boutonValiderInactif.setStyle('display', 'none');
			this.boutonValiderLink.setStyle('display', 'inline');
		} else {
			this.boutonValiderLink.setStyle('display', 'none');
			this.boutonValiderInactif.setStyle('display', 'inline');
		}
	},

	validPrenom: function() {
		var prenom = this.prenomInput.value;
		if (prenom == null) {
			prenom = '';
		}
		var prenom_string = new String(prenom).trim();
		if (!prenom_string.match('^(.+)$')) {
			this.setPrenomOK(false);
		} else {
			this.setPrenomOK(true);
		}
	},

	setPrenomOK: function(is_OK) {
		if (is_OK == this.prenomOK) {
			return;
		}
		if (is_OK == true) {
			this.prenomIcoWarning.setStyle('display', 'none');
			this.prenomIcoOk.setStyle('display', 'inline');
		} else {
			this.prenomIcoOk.setStyle('display', 'none');
			this.prenomIcoWarning.setStyle('display', 'inline');
		}
		this.prenomOK = is_OK;
		//this.checkIfAllValid();
	},

	validNom: function() {
		var nom = this.nomInput.value;
		if (nom == null) {
			nom = '';
		}
		var nom_string = new String(nom).trim();
		if (!nom_string.match('^(.+)$')) {
			this.setNomOK(false);
		} else {
			this.setNomOK(true);
		}
	},

	setNomOK: function(is_OK) {
		if (is_OK == this.nomOK) {
			return;
		}
		if (is_OK == true) {
			this.nomIcoWarning.setStyle('display', 'none');
			this.nomIcoOk.setStyle('display', 'inline');
		} else {
			this.nomIcoOk.setStyle('display', 'none');
			this.nomIcoWarning.setStyle('display', 'inline');
		}
		this.nomOK = is_OK;
		//this.checkIfAllValid();
	},

	validEmail: function() {
		var email = this.emailInput.value;
		if (email == null) {
			email = '';
		}
		var email_string = new String(email).trim();
		if (!email_string.match('^[a-zA-Z0-9]{1}[-_\.0-9a-zA-Z]*@[a-zA-Z0-9_-]{1}[-_\.0-9a-zA-Z]*[\.][0-9a-zA-Z]{2,}$')) {
			this.setEmailOK(false);
		} else {
			this.setEmailOK(true);
		}
	},

	setEmailOK: function(is_OK) {
		if (is_OK == this.emailOK) {
			return;
		}
		if (is_OK == true) {
			this.emailIcoWarning.setStyle('display', 'none');
			this.emailIcoOk.setStyle('display', 'inline');
		} else {
			this.emailIcoOk.setStyle('display', 'none');
			this.emailIcoWarning.setStyle('display', 'inline');
		}
		this.emailOK = is_OK;
		//this.checkIfAllValid();
	},

	validAdresse: function() {
		var adresse = this.adresseInput.value;
		if (adresse == null) {
			adresse = '';
		}
		var adresse_string = new String(adresse).trim();
		if (!adresse_string.match('^(.+)$')) {
			this.setAdresseOK(false);
		} else {
			this.setAdresseOK(true);
		}
	},

	setAdresseOK: function(is_OK) {
		if (is_OK == this.adresseOK) {
			return;
		}
		if (is_OK == true) {
			this.adresseIcoWarning.setStyle('display', 'none');
			this.adresseIcoOk.setStyle('display', 'inline');
		} else {
			this.adresseIcoOk.setStyle('display', 'none');
			this.adresseIcoWarning.setStyle('display', 'inline');
		}
		this.adresseOK = is_OK;
		//this.checkIfAllValid();
	},

	validCodePostal: function() {
		var codePostal = this.codePostalInput.value;
		if (codePostal == null) {
			codePostal = '';
		}
		var codePostal_string = new String(codePostal).trim();
		if (!codePostal_string.match('^(.+)$')) {
			this.setCodePostalOK(false);
		} else {
			this.setCodePostalOK(true);
		}
	},

	setCodePostalOK: function(is_OK) {
		if (is_OK == this.codePostalOK) {
			return;
		}
		if (is_OK == true) {
			this.codePostalIcoWarning.setStyle('display', 'none');
			this.codePostalIcoOk.setStyle('display', 'inline');
		} else {
			this.codePostalIcoOk.setStyle('display', 'none');
			this.codePostalIcoWarning.setStyle('display', 'inline');
		}
		this.codePostalOK = is_OK;
		//this.checkIfAllValid();
	},

	validVille: function() {
		var ville = this.villeInput.value;
		if (ville == null) {
			ville = '';
		}
		var ville_string = new String(ville).trim();
		if (!ville_string.match('^(.+)$')) {
			this.setVilleOK(false);
		} else {
			this.setVilleOK(true);
		}
	},

	setVilleOK: function(is_OK) {
		if (is_OK == this.villeOK) {
			return;
		}
		if (is_OK == true) {
			this.villeIcoWarning.setStyle('display', 'none');
			this.villeIcoOk.setStyle('display', 'inline');
		} else {
			this.villeIcoOk.setStyle('display', 'none');
			this.villeIcoWarning.setStyle('display', 'inline');
		}
		this.villeOK = is_OK;
		//this.checkIfAllValid();
	},

	validPays: function() {
		var pays = this.paysSelect.value;
		if (pays == null) {
			pays = '0';
		}
		if (pays != '0') {
			this.setPaysOK(true);
		} else {
			this.setPaysOK(false);
		}
	},

	setPaysOK: function(is_OK) {
		if (is_OK == this.paysOK) {
			return;
		}
		if (is_OK == true) {
			this.paysIcoWarning.setStyle('display', 'none');
			this.paysIcoOk.setStyle('display', 'inline');
		} else {
			this.paysIcoOk.setStyle('display', 'none');
			this.paysIcoWarning.setStyle('display', 'inline');
		}
		this.paysOK = is_OK;
		//this.checkIfAllValid();
	},

	validTelephone: function() {
		var telephone = this.telephoneInput.value;
		if (telephone == null) {
			telephone = '';
		}
		var telephone_string = new String(telephone).trim();
		if (!telephone_string.match('^[\+]?[ \.-]*([0-9]{1}[ \.-]*){10,}$')) {
			this.setTelephoneOK(false);
		} else {
			this.setTelephoneOK(true);
		}
	},

	setTelephoneOK: function(is_OK) {
		if (is_OK == this.telephoneOK) {
			return;
		}
		if (is_OK == true) {
			this.telephoneIcoWarning.setStyle('display', 'none');
			this.telephoneIcoOk.setStyle('display', 'inline');
		} else {
			this.telephoneIcoOk.setStyle('display', 'none');
			this.telephoneIcoWarning.setStyle('display', 'inline');
		}
		this.telephoneOK = is_OK;
		//this.checkIfAllValid();
	},

	validPwd: function() {
		var pwd = this.pwdInput.value;
		if (pwd == null) {
			pwd = '';
		}
		var pwd_string = new String(pwd).trim();
		if (!pwd_string.match('^(.){4,}$')) {
			this.setPwdOK(false);
		} else {
			this.setPwdOK(true);
			var pwdConfirm = this.pwdConfirmInput.value;
			if (pwdConfirm == null) {
				pwdConfirm = '';
			}
			
			if (pwdConfirm == pwd) {
				this.setPwdConfirmOK(true);
			} else {
				this.setPwdConfirmOK(false);
			}
		}
	},

	setPwdOK: function(is_OK) {
		if (is_OK == this.pwdOK) {
			return;
		}
		if (is_OK == true) {
			this.pwdIcoWarning.setStyle('display', 'none');
			this.pwdIcoOk.setStyle('display', 'inline');
		} else {
			this.pwdIcoOk.setStyle('display', 'none');
			this.pwdIcoWarning.setStyle('display', 'inline');
			this.setPwdConfirmOK(false);
		}
		this.pwdOK = is_OK;
		//this.checkIfAllValid();
	},

	setPwdConfirmOK: function(is_OK) {
		if (is_OK == this.pwdConfirmOK) {
			return;
		}
		if (is_OK == true) {
			this.pwdConfirmIcoWarning.setStyle('display', 'none');
			this.pwdConfirmIcoOk.setStyle('display', 'inline');
		} else {
			this.pwdConfirmIcoOk.setStyle('display', 'none');
			this.pwdConfirmIcoWarning.setStyle('display', 'inline');
		}
		this.pwdConfirmOK = is_OK;
		//this.checkIfAllValid();
	},

	validFormular: function() {
		params = {};

		//var genre = '';
		var prenom = '';
		var nom='';
		var email='';
		var adresse='';
		var code_postal='';
		var ville='';
		var pays='';
		var telephone = '';
		//var portable = '';
		var pwd = '';

		/*if (this.genreHommeRadio.checked == true) {
			genre = 'Homme';
		} else if (this.genreFemmeRadio.checked == true) {
			genre = 'Femme';
		}*/

		if (this.nomOK == false) {
			alert("Veuillez saisir votre nom");
			return;
		}
		nom = this.nomInput.value;

		if (this.prenomOK == false) {
			alert("Veuillez saisir votre prénom");
			return;
		}
		prenom = this.prenomInput.value;

		if (this.adresseOK == false) {
			alert("Veuillez saisir votre adresse");
			return;
		}
		adresse = this.adresseInput.value;

		if (this.codePostalOK == false) {
			alert("Code postal non valide");
			return;
		}
		code_postal = this.codePostalInput.value;

		if (this.villeOK == false) {
			alert("Veuillez saisir votre ville");
			return;
		}
		ville = this.villeInput.value;

		if (this.paysOK == false) {
			alert("Veuillez choisir votre pays");
			return;
		}
		pays = this.paysSelect.value;

		if (this.emailOK == false) {
			alert("email non valide");
			return;
		}
		email = this.emailInput.value;

		if (this.telephoneOK == false) {
			alert("Veuillez saisir votre numéro de téléphone");
			return;
		}
		telephone = this.telephoneInput.value;

		//portable = this.portableInput.value;

		if (this.pwdOK == false) {
			alert("Mot de passe non valide");
			return;
		}
		if (this.pwdConfirmOK == false) {
			alert("Veuillez saisir 2 fois le même mot de passe");
			return;
		}
		pwd = this.pwdInput.value;

		this.form.submit();
		//alert(genre+' - '+prenom+' - '+nom+' - '+email+' - '+adresse+' - '+code_postal+' - '+ville+' - '+pays+' - '+telephone+' - '+portable+' - '+pwd);

	}
});




function accueil_suivi_colis() {
	var email_suivi_input = $('email_suivi');
	var password_suivi_input = $('password_suivi');
	var colis_suivi_input = $('colis_suivi');

	params = {};
	if (email_suivi_input != null) {
		params['email'] = email_suivi_input.value;
	}
	if (password_suivi_input != null) {
		params['pwd'] = password_suivi_input.value;
	}
	params['colis'] = colis_suivi_input.value;

	var myAjax = new Ajax('/ajax_suivi_commande', {method: 'post', data: params, onComplete: function(result) {
		if (result.substring(0, 2) == 'OK') {
			var modeLiv = result.substring(3, result.length);
			document.location = 'http://www.coliposte.net/gp/services/main.jsp?m=10003005&colispart='+colis_suivi_input.value;
			return;
		}
		// If we get there, we add a KO
		error_code = parseInt(result.substring(3, result.length));

		error_msg = 'Erreur interne : '+error_code;
		if (error_code == 3) {
			error_msg = 'Veuillez saisir un numéro de colis';
		} else if (error_code == 4) {
			error_msg = 'Vous devez vous connecter';
		} else if (error_code == 5) {
			error_msg = 'Identifiants de compte non valides';
		} else if (error_code == 7) {
			error_msg = 'Vous n\'avez pas de colis : '+colis_suivi_input.value;
		} else {
			error_msg = 'Erreur inconnue';
		}
		alert(error_msg);
	} }).request();	
}


function accueil_news_letter() {
	var email_nl_input = $('email_newsletter');

	params = {};
	params['email'] = email_nl_input.value;

	var myAjax = new Ajax('/ajax_accueil_connect_newsletter', {method: 'post', data: params, onComplete: function(result) {
		//alert(result);
		if (result.substring(0, 2) == 'OK') {
			rescode = error_code = parseInt(result.substring(3, result.length));
			//alert(rescode);
			var nl_div = $('accueil_newsletter');
			if (nl_div != null) {
				nl_div.innerHTML = '<h1>Newsletter</h1>\n<br/><br/>Votre inscription à la NewsLetter Central13 a bien été enregistrée.';
			} else {
				alert('Votre inscription à la NewsLetter Central13 a bien été enregistrée.');
			}
			return;
		}
		// If we get there, we add a KO
		error_code = parseInt(result.substring(3, result.length));

		error_msg = 'Erreur interne : '+error_code;
		if (error_code == 3) {
			error_msg = 'Veuillez saisir votre adresse email';
		} else if (error_code == 4) {
			error_msg = 'Email non valide';
		} else {
			error_msg = 'Erreur inconnue';
		}
		alert(error_msg);
	} }).request();	
}



var Basket = new Class({
	initialize: function(el) {
		this.element = el;
		this.parent = this.element.getParent().getParent().getParent();

		window.addEvent('windowResized', this.checkPos.bind(this));
		window.addEvent('windowScrolled', this.checkPos.bind(this));
	},

	getElement: function() {
		return this.element;
	},

	checkPos: function() {
		var window_scroll = window.getScrollTop();

		var parentCoords = this.parent.getCoordinates();
		var bottom_limit = parentCoords.top + parentCoords.height - 20;

		coords = this.element.getCoordinates();

		margin_top = this.element.getStyle('margin-top');
		if (margin_top == null || margin_top.length == 0) {
			margin_top = 0;
		} else {
			if (margin_top.test('px$', 'i') == true) {
				margin_top = margin_top.toInt();
			} else {
				// ERROR
				return;
			}
		}
		margin_bottom = this.element.getStyle('margin-bottom');
		if (margin_bottom == null || margin_bottom.length == 0) {
			margin_bottom = 0;
		} else {
			if (margin_bottom.test('px$', 'i') == true) {
				margin_bottom = margin_bottom.toInt();
			} else {
				// ERROR
				return;
			}
		}

		zeroPos = coords.top - margin_top;
		maximumMargin = bottom_limit - coords.height - margin_bottom - zeroPos;

		if (margin_top > maximumMargin) {
			this.element.setStyle('margin-top', maximumMargin);
			margin_top = maximumMargin;
		}

		requiredPos = window_scroll + 5;
		final_margin = requiredPos - zeroPos;

		if (final_margin > maximumMargin) {
			final_margin = maximumMargin;
		} if (final_margin < 0) {
			final_margin = 0;
		}

		if (final_margin != margin_top) {
			if (this.fxPanier == null) {
				this.fxPanier = new Fx.Style(this.element, 'margin-top', {duration:150});
			}
			this.fxPanier.stop();
			this.fxPanier.start(final_margin);
		}
	}
});
