var ShopTools = Class.create(ShopCommun,{
		timer: null,
		lastMouseY: null,
		bExecute: false,

		initialize : function(){
			Prototype.Browser.onLoad(function(){
				this.initAllBtn();
			}.bind(this));
		},

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

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

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

			Event.observe(sUsernameId, 'click',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 + "Display").hide();
					$(sPasswordId).show();
					$(sPasswordId).setValue("").show().focus();
				}
			});

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

			Event.observe(frmLogin, "submit",
				function (){
					var sQuery = "bSubmit=1&iStep=5&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().focus();
						return false;
					}
					var sUrl = "shop.php";
					var oMessageObjet = this;

					new Ajax.Request(sUrl, {
											method:'post',
											postBody:sQuery,
											onComplete : function(xhr){
												var oResult = xhr.responseText.evalJSON();
												if(parseInt(oResult.bValid,10) === 1){
													new Ajax.Updater($("divLogin"), sUrl, {//contentLoginTop
																								method:'post',
																								postBody:'bRefresh=1&sPage=user',
																								evalScripts:true,
																								insertion:Element.replace,
																								onComplete:function(){
																									$("frmLogin").remove();
																									new Ajax.Updater("customer", "shop.php", {
																																			method:'post',
																																			postBody:"iStep=20",
																																			evalScripts:true,
																																			onComplete:function(){
                                                                                                                                                new Ajax.Updater("contentUpdate", "shop.php", {method:'post',postBody:"bReinit=1",evalScripts:true});
																																				$$('div.moreBlock').each(function(oBlock){oBlock.hide();});
																																				$('onglets').show();
																																				oTools.selectOnglet($('reservations|20'));
																																			}
																									});
																								}
													});
												}else{
													oMessageObjet.message("error", oResult.sText);
													$(sUsernameId).activate();
												}
					}});
				}.bindAsEventListener(this)
			);
		},

		preLogSubmit : function (){
			$("message").hide();
			if(![$('sEmailPreLog'),$('sPasswordPreLog')].all(function(oInput){
				if(oInput.getValue().blank()){
					var oError = oInput.next('.sError');
					if(oError)this.message("error", oError.innerHTML);
					oInput.focus();
					return false;
				}
				return true
			}.bind(this)))return false;
			var sUrl = "shop.php";
			new Ajax.Request(	sUrl, {
								method:'post',
								parameters:{
									bSubmit:1,
									iStep:5,
									bLoginWithTop:1,
									sEmail:$F('sEmailPreLog'),
									sPassword:$F('sPasswordPreLog')
								},
								onComplete : function(xhr){
									var oResult = xhr.responseText.evalJSON();
									if(parseInt(oResult.bValid,10) !== 1){
										this.message("error", oResult.sText);
										$('sEmailPreLog').activate();
									}else{
										$('preLog').object.hide();
										new Ajax.Updater(	$("divLogin"), sUrl, {
															method:'post',
															postBody:'bRefresh=1&sPage=user',
															evalScripts:true,
															insertion:Element.replace,
															onComplete:function(){
																$("frmLogin").remove();
																new Ajax.Updater(	"customer", "shop.php", {
																					method:'post',
																					postBody:"iStep=20",
																					evalScripts:true,
																					onComplete:function(){
																						new Ajax.Updater("contentUpdate", "shop.php", {method:'post',postBody:"bReinit=1",evalScripts:true});
																						$$('div.moreBlock').invoke('hide');
																						$('onglets').show();
																						this.selectOnglet($('reservations|20'));
																					}.bind(this)
																});
															}.bind(this)
										});
									}
								}.bind(this)
			});
		},

		selectOnglet : function (onglet){
			if($("message")){
				$("message").hide();
			}
			onglet.addClassName('NavBarItemSelected').siblings().invoke('removeClassName','NavBarItemSelected');
			if(onglet.id != "return"){
				$('corp').hide();
				var aInfos = onglet.id.split("|");
				this.getPage(aInfos[1]);
			}else{
				$$('tr.moreInformationMerge').invoke('stopObserving','click');
				this.initShowInformation("moreInformationMerge", "Group");
				this.initLink("moreInformationMergeDetailCategories", "Group");
				$('corp').show();
				$('customer').hide();
			}
		},

		getPage : function (iStep){
			var sUrl = "shop.php";
			var sQuery = "iStep="+iStep;
			$('customer').update(new Element('img',{src:"/shared/images/ico/ico-ajax-busy-32.gif"})).show();
			new Ajax.Updater("customer", sUrl, {
				method:'post',
				postBody:sQuery,
				evalScripts:true
			});
		},

		initNavBar : function (){
			$$('td.NavBarItem').each(function(oBtn){;
				oBtn.stopObserving('click').observe("click", this.selectOnglet.bind(this,oBtn));
				oBtn.stopObserving('mouseover').observe("mouseover", Element.addClassName.curry(oBtn,"NavBarItemHover"));
				oBtn.stopObserving('mouseout').observe("mouseout", Element.removeClassName.curry(oBtn,"NavBarItemHover"));
			}.bind(this));
		},

		initReservationTable : function(iStep){
			$$('tr.moreInformationMerge').each(function(tr){
				tr.stopObserving('mouseenter').observe('mouseenter',Element.addClassName.curry(tr,'hover'));
				tr.stopObserving('mouseleave').observe('mouseleave',Element.removeClassName.curry(tr,'hover'));
			});

			$$('a.showReservationDetail').each(function(oBtn){
				var iReservationCode = oBtn.id.split("|")[1];
				oBtn.stopObserving('click').observe("click", function(event){
					event.stop();
					this.detailAjaxHandler && this.detailAjaxHandler.abort();
					if($('detailResa|'+iReservationCode) && !$('detailResa|'+iReservationCode).visible()){
						$$('tr.moreInformationMergeDetail').invoke('hide');
						$$('tr.moreInformationMerge').invoke('removeClassName','selected');
						$('infoResa|'+iReservationCode).addClassName('selected');
						$('detailResa|'+iReservationCode).update('<tr><td colspan="6"><center><img src="/shared/images/ico/ico-ajax-busy-32.gif"></center></td></tr>').show();
						this.detailAjaxHandler = new Ajax.Updater("detailResa|"+iReservationCode, this.sUrl, {method:'post', postBody:"bSubmit=1&iReservationCode="+iReservationCode+"&iStep="+iStep, evalScripts:true});						
					}else{
						$('detailResa|'+iReservationCode).hide();
						$('infoResa|'+iReservationCode).removeClassName('selected');
					}
				}.bind(this));
			}.bind(this));

			$$('a.Facture').each(function(oBtn){
				oBtn.stopObserving('click');
				oBtn.observe("click", function(){
					var iReservationCode = oBtn.id.split("|")[1];
					var iReservationCodeSHA = this.SHA1(iReservationCode);
					var sCode = "";
					var iJ = 0;
					var iI = 0;

					for (iI=0; iI<iReservationCodeSHA.length; iI++) {
						if (iI>0 && iI%2 === 0 && iJ<iReservationCode.length){
							sCode += iReservationCode.charAt(iJ);
							iJ++;
						}
						sCode += iReservationCodeSHA.charAt(iI);
					}
					window.open("print.php?iMode=2&sCode="+encodeURIComponent(sCode), "Facture");
				}.bindAsEventListener(this));
			}.bind(this));
		},

		initReservationTableDetails : function(){
			var iJ = 0;
			var iI = 0;
			$$('a.PrintTicket').each(function(oBtn){
				oBtn.stopObserving('click');
				oBtn.observe("click", function(){
					var aInfos = oBtn.id.split("|");
					var bUnique = (aInfos[3] && aInfos[3]==="unique");
					var iReservationCode = aInfos[2];
					var iReservationCodeSHA = this.SHA1(iReservationCode);
					var sReservationCode = "";
					iJ = 0;

					for (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 = "";
					iJ = 0;

					for (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 = "print.php?iMode=1&nbTemplate=0&bEncrypt=1&sCode1="+encodeURIComponent(sReservationCode)+"&sCode2=" + encodeURIComponent(sTicketCode)+"&bUnique="+(bUnique?1:0);
                    if(aInfos[4] == "print"){
                        this.generateAndPrint(sUrl);
                    }else{
                        window.open(sUrl, "Ticket");
                    }
				}.bindAsEventListener(this));
			}.bind(this));

			$$('input.checked').each(function(oBtn){
				oBtn.checked = true;
			});
			$$('input.CheckAll').each(function(oBtn){
				oBtn.checked = true;
				var iReservationCode = oBtn.id.split("|")[1];
				var sBtnClass = 'input.'+iReservationCode;
				$$(sBtnClass).each(function(oBtn){oBtn.checked = true;});

				oBtn.stopObserving('click').observe("click", function(){
					if(oBtn.checked){
						$$(sBtnClass).each(function(oBtn){oBtn.checked = true;});
					}else{
						$$(sBtnClass).each(function(oBtn){oBtn.checked = false;});
					}
				}.bindAsEventListener(this));
			}.bind(this));

			$$('button.PrintTickets').each(function(oBtn){
				oBtn.stopObserving('click');
				oBtn.observe("click", function(){
					var aInfos = oBtn.id.split("|");
					var iReservationCode = aInfos[1];
					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 aTicketCodes = oElement.id.split('|');
							var iTicketCodeSHA = oTools.SHA1(aInfos[1]);
							aTicketCodes.each(function(iTicketCode){
								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 += "&sCode2[]=" + encodeURIComponent(sTicketCode);
							});
						}
					});
					if(aTicketsCode.length > 0){
						var sUrl = "print.php?iMode=1&bEncrypt=1&nbTemplate=0&sCode1=" + encodeURIComponent(sReservationCode) + aTicketsCode;
                        if(aInfos[2] == "print"){
                            this.generateAndPrint(sUrl);
                        }else{
                            window.open(sUrl, "Tickets");
                        }
					}else{
						this.message("error",this.aMessages.sMsgSelectTicket,{iDuration:3});
					}
				}.bindAsEventListener(this));
			}.bindAsEventListener(this));

			$$('select.PersonalizeTickets').each(function(oSelect){
				oSelect.stopObserving('change');
				oSelect.observe('change', function(){
					new Ajax.Request('shop.php', {
						method:'post',
						postBody:'iStep=11&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 bRequired = true;
					if($('iCiviliteVisible')){
						var aoCivilite = $('frmCustomerProfile').getInputs('radio','iCivilite');
						if(aoCivilite){
							var oCheckedCivilite = aoCivilite.find(function(radio) { return radio.checked; });
							if(!oCheckedCivilite){
								if(aoCivilite.first().hasAttribute('required')){
									bRequired=false;
									this.message("error", "Veuillez saisir tous les champs obligatoire !",{iDuration:3});
								}
							}
						}
					}

					if(bRequired){
						var aRequired = $$('[required=yes]');
						if(aRequired){
							aRequired.each(function(oField){
                                if((oField.type =="text") || (oField.type =="select-one")){
                                    if((oField.value.strip() === "")||(parseInt(oField.value,10) === 0)){
                                        bRequired=false;
                                        this.message("error", "Veuillez saisir tous les champs obligatoire !",{iDuration:3});
                                    }
                                }
                            }.bindAsEventListener(this));
						}
					}
					if(bRequired){
						var aParameters = Object.extend($('frmCustomerProfile').serialize(true),{
							iStep : 22,
							modifyCustomer : 1,
							backup : 1,
							bSubmit : 1,
							bNewsletter : $('bCustomerNewsletter').checked?1:0
						});
						new Ajax.Request("shop.php", {method:'post',
							parameters:aParameters,
							onComplete:function(xhr){
								var oResult = xhr.responseText.evalJSON();
								if(oResult.result=="success"){
									this.message("confirmation",oResult.message,{iDuration:3});
									new Ajax.Updater($("userBar"), "shop.php", {method:'post',postBody:'bRefresh=1&sPage=user',evalScripts:true});
									if($F('loginOngletPaie')=='login'){
										new Ajax.Updater("contentUpdate", "shop.php", {method:'post',postBody:"&iStep=5",evalScripts:true});
									}
								}else{
									this.message("error",oResult.message,{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 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));
		},

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

			switch(iMode) {
			case 0 :
				//Page d edition d une carte
				sQuery += "&iMode=1&iMembershipCardCode="+iMembershipCardCode;
				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";
				new Ajax.Updater("customer", sUrl, {method:'post', postBody:sQuery, evalScripts:true});
				break;
			case 2 :
				//Charge la partie webcam photo
				sQuery += "&iMode=3";
				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";
				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";
				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("|");
			var bTicket = false;
			this.bUnique=false;
			if(aInfos[0] == "send"){
				if(aInfos[2]&&aInfos[2]=='unique'){
					this.bUnique = true;
				}
				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+'"/>');
				}
				bTicket = true;
			}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;
							bTicket = true;
						}
					}
				});

				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+'"/>');
				}
			}
			if(bTicket){
				oPopup.show();
				$('frmSendTickets').reset();
			}else{
				this.message("error",this.aMessages.sMsgSelectTicket,{iDuration:5});
			}
		},

		managePopup : function(oButton){
			if(oButton.id == "hideTicketsToSend|ticketsToSend"){
				oPopup.hide();
			}else if(oButton.id == "sendSendTickets" && $('senderTicketCode')){
				if($('senderEmail').value !== ""){
				var senderTicketCode = $('senderTicketCode').value;
				var bGroupedTicket= this.bUnique?"&bGroupedTicket=1":"";
				var sQuery = "&iStep=27&backup=1&bSubmit=1"+bGroupedTicket+"&sEmail="+$('senderEmail').value+"&aTicketCode="+encodeURIComponent(senderTicketCode)+"&tMessage="+encodeURIComponent($("senderMessage").value);
				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",oTools.aMessages.sFieldMissing,{iDuration:3, sDiv:'overlay_top_ticketsToSend'});
				}
			}
		},

		expandSubBlock : function(){
			if(this.subDiv.visible()){
				this.update("+");
				this.subDiv.hide();
			}else{
				this.update("-");
				this.subDiv.show();
			}
		},

		SHA1 : function(msg) {

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


			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 = [];
			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;

			}

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

			return temp.toLowerCase();

		},

		changePeriodShop : function(sText,sTitle){
			if($('cancelOrder').visible()){
				Prototype.overlayConfirm(sText,{
					title:sTitle,
					onValid:function(){
						window.location.href='?bInitPeriod=1';
					}
				});
				
				if($('divOverlayConfirm').object){
					$('divOverlayConfirm').object.options.onShow=function(){this.onScrollHandler();}
				}
			}else{
				window.location.href='?bInitPeriod=1';
			}
		}

});
