var lastItemShow = null;
var lastItemShowEvt = null;
var oMsgEffect = null;


ShopTools = Class.create(CommunTools,{
		timer: null,
		lastMouseY: null,
		aButtons: new Array(),
		bExecute: false,
		aMembershipCards : new Array(),

		message : function (sType, sMsg){
			scroll(0,0);
			var aOptions = {};

			if(arguments.length > 2){
				aOptions = arguments[2] || {};
			}

			var sClassname = "";

			switch (sType){
				case "error" : sClassname = "msgError"; break;
				case "confirmation" : sClassname = "msgConfirmation"; break;
				case "information" : sClassname = "msgInformation"; break;
				case "warning" : sClassname = "msgWarning"; break;
			}

			if(aOptions.sClassname){
				sClassname = aOptions.sClassname;
			}

			var sDiv = "message";
			if(aOptions.sDiv){
				sDiv = aOptions.sDiv;
			}

			$(sDiv).hide();
			$(sDiv).style.opacity = 1;
			$(sDiv).update(sMsg);
			$(sDiv).className = sClassname;
			$(sDiv).show();
			if(aOptions.iDuration){
				if(oMsgEffect != null){
					oMsgEffect.cancel();
				}
				oMsgEffect = new Effect.Fade(sDiv,{duration:aOptions.iDuration});
			}
		},

		initForm : function (sForm, sAction) {
			var aOptions = {};

			if(arguments.length > 2){
				aOptions = arguments[2] || {};
			}

			if(!aOptions.sClassName){
				aOptions.sClassName = sAction;
			}

			$(sForm).observe("submit",
				function(){
					this.initClick($(sAction), aOptions.sClassName, aOptions);
				}.bindAsEventListener(this)
			);
		},

		isEmail : function (sEmail){
			var oRegExp = new RegExp('^([a-z]|[0-9]|_|&|(\\.(?!\\.))|\\-)+@([a-z]|[0-9]|(\\.(?!\\.))|(\\-(?!\\.)))+\\.[a-z]{1,6}$', 'gi');
			if(sEmail.match(oRegExp)){
				return true;
			}else{
				return false;
			}
		},

		hideClassName : function(sClassName){
			$$("." + sClassName).each(
					function (oElement){
						oElement.hide();
					}
			);
		},

		showClassName : function(sClassName){
			$$("." + sClassName).each(
					function (oElement){
						oElement.show();
					}
			);
		},

		highlight : function (sClassName){
			var aOptions = {};

			if(arguments.length > 1){
				aOptions = arguments[1] || {};
			}

			$$('.' + sClassName).each(
					function (oElement){
						oElement.observe("mouseover", function(){
								oElement.addClassName("hover");
							}
						);

						oElement.observe("mouseout", function(){
							oElement.removeClassName("hover");
							}
						);

						if(aOptions.sNotHighlight !== ""){
							var aIdElement = aOptions.sNotHighlight.split(",");
							aIdElement.each(
									function(sContainer){
										$(sContainer).observe("mouseover", function(){oElement.addClassName("notHover");});
										$(sContainer).observe("mouseout", function(){oElement.removeClassName("notHover");});
									}.bindAsEventListener(oElement)
							);
						}
					}
			);
		},

		viewThumbOfTmpFile : function(sFile,id){
			$('photoPath'+id).value= sFile;
			$('imgMember'+id).innerHTML= "<img src='images/preview.php?tmp="+sFile+"' width='100'/>";
		},

		prepaCropping : function(id,sChemin,nWidth,nHeight){
			$('creaPhotoCrop').object.updateDivContent('overlay_creaPhotoCrop','shop.php','iStep=23&current=crop&id='+id+"&sChemin="+sChemin+"&nWidth="+nWidth+"&nHeight="+nHeight,'$(\'creaPhotoCrop\').object.show()');
		},

		authentification : function (frmLogin, sUsernameId, sPasswordId){
			var aOptions = {};

			if(arguments.length > 3){
				aOptions = arguments[3] || {};
			}

			if($F(sUsernameId) === ""){
				$(sUsernameId).value = aOptions.sFieldTextUsername;
			}

			Event.observe(sUsernameId, 'focus',
				function(){
					if($F(sUsernameId) == aOptions.sFieldTextUsername){
						$(sUsernameId).value = "";
					}
				}
			);

			Event.observe(sUsernameId, 'blur',
				function(){
					if($F(sUsernameId) === ""){
						$(sUsernameId).value = aOptions.sFieldTextUsername;
					}
				}
			);

			if($F(sPasswordId) === ""){
				$(sPasswordId + "Display").value = aOptions.sFieldTextPassword;
			}

			Event.observe(sPasswordId + "Display", 'focus',
				function(){
					if($F(sPasswordId + "Display") == aOptions.sFieldTextPassword){
						$(sPasswordId).value = "";
						$(sPasswordId + "Display").hide();
						$(sPasswordId).show();
						$(sPasswordId).focus();
					}
				}
			);

			Event.observe(sPasswordId, 'blur',
				function(){
					if($F(sPasswordId) === ""){
						$(sPasswordId + "Display").value = aOptions.sFieldTextPassword;
						$(sPasswordId).hide();
						$(sPasswordId + "Display").show();
					}
				}
			);

			Event.observe(frmLogin, "submit",
				function (){
					var sQuery = "bSubmit=1&iStep=4&bLoginWithTop=1";
					if($F(sUsernameId) !== "" && $F(sUsernameId) !== aOptions.sFieldTextUsername){
						sQuery += "&sEmail=" + encodeURIComponent($F(sUsernameId));
						$("message").hide();
					}else{
						this.message("error", aOptions.sMsgErrorUsername);
						$(sUsernameId).focus();
						return false;
					}

					if($F(sPasswordId) !== "" && $F(sPasswordId) !== aOptions.sFieldTextPassword){
						sQuery += "&sPassword=" + encodeURIComponent($F(sPasswordId));
					}else{
						this.message("error", aOptions.sMsgErrorPassword);
						$(sPasswordId + "Display").hide();
						$(sPasswordId).show();
						$(sPasswordId).focus();
						return false;
					}
					var sUrl = "shop.php";
					var oMessageObjet = this;

					var oRequest = new Ajax.Request(sUrl, {method:'post',
														   postBody:sQuery,
														   onComplete : function(xhr){
																var oResult = xhr.responseText.evalJSON();
																if(parseInt(oResult.bValid,10) === 1){
																	var oRefresh = new Ajax.Updater("contentLoginTop", sUrl, {method:'post',
																																				 postBody:'bRefresh=1&sPage=login',
																																				 evalScripts:true,
																																				 onComplete:function(){
																																				 	$('contentCommand').show();
																																					$('btnLogAccount').hide();
																																					var oRefresh = new Ajax.Updater("customer", "shop.php", {method:'post',
																																																	 postBody:"iStep=24",
																																																	 evalScripts:true,
																																																	 onComplete:function(){
																																																		$('reservations|24').addClassName('Selected');
																																																		$('contentUpdate').hide();
																																																		$('contentCommand').hide();
																																																		$$('div.moreBlock').each(function(oBlock){oBlock.hide();});
																																																		$('return').innerHTML='<span>Retour sur l evennement</span>';
																																																	 	$('customer').show();
																																																	 }
																																					});
																																				 }
																	});
																}else{
																	oMessageObjet.message("error", oResult.sText);
																	$(sUsernameId).activate();
																}
					}});
				}.bindAsEventListener(this)
			);
		},

		initShowInformation : function (sClassName, sMode) {
			Prototype.require('effects.js');
			$$('.' + sClassName).each(
				function(oElement){
					oElement.observe('click',
							function(oGroup){
								$$('.' + sClassName + 'Detail').invoke('hide');
								var sUrl = "shop.php";
								var sQuery = "bSubmit=1";

								switch (sMode) {
									case "Group" :
										var iIdCode = parseInt(oElement.id.replace("Group", ""), 10);
										break;
								}

								if(lastItemShow==oElement.id) {
									lastItemShow = null;
									Effect.Fade(sClassName + iIdCode, {duration: 0.3});
								}else{
									lastItemShow=oElement.id;
									Effect.Appear(sClassName + iIdCode, {duration: 0.3});
								}
							}.bindAsEventListener(this)
					);
				}.bind(this)
			);
		},

		initShowInformationDetailsMember : function (sClassName) {
			Prototype.require('effects.js');
			$$('.' + sClassName).each(
				function(oElement){
					oElement.observe('click',
						function(event){
							var aTmp = oElement.id.split("|");
							$("detail"+sClassName + aTmp[0] + "|" + aTmp[1] + "|" + aTmp[2] + "|" + aTmp[3]).innerHTML = '<img src="http://etickets.infomaniak.ch/shared/images/ajax_busy_24x24.gif"/>';

							clearTimeout(this.timer);

							$$('.' + sClassName + 'Detail').invoke('hide');

							var aClassUsed = oElement.classNames();
							aClassUsed.each(
									function (sClassUsed) {
										if(sClassUsed != sClassName){
											$(sClassName + aTmp[0] + "|" + aTmp[1] + "|" + aTmp[2] + "|" + aTmp[3]).addClassName(sClassUsed);
										}
									}
							);
							var sUrl = "shop.php";
							this.timer=setTimeout("Effect.Appear('" + sClassName + aTmp[0] + "|" + aTmp[1] + "|" + aTmp[2] + "|" + aTmp[3] + "', {duration: 0.3})", 300);
							var oRefresh = new Ajax.Updater("detail"+sClassName + aTmp[0] + "|" + aTmp[1] + "|" + aTmp[2] + "|" + aTmp[3], sUrl, {method:'post', postBody:'iStep=20&iSubStep=2&iLocationCode='+aTmp[2]+'&iCategoryCode='+aTmp[3]+'&iDateCode='+aTmp[1], evalScripts:true});
						}.bindAsEventListener(this)
					);
				}.bind(this)
			);
		},

		initShowInformationDetails : function (sClassName) {
			Prototype.require('effects.js');
			$$('.' + sClassName).each(
				function(oElement){
					oElement.observe('click',
							function(event){
								clearTimeout(this.timer);
								$$('.' + sClassName + 'Detail').invoke('hide');
								// if last item was this item, show it immediatly because event occurs per table column
								if (lastItemShow==oElement.id) {
									$(sClassName + oElement.id).show();

								} else {
									lastItemShow=oElement.id;
									var aClassUsed = oElement.classNames();
									aClassUsed.each(
											function (sClassUsed) {
												if(sClassUsed != sClassName){
													$(sClassName + oElement.id).addClassName(sClassUsed);
												}
											}
									);
									this.timer=setTimeout("Effect.Appear('" + sClassName + oElement.id + "', {duration: 0.3})", 300);
								}
							}.bindAsEventListener(this)
					);
				}.bind(this)
			);
		},

		initLink : function (sClassName, sIdSubstr) {
			var aInfos = "";

			$$('.' + sClassName).each(
					function (oElement) {
						var iIdCode = parseInt(oElement.id.replace(sIdSubstr, ""), 10);
						Event.stopObserving(oElement, "click");
						oElement.observe("click",
								function(event){
									Event.stop(event);
									var sUrl = "shop.php";
									var sQuery = "bSubmit=1";
									var sContentReceiver = "contentUpdate";
									var bShowAfterRequest = 0;
									switch (sIdSubstr){
										case "GroupDates" :
											sQuery += "&iStep=1&iGroupDates=" + iIdCode;
											break;
										case "goToPersoDate" :
											sQuery += "&iStep=18&bSubmit=0&iReservationCode=" + iIdCode;
											break;
										case "goToViewDate" :
										case "Date" :
											sQuery += "&iStep=1&iDateCode=" + iIdCode;
											break;
										case "Abonnement" :
											sQuery += "&iStep=1&iCategoryCode=" + iIdCode;
											break;
										case "Member" :
											sQuery += "&iStep=1&iCategoryCode=" + iIdCode + "&membership_card=1";
											break;
										case "addMemberShipCardDate" :
											iIdCode = oElement.id.replace(sIdSubstr, "");
											aInfos = iIdCode.split("|");
											sQuery += "&iStep=1&iCategoryCode=" + aInfos[0] + "&iParentCategoryCode=" + aInfos[1] + "&membership_card=1&iNumber="+parseInt($F("iNumber|" + aInfos[0] + "|" +aInfos[2]),10);
											break;
										case "AbonnementEdit" :
											sQuery = "iStep=7&iCategoryCode=" + iIdCode;
											break;
										case "memberCardEdit" :
											sQuery = "iStep=20&iSubStep=1&iCategoryCode=" + iIdCode;
											break;
										case "Group" :
											sQuery += "&iStep=1&iDateCode=" + iIdCode;
											break;
									}

									if(bShowAfterRequest == 1){
										$(sContentReceiver).update("");
										$(sContentReceiverGlobal+"Loader").show();
										$(sContentReceiverGlobal).show();
									}

									var oRequest = new Ajax.Updater(sContentReceiver, sUrl, {method:'post',
																												postBody:sQuery,
																												evalScripts:true,
																												onComplete:function(){
																													if(bShowAfterRequest == 1){
																														$(sContentReceiverGlobal+"Loader").hide();
																														$(sContentReceiver).show();
																													}
																												}
									});
								}
						);
					}
			);
		},

		initGestionMemberShip : function (sClassName, sIdSubstr) {
			var aInfos = "";
			var oMessageError = this;

			$$('.' + sClassName).each(
					function (oElement) {
						var iIdCode = parseInt(oElement.id.replace(sIdSubstr, ""), 10);
						Event.stopObserving(oElement, "click");
						oElement.observe("click",
								function(event){
									Event.stop(event);
									var sUrl = "shop.php";
									var sQuery = "";
									switch (sIdSubstr){
										case "codeBarMemberShipCard" :
											iIdCode = oElement.id.replace(sIdSubstr, "");
											aInfos = iIdCode.split("|");
											sQuery += "&iStep=20&iSubStep=1&bSubmit=0&iDateCode=" + aInfos[1] + "&sMode=getMC&sCodeBar="+$F('sCardBarCode');
											break;
										case "addExistingMemberShipCard" :
											iIdCode = oElement.id.replace(sIdSubstr, "");
											aInfos = iIdCode.split("|");
											sQuery += "&iStep=20&iSubStep=1&bSubmit=0&iDateCode=" + parseInt(aInfos[1],10) + "&sMode=getExistingMC&iMemberShipCardCode="+parseInt(aInfos[2],10)+"&iCardAlwaysPresent="+parseInt(aInfos[3],10);
											break;
									}


									var	oRequest = new Ajax.Request(sUrl, {method:'post',
																		   postBody:sQuery,
																		   onComplete:function(xhr){
																		   		var sResult = xhr.responseText;
																				if(parseInt(sResult,10) != 1){
																					$('contentUpdate').update(sResult);
																				}else{
																					var messagea = sResult.split("1");
																					oMessageError.message("error", messagea[1]);
																				}
																		   }.bindAsEventListener(this)
										});

								}.bindAsEventListener(this)
						);
					}
			);
		},

		inputHint : function(id, deftxt)
		{
			//default color.
			$(id).setStyle({color:'#666'});

			//def txt
			$(id).value = deftxt;

			//observe on focus / blur
			$(id).observe('focus', function() {
			  if (this.value == deftxt) {
			    this.value = '';
			    this.setStyle({color:'#000'});
			  }
			});

			$(id).observe('blur', function() {
			  if (this.value === '') {
			    this.value = deftxt;
			    this.setStyle({color:'#666'});
			  }
			});
		},
		initSearchForm : function (sForm, sInput, sDestination) {
			$(sForm).observe("submit",
					function(){
						var sUrl = "shop.php";
						var sQuery = "iStep=1&bSearch=1&sSearch=" + encodeURIComponent($F(sInput));
						var oRequest = new Ajax.Updater(sDestination, sUrl, {method:'post', postBody:sQuery, evalScripts:true});
					}
			);

			$(sForm + "Btn").observe("click",
					function(){
						var sUrl = "shop.php";
						var sQuery = "iStep=1&bSearch=1&sSearch=" + encodeURIComponent($F(sInput));
						var oRequest = new Ajax.Updater(sDestination, sUrl, {method:'post', postBody:sQuery, evalScripts:true});
					}
			);
		},

		initSearchFormEvents : function () {
			var sSearchTextEvent = $('sSearchTxtEvt');
			sSearchTextEvent.observe('change', function(){
										var sUrl = "shop.php";
										var sQuery2 = "iStep=20&iSubStep=1&bSubmit=0&sMode=searchEvents&sSearch="+sSearchTextEvent.value;
										var oRequest2 = new Ajax.Updater("listMemberEvents", sUrl, {method:'post', postBody:sQuery2, evalScripts:true});}.bind(this));

		},

		initKeywords : function (sClassName, sDestination) {
			$$("." + sClassName).each(
					function (oElement){
						oElement.observe("change",
								function(){
									var aIdentifiant = oElement.id.split("_");
									var sUrl = "shop.php";
									var iKeywordCode = $F(oElement.id);
									if((aIdentifiant[1] == 1)&&(oElement.checked === false)){
										iKeywordCode = 0;
									}
									
									var sQuery = "iStep=1&bFilterDates=1&bCheckbox=" + parseInt(aIdentifiant[1], 10) + "&iLevelFilter=" + parseInt(aIdentifiant[2], 10) + "&iKeywordCode=" + iKeywordCode;
									var oRequest = "";
									if(parseInt(aIdentifiant[2],10) === 1){
										 oRequest = new Ajax.Updater(sDestination,sUrl,{
											 method:'post',
											 postBody:sQuery,
											 evalScripts:true,
											 onComplete:function(){
												var iLevel = 1;
												if(aIdentifiant[2] == 1){
													iLevel = 2;
												}
												var sDestinationOptions = aIdentifiant[0].substring(0,(aIdentifiant[0].length-1)) + iLevel + "_" + aIdentifiant[1] + "_" + iLevel;
												if(iKeywordCode!=0){
													var oRequestOptions = new Ajax.Updater(sDestinationOptions + "Zone", sUrl, {
														method:'post',
														postBody:'bGetOptionsFilter=1&sField=' + sDestinationOptions,
														evalScripts:true
													});
											 	}else{
											 		$(sDestinationOptions + "Zone").update();
											 	}
											 }
										});
									}else{
										oRequest = new Ajax.Updater(sDestination, sUrl, {
											method:'post',
											postBody:sQuery,evalScripts:true
										});
									}
								}
						);
					}
			);
		},

		initBtnShopping : function (sClassName){
			if($('btnLogAccount')){
				$('btnLogAccount').hide();
			}

			$$("." + sClassName).each(
				function(oBtnCart){
					oBtnCart.show();
					var aClassNameUsed = oBtnCart.classNames();
					aClassNameUsed.each(
							function (sClassUsed) {
								if(sClassUsed.indexOf("perso_") != 0 && sClassUsed.indexOf("button_") != 0){
									if(sClassUsed != "btnShoppingCart"){
										this.initBtn(sClassUsed);
									}
								}
							}.bindAsEventListener(this)
					);
				}.bindAsEventListener(this)
			);
		},

		hideBtnShopping : function (sClassName){
	 		$$("." + sClassName).each(
				function(oBtnCart){
					Event.stopObserving(oBtnCart, "click");
					oBtnCart.hide();
				}
			);
		},

		initBtnLogAccount : function (sClassName){
			var aOptions = {};

			if(arguments.length > 1){
				aOptions = arguments[1] || {};
			}

			if(parseInt(aOptions.bLogged,10) == 1){
				$('contentLoginTop').show();
				$('contentCommand').show();
				$('btnLogAccount').hide();
			}else{
				$$("." + sClassName).each(
						function(oBtn){
							oBtn.stopObserving('click');
							oBtn.observe("click", function(){
								$("message").hide();
								$('contentCommand').hide();
								$('contentLoginTop').show();
								$('sEmailTop').focus();
							}.bindAsEventListener(this));
						}.bind(this)
				);
			}
		},

		hideBtnLogAccount : function (bLogged){
			if($('showLogAccount')){
				$('showLogAccount').hide();
			}

			if($('contentLoginTop')){
				if(bLogged == 1){
					$('contentLoginTop').show();
				}else{
					$('contentLoginTop').hide();
				}
			}
		},

		preCreateMemberShipCard : function(id){
			var sUrl = "shop.php";
			var sQuery2 = "iStep=19&bLayoutFull=0&nbNewMembers="+$('iNumber'+id).value+"&iCategory="+id;
			var oRequest2 = new Ajax.Updater("listUsers", sUrl, {method:'post', postBody:sQuery2, evalScripts:true});
		},

		supprimerOverlay : function(){
			$$('.overlayCrop').each( function(elem){
				elem.remove();
			});
			$$('.overlayCam').each( function(elem){
				elem.remove();
			});
			$$('.overlayUpload').each( function(elem){
				elem.remove();
			});
		},

		initClick : function (oBtn, sAction, aOptions) {
			var bSpecial = 0;
			var aInfos = "";
			var sQuery = "";
			var sUrl = "shop.php";
			var oRequest = "";
			var oForm = "";

			switch (sAction) {
				case "printTicket" :
					bSpecial = 1;
					window.open('pdftest.php', 'ticket');
					break;
				case "btnBack" :
					aInfos = oBtn.id.split("|");
					sQuery += "iStep=" + parseInt(aInfos[1], 10);
					break;
				case "btnPageNext" :
				case "btnPageBack" :
					aInfos = oBtn.id.split("|");
					sQuery += "iStep=1&iPage=" + parseInt(aInfos[1], 10);
					break;

				case "saveLabelAll" :
					var hParams = new $H($('frmLabel').serialize(true));
					hParams.set('bAll', "1");
					hParams.set('iStep', "18");
					hParams.set('bSubmit', "1");
					if ($F('iOriginStep') != 3 && $F('iOriginStep') != 5){
						iOriginStep = 3;
					}else{
						iOriginStep = $F('iOriginStep');
					}

					oRequest = new Ajax.Request(sUrl, {method:'post',
												parameters: hParams,
												onComplete:function(xhr){
														var oResult = xhr.responseText.evalJSON();
															if(parseInt(oResult.bValid,10) === 1){
																var oRequestRefresh = new Ajax.Updater("contentUpdate", sUrl, {method:'post',
																															   postBody:"iStep="+iOriginStep,
																															   evalScripts:true,
																															   onComplete:function(){
																															   		this.message("confirmation",oResult.sText,{iDuration:5});
																															   }.bindAsEventListener(this)
																});
															}else{
																this.message("error", oResult.sText);
															}
														}.bindAsEventListener(this)
					});
					bSpecial = 1;
					break;

				case "saveLabel" :
					var hParams = new $H($('frmLabel').serialize(true));
					hParams.set('bAll', "0");
					hParams.set('iStep', "18");
					hParams.set('bSubmit', "1");
					if ($F('iOriginStep') != 3 && $F('iOriginStep') != 5){
						iOriginStep = 3;
					}else{
						iOriginStep = $F('iOriginStep');
					}

					oRequest = new Ajax.Request(sUrl, {method:'post',
												parameters: hParams,
												onComplete:function(xhr){
														var oResult = xhr.responseText.evalJSON();
															if(parseInt(oResult.bValid,10) === 1){
																var oRequestRefresh = new Ajax.Updater("contentUpdate", sUrl, {method:'post',
																															   postBody:"iStep="+iOriginStep,
																															   evalScripts:true,
																															   onComplete:function(){
																															   		this.message("confirmation",oResult.sText,{iDuration:5});
																															   }.bindAsEventListener(this)
																});
															}else{
																this.message("error", oResult.sText);
															}
														}.bindAsEventListener(this)
					});
					bSpecial = 1;
					break;

				case "btnAjoutLigne":
					bSpecial = 1;
					$('iNumber'+$('iCategoryCode').value).value = eval($('iNumber'+$('iCategoryCode').value).value)+1;
					oTools.recalcTotal($('iCategoryMembershipCard').value);
					bHasLoaded=true;
					this.addRowToTable();
					$('creaMemberCard2ndStep').setStyle({display:"block"});
					break;

				case "killNewMC":
					$('iNumber'+$('iCategoryCode').value).value = eval($('iNumber'+$('iCategoryCode').value).value)-1;
					oTools.recalcTotal($('iCategoryCode').value);
					if($('iNumber'+$('iCategoryCode').value).value == 0){
						$('creaMemberCard2ndStep').setStyle({display:"none"});
					}
					this.deleteCurrentRow(oBtn);
						bSpecial = 1;
					break;

				case "btnUploadPhoto":
					aInfos = oBtn.id.split("|");
					$('idCurrentPhoto').value = aInfos[1];
					$('creaPhotoUpload').object.updateDivContent('overlay_creaPhotoUpload','shop.php','iStep=23&current=upload&id='+aInfos[1],'$(\'creaPhotoUpload\').object.show()');
					bSpecial = 1;
					break;

				case "btnPhotoByCam":
					aInfos = oBtn.id.split("|");
					$('idCurrentPhoto').value = aInfos[1];
					$('creaPhotoByCam').object.updateDivContent('overlay_creaPhotoByCam','shop.php','iStep=23&current=snapshot&id='+aInfos[1],'$(\'creaPhotoByCam\').object.show()');
					bSpecial = 1;
					break;


				case "btnHidePhotoUpload":
					$('creaPhotoUpload').object.hide();
					bSpecial = 1;
					break;

				case "btnHidePhotoCrop":
//					$('creaPhotoCrop').object.hide();
					closeThePopup('creaPhotoCrop');
					bSpecial = 1;
					break;
				case "btnHidePhotoByCam":
					$('creaPhotoByCam').object.hide();
					bSpecial = 1;
					break;

				case "btnEtapeMembreEvent":
					var iValid = 1;
					if($F("checkPhoto")=="1"){
						if($F("checkPhotoMandatory")=="yes"){
							for(var i=0; i<this.aMembershipCards.length; i++){
								if($F('photoPath'+this.aMembershipCards[i])==""){
									iValid=0;
								}
							}
						}
					}
					//this.supprimerOverlay();
					hParams = new $H($('formMembers').serialize(true));
					hParams.set('iStep', "2");
					hParams.set('bJustCreateMemberCard', "1");
					hParams.set('bSubmit', "1");
					hParams.set('iSubStep', "1");
					hParams.set('aMembershipCards[]', this.aMembershipCards);
					hParams.set('iValid', iValid);
					oRequest = new Ajax.Request(sUrl, {method:'post',
												parameters: hParams,
												onComplete:function(xhr){
														var oResult = xhr.responseText.evalJSON();
														if(parseInt(oResult.bValid,10) === 1){
																$('iTotalMemberShipCards').update(parseInt(oResult.iTotalMemberShipCard, 10));
																if(oResult.iTotalMemberShipCard > 1){
																	$('sTextMemberShipCard').update(oResult.sTextMemberShipCard);
																}
																$('fAmountCart').update(oResult.fAmountCart);
																$('fAmountCart').show();
																$('sCurrencyCart').show();

																if($('currenciesSelector')){
																	$('currenciesSelector').hide();
																}

																if(oResult.iTotalMemberShipCard > 0 || oResult.iTotalPlace > 0){
																	this.initBtnShopping("btnShoppingCart");
																}else{
																	this.hideBtnShopping("btnShoppingCart");
																}
																var oRequestRefresh = new Ajax.Updater("contentUpdate", sUrl, {method:'post',
																															   postBody:"iStep=20&iSubStep=1",
																															   evalScripts:true,
																															   onComplete:function(){
																															   		this.message("confirmation",oResult.sText,{iDuration:5});
																															   }.bindAsEventListener(this)
																});
														}else{
															this.message("error", oResult.sText);
															$("formMembers").object.checkErrorsOnly();
														}
												}.bindAsEventListener(this)
					});

					bSpecial = 1;

				break;
				case "preReserveCard" :
					this.aMembershipCards.length = 0;
					if($('iNumber'+$('iCategoryCode').value).value == 0){
						$('creaMemberCard2ndStep').setStyle({display:"none"});
					}else{
						$('creaMemberCard2ndStep').setStyle({display:"block"});
					}

					aInfos = oBtn.id.split("|");
					this.preCreateMemberShipCard(aInfos[1]);
					/*
					var oRequestAbo = new Ajax.Updater("listUsers", sUrl, {method:'post',
																			   postBody:sQueryAbo,
																			   evalScripts:true,
																			   onComplete:function(){
																					if($('contentCart').style.display != "none"){
																						var sQuery2 = "iStep=19";
																						var oRequest2 = new Ajax.Updater("contentCart", sUrl, {method:'post', postBody:sQuery2, evalScripts:true});
																					}
																				}
														});*/
					bSpecial = 1;
					break;
				case "addToCart" :
					this.aMembershipCards.length = 0;
					aInfos = oBtn.id.split("|");
					switch (aInfos[0]){
						case "addDateCategory" :
							sQuery += "bSubmit=1&iStep=2&iPlace=" + parseInt($F("iNumber|" + aInfos[2] + "|" + aInfos[3]),10);
							sQuery += "&iDateCode=" + parseInt(aInfos[1], 10);
							sQuery += "&iLocationCode=" + parseInt(aInfos[2], 10);
							sQuery += "&iCategoryCode=" + parseInt(aInfos[3], 10);
							break;

						case "addPassCategory" :
							sQuery += "bSubmit=1&iStep=2&iPlace=" + parseInt($F("iNumber|" + aInfos[1]),10);
							sQuery += "&iCategoryCode=" + parseInt(aInfos[1], 10);
							break;

						case "addPassCategoryDate" :
							sQuery += "bSubmit=1&iStep=7&" + oBtn.id + "=" + parseInt($F("iNumber|" + aInfos[1] + "|" + aInfos[2] + "|" + aInfos[3]),10);
							break;

						case "addMemberCategory" :
							sQuery += "iStep=3";
						break;

						case "addMemberToEvent" :

						break;
					}

					bSpecial = 1;
					oRequest = new Ajax.Request(sUrl, {method:'post',
													   postBody:sQuery,
													   onComplete:function(xhr){
													   		var oResult = xhr.responseText.evalJSON();
													   		if(parseInt(oResult.bValid,10) == 1){
													   			$('iTotalPlace').update(parseInt(oResult.iTotalPlace, 10));

														   		if(oResult.iTotalPlace > 1){
																		$('sTextPlace').update(oResult.sTextPlace);
																	}

																	if($('iTotalPassCategories')){
																		$('iTotalPassCategories').update(parseInt(oResult.iTotalPassCategory, 10));
																		if(oResult.iTotalPassCategory > 1){
																			$('sTextPassCategory').update(oResult.sTextPassCategory);
																		}
																	}

																	$('fAmountCart').update(oResult.fAmountCart);
																	$('fAmountCart').show();
																	$('sCurrencyCart').show();
																	if($('currenciesSelector')){
																		$('currenciesSelector').hide();
																	}

																	if(oResult.iTotalPassCategory > 0 || oResult.iTotalPlace > 0){
																		this.initBtnShopping("btnShoppingCart");
																		if(oResult.bAdmin){
																			if(parseInt(oResult.bAdmin, 10) == 0){
																				this.hideBtnLogAccount(oResult.bLogged);
																			}
																		}else{
																			this.hideBtnLogAccount(oResult.bLogged);
																		}
																	}else{
														   			this.hideBtnShopping("btnShoppingCart");
																		this.initBtnLogAccount("showLogAccount", {bLogged : oResult.bLogged});
																		if(oResult.bAdmin){
																			if(parseInt(oResult.bAdmin, 10) == 0){
																				this.initBtnLogAccount("showLogAccount", {bLogged : oResult.bLogged});
																			}
																		}else{
																			this.initBtnLogAccount("showLogAccount", {bLogged : oResult.bLogged});
																		}
																	}
																	this.message("confirmation", oResult.sText, {iDuration:5});

																	if(oResult.sMode == "abo"){
																		var sQueryAbo = "iStep=7";
																		var oRequestAbo = new Ajax.Updater("contentUpdate", sUrl, {method:'post',
																																   postBody:sQueryAbo,
																																   evalScripts:true,
																																   onComplete:function(){
																																				if($('contentCart').style.display != "none"){
																																					var sQuery2 = "iStep=3&bMiniCart=1";
																																					var oRequest2 = new Ajax.Updater("contentCart", sUrl, {method:'post', postBody:sQuery2, evalScripts:true});
																																				}
																																	}
																		});
																	}else{
																		$('contentCart').hide();
																		sQuery = "bCheckCommandValid=1";
																		oRequest = new Ajax.Request(sUrl, {method:'post',
																										   postBody:sQuery,
																										   onComplete:function(xhr){
																												var oResult = xhr.responseText.evalJSON();
																												if(parseInt(oResult.bValid,10) === 1){
																													sQuery = "iStep=3&bMiniCart=0";
																													var oRequestRefresh = new Ajax.Updater("contentUpdate", sUrl, {method:'post', postBody:sQuery, evalScripts:true});
																												}else{
																													this.message("error", oResult.sText);
																												}
																											}.bindAsEventListener(this)
																		});
																	}
																}else{
																	this.message("error", oResult.sText);
																}
													   	}.bindAsEventListener(this)
					});
					break;

				case "showCart" :
					var oEffect = "";
					if($('contentCart').style.display == "none"){
						oEffect = new Effect.BlindDown('contentCart', {duration:0.2});
						aInfos = oBtn.id.split("|");
						sQuery += "iStep=" + parseInt(aInfos[1], 10) + "&bMiniCart=1";
						oRequest = new Ajax.Updater("contentCart", sUrl, {method:'post', postBody:sQuery, evalScripts:true});
					}else{
						oEffect = new Effect.BlindUp('contentCart', {duration:0.2});
					}
					bSpecial = 1;
					break;
				case "payCart" :
					$('contentCart').hide();
					aInfos = oBtn.id.split("|");
					sQuery = "bCheckCommandValid=1";
					oRequest = new Ajax.Request(sUrl, {method:'post',
													   postBody:sQuery,
													   onComplete:function(xhr){
															var oResult = xhr.responseText.evalJSON();
															if(parseInt(oResult.bValid,10) === 1){
																sQuery = "bSubmit=1&iStep=" + parseInt(aInfos[1], 10) + "&bMiniCart=0";
																var oRequestRefresh = new Ajax.Updater("contentUpdate", sUrl, {method:'post', postBody:sQuery, evalScripts:true});
															}else{
																this.message("error", oResult.sText);
															}
														}.bindAsEventListener(this)
					});
					bSpecial = 1;
					break;
				case "listDates" :
					this.supprimerOverlay();
					sQuery += "iStep=1";
					break;
				case "cancelOrder" :
					//Annuler la commande
					sQuery += "bCancelOrder=1";
					bSpecial = 1;
					oRequest = new Ajax.Request(sUrl, {method:'post',
													   postBody:sQuery,
													   onComplete:function(xhr){
															var oResult = xhr.responseText.evalJSON();
															if(parseInt(oResult.bValid,10) == 1){
																document.location.href="index.php";
															}else{
																this.message("error", oResult.sText);
															}
													   }
					});
					break;

				case "confirmCart" :
					//Page de confirmation de paiement
					sQuery = "bCheckCommandValid=1";
					oRequest = new Ajax.Request(sUrl, {method:'post',
													   postBody:sQuery,
													   onComplete:function(xhr){
															var oResult = xhr.responseText.evalJSON();
															if(parseInt(oResult.bValid,10) === 1){
																sQuery = "bReinitCustomer=1&iStep=4";
																var oRequestRefresh = new Ajax.Updater("contentUpdate", sUrl, {method:'post', postBody:sQuery, evalScripts:true});
															}else{
																this.message("error", oResult.sText);
															}
														}.bindAsEventListener(this)
					});
					bSpecial = 1;
					break;

				case "checkEmailCustomer" :
					//Check si l'email est déjà existant
					if(this.isEmail($F('sEmailCustomer'))){
						sQuery += "bCheckCustomerEmail=1&sEmail=" + encodeURIComponent($F('sEmailCustomer'));
						oRequest = new Ajax.Request(sUrl, {method:'post',
														   postBody:sQuery,
														   onComplete:function(){
																oRequest = new Ajax.Updater("contentUpdate", sUrl, {method:'post', postBody:'iStep=4', evalScripts:true});
														   }
						});
					}else{
						this.message("error", aOptions.sMsg);
					}
					bSpecial = 1;
					break;

				case "forgetPasswordTop" :
				case "forgetPassword" :
					if(this.isEmail($F(aOptions.sField))){
						sQuery += "bForgetPassword=1&sEmail=" + encodeURIComponent($F(aOptions.sField));
						oRequest = new Ajax.Request(sUrl, {method:'post',
														   postBody:sQuery,
														   onComplete:function(xhr){
																var oResult = xhr.responseText.evalJSON();
																if(parseInt(oResult.bValid,10) === 1){
																	this.message("confirmation", oResult.sText, {iDuration:5});
																}else{
																	this.message("error", oResult.sText);
																}
				    									  }.bindAsEventListener(this)
					    });
					}else{
						this.message("error", aOptions.sMsg);
						$(aOptions.sField).activate();
					}
					bSpecial = 1;
					break;

				case "loginCustomer" :
					sQuery += "bSubmit=1&iStep=4&sEmail=" + encodeURIComponent($F('sEmailCustomer')) + "&sPassword=" + encodeURIComponent($F('sPasswordCustomer'));
					oRequest = new Ajax.Request(sUrl, {method:'post',
													   postBody:sQuery,
													   onComplete:function(xhr){
															var oResult = xhr.responseText.evalJSON();
															if(parseInt(oResult.bValid,10) == 1){
																oRequest = new Ajax.Updater("contentUpdate", sUrl, {method:'post',
																													postBody:"iStep=4",
																													evalScripts:true,
																													onComplete:function(){
																																var oRefresh = new Ajax.Updater("contentLoginTop", sUrl, {method:'post',
																																																			 postBody:'bRefresh=1&sPage=login',
																																																			 evalScripts:true,
																																																			 onComplete:function(){
																																																			 	$('contentLoginTop').show();
																																																				$('btnLogAccount').hide();
																																																			 }
																																																			 });
																														}
																													});
															}else{
																this.message("error", oResult.sText);
															}
			    									  }.bindAsEventListener(this)
				    });
					bSpecial = 1;
					break;

				case "createCustomer" :
					if(this.isEmail($F('sEmailCustomer')) && this.isEmail($F('sEmailCustomerConfirm'))){
						if($F('sEmailCustomer') === $F('sEmailCustomerConfirm')){
							if($F('sPasswordCustomer') !== ""){
								if($F('sPasswordCustomer') === $F('sPasswordCustomerConfirm')){
									var oCheckFields = $$('.mandatory');
									oCheckFields.each(
										function(oField){
											switch (oField.type) {
												case "text" :
													if(this.trim(oField.value) == ""){
														this.message("error", aOptions.sMsgErrorMandatoryField);
													}
													break;

												case "select-one" :
													if(oField.value == 0){
														this.message("error", aOptions.sMsgErrorMandatoryField);
													}
													break;
											}
										}.bindAsEventListener(this)
									);

									sQuery += "bSubmit=1&iStep=4&bCreate=1&" + $('frmLoginCustomer').serialize();

									oRequest = new Ajax.Request(sUrl, {method:'post',
																	   postBody:sQuery,
																	   onComplete:function(xhr){
																			var oResult = xhr.responseText.evalJSON();
																			if(parseInt(oResult.bValid,10) === 1){
																				oRequest = new Ajax.Updater("contentUpdate", sUrl, {method:'post',
																																				postBody:"iStep=4",
																																				evalScripts:true,
																																				onComplete:function(){
																																							var oRefresh = new Ajax.Updater("contentLoginTop", sUrl, {method:'post', postBody:'bRefresh=1&sPage=login',
																																															 evalScripts:true
																																															 });
																																					}
																																				});
																			}else{
																				this.message("error", oResult.sText);
																			}
							 									  }.bindAsEventListener(this)
									 });
								}else{
									this.message("error", aOptions.sMsgErrorPasswordNotSame);
								}
							}else{
								this.message("error", aOptions.sMsgErrorPasswordEmpty);
							}
						}else{
							this.message("error", aOptions.sMsgErrorEmailNotSame);
						}
					}else{
						this.message("error", aOptions.sMsgErrorEmailNotValid);
					}
					bSpecial = 1;
					break;

				case "updateCustomer" :
					if(this.isEmail($F('sEmailCustomer')) && this.isEmail($F('sEmailCustomerConfirm'))){
						if($F('sEmailCustomer') === $F('sEmailCustomerConfirm')){
							if($F('sPasswordCustomer') !== ""){
								if($F('sPasswordCustomer') === $F('sPasswordCustomerConfirm')){
									sQuery += "bSubmit=1&iStep=14&bCreate=1&sEmail=" + encodeURIComponent($F('sEmailCustomer')) + "&sPassword=" + encodeURIComponent($F('sPasswordCustomer'));
									sQuery += "&iCustomerCode=" + encodeURIComponent($F('iCustomerCode'));
									sQuery += "&sFirstname=" + encodeURIComponent($F('sFirstnameCustomer'));
									sQuery += "&sLastname=" + encodeURIComponent($F('sLastnameCustomer'));
									sQuery += "&sPhone=" + encodeURIComponent($F('sPhoneCustomer'));
									sQuery += "&bNewsletter=" + encodeURIComponent($F('bNewsletterCustomer'));
									oRequest = new Ajax.Request(sUrl, {method:'post',
																	   postBody:sQuery,
																	   onComplete:function(xhr){
																			var oResult = xhr.responseText.evalJSON();
																			if(parseInt(oResult.bValid,10) === 1){
																				oRequest = new Ajax.Updater("theTools", sUrl, {method:'post',
																																	postBody:"iStep=14",
																																	evalScripts:true,
																																	onComplete:function(){
																																	$('message').update("Modification prise en compte");
																															 		$('message').className = "msgConfirmation";
																																 	$('message').show();
																																	}
																																});
																			}
							 									  }.bindAsEventListener(this)
									 });
								}else{
									this.message("error", aOptions.sMsgErrorPasswordNotSame);
								}
							}else{
								this.message("error", aOptions.sMsgErrorPasswordEmpty);
							}
						}else{
							this.message("error", aOptions.sMsgErrorEmailNotSame);
						}
					}else{
						this.message("error", aOptions.sMsgErrorEmailNotValid);
					}
					bSpecial = 1;
					break;

				case "logout" :
					document.location.href="index.php?bLogout=1";
					bSpecial = 1;
					break;

				case "selectCurrencies" :
					aInfos = oBtn.id.split("|");
					oRequest = new Ajax.Request(sUrl, {method:'post', postBody:'iCurrencyCode=' + parseInt(aInfos[1], 10),onComplete:function(){document.location.reload();}});
					bSpecial = 1;
					break;

				case "changeLanguage" :
					aInfos = oBtn.id.split("|");
					oRequest = new Ajax.Request(sUrl, {method:'post', postBody:'sLocale=' + aInfos[1],onComplete:function(){document.location.reload();}});
					bSpecial = 1;
					break;

				case "checkPromotion" :
					if($F('sCodePromotion') !== ""){
						sQuery += "bCheckPromotion=1&sPromotionCode=" + encodeURIComponent($F('sCodePromotion'));
						oRequest = new Ajax.Request(sUrl, {method:'post',
														   postBody:sQuery,
														   onComplete:function(xhr){
																var oResult = xhr.responseText.evalJSON();
																if(parseInt(oResult.bValid,10) == 1){
																	var oRefresh = new Ajax.Updater("contentUpdate", sUrl, {method:'post',
																																  postBody:'bRefresh=1&sPage=payment',
																																  evalScripts:true
																																 });
																}else{
																	this.message("error", oResult.sText);
																}
														   }.bindAsEventListener(this)
						});
					}else{
						this.message("error", aOptions.sMsgEmpty);
					}
					bSpecial = 1;
					break;

				case "btnHelp" :
					bSpecial = 1;
					aInfos = oBtn.id.split("|");
					oRequest = new Ajax.Updater("overlay_help", sUrl, {method:'post',
																		  postBody:"bHelp=1&sFileToInclude=" + encodeURIComponent(aInfos[1]),
																		  evalScripts:true,
																		  onComplete:function(){
																		  	this.createPopup("help");
																		  	this.showPopup("help");
																		  }.bindAsEventListener(this)});
					break;

				case "showPopup" :
					aInfos = oBtn.id.split("|");
					$(aInfos[1]).object.show();
					bSpecial = 1;
					break;

				case "hidePopup" :
					aInfos = oBtn.id.split("|");
					$(aInfos[1]).object.hide();
					bSpecial = 1;
					break;

				case "confirmPaymentWithPlace" :
					oForm = $(aOptions.sForm).serialize(true);
					if(oForm.sPaymentType){
						if(oForm.iConfirmCondition == "on"){
							var sAttributionSeats = "&sAttributionSeatsMode=";

							if($('setManualSeats')){
								if($('setManualSeats').checked){
									sAttributionSeats += $F('setManualSeats');
								}else{
									sAttributionSeats += $F('setAutoSeats');
								}
							}else{
								sAttributionSeats += 'auto';
							}
							sQuery += "iStep=9&bSubmit=1" + sAttributionSeats + "&sPaymentMode=" + encodeURIComponent(oForm.sPaymentType) + "&bCondition=1";
						}else{
							this.message("error", aOptions.sMsgConditionsEmpty);
							return false;
						}
					}else{
						this.message("error", aOptions.sMsgPaymentModeEmpty);
						return false;
					}
					break;

				case "confirmPayment" :
					oForm = $(aOptions.sForm).serialize(true);
					if(oForm.sPaymentType){
						if(oForm.iConfirmCondition == "on"){
							sQuery += "iStep=5&bSubmit=1&sPaymentMode=" + encodeURIComponent(oForm.sPaymentType) + "&bCondition=1";
						}else{
							this.message("error", aOptions.sMsgConditionsEmpty);
							return false;
						}
					}else{
						this.message("error", aOptions.sMsgPaymentModeEmpty);
						return false;
					}
					break;

				case "goToResume" :
					sQuery += "iStep=5&bAutoSeat=0";
					break;

				case "setAutoSeats" :
					sQuery += "iStep=5bAutoSeat=1";
					break;

				case "setManualSeats" :
					sQuery += "iStep=10";
					break;

				case "btnClose" :
					aInfos = oBtn.id.split("|");
					$(aInfos[1]).object.hide();
					sQuery = "iStep=9";
					break;

				case "btnEditSeat" :
					selectSeats_object = new adminOverlay('selectSeats');
					$('selectSeats').object = selectSeats_object;

					loading_object = new adminOverlay('iIdLoader', {
						onHide: function(){
							$('selectSeats').object.show();
						}
					});
					$('iIdLoader').object = loading_object;
					$('iIdLoaderText').update(aOptions.sLoadingText);
					$('iIdLoader').object.show();
					aInfos = oBtn.id.split("|");
					sQuery = "iStep=11&iDateCode=" + parseInt(aInfos[1], 10) + "&iTariffZoneCode=" + parseInt(aInfos[2], 10);
					oRequest = new Ajax.Updater("selectSeats", sUrl, {method:'post',
																	  postBody:sQuery,
																	  evalScripts:true,
																	  onComplete:function(){
																	  	$('iIdLoader').object.hide();
																	  }
					});
					bSpecial = 1;
					break;

				case "goToPaid" :
					sQuery = "bSubmit=1&iStep=6";
					if($(aOptions.sForm)){
						oForm = $(aOptions.sForm).serialize(true);
						if(oForm.sPaymentType){
							if(oForm.iConfirmCondition == "on"){
								sQuery += "&sPaymentMode=" + encodeURIComponent(oForm.sPaymentType) + "&bCondition=1";
							}else{
								this.message("error", aOptions.sMsgConditionsEmpty);
								return false;
							}
						}else{
							this.message("error", aOptions.sMsgPaymentModeEmpty);
							return false;
						}
					}

					oRequest = new Ajax.Request(sUrl, {method:'post',
													   postBody:sQuery,
													   onComplete:function(xhr){
															var aResult = xhr.responseText.split("|");
															if(parseInt(aResult[0],10) == 1){
																switch(aResult[1]){
														       		case "postcard" :
														       			$('containerPayment').update(aResult[2]);
														       			$('form1').submit();
														       			$('form1').reset();
														       			$('containerPayment').update("");
														       			break;

														       		case "free" :
														       			window.location.href = aResult[2];
														       			break;

														       		case "cash" :
														       			window.location.href = aResult[2];
														       			break;

														       		case "credit" :
														       			$('containerPayment').update(aResult[2]);
														       			$('frmCmcic').submit();
														       			$('frmCmcic').reset();
														       			$('containerPayment').update("");
														       			break;
														       	}
															}else{
																this.message("error", aResult[1]);
															}
														}.bindAsEventListener(this)
					});
					bSpecial = 1;
					break;

				case "InitCommand" :
					window.location.href = "shop.php";
					bSpecial = 1;
					break;

				case "btnCustomizeTickets" :
					$$(".btnCustomizeTickets").each(
							function (oBtn){
								oBtn.observe("click",
									function(){
										$('contentCustomizeTickets').object.show();
									}
								);
							}
					);
					break;

				case "viewDatesToPassCategory" :
					sQuery += "iStep=7";
					break;

				case "btnPassCategoryDetail" :
					sQuery += "&bSubmit=1&iStep=1";
					break;

				case "btnCancelCurrent" :
					$$('.moreInformationDetail').invoke('hide');
					bSpecial = 1;
					break;

				case "btnValidCurrent" :
					$$('.moreInformationDetail').invoke('hide');
					aInfos = oBtn.id.split("|");
					hParams = new $H($("frmMemberEvents" + aInfos[1] + "|" + aInfos[2] + "|" + aInfos[3]).serialize(true));
					hParams.set('iStep', "20");
					hParams.set('bSubmit', "1");
					oRequest = new Ajax.Request(sUrl, {method:'post',
												parameters: hParams,
												onComplete:function(xhr){
														var oResult = xhr.responseText.evalJSON();
															if(parseInt(oResult.bValid,10) === 1){
																$('iTotalPlace').update(parseInt(oResult.iTotalPlace, 10));
																if(oResult.iTotalPlace > 1){
																	$('sTextPlace').update(oResult.sTextPlace);
																}
																$('iTotalMemberShipCards').update(parseInt(oResult.iTotalMemberShipCard, 10));
																if(oResult.iTotalMemberShipCard > 1){
																	$('sTextMembersShipCard').update(oResult.sTextMemberShipCard);
																}

																$('fAmountCart').update(oResult.fAmountCart);
																$('fAmountCart').show();
																$('sCurrencyCart').show();
																if($('currenciesSelector')){
																	$('currenciesSelector').hide();
																}

																if(oResult.iTotalMemberShipCard > 0 || oResult.iTotalPlace > 0){
																	this.initBtnShopping("btnShoppingCart");
																}else{
																	this.hideBtnShopping("btnShoppingCart");
																}

																this.message("confirmation", oResult.sText, {iDuration:5});
															}else{
																this.message("error", oResult.sText);
															}
														}.bindAsEventListener(this)
					});

					bSpecial = 1;
					break;
			}

			if(parseInt(bSpecial,10) === 0){
				oRequest = new Ajax.Updater("contentUpdate", sUrl, {method:'post', postBody:sQuery, evalScripts:true});
			}
		},

		addBtn : function (sClass) {
			this.aButtons.push(sClass);
		},

		initAllBtn : function () {
			this.aButtons.push("printTicket");
			this.aButtons.push("logout");
			this.aButtons = this.aButtons.uniq();
			this.aButtons.each(
				function (sClass) {
					this.initBtn(sClass);
				}.bindAsEventListener(this)
			);
		},

		initBtn : function (sClass) {
			var aOptions = {};

			if(arguments.length > 1){
				aOptions = arguments[1] || {};
			}

			$$("." + sClass).each(
					function(oBtn){
						oBtn.stopObserving('click');
						oBtn.observe("click", function(){
							$("message").hide();
							this.initClick(oBtn, sClass, aOptions);
						}.bindAsEventListener(this));
					}.bind(this)
			);
		},

		hideBtn : function (sClassName){
			$$("." + sClassName).each(function(oBtn){oBtn.hide();});
		},

		initDatePerPage : function (sIdSelect) {
			$(sIdSelect).observe("change",
				function(){
					var sUrl = "shop.php";
					var sQuery = "iStep=1&iDatePerPage=" + parseInt($F(sIdSelect), 10);
					var oRequest = new Ajax.Updater("contentUpdate", sUrl, {method:'post', postBody:sQuery, evalScripts:true});
				}
			);
		},

		initDeleteDate : function (sClassName, sSubId, sContainer, bMiniCart) {
			$$("." + sClassName).each(
					function (oBtnDelete) {
						oBtnDelete.observe("click", function(){
							var sUrl = "shop.php";
							var sQuery = "bDeleteDate=1&iDateCode=" + parseInt(oBtnDelete.id.replace(sSubId,""),10);
							var oRequest = new Ajax.Request(sUrl, {method:'post',
																   postBody:sQuery,
																   onComplete:function(xhr){
																		var oResult = xhr.responseText.evalJSON();
																		if(parseInt(oResult.bValid,10) == 1){
																			$('iTotalPlace').update(parseInt(oResult.iTotalPlace, 10));
																			$('sTextPlace').update(oResult.sTextPlace);
																			if(oResult.iTotalPlace > 1){
																				$('fAmountCart').update(oResult.fAmountCart);
																				$('fAmountCart').show();
																				$('sCurrencyCart').show();
																				$('currenciesSelector').hide();
																				this.initBtnShopping("btnShoppingCart");
																			}else{
																				$('currenciesSelector').show();
																				this.hideBtnShopping("btnShoppingCart");
																				$('fAmountCart').update(oResult.fAmountCart);
																				$('fAmountCart').hide();
																				$('sCurrencyCart').hide();
																			}

																			//Check Step
																			var oRequestStep = new Ajax.Request(sUrl, {method:'post',
																													   postBody:'bCheckStep=1',
																													   onComplete:function(xhr){
																															var oResult = xhr.responseText.evalJSON();
																															if((bMiniCart == 1 && !($('frmRecherche')) && oResult.iCurrentDateCode == parseInt(oBtnDelete.id.replace(sSubId,""),10))){
																																var sQueryRefreshContent = "iStep=1&bSubmit=1&iDateCode=" + parseInt(oBtnDelete.id.replace(sSubId,""),10);
																																var oRequestRefreshContent = new Ajax.Updater("contentUpdate", sUrl, {method:'post',
																																																																	 postBody:sQueryRefreshContent,
																																																																	 evalScripts:true,
																																																																	 onSuccess:function(){
																																																																						var sQuery2 = "iStep=3&bMiniCart=" + bMiniCart;
																																																																						var oRequest2 = new Ajax.Updater(sContainer, sUrl, {method:'post',postBody:sQuery2, evalScripts:true});
																																}});
																															}else{
																																var sQuery2 = "iStep=3&bMiniCart=" + bMiniCart;
																																var oRequest2 = new Ajax.Updater(sContainer, sUrl, {method:'post',postBody:sQuery2, evalScripts:true});
																															}
																														}
																			});
																		}else{
																			this.message("error", oResult.sText);
																		}
																   }
							});
						}.bindAsEventListener(this));
					}
			);
		},

		initDeleteReservationDetail : function (sClassName, sContainer, iStep, bMiniCart) {
			$$("." + sClassName).each(
					function (oBtnDelete) {
						oBtnDelete.observe("click", function(){
							$('message').hide();
							var sUrl = "shop.php";
							var aInfos = oBtnDelete.id.split("|");
							var sQuery = "bDeleteReservationDetail=1&iReservationDetailCode=" + parseInt(aInfos[1],10);
							var oRequest = new Ajax.Request(sUrl, {method:'post',
																   postBody:sQuery,
																   onComplete:function(xhr){
																   	var oResult = xhr.responseText.evalJSON();

																   	if(parseInt(oResult.bValid,10) == 1){
																			$('iTotalPlace').update(parseInt(oResult.iTotalPlace, 10));
																			$('sTextPlace').update(oResult.sTextPlace);

																			$('iTotalPassCategories').update(parseInt(oResult.iTotalPassCategory, 10));
																			$('sTextPassCategory').update(oResult.sTextPassCategory);

																			if($("payCart|3")){
																				if(oResult.iTotalPassCategory > 0 || oResult.iTotalPlace > 0){
																					this.initBtnShopping("btnShoppingCart");
																					if(oResult.bAdmin){
																						if(parseInt(oResult.bAdmin, 10) == 0){
																							this.hideBtnLogAccount(oResult.bLogged);
																						}
																					}else{
																						this.hideBtnLogAccount(oResult.bLogged);
																					}
																				}else{
																					this.hideBtnShopping("btnShoppingCart");

																					if(oResult.bAdmin){
																						if(parseInt(oResult.bAdmin, 10) == 0){
																							this.initBtnLogAccount("showLogAccount", {bLogged : oResult.bLogged});
																						}
																					}else{
																						this.initBtnLogAccount("showLogAccount", {bLogged : oResult.bLogged});
																					}
																				}
																			}

																			if(oResult.iTotalPlace > 1){
																				$('fAmountCart').update(oResult.fAmountCart);
																				$('fAmountCart').show();
																				$('sCurrencyCart').show();
																				if($('currenciesSelector')){
																					$('currenciesSelector').hide();
																				}
																			}else{
																				if($('currenciesSelector')){
																					$('currenciesSelector').show();
																				}

																				if($("payCart|3")){
																					this.hideBtnShopping("btnShoppingCart");
																				}

																				if($('confirmCart')){
																					$('confirmCart').hide();
																				}
																				$('fAmountCart').update(oResult.fAmountCart);
																				$('fAmountCart').hide();
																				$('sCurrencyCart').hide();
																			}

																			var sQuery2 = "";
																			var oRequest2 = "";
																			if(parseInt(iStep,10) === 2){
																				sQuery2 = "iStep=" + parseInt(iStep,10) + "&bMiniCart=" + parseInt(bMiniCart,10);
																				oRequest2 = new Ajax.Updater(sContainer, sUrl, {method:'post',
																															    postBody:sQuery2,
																																evalScripts:true,
																																onComplete:function(){
																																	var sQuery3 = "iStep=3&bMiniCart=1";
																																	var oRequest3 = new Ajax.Updater("contentCart", sUrl, {method:'post',postBody:sQuery3, evalScripts:true});
																				}});
																			}else{
																				if(oResult.bRefresh){

																				}else{
																					sQuery2 = "iStep=" + parseInt(iStep,10) + "&bMiniCart=" + parseInt(bMiniCart,10);
																					oRequest2 = new Ajax.Updater(sContainer, sUrl, {method:'post', postBody:sQuery2, evalScripts:true});
																				}
																			}
																		}else{
																			this.message("error", oResult.sText);
																		}
																   }.bindAsEventListener(this)
							});
						}.bindAsEventListener(this));
					}.bindAsEventListener(this)
			);
		},

		initDeleteMembershipDetail : function (sClassName, sContainer, iStep, bMiniCart) {
			$$("." + sClassName).each(
					function (oBtnDelete) {
						oBtnDelete.observe("click", function(){
							$('message').hide();
							var sUrl = "shop.php";
							var aInfos = oBtnDelete.id.split("|");
							var sQuery = "bDeleteReservationDetail=1&iReservationDetailCode=" + parseInt(aInfos[1],10);
							var oRequest = new Ajax.Request(sUrl, {method:'post',
																   postBody:sQuery,
																   onComplete:function(xhr){
																		var oResult = xhr.responseText.evalJSON();
																		if(parseInt(oResult.bValid,10) == 1){
																			$('iTotalPlace').update(parseInt(oResult.iTotalPlace, 10));
																			$('sTextPlace').update(oResult.sTextPlace);

																			$('iTotalMemberShipCards').update(parseInt(oResult.iTotalMemberShipCard, 10));
																			$('sTextMemberShipCard').update(oResult.sTextMemberShipCard);
																			if($("payCart|3") && $("btnShoppingCart")){
																				if(oResult.iTotalMemberShipCard > 0 || oResult.iTotalPlace > 0){
																					this.initBtnShopping("btnShoppingCart");
																				}else{
																					this.hideBtnShopping("btnShoppingCart");
																				}
																			}

																			if(oResult.iTotalPlace > 1){
																				$('fAmountCart').update(oResult.fAmountCart);
																				$('fAmountCart').show();
																				$('sCurrencyCart').show();
																				if($('currenciesSelector')){
																					$('currenciesSelector').hide();
																				}
																			}else{
																				if($('currenciesSelector')){
																					$('currenciesSelector').show();
																				}

																				if($("payCart|3")){
																					this.hideBtnShopping("btnShoppingCart");
																				}

																				if($('confirmCart')){
																					$('confirmCart').hide();
																				}
																				$('fAmountCart').update(oResult.fAmountCart);
																				$('fAmountCart').hide();
																				$('sCurrencyCart').hide();
																			}

																			var sQuery2 = "";
																			var oRequest2 = "";

																			if(parseInt(iStep,10) === 2){
																				sQuery2 = "iStep=" + parseInt(iStep,10) + "&bMiniCart=" + parseInt(bMiniCart,10);
																				oRequest2 = new Ajax.Updater(sContainer, sUrl, {method:'post',
																															    postBody:sQuery2,
																																evalScripts:true,
																																onComplete:function(){
																																	var sQuery3 = "iStep=3&bMiniCart=1";
																																	var oRequest3 = new Ajax.Updater("contentCart", sUrl, {method:'post',postBody:sQuery3, evalScripts:true});
																				}});
																			}else{
																				if(oResult.bRefresh){

																				}else{
																					sQuery2 = "iStep=" + parseInt(iStep,10) + "&bMiniCart=" + parseInt(bMiniCart,10);
																					oRequest2 = new Ajax.Updater(sContainer, sUrl, {method:'post', postBody:sQuery2, evalScripts:true});
																				}
																			}
																		}else{
																			this.message("error", oResult.sText);
																		}
																   }.bindAsEventListener(this)
							});
						}.bindAsEventListener(this));
					}
			);
		},

		initCart : function (){
			$('iTotalPlace').update(0);
			$('currenciesSelector').show();
			$('fAmountCart').update(0);
			$('fAmountCart').hide();
			$('sCurrencyCart').hide();
		},

		recalcTotal : function (sCur){
			$('memberTotal|'+sCur).innerHTML = $('iNumber'+sCur).value*$('iPrice|'+sCur).innerHTML;
		},

		initOnePerDay : function () {
			var aElements = new Array();
			$$('.line').each(
				function (oElement) {
					$$("#"+oElement.id+" > td.numbers select").each(
						function (oSelect) {
							if(oSelect.value > 0){
								var aClassnames = oElement.classNames();
								aClassnames.each(
									function (sClassname){
										if(sClassname != "line" && sClassname != "linePair" && sClassname != "disabled"){
											aElements.push(sClassname);
										}
									}
								);
							}
						}
					);
				}
			);

			aElements.each(
				function (sClassname) {
					$$('.'+sClassname).each(
						function (oElement){
							$$('#'+oElement.id+' > td.numbers select').each(
								function (oSelect){
									if(oSelect.value == 0){
										oElement.addClassName("disabled");
										oSelect.hide();
									}
								}
							);
						}
					);
				}
			);
		},

		validOnePerDay : function (iValue, sDate, iDateCode, iTariffZoneCode) {
			$$(".onePerDay" + sDate).each(
				function (oDate) {
					if(parseInt(iValue,10) > 0){
						$$("#"+oDate.id+" > td.numbers select").each(
							function (oSelect) {
								var aInfos = oSelect.id.split("|");
								if("Date"+iDateCode != oDate.id || aInfos[2] != iTariffZoneCode){
									oDate.addClassName("disabled");
									oSelect.hide();
								}
							}
						);
					}else{
						oDate.removeClassName("disabled");
						$$("#"+oDate.id+" > td.numbers select").each(
							function (oSelect) {
								oSelect.show();
							}
						);
					}
				}
			);
		},

		checkAvailablePlace : function (sClassName, iTotalMaxPlace){
			var iTotalPlace = 0;
			var aFields = $$("." + sClassName);
			aFields.each(
					function (oElement){
						iTotalPlace += parseInt($F(oElement),10);
					}
			);
			var iDifference = iTotalMaxPlace - iTotalPlace;
			aFields.each(
					function (oElement){
						var aInfos = oElement.id.split("|");
						var iPlace = parseInt($F(oElement),10);
						oElement.update("");

						if(iDifference > 0 && iPlace <= iTotalMaxPlace){
							for(var i = 0; i <= (iPlace+iDifference); i++){
								if(i <= aInfos[4]){
									oElement[i] = new Option(i, i);
								}
							}
						}else{
							for(var j = 0; j < (iPlace+1); j++){
								oElement[j] = new Option(j, j);
							}
						}

						oElement.options.selectedIndex = iPlace;
					}
			);
		},

		addToMC : function (oElement,event){
			Event.stop(event);
			var sUrl = "shop.php";
			hParams = new $H();
			hParams.set(oElement.id, $F(oElement));
			hParams.set('iStep', "2");
			hParams.set('bSubmit', "1");
			oRequest = new Ajax.Request(sUrl, {
				method:'post',
				parameters: hParams,
				onComplete:function(xhr){//echo(xhr.responseText);
					var oResult = xhr.responseText.evalJSON();
					if(parseInt(oResult.bValid,10) === 1){
//						echo('<div style="color:green;font-weight:bold;">SUPER CA MARCHE !!!!<div>');
						$('iTotalPlace').update(parseInt(oResult.iTotalPlace, 10));
						if(oResult.iTotalPlace > 1){
							$('sTextPlace').update(oResult.sTextPlace);
						}
						$('iTotalMemberShipCards').update(parseInt(oResult.iTotalMemberShipCard, 10));
						if(oResult.iTotalMemberShipCard > 1){
							$('sTextMembersShipCard').update(oResult.sTextMemberShipCard);
						}

						$('fAmountCart').update(oResult.fAmountCart);
						$('fAmountCart').show();
						$('sCurrencyCart').show();
						if($('currenciesSelector')){
							$('currenciesSelector').hide();
						}

						if(oResult.iTotalMemberShipCard > 0 || oResult.iTotalPlace > 0){
							this.initBtnShopping("btnShoppingCart");
						}else{
							this.hideBtnShopping("btnShoppingCart");
						}
						var sQuery2 = "iStep=3&bMiniCart=1";
						var oRequest2 = new Ajax.Updater("contentCart", sUrl, {method:'post',postBody:sQuery2, evalScripts:true,onSuccess:function(){this.message("confirmation", oResult.sText, {iDuration:5});}.bindAsEventListener(this)});

						//this.message("confirmation", oResult.sText, {iDuration:5});
					}else{
						this.message("error", oResult.sText);
					}
				}.bindAsEventListener(this)
			});
		},

		addToCart : function (oElement) {
			var aInfos = oElement.id.split("|");
			var sUrl = "shop.php";
			var oRequest = "";

			var sQuery = "bSubmit=1&iStep=2&iPlace=" + parseInt($F(oElement.id),10);
			sQuery += "&iDateCode=" + parseInt(aInfos[1], 10);
			sQuery += "&iLocationCode=" + parseInt(aInfos[2], 10);
			sQuery += "&iCategoryCode=" + parseInt(aInfos[3], 10);
			oRequest = new Ajax.Request(sUrl, {method:'post',
											   postBody:sQuery,
											   onComplete:function(xhr){
												   	var oResult = xhr.responseText.evalJSON();
												   	if(parseInt(oResult.bValid,10) == 1){
												   		$('iTotalPlace').update(parseInt(oResult.iTotalPlace, 10));
														if(oResult.iTotalPlace > 1){
															$('sTextPlace').update(oResult.sTextPlace);
														}

														if($('iTotalPassCategories')){
															$('iTotalPassCategories').update(parseInt(oResult.iTotalPassCategory, 10));
															if(oResult.iTotalPassCategory > 1){
																$('sTextPassCategory').update(oResult.sTextPassCategory);
															}
														}

														$('fAmountCart').update(oResult.fAmountCart);
														$('fAmountCart').show();
														$('sCurrencyCart').show();
														if($('currenciesSelector')){
															$('currenciesSelector').hide();
														}

														if(oResult.iTotalPassCategory > 0 || oResult.iTotalPlace > 0){
															this.initBtnShopping("btnShoppingCart");
															if(oResult.bAdmin){
																if(parseInt(oResult.bAdmin, 10) == 0){
																	this.hideBtnLogAccount(oResult.bLogged);
																}
															}else{
																this.hideBtnLogAccount(oResult.bLogged);
															}
														}else{
															this.hideBtnShopping("btnShoppingCart");
															if(oResult.bAdmin){
																if(parseInt(oResult.bAdmin, 10) == 0){
																	this.initBtnLogAccount("showLogAccount", {bLogged : oResult.bLogged});
																}
															}else{
																this.initBtnLogAccount("showLogAccount", {bLogged : oResult.bLogged});
															}
															this.initBtnLogAccount("showLogAccount", {bLogged : oResult.bLogged});
														}

														this.message("confirmation", oResult.sText, {iDuration:5});
														$('contentCart').hide();
													}else{
														this.message("error", oResult.sText);
													}
											   }.bindAsEventListener(this)
			});
		},

		addDateToCart : function (oSelect) {
			var sUrl = "shop.php";
			var sQuery = "bSubmit=1&iStep=7&" + oSelect.id + "=" + oSelect.value;
			oRequest = new Ajax.Request(sUrl, {method:'post',
														   postBody:sQuery,
														   onComplete:function(xhr){
																var oResult = xhr.responseText.evalJSON();
																if(parseInt(oResult.bValid,10) == 1){
																	$('iTotalPlace').update(parseInt(oResult.iTotalPlace, 10));
																	if(oResult.iTotalPlace > 1){
																		$('sTextPlace').update(oResult.sTextPlace);
																	}

																	if($('iTotalPassCategories')){
																		$('iTotalPassCategories').update(parseInt(oResult.iTotalPassCategory, 10));
																		if(oResult.iTotalPassCategory > 1){
																			$('sTextPassCategory').update(oResult.sTextPassCategory);
																		}
																	}

																	$('fAmountCart').update(oResult.fAmountCart);
																	$('fAmountCart').show();
																	$('sCurrencyCart').show();
																	$('currenciesSelector').hide();

																	if(oResult.iTotalPassCategory > 0 || oResult.iTotalPlace > 0){
																		this.initBtnShopping("btnShoppingCart");
																		this.hideBtnLogAccount("showLogAccount", {bLogged : oResult.bLogged});
																	}else{
																		this.hideBtnShopping("btnShoppingCart");
																		this.initBtnLogAccount("showLogAccount", {bLogged : oResult.bLogged});
																	}

																	var sQuery2 = "iStep=3&bMiniCart=1";
																	var oRequest2 = new Ajax.Updater("contentCart", sUrl, {method:'post',postBody:sQuery2, evalScripts:true,onSuccess:function(){this.message("confirmation", oResult.sText, {iDuration:1});}.bindAsEventListener(this)});
																}else{
																	this.message("error", oResult.sText);
																}
														   }.bindAsEventListener(this)
			});
		},

		addMemberCardDateToCart : function (oSelect) {
			var sUrl = "shop.php";
			var sQuery = "bSubmit=1&iStep=7&" + oSelect.id + "=" + oSelect.value;
			oRequest = new Ajax.Request(sUrl, {method:'post',
											   postBody:sQuery,
											   onComplete:function(xhr){
													var oResult = xhr.responseText.evalJSON();
													if(parseInt(oResult.bValid,10) == 1){
														$('iTotalPlace').update(parseInt(oResult.iTotalPlace, 10));
														if(oResult.iTotalPlace > 1){
															$('sTextPlace').update(oResult.sTextPlace);
														}
														$('iTotalMemberShipCards').update(parseInt(oResult.iTotalMemberShipCard, 10));
														if(oResult.iTotalMemberShipCard > 1){
															$('sTextMemberShipCard').update(oResult.sTextMemberShipCard);
														}

														$('fAmountCart').update(oResult.fAmountCart);
														$('fAmountCart').show();
														$('sCurrencyCart').show();
														$('currenciesSelector').hide();

														if(oResult.iTotalMemberShipCard > 0 || oResult.iTotalPlace > 0){
															this.initBtnShopping("btnShoppingCart");
														}else{
															this.hideBtnShopping("btnShoppingCart");
														}

														var sQuery2 = "iStep=3&bMiniCart=1";
														var oRequest2 = new Ajax.Updater("contentCart", sUrl, {method:'post',postBody:sQuery2, evalScripts:true,onSuccess:function(){this.message("confirmation", oResult.sText, {iDuration:1});}.bindAsEventListener(this)});
													}else{
														this.message("error", oResult.sText);
													}
											   }.bindAsEventListener(this)
			});
		},

		initSeatSelect : function (oSeat) {
			oSeat.observe('click',
				function () {
					if(oSeat.hasClassName('movingSeat')){
						oSeat.removeClassName('movingSeat');
					}else{
						$$('.movingSeat').each(
							function(oSeatMoving){
								oSeatMoving.removeClassName('movingSeat');
							}
						);
						oSeat.addClassName('movingSeat');
					}
				}.bindAsEventListener(oSeat)
			);
		},

		disableSeatSelect : function (oSeat) {
			oSeat.removeClassName('movingSeat');
			oSeat.removeClassName('selectSeat');
			oSeat.removeClassName('SeatBooked');
			oSeat.removeClassName('SeatReserved');
			oSeat.stopObserving('click');
		},

		initSeatSingle : function (oSeat) {
			oSeat.observe('mouseover', function(){
				oSeat.addClassName('seatHover');
			}.bindAsEventListener(oSeat));

			oSeat.observe('mouseout', function(){
				oSeat.removeClassName('seatHover');
			}.bindAsEventListener(oSeat));

			oSeat.observe('click',
				function() {
					$('messageSeats').hide();
					var oMovingSeat = $$('.movingSeat');
					var iSelectSeatToMove = oMovingSeat.length;

					if(parseInt(iSelectSeatToMove,10) === 1){
						var aInfosNew = oSeat.id.split("|");
						var aInfosOld = oMovingSeat[0].id.split("|");
						var sQuery = "iStep=10&bSubmit=1&iSeatCode=" + aInfosNew[1] + "&iTicketCode=" + aInfosOld[2] + "&sClassName=" + oSeat.classNames();
						var oRequest = new Ajax.Request("shop.php", {method:'post',
																	 postBody:sQuery,
																     onComplete:function(xhr){
																     	var oResult = xhr.responseText.evalJSON();
																     	if(parseInt(oResult.bValid, 10) === 1){
																     		if(aInfosNew[2] === ""){
																     			oSeat.id = oSeat.id + aInfosOld[2];
																     		}
																     		this.disableSeatSelect(oMovingSeat[0]);
																			this.initSeatSingle(oMovingSeat[0]);
																			oSeat.stopObserving('click');
																			oSeat.addClassName('selectSeat');
																			oSeat.removeClassName('SeatReserved');
																			oSeat.addClassName('SeatBooked');
																			this.initSeatSelect(oSeat);
																     	}else{
																     		this.message("error", oResult.sText, {sDiv:'messageSeats'});
																     	}
																     }.bindAsEventListener(this)
						});
					}
				}.bindAsEventListener(this)
			);
		},

		initSeats : function() {
			$$(".Seat").each(
				function (oSeat) {
					if (!oSeat.hasClassName('SeatBooked') && oSeat.id !== '' && !oSeat.hasClassName('noClick')) {
						this.initSeatSingle(oSeat);
					}

					if(oSeat.hasClassName('selectSeat')){
						this.initSeatSelect(oSeat);
					}
				}.bindAsEventListener(this)
			);
		},

		selectPersonalisationTicket : function (iTicketCode, sValue){
			var bTrouver = 0;
			for (var i = 0; i < $('sLabelType'+iTicketCode).options.length; i++){
				if($('sLabelType'+iTicketCode).options[i].value == sValue){
					$('sLabelType'+iTicketCode).selectedIndex = i;
					bTrouver = 1;
				}
			}

			if(bTrouver === 0 && sValue !== ""){
				$('sLabelType'+iTicketCode).selectedIndex = $('sLabelType'+iTicketCode).options.length-1;
				$('ligneSupplementaire'+iTicketCode).show();
				$('sLabel'+iTicketCode).value = sValue;
			}
		},

		displayLineLabel : function (iValue,iTicketCode){
			if(iValue == 1){
				if($('ligneSupplementaire'+iTicketCode).style.display == "none"){
					$('ligneSupplementaire'+iTicketCode).show();
					$('sLabel'+iTicketCode).focus();
				}
			}else{
				$('ligneSupplementaire'+iTicketCode).hide();
			}
		},

		fillInRows : function(){
			bHasLoaded = true;
			this.addRowToTable();
		},

		myRowObject : function(one, two, three, five){
			this.one = one;
			this.two = two;
			this.three = three;
			this.five = five;
		},

		myRowObject2 : function(four){
			this.four = four;
		},

		//variable static pour compter le nombre rows au dŽbut
		totalRow : function(){
			 if ( typeof this.count == 'undefined' ) this.count = 0;
			 this.count++;
			 return this.count;
		},

		/*
		 * addRowToTable
 		 * Ajoute à la ligne 'num', ou à la fin si pas d'argument passé en parametre.
 		*/
		addRowToTable : function (iNum){
			if (bHasLoaded) {
				var oTable = $('newMembersTable');
				var iNextRow = oTable.tBodies[0].rows.length;
				var iTotal = this.totalRow()-1;

				if (iTotal != iNextRow){
					if (iNum == null){
						iNum = iTotal;
					}
				}else{
					if(iNum == null){
						iNum = iNextRow;
					}
				}
				iNum++;

				this.aMembershipCards.push(iNum);

				var oRow = oTable.tBodies[0].insertRow(-1);
				var oCell = oRow.insertCell(0);
				oCell.setAttribute('id', 'cell' + (iNum));
				oCell.setAttribute('style', 'padding:5px;');
				oCell.colSpan = 4;

				var sQuery = "iStep=21&bLayoutFull=0&current=" + iNum +"&iCategoryMembershipCard="+$('iCategoryMembershipCard').value;
				oRequest = new Ajax.Updater(oCell.id, "shop.php", {method:'post',
																   postBody : sQuery,
																   evalScripts : true,
																   onComplete:function(){
																   		$('formMembers').object.initFields();
																   }.bindAsEventListener(this)
				});

				var oTxtNom = document.createElement('input');
				oTxtNom.setAttribute('type', 'text');
				oTxtNom.setAttribute('name', 'inputLastName' + iNum);
				oTxtNom.setAttribute('size', '15');
				oTxtNom.setAttribute('value', '');

				oRow.myRow = new this.myRowObject2(oTxtNom);
			}
		},

		deleteCurrentRow : function(oObj){
			var oDelRow = oObj.parentNode.parentNode.parentNode;
			var table = oDelRow.parentNode.parentNode;
			var iIndex = oDelRow.sectionRowIndex;
			this.aMembershipCards.splice(iIndex,1);
			var aRowArray = new Array(oDelRow);
			this.deleteRows(aRowArray);
		},

		reorderRows : function(tbl, startingIndex){
			if (tbl.tBodies[0].rows[startingIndex]) {
				var count = startingIndex + 1;
				for (var i=startingIndex; i<tbl.tBodies[0].rows.length; i++) {
					count++;
				}
			}
		},


		deleteRows : function(aRowObjArray){
			for (var i=0; i<aRowObjArray.length; i++) {
				var iIndex = aRowObjArray[i].sectionRowIndex;
				aRowObjArray[i].parentNode.deleteRow(iIndex);
			}
		},

		createPopup : function(sId) {
			oObject = new adminOverlay(sId, {
				showWaitingPopup: true,
				onHide: function(){
					if( $('overlay_bottom_content_'+sId) ){
						$('overlay_bottom_content_'+sId).hide();
					}
				},
				divAppend:"contentUpdate"
			});

			$(sId).object = oObject;
		},

		showPopup : function (sId) {
			$(sId).object.show();
		},

		autoValidDateForMembercards : function (iDateCode, iLocationCode, iCategoryCode, iMembershipCode, iQuantity) {
			$("message").hide();
			var sQuery = "bSubmit=1&iStep=20&bDetailDate=1&iNumber|"+parseInt(iDateCode,10)+"|"+parseInt(iLocationCode,10)+"|"+parseInt(iCategoryCode,10)+"|"+parseInt(iMembershipCode,10)+"="+parseInt(iQuantity, 10);
			var oRequest = new Ajax.Request("shop.php", {method:'post',
																	   postBody:sQuery,
																	   onComplete:function(xhr){
																				var oResult = xhr.responseText.evalJSON();
																				if(parseInt(oResult.bValid,10) === 1){
																					$('iTotalPlace').update(parseInt(oResult.iTotalPlace, 10));

																					if(oResult.iTotalPlace > 1){
																						$('sTextPlace').update(oResult.sTextPlace);
																					}

																					$('iTotalMemberShipCards').update(parseInt(oResult.iTotalMemberShipCard, 10));

																					if(oResult.iTotalMemberShipCard > 1){
																						$('sTextMembersShipCard').update(oResult.sTextMemberShipCard);
																					}

																					$('fAmountCart').update(oResult.fAmountCart);
																					$('fAmountCart').show();
																					$('sCurrencyCart').show();
																					if($('currenciesSelector')){
																						$('currenciesSelector').hide();
																					}

																					if(oResult.iTotalMemberShipCard > 0 || oResult.iTotalPlace > 0){
																						this.initBtnShopping("btnShoppingCart");
																					}else{
																						this.hideBtnShopping("btnShoppingCart");
																					}

																					var oRequest2 = new Ajax.Updater("contentUpdate", "shop.php", {method:'post', postBody:"bSubmit=1&iDateCode="+iDateCode+"&iStep=1", evalScripts:true});
																					this.message("confirmation", oResult.sText, {iDuration:5});
																				}else{
																					this.message("error", oResult.sText);
																				}
																			}.bindAsEventListener(this)});
		},

		selectOnglet : function (onglet){
			if($("message")){
				$("message").hide();
			}
			if($$('td.Selected')){
				$$('td.Selected').each(function (oElement){oElement.removeClassName('Selected');});
			}
			onglet.addClassName('Selected');
			if(onglet.id != "return"){
				$('contentUpdate').hide();
				$('contentCommand').hide();
				$$('div.moreBlock').each(function(oBlock){oBlock.hide();});
				var aInfos = onglet.id.split("|");
				this.getPage(aInfos[1]);
				$('return').innerHTML='Retour sur l\'evennement';
			}else{
				$$('tr.moreInformationMerge').each(function(oBtn){
					oBtn.stopObserving('click');
				});
				this.initShowInformation("moreInformationMerge", "Group");
				this.initLink("moreInformationMergeDetailCategories", "Group");
				$('contentUpdate').show();
				$('contentCommand').show();
				$$('div.moreBlock').each(function(oBlock){oBlock.show();});
				$('customer').hide();
				$('return').innerHTML='Evennement';
			}
		},

		getPage : function (iStep){
			var sUrl = "shop.php";
			var sQuery = "iStep="+iStep;
			var oRefresh = new Ajax.Updater("customer", sUrl, {method:'post',
															 postBody:sQuery,
															 evalScripts:true,
															 onComplete:function(){
																$('customer').show();
															 }
			});
		},

		initNavBar : function (){
			$$('td.NavBarItem').each(function(oBtn){
				oBtn.stopObserving('click');
				oBtn.observe("click", function(){
					this.selectOnglet(oBtn);
				}.bindAsEventListener(this));

				oBtn.stopObserving('mouseover');
				oBtn.observe("mouseover", function(){
					oBtn.addClassName("NavBarItemHover");
				}.bindAsEventListener(this));

				oBtn.stopObserving('mouseout');
				oBtn.observe("mouseout", function(){
					oBtn.removeClassName("NavBarItemHover");
				}.bindAsEventListener(this));
			}.bind(this));
		},

		switchLine : function (iReservationCode){
			if($('detailResa|'+iReservationCode) && $('detailResa|'+iReservationCode).style.display == "none"){
				$$('tr.moreInformationMergeDetail').each(function(oElement){oElement.hide();});
				$('detailResa|'+iReservationCode).show();
			}else{
				$('detailResa|'+iReservationCode).hide();
			}
		},

		initReservationTable : function(iStep){
			$$('input.moreInformation').each(function(oBtn){
				oBtn.stopObserving('click');
				oBtn.observe("click", function(){
					var aInfos = oBtn.id.split("|");
					var iReservationCode = aInfos[1];
					var oRequest = new Ajax.Updater("detailResa|"+iReservationCode, "shop.php", {method:'post', postBody:"bSubmit=1&iReservationCode="+iReservationCode+"&iStep="+iStep, evalScripts:true});
					this.switchLine(iReservationCode);
				}.bindAsEventListener(this));
			}.bind(this));

			$$('input.Facture').each(function(oBtn){
				oBtn.stopObserving('click');
				oBtn.observe("click", function(){
					
					var aInfos = oBtn.id.split("|");
					var iReservationCode = aInfos[1];
					var iReservationCodeSHA = this.SHA1(aInfos[1]);
					var sCode = "";
					var iJ = 0;
					
					for (var iI=0; iI<iReservationCodeSHA.length; iI++) {
						if (iI>0 && iI%2 == 0 && iJ<iReservationCode.length){
							sCode += iReservationCode[iJ];
							iJ++;
						}
							sCode += iReservationCodeSHA.charAt(iI);
					}
					var sUrl = "shop.php?iStep=30&backup=1&sCode="+encodeURIComponent(sCode);
					window.open(sUrl, "Facture");
				}.bindAsEventListener(this));
			}.bind(this));
			if(iStep == 24){
				$('return').removeClassName("Selected");
			}
		},

		initReservationTableDetails : function(){
			$$('input.PrintTicket').each(function(oBtn){
				oBtn.stopObserving('click');
				oBtn.observe("click", function(){
					var aInfos = oBtn.id.split("|");
					var iReservationCode = aInfos[2];
					var iReservationCodeSHA = this.SHA1(iReservationCode);
					var sReservationCode = "";
					var iJ = 0;
					
					for (var iI=0; iI<iReservationCodeSHA.length; iI++) {
						if (iI>0 && iI%2 == 0 && iJ<iReservationCode.length){
							sReservationCode += iReservationCode.charAt(iJ);
							iJ++;
						}
							sReservationCode += iReservationCodeSHA.charAt(iI);
					}
					var iTicketCode = aInfos[1];
					var iTicketCodeSHA = this.SHA1(aInfos[1]);
					var sTicketCode = "";
					var iJ = 0;
					
					for (var iI=0; iI<iTicketCodeSHA.length; iI++) {
						if (iI>0 && iI%2 == 0 && iJ<iTicketCode.length){
							sTicketCode += iTicketCode.charAt(iJ);
							iJ++;
						}
						sTicketCode += iTicketCodeSHA.charAt(iI);
					}
					
					var sUrl = "shop.php?iStep=28&backup=1&submited=1&nbTemplate=0&bEncrypt=1&sCode1="+encodeURIComponent(sReservationCode)+"&sCode2=" + encodeURIComponent(sTicketCode);
					window.open(sUrl, "Ticket");
				}.bindAsEventListener(this));
			}.bind(this));

			$$('input.CheckAll').each(function(oBtn){
				oBtn.stopObserving('click');
				oBtn.observe("click", function(){
					var aInfos = oBtn.id.split("|");
					var iReservationCode = aInfos[1];
					var sBtnClass = 'input.'+iReservationCode;
					if(oBtn.checked){
						$$(sBtnClass).each(function(oBtn){oBtn.checked = true;});
					}else{
						$$(sBtnClass).each(function(oBtn){oBtn.checked = false;});
					}
				}.bindAsEventListener(this));
			}.bind(this));

			$$('input.PrintTickets').each(function(oBtn){
				oBtn.stopObserving('click');
				oBtn.observe("click", function(){
					var aInfos = oBtn.id.split("|");
					var iReservationCode = aInfos[1];
					var sBtnClass = 'input.'+iReservationCode;
					var iJ = 0;
					var sReservationCode = "";
					var iReservationCodeSHA = oTools.SHA1(iReservationCode);
					for (var iI=0; iI<iReservationCodeSHA.length; iI++) {
						if (iI>0 && iI%2 == 0 && iJ<iReservationCode.length){
							sReservationCode += iReservationCode.charAt(iJ);
							iJ++;
						}
							sReservationCode += iReservationCodeSHA.charAt(iI);
					}
					var aTicketsCode = "";
					var sTicketCode = "";
					nbTemplate = 0;
					$$('input[name='+iReservationCode+']').each(function(oElement){
						if(oElement.checked){
							var iTicketCode = oElement.id;
							var iTicketCodeSHA = oTools.SHA1(aInfos[1]);
							var sTicketCode = "";
							var iJ = 0;
							
							for (var iI=0; iI<20; iI++) {
								if (iI>0 && iI%2 == 0 && iJ<iTicketCode.length){
									sTicketCode += iTicketCode.charAt(iJ);
									iJ++;
								}
								sTicketCode += iTicketCodeSHA.charAt(iI);
							}
							//aTicketsCode += "&aTicketCode[]=" + encodeURIComponent(oElement.id);
							aTicketsCode += "&sCode2[]=" + encodeURIComponent(sTicketCode);
						}
					});
					//var sUrl = "shop.php?iStep=28&backup=1&submited=1&nbTemplate=0&iReservationCode=" + parseInt(iReservationCode, 10) + aTicketsCode;
					var sUrl = "shop.php?iStep=28&backup=1&submited=1&bEncrypt=1&nbTemplate=0&sCode1=" + encodeURIComponent(sReservationCode) + aTicketsCode;
					window.open(sUrl, "Tickets");
				});
			}.bindAsEventListener(this));

			$$('select.PersonalizeTickets').each(function(oSelect){
				oSelect.stopObserving('change');
				oSelect.observe('change', function(){
					new Ajax.Request('shop.php', {
						method:'post',
						postBody:'iStep=18&bSubmit=1&sLabelTypeAll=0&sLabelType'+encodeURIComponent(oSelect.name)+'='+encodeURIComponent(oSelect.value),
						evalScripts: true,
						onSuccess: function (xhr) {
							var oResult = xhr.responseText.evalJSON();
							if(parseInt(oResult.bValid, 10) === 1){
					     		this.message("confirmation",oResult.sText,{iDuration:3});
					     	}else{
					     		this.message("error",oResult.sText,{iDuration:3});
					     	}
						}.bindAsEventListener(this)
					});

				}.bind(this));
			}.bindAsEventListener(this));
		},

		initFormProfile : function(){
			$('modifyAccount').stopObserving('click');
			$('modifyAccount').observe("click", function(){
				if($F('sCustomerEmail') == $F('sCustomerEmailConfirm') && $F('sCustomerPassword') == $F('sCustomerPasswordConfirm')){
					var aParameters = {
						iStep : 26,
						sEmail : $F("sCustomerEmail"),
						sLastname : $F("sCustomerLastname"),
						sFirstname : $F("sCustomerFirstname"),
						sPassword : $F("sCustomerPassword"),
						sCellularPhone : $F("sCustomerPhone"),
						sAddress : $F("sCustomerAddress"),
						sZipCode : $F("sCustomerZipCode"),
						sCity : $F("sCustomerCity"),
						sCustomerCountry : $F("sCustomerCountry"),
						modifyCustomer : 1,
						backup : 1,
						bSubmit : 1,
						bNewsletter : $('bCustomerNewsletter').checked?1:0
					};

					var oRequest = new Ajax.Request("shop.php", {method:'post',
						 parameters:aParameters,
					     onComplete:function(xhr){
					     	var oResult = xhr.responseText.evalJSON();
					     	if(parseInt(oResult.bValid, 10) === 1){
					     		this.message("confirmation",oResult.sText,{iDuration:3});
					     	}else{
					     		this.message("error",oResult.sText,{iDuration:3});
					     	}
					     }.bindAsEventListener(this)
					});
				}else{
					this.message("error",'champs differents',{iDuration:3});
				}

			}.bind(this));
		},

		initMembercards : function(){

			$$('input.CheckAll').each(function(oBtn){
				oBtn.stopObserving('click');
				oBtn.observe("click", function(){
					var aInfos = oBtn.id.split("|");
					var iCode = aInfos[1];
					var sBtnClass = 'input.'+iCode;
					if(oBtn.checked){
						$$(sBtnClass).each(function(oBtn){oBtn.checked = true;});
					}else{
						$$(sBtnClass).each(function(oBtn){oBtn.checked = false;});
					}
				}.bindAsEventListener(this));
			}.bind(this));
		},

		editStepMembershipCard : function (iMembershipCardCode, iMode){
			var sUrl = "shop.php";
			var sQuery = "backup=1&iStep=16";

			switch(iMode) {
			case 0 :
				//Page d edition d une carte
				sQuery += "&iMode=1&iMembershipCardCode="+iMembershipCardCode;
				var oRequest = new Ajax.Updater("customer", sUrl, {method:'post', postBody:sQuery, evalScripts:true, onComplete:function(){
					//On recharge l'image a chaque fois qu'on charge le template
					var src = $('imgShowMembershipCard').src;
					var img = src+'?'+new Date()*Math.random();
					$('imgContenu').innerHTML = "<img id='imgShowMembershipCard' src='"+img+"' border='0' />";
				}});
				break;
			case 1 :
				//Chargement de la partie Upload
				sQuery += "&iMode=2";
				var oRequest = new Ajax.Updater("customer", sUrl, {method:'post', postBody:sQuery, evalScripts:true});
				break;
			case 2 :
				//Charge la partie webcam photo
				sQuery += "&iMode=3";
				var oRequest = new Ajax.Updater("customer", sUrl, {method:'post', postBody:sQuery, evalScripts:true});
				break;
			case 3 :
				//Page de visualisation d une carte
				sQuery += "&iMode=1&iMembershipCardCode="+iMembershipCardCode+"&bEditable=false";
				var oRequest = new Ajax.Updater("customer", sUrl, {method:'post', postBody:sQuery, evalScripts:true, onComplete:function(){
					//On recharge l'image a chaque fois qu'on charge le template
					var src = $('imgShowMembershipCard').src;
					var img = src+'?'+new Date()*Math.random();
					$('imgContenu').innerHTML = "<img id='imgShowMembershipCard' src='"+img+"' border='0' />";
				}});
				break;
			default :
				sQuery += "&iMode=0";
				var oRequest = new Ajax.Updater("customer", sUrl, {method:'post', postBody:sQuery, evalScripts:true});
			break;
			}
		},

		initPopup : function(oButton){
			Prototype.require("jojoPopup.js");
			oPopup = new Popup('ticketsToSend', {fadeBackground:true, alpha: 80, fadeBackgroundOption:{backgroundColor: '#000',alpha: 80}, setwidth:'220px'});
			var aTicketCode = "";
			var aInfos = oButton.id.split("|");
			if(aInfos[0] == "send"){
				var iTicketCode = aInfos[1];
				if($('senderTicketCode')){
					$('senderTicketCode').replace('<input id="senderTicketCode" type="hidden" name="senderTickets" value="'+iTicketCode+'"/>');
				}else{
					$('frmSendTickets').insert('<input id="senderTicketCode" type="hidden" name="senderTickets" value="'+iTicketCode+'"/>');
				}
			}else{
				var first = true;
				$$('input[name='+aInfos[1]+']').each(function(oElement){
					if(oElement.checked){
						if(first==false){
							aTicketCode += "|" + encodeURIComponent(oElement.id);
						}else{
							aTicketCode += encodeURIComponent(oElement.id);
							first = false;
						}
					}
				});

				if($('senderTicketCode')){
					$('senderTicketCode').replace('<input id="senderTicketCode" type="hidden" name="senderTickets" value="'+aTicketCode+'"/>');
				}else{
					$('frmSendTickets').insert('<input id="senderTicketCode" type="hidden" name="senderTickets" value="'+aTicketCode+'"/>');
				}
			}
			oPopup.show();
			$('frmSendTickets').reset();
		},

		managePopup : function(oButton){
			if(oButton.id == "hideTicketsToSend|ticketsToSend"){
				oPopup.hide();
			}else if(oButton.id == "sendSendTickets" && $('senderTicketCode')){
				//$('overlay_top_ticketsToSend').innerHTML = "";
				if($('senderEmail').value != ""){
				var senderTicketCode = $('senderTicketCode').value;
				var sQuery = "&iStep=31&backup=1&bSubmit=1&sEmail="+$('senderEmail').value+"&aTicketCode="+encodeURIComponent(senderTicketCode)+"&tMessage="+encodeURIComponent($("senderMessage").value);
				var oRequest = new Ajax.Request("shop.php", {method:'post',
								 postBody:sQuery,
							     onComplete:function(xhr){
									var oResult = xhr.responseText.evalJSON();
									oPopup.hide();
									if(parseInt(oResult.bValid, 10) === 1){
							     		this.message("confirmation",oResult.sText,{iDuration:5});
							     	}else{
							     		this.message("error",oResult.sText,{iDuration:5});
							     	}
							     }.bindAsEventListener(this)
							});
				}else{
					this.message("error","Veuillez completer tous les champs",{iDuration:3, sDiv:'overlay_top_ticketsToSend'});
				}
			}
		},
		
		SHA1 : function(msg) {

			function rotate_left(n,s) {
				var t4 = ( n<<s ) | (n>>>(32-s));
				return t4;
			};

			function lsb_hex(val) {
				var str="";
				var i;
				var vh;
				var vl;

				for( i=0; i<=6; i+=2 ) {
					vh = (val>>>(i*4+4))&0x0f;
					vl = (val>>>(i*4))&0x0f;
					str += vh.toString(16) + vl.toString(16);
				}
				return str;
			};

			function cvt_hex(val) {
				var str="";
				var i;
				var v;

				for( i=7; i>=0; i-- ) {
					v = (val>>>(i*4))&0x0f;
					str += v.toString(16);
				}
				return str;
			};


			function Utf8Encode(string) {
				string = string.replace(/\r\n/g,"\n");
				var utftext = "";

				for (var n = 0; n < string.length; n++) {

					var c = string.charCodeAt(n);

					if (c < 128) {
						utftext += String.fromCharCode(c);
					}
					else if((c > 127) && (c < 2048)) {
						utftext += String.fromCharCode((c >> 6) | 192);
						utftext += String.fromCharCode((c & 63) | 128);
					}
					else {
						utftext += String.fromCharCode((c >> 12) | 224);
						utftext += String.fromCharCode(((c >> 6) & 63) | 128);
						utftext += String.fromCharCode((c & 63) | 128);
					}
				}

				return utftext;
			};

			var blockstart;
			var i, j;
			var W = new Array(80);
			var H0 = 0x67452301;
			var H1 = 0xEFCDAB89;
			var H2 = 0x98BADCFE;
			var H3 = 0x10325476;
			var H4 = 0xC3D2E1F0;
			var A, B, C, D, E;
			var temp;

			msg = Utf8Encode(msg);

			var msg_len = msg.length;

			var word_array = new Array();
			for( i=0; i<msg_len-3; i+=4 ) {
				j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
				msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
				word_array.push( j );
			}

			switch( msg_len % 4 ) {
				case 0:
					i = 0x080000000;
				break;
				case 1:
					i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
				break;

				case 2:
					i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
				break;

				case 3:
					i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8	| 0x80;
				break;
			}

			word_array.push( i );

			while( (word_array.length % 16) != 14 ) word_array.push( 0 );

			word_array.push( msg_len>>>29 );
			word_array.push( (msg_len<<3)&0x0ffffffff );


			for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {

				for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
				for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);

				A = H0;
				B = H1;
				C = H2;
				D = H3;
				E = H4;

				for( i= 0; i<=19; i++ ) {
					temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
					E = D;
					D = C;
					C = rotate_left(B,30);
					B = A;
					A = temp;
				}

				for( i=20; i<=39; i++ ) {
					temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
					E = D;
					D = C;
					C = rotate_left(B,30);
					B = A;
					A = temp;
				}

				for( i=40; i<=59; i++ ) {
					temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
					E = D;
					D = C;
					C = rotate_left(B,30);
					B = A;
					A = temp;
				}

				for( i=60; i<=79; i++ ) {
					temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
					E = D;
					D = C;
					C = rotate_left(B,30);
					B = A;
					A = temp;
				}

				H0 = (H0 + A) & 0x0ffffffff;
				H1 = (H1 + B) & 0x0ffffffff;
				H2 = (H2 + C) & 0x0ffffffff;
				H3 = (H3 + D) & 0x0ffffffff;
				H4 = (H4 + E) & 0x0ffffffff;

			}

			var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);

			return temp.toLowerCase();

		}

});