var SeyesTools = Class.create ({
	Version : "1.0",
	sMsgEmpty : "",
	sMsgError : "",
	oRequest : "",

	CheckForm : function (sForm) {
		var oForm = $(sForm).serialize(true);
		var iField = 0;
		for (var sProperty in oForm) {
			if ($(sProperty)) {
				if($(sProperty).hasClassName("mandatory")){
					if (oForm[sProperty] === "") {
						this.GetMessage(sForm, sProperty, 'empty', 1);
						return false;
					} else {
						switch (sProperty){
							case "sEmail" :
							case "sEmailNewCustomer" :
								if(!this.CheckEmail(sForm, sProperty)){
									return false;
								}else{
									iField++;
								}
								break;
							case "sUrl" :
							case "sUrlNewCustomer" :
								if(!this.CheckUrl(sForm, sProperty)){
									return false;
								}else{
									iField++;
								}
								break;
							default :
								this.GoodField(sProperty);
								iField++;
								break;
						}
					}
				}else{
					if (oForm[sProperty] !== "") {
						switch (sProperty){
							case "sEmail" :
								if(!this.CheckEmail(sForm, sProperty)){
									return false;
								}else{
									iField++;
								}
								break;
							case "sUrl" :
							case "sUrlNewCustomer" :
								if(!this.CheckUrl(sForm, sProperty)){
									return false;
								}else{
									iField++;
								}
								break;
							case "iPrestationsType" :
							case "iCountry" :
								if(!(parseInt($F(sProperty), 10) > 0)){
									return false;
								}else{
									iField++;
								}
								break;
							case "iTournage" :
							case "iPostprod" :
							case "iRealisation" :
							case "sMontage" :
							case "sMontageExterne" :
								if(!(parseInt($F(sProperty), 10) >= 0)){
									//this.GetMessage(sForm, sProperty, 'empty', 1);
									//return false;
									iField++;
								}else{
									if(parseInt($F(sProperty), 10) == 0 && $F(sProperty+"Other") == ""){
										this.GetMessage(sForm, sProperty+"Other", 'empty', 1);
										return false;
									}else{
										iField++;
									}
								}
								break;
							default :
								this.GoodField(sProperty);
								iField++;
								break;
						}
					}
				}
			}
		}

		if(iField === 0){
			return false;
		}else{
			return true;
		}
	},


	GetMessage : function (sForm, sDiv, sMode, bActivate) {
		var sMessage = "";
		switch (sMode) {
			case "empty" :
				$(sDiv).addClassName("fieldError");
				if(bActivate == 1){
					$(sDiv).activate();
				}
				sMessage = this.sMsgEmpty;
				break;
			case "error" :
				$(sDiv).addClassName("fieldError");
				if(bActivate == 1){
					$(sDiv).activate();
				}
				sMessage = this.sMsgError;
				break;
		}
		this.ShowMessage(sForm, "error", sMessage);
	},


	GoodField : function (sDiv) {
		$(sDiv).removeClassName("fieldError");
	},


	ShowMessage : function (sForm, sClassname, sMessage) {
		$(sForm + "Msg").update(sMessage);
		$(sForm + "Msg").addClassName(sClassname);
		$(sForm + "Msg").show();
	},

	CheckEmail : function (sForm, sProperty) {
		var bError = 1;
		if (!($F(sProperty).indexOf ('@', 0) == -1)) {
			if (!($F(sProperty).indexOf ( '@', 0 ) < 1 )) {
				if (!($F(sProperty).indexOf ( '[', 0 ) == -1 && $F(sProperty).charAt ($F(sProperty).length - 1) == ']')) {
					if (!($F(sProperty).indexOf ( '[', 0 ) > -1 && $F(sProperty).charAt ($F(sProperty).length - 1) != ']')) {
						if (!($F(sProperty).indexOf ( '@', 0 ) > 1 && $F(sProperty).charAt ($F(sProperty).length - 1 ) == ']')) {
        					if (!($F(sProperty).indexOf ( '.', 0 ) == -1)) {
        						if (!($F(sProperty).indexOf('@', 0) > 1 && $F(sProperty).charAt($F(sProperty).length - 1) == ']')) {
							        var len = $F(sProperty).length;
							    	var pos = $F(sProperty).lastIndexOf ( '.', len - 1 ) + 1;
								    if (!(( len - pos ) < 2 || ( len - pos ) > 4 )) {
								    	this.GoodField(sProperty);
						    			bError = 0;
								    }
        						}
        					}
						}
					}
				}
			}
		}

		if(bError == 1){
			this.GetMessage(sForm, sProperty, 'error', 1);
			return false;
		}else{
			return true;
		}
	},

	CheckUrl : function (sForm, sProperty) {
		var bError = 1;

		var sRegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;

		if(sRegExp.test($F(sProperty))){
			this.GoodField(sProperty);
			bError = 0;
		}

		if(bError == 1){
			this.GetMessage(sForm, sProperty, 'error', 1);
			return false;
		}else{
			return true;
		}
	},

	copyValue : function (sValue, sDestination) {
		$(sDestination).value = sValue;
	},


	AjaxUpdater : function (sDiv, sUrl, sQuery, sReturnValid, sReturnError) {
		this.loading('start');
		this.oRequete = new Ajax.Updater(sDiv,
										sUrl, {method:'post',
											   postBody:sQuery,
											   evalScripts:true,
											   onSuccess:function(xhr) {
											   		var oResult = xhr.responseText.evalJSON();
											   		if (parseInt(oResult.bValid,10) === 1) {
											   			if(sReturnValid !== ""){
											   				eval(sReturnValid);
											   			}
											   			if (oResult.sText !== "") {
											   				eval(oResult.sText);
											   			}
											   		} else {
										   				if(sReturnError !== ""){
											   				eval(sReturnError);
											   			}
											   		}
										   			this.loading('stop');
											   }.bindAsEventListener(this),
											   onFailure:function() {
											   		if(sReturnError !== ""){
										   				eval(sReturnError);
										   			}
										   			this.loading('stop');
											   }.bindAsEventListener(this),
											   onComplete : function () {
													if(sReturnError === "frmPaypal") {
										   				$('frmPaypal').submit();
										   			}else{
										   				this.loading('stop');
										   			}
											   }.bindAsEventListener(this)});
	},


	AjaxRequest : function (sUrl, sQuery, sReturnValid, sReturnError) {
		var aOptions = {};
		if(arguments.length > 4){
			aOptions = arguments[4] || {};
		}

		if(aOptions.bOverlay && aOptions.bOverlay != false){
			this.loading('start');
		}

		this.oRequete = new Ajax.Request(sUrl, {method:'post',
											   postBody:sQuery,
											   onSuccess:function(xhr) {
											   		var oResult = xhr.responseText.evalJSON();
											   		if (parseInt(oResult.bValid,10) === 1) {
											   			if(sReturnValid !== ""){
											   				eval(sReturnValid);
											   			}
											   			if (oResult.sText !== "") {
											   				eval(oResult.sText);
											   			}
											   		} else {
											   			if(sReturnError !== ""){
											   				eval(sReturnError);
											   			}
											   		}
											   }.bindAsEventListener(this),
											   onFailure:function() {
											   		if(sReturnError !== ""){
										   				eval(sReturnError);
										   			}
											   }.bindAsEventListener(this),
											   onComplete : function () {
											   		if(aOptions.bOverlay && aOptions.bOverlay != false){
											   			this.loading('stop');
											   		}
											   }.bindAsEventListener(this)
		});
	},

	Accordeon : function (sClass, bOpen){
		var oElements = $$("." + sClass);
		oElements.each(
			function (oElement) {
				Event.stopObserving($(oElement.id + "Title"), "click");
				$(oElement.id + "Title").observe('click', function(){
															if(oElements.length > 1){
																oElements.each(
																	function (oElementClose){
																		if($(oElementClose).hasClassName('open')){
																			$(oElementClose.id + "Content").BlindUp({duration:0.2,
																													 afterFinish:function(){
																													 	$(oElementClose).removeClassName("open");
																												 	 	$(oElement).addClassName("open");
																													 	$(oElement.id + "Content").toggle('blind', {duration:0.2});}});
																		}
																	}
																);
															}else{
																if($(oElement).style.display === "none"){
																	$(oElement).addClassName("open");
																}else{
																	$(oElement).removeClassName("open");
																}
															 	$(oElement.id + "Content").toggle('blind', {duration:0.2});
															}
				});
				$(oElement.id + "Content").hide();
			}
		);

		$(oElements[0]).addClassName("open");
		if(bOpen === 1){
			$(oElements[0].id + "Content").show();
		}
	},

	RSSLoad : function (sUrlModule, sContent, sUrlRSS, sTarget, iMaxResult){
		var sQuery = "sUrlRSS=" + encodeURIComponent(sUrlRSS);
		sQuery += "&sTarget=" + encodeURIComponent(sTarget);
		sQuery += "&iMaxResult=" + parseInt(iMaxResult, 10);
		this.oRequest = new SeyesTools.AjaxUpdater(sContent, sUrlModule, sQuery, "", "");
	},

	RSSLink : function (sClassLink, sLinkId, sInfoId){
		var oElements = $$("." + sClassLink);
		oElements.each(
			function (oElement) {
				var sNewElement = oElement.id;
				sNewElement = sNewElement.replace(sLinkId, sInfoId);
				Event.stopObserving($(oElement.id), "mouseover");
				$(oElement.id).observe('mouseover', function(){
					$(sNewElement).BlindDown({duration:0.1});
				});
				Event.stopObserving($(oElement.id), "mouseout");
				$(oElement.id).observe('mouseout', function(){
					$(sNewElement).BlindUp({duration:0.1});
				});
			}
		);
	},

	checkAuthentification : function (sForm) {
		if(this.CheckForm(sForm)){
			var sUrl = "init.php";
			var sQuery = "iAction=1&" + $(sForm).serialize();
			this.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.reload();
												   	}else{
												   		this.ShowMessage(sForm, "error", oResult.sText);
												   	}
												   }.bindAsEventListener(this)});
		}
	},

	quickAuthentification : function (sForm){
		var aOptions = {};
		if(arguments.length > 1){
			aOptions = arguments[1] || {};
		}

		Event.stopObserving($(sForm), "keyup");
		$(sForm).observe("keyup",
			function(event){
				if(typeof(event.wich) == 'undefined') {
					event.wich = event.keyCode;
				}
				if (parseInt(event.wich,10) === 13) {
					if($F(aOptions.sUsername) !== aOptions.sUsernameTextDefault && $F(aOptions.sPassword) !== aOptions.sPasswordTextDefault){
						this.checkAuthentification(sForm);
					}
				}
			}.bindAsEventListener(this)
		);

		//Init Field
		$(aOptions.sUsername).value = aOptions.sUsernameTextDefault;
		$(aOptions.sPassword).value = aOptions.sPasswordTextDefault;

		if(aOptions.sUsername !== ""){
			Event.stopObserving(aOptions.sUsername, "focus");
			$(aOptions.sUsername).observe('focus',
				function(){
					if($F(aOptions.sUsername) === aOptions.sUsernameTextDefault){
						$(aOptions.sUsername).value = "";
					}
				}
			);

			Event.stopObserving(aOptions.sUsername, "blur");
			$(aOptions.sUsername).observe('blur',
				function(){
					if($F(aOptions.sUsername) === ""){
						$(aOptions.sUsername).value = aOptions.sUsernameTextDefault;
					}
				}
			);
		}

		if(aOptions.sPassword !== ""){
			Event.stopObserving(aOptions.sPassword, "focus");
			$(aOptions.sPassword).observe('focus',
				function(){
					if($F(aOptions.sPassword) === aOptions.sPasswordTextDefault){
						$(aOptions.sPassword).value = "";
					}
				}
			);

			Event.stopObserving(aOptions.sPassword, "blur");
			$(aOptions.sPassword).observe('blur',
				function(){
					if($F(aOptions.sPassword) === ""){
						$(aOptions.sPassword).value = aOptions.sPasswordTextDefault;
					}
				}
			);
		}
	},

	createButton : function (sClassName, oElement) {
		var oRequest = "";
		var sQuery = "";
		var aInfos = "";

		switch (sClassName){
			case "observeChange" :
			case "observeClick" :
				if(oElement.hasClassName("checkbox")){
					if(oElement.name == "sContactMode") {
						if(oElement.id == "sContactModePhone") {
							$('sContactModePhone_value').show();
						}else{
							$('sContactModePhone_value').hide();
						}
					}
					if(oElement.id == "sMediaDiffusionOther") {
						if(oElement.checked == true){
							$('sMediaDiffusionOther_value').show();
							$('sMediaDiffusionOther_value').focus();
						}else{
							$('sMediaDiffusionOther_value').hide();
						}
					}
				}else{
					if(oElement.id != "sMontage" && oElement.id != "sMontageExterne"){
						$(oElement.id+"_intervenant").hide();
					}

					if($F(oElement.id) > 0){
						$(oElement.id+"Other").hide();
						if(oElement.id != "sMontage" && oElement.id != "sMontageExterne"){
							$(oElement.id+"_intervenant").show();
							oRequest = this.AjaxUpdater(oElement.id+"_intervenant", "init.php", "iAction=33&sMode="+encodeURIComponent(oElement.id)+"&iIdService="+parseInt($F(oElement.id),10), "", "");
						}
					}else{
						if(oElement.id != "sMontage" && oElement.id != "sMontageExterne"){
							$(oElement.id+"_intervenant").update(" ");
						}

						if($F(oElement.id) == 0){
							$(oElement.id+"Other").show();
							$(oElement.id+"Other").focus();
						}else{
							$(oElement.id+"Other").hide();
						}
					}
				}
				break;
			case "intervenant" :
				if($(oElement.id).hasClassName('intervenantSelected')){
					$(oElement.id).removeClassName('intervenantSelected');
				}else{
					$(oElement.id).addClassName('intervenantSelected');
				}
				break;
			case "btnLogout" :
				oRequest = this.AjaxRequest("init.php", "iAction=2", "document.location.href='index.php'", "");
				break;
			case "createLink" :
				window.open($F(oElement.id + "_sUrl"));
				break;
			case "more" :
				aInfos = oElement.id.split("|");
				switch(aInfos[0]){
					case "news" :
						oRequest = this.AjaxRequest("init.php", "iAction=4&iIdNews=" + parseInt(aInfos[1], 10), "", "");
						break;

					case "produits" :
						oRequest = this.AjaxRequest("init.php", "iAction=5&iIdProduct=" + parseInt(aInfos[1], 10), "", "");
						break;
				}
				break;
			case "btnBuy" :
			case "buyLink" :
				aInfos = oElement.id.split("|");
				oRequest = this.AjaxRequest("init.php", "iAction=5&iIdProduct=" + parseInt(aInfos[1], 10), "", "");
				break;
			case "watchMoreLink" :
				aInfos = oElement.id.split("|");
				oRequest = this.AjaxRequest("init.php", "iAction=5&iIdProduct=" + parseInt(aInfos[1], 10), "", "");
				break;
			case "sort" :
				aInfos = oElement.id.split("|");
				sQuery += "iAction=24&sMode=" + encodeURIComponent(aInfos[0]) + "&sField=" + encodeURIComponent(aInfos[1]);
				if(oElement.hasClassName("asc")){
					sQuery += "&bDesc=0";
					oElement.removeClassName("asc");
					oElement.addClassName("desc");
				}else{
					sQuery += "&bDesc=1";
					oElement.removeClassName("desc");
					oElement.addClassName("asc");
				}
				oRequest = this.AjaxUpdater(encodeURIComponent(aInfos[0]), "init.php", sQuery, "");
				break;
			case "commentLink" :
				aInfos = oElement.id.split("|");
				oRequest = this.AjaxRequest("init.php", "iAction=5&sAncre=comments&iIdProduct=" + parseInt(aInfos[1], 10), "", "");
				break;
			case "addToCart" :
				aInfos = oElement.id.split("|");
				$$('#lineProduct' + aInfos[1] + ' td').each(
					function(oLine){
						oLine.addClassName("select");
					}
				);
				sQuery = "iAction=9&iIdPrixproduits=" + parseInt(aInfos[1], 10);
				if($("cart")){
					sQuery += "&bUpdateContent=1";
					oRequest = this.AjaxUpdater("cart", "init.php", sQuery, "", "");
				}else{
					sQuery += "&bUpdateContent=0";
					oRequest = this.AjaxRequest("init.php", sQuery, "document.location.href='index.php'", "");
				}
				break;
			case "deleteToCart" :
				aInfos = oElement.id.split("|");
				if($('lineProduct' + aInfos[3])){
					$$('#lineProduct' + aInfos[3] + ' td').each(
						function(oLine){
							oLine.removeClassName("select");
						}
					);
				}

				sQuery = "iAction=10&iIdProduit=" + parseInt(aInfos[1], 10) + "&iIdType=" + parseInt(aInfos[2], 10) + "&iIdPrix=" + parseInt(aInfos[3], 10);
				oRequest = this.AjaxUpdater("cart", "init.php", sQuery, "", "");
				break;
			case "btnGoToPaid" :
				oRequest = this.AjaxRequest("init.php", "iAction=11", "", "");
				break;
			case "buyDifference" :
				oRequest = this.AjaxUpdater("paypalPayment", "init.php", "iAction=26", "", "frmPaypal");
				break;
			case "pageSelect" :
				aInfos = oElement.id.split("|");
				oRequest = this.AjaxUpdater("iIdPage1_1", "modules/news/list.php", "bAjax=1&iOffset="+parseInt(aInfos[1], 10), "", "");
				break;
			case "buyPacks" :
				oRequest = this.AjaxRequest("init.php", "iAction=15", "", "");
				break;
			case "viewAllProducts" :
				oRequest = this.AjaxRequest("init.php", "iAction=8&sSearch=");
				break;
			case "pack" :
				aInfos = oElement.id.split("|");
				oRequest = this.AjaxUpdater("paypalPayment", "init.php", "iAction=20&iIdPack=" + aInfos[1], "", "frmPaypal");
				break;
			case "devise" :
				$$(".devise").each(
					function(oDevise){
						if(oDevise.hasClassName("select")){
							oDevise.removeClassName("select");
							$(oDevise.id).src = $(oDevise.id).src.replace("on", "off");
						}
					}
				);
				oElement.addClassName("select");
				aInfos = oElement.id.split("|");
				sQuery = "iAction=14&iIdCurrency=" + parseInt(aInfos[1], 10);
				oRequest = this.AjaxUpdater("contentPacks", "init.php", sQuery, "", "");
				break;
			case "cancelOrder" :
				oRequest = this.AjaxRequest("init.php", "iAction=21", "", "");
				break;
			case "confirmOrder" :
				oRequest = this.AjaxRequest("init.php", "iAction=22", "", "");
				break;
			case "btnDownload" :
				aInfos = oElement.id.split("|");
				//oRequest = new Ajax.Request("init.php", {method:'post', postBody:"iAction=23&iKeyFile=" + parseInt(aInfos[1], 10) + "&sMode=" + encodeURIComponent(aInfos[2]), onComplete:function(xhr){window.open(xhr.responseText);}});
				break;
			case "clickToDeleteDownload" :
				aInfos = oElement.id.split("|");
				oRequest = new Ajax.Request("init.php", {method:'post', postBody:"iAction=31&dDate=" + encodeURIComponent(aInfos[2]) + "&iIdProduit=" + parseInt(aInfos[0], 10) + "&iIdPrice=" + encodeURIComponent(aInfos[1]), onComplete:function(){document.location.reload();}});
				break;
			case "clickToDownload" :
				aInfos = oElement.id.split("|");
				oRequest = new Ajax.Request("init.php", {method:'post', postBody:"iAction=25&dDate=" + encodeURIComponent(aInfos[2]) + "&iIdProduit=" + parseInt(aInfos[0], 10) + "&iIdPrice=" + encodeURIComponent(aInfos[1]), onComplete:function(xhr){window.open(xhr.responseText);document.location.reload();}});
				break;
			case "btnShowFile" :
				aInfos = oElement.id.split("|");
				oRequest = new Ajax.Updater("overlayContent", "init.php", {method:'post',
																		   postBody:"iAction=29&sContent=show_file&iKeyFile=" + parseInt(aInfos[1], 10),
																		   evalScripts:true,
																		   onComplete:function(){
																		   		$('overlayContent').style.top = '5%';
																				$('overlayContent').style.left = "50%";
																				$('overlayContent').style.marginLeft = "-515px";
																				$('overlay').show();
																		   		$('overlayContent').show();
																		   }
				});
				break;
			case "forgotPasswordLink" :
				oRequest = new Ajax.Updater("overlayContent", "init.php", {method:'post',
																		   postBody:"iAction=29&sContent=forgot_password",
																		   evalScripts:true,
																		   onComplete:function(){
																		   		$('overlayContent').style.top = '25%';//parseInt(((document.body.clientHeight / 2) - ($('overlayContent').getHeight() / 2)),10) + "px";
																				$('overlayContent').style.left = parseInt(((document.body.clientWidth / 2) - ($('overlayContent').getWidth() / 2)),10) + "px";
																		   		$('overlay').show();
																		   		$('overlayContent').show();
																		   }
				});
				break;
			case "closeOverlay" :
				$('overlayContent').update("");
				$('overlayContent').hide();
				$('overlay').hide();
				break;

			case "intervenantToMail" :
				aInfos = oElement.id.split("|");
				oRequest = this.AjaxRequest("init.php", "iAction=32&iIdIntervenant=" + parseInt(aInfos[1], 10), "", "");
				break;
		}
	},

	loading : function (sMode) {
		if(sMode == "start") {
			this.loadingShow();
		}else{
			this.loadingHide();
		}
	},

	loadingShow : function () {
		$('overlay').show();
		$('loading').show();
	},

	loadingHide : function () {
		$('loading').hide();
		$('overlay').hide();
	},

	removeLink : function (sClassName) {
		if($(sClassName)){
			$(sClassName).setStyle("cursor:default");
		}else{
			$$("." + sClassName).each(
				function (oElement){
					oElement.setStyle("cursor:default");
				}
			);
		}
	},

	rollover : function (sClassName) {
		if($(sClassName)){
			$(sClassName).stopObserving("mouseover");
			$(sClassName).observe("mouseover", function(){$(sClassName).addClassName("rollover");});
			$(sClassName).stopObserving("mouseout");
			$(sClassName).observe("mouseout", function(){$(sClassName).removeClassName("rollover");});
		}else{
			$$("." + sClassName).each(
				function (oElement){
					oElement.stopObserving("mouseover");
					oElement.observe('mouseover',
						function(){
							oElement.addClassName("rollover");
						}
					);

					oElement.stopObserving("mouseout");
					oElement.observe('mouseout',
						function(){
							oElement.removeClassName("rollover");
						}
					);
				}
			);
		}
	},

	createLinks : function (sClassName){
		if($(sClassName)){
			$(sClassName).stopObserving("click");
			$(sClassName).observe("click", function(){this.createButton(sClassName);}.bindAsEventListener(this));
		}else{
			$$("." + sClassName).each(
				function (oElement){
					oElement.stopObserving("click");
					oElement.observe('click',
						function(){
							this.createButton(sClassName, oElement);
						}.bindAsEventListener(this)
					);
				}.bindAsEventListener(this)
			);
		}
	},

	change : function (sClassName){
		if($(sClassName)){
			$(sClassName).stopObserving("change");
			$(sClassName).observe("change", function(){this.createButton(sClassName);}.bindAsEventListener(this));
		}else{
			$$("." + sClassName).each(
				function (oElement){
					oElement.stopObserving("change");
					oElement.observe('change',
						function(){
							this.createButton(sClassName, oElement);
						}.bindAsEventListener(this)
					);
				}.bindAsEventListener(this)
			);
		}
	},

	ListenForm : function (sForm, iAction){
		var aOptions = {};
		if(arguments.length > 2){
			aOptions = arguments[2] || {};
		}

		$(sForm).focusFirstElement();

		if($(sForm + 'Reset')){
			Event.stopObserving(sForm + 'Reset', "click");
			$(sForm + 'Reset').observe('click', function(){
													$(sForm + "Msg").hide();
													$$('.fieldError').each(
														function (oField){
															$(oField.id).removeClassName('fieldError');
														}
													);
													$(sForm).focusFirstElement();
			});
		}

		Event.stopObserving(sForm, "submit");
		$(sForm).observe('submit', function(){
										$(sForm + "Msg").hide();
										if(sForm == "frmNewCustomer"){
											if($('bConditionsGeneral').checked === false){
												this.ShowMessage(sForm, "error", aOptions.sTextConditions);
												return false;
											}
										}
										if(this.CheckForm(sForm)){
											var sQueryMore = "";
											if(sForm == "frmPrestations") {
												if($('sContactModeEmail').checked == true){
													sQueryMore += "&sContactModeTrue=email";
												}else{
													sQueryMore += "&sContactModeTrue=phone";
												}

												if($('sContactTimeMatin').checked == true){
													sQueryMore += "&sContactTimeTrue=matin";
												}

												if($('sContactTime12h14h').checked == true){
													sQueryMore += "&sContactTimeTrue=12h14h";
												}

												if($('sContactTime14h').checked == true){
													sQueryMore += "&sContactTimeTrue=14h";
												}

												var aRealisation = new Array();
												var aTournage = new Array();
												var aPostprod = new Array();
												$$('.intervenantSelected').each(
													function (oIntervenant) {
														var aInfos = oIntervenant.id.split("|");
														if(aInfos[1] == "iRealisation"){
															aRealisation.push(aInfos[2]);
														}
														if(aInfos[1] == "iTournage"){
															aTournage.push(aInfos[2]);
														}
														if(aInfos[1] == "iPostprod"){
															aPostprod.push(aInfos[2]);
														}
													}
												);
												if(aRealisation.length > 0){
													sQueryMore += "&sIntervenantRealisation=";

													aRealisation.each(
														function (sValue){
															sQueryMore += sValue+"|";
														}
													);
												}
												if(aTournage.length > 0){
													sQueryMore += "&sIntervenantTournage=";

													aTournage.each(
														function (sValue){
															sQueryMore += sValue+"|";
														}
													);
												}
												if(aPostprod.length > 0){
													sQueryMore += "&sIntervenantPostprod=";

													aPostprod.each(
														function (sValue){
															sQueryMore += sValue+"|";
														}
													);
												}
											}
											var sUrl = "init.php";
											this.oRequest = new Ajax.Request(sUrl, {method:'post',
																				   postBody:"iAction=" + parseInt(iAction, 10) + "&" + $(sForm).serialize()+sQueryMore,
																				   onComplete:function(xhr){
																				   	var oResult = xhr.responseText.evalJSON();
																				   	if(parseInt(oResult.bValid, 10) == 1){
																				   		switch(sForm) {
																				   			case "frmAuthFull" :
																				   			case "frmNewCustomer" :
																				   			case "frmAuth" :
																				   				eval(oResult.sText);
																				   				break;
																				   			default :
																					   			this.ShowMessage(sForm, "valid", oResult.sText);
																					   			if(parseInt(oResult.bNotReset, 10) !== 1){
																					   				$(sForm).reset();
																					   				if(sForm == "frmPrestations") {
																					   					$('sContactModePhone_value').hide();
																					   					$$('.tableauIntervenant').each(
																					   						function(oElement){
																					   							oElement.hide();
																					   						}
																					   					);
																					   				}
																					   			}
																					   			if(parseInt(oResult.bResetPassword, 10) === 1){
																									$(sForm).getInputs('password').each(
																										function(oField) {
																											oField.value = "";
																										}
																									);
																					   			}
																					   			break;
																				   		}
																				   	}else{
																				   		this.ShowMessage(sForm, "error", oResult.sText);
																				   	}
																				   }.bindAsEventListener(this)});
										}
									}.bindAsEventListener(this)
		);

		$$(".checkbox").each(
			function (oElement){
				oElement.observe("click", function(){
					$$(".checkboxChecked").each(
						function (oElementChecked){
							if(oElementChecked.id.substr(0,(oElementChecked.id.length-2)) === oElement.id.substr(0,(oElement.id.length-2))){
								oElementChecked.removeClassName("checkboxChecked");
							}
						}
					);
					oElement.addClassName("checkboxChecked");

					var aElement = oElement.id.split("_");
					$(aElement[0]).value = aElement[1];
				});
			}
		);

	},

	Search : function (sDiv, sLabel, sForm, sBtn) {
		if($F(sDiv) === ""){
			$(sDiv).value = sLabel;
		}

		Event.stopObserving(sDiv, "focus");
		$(sDiv).observe('focus', function(){
									if($F(sDiv) === sLabel){
										$(sDiv).value = "";
									}
		});

		Event.stopObserving(sDiv, "blur");
		$(sDiv).observe('blur', function(){
									if($F(sDiv) === ""){
										$(sDiv).value = sLabel;
									}
		});

		Event.stopObserving(sForm, "submit");
		$(sForm).observe('submit',
			function(){
				if($F(sDiv) === sLabel){
					$(sDiv).value = "";
				}
				var sQuery = "iAction=8&sSearch=" + encodeURIComponent($F(sDiv));
				this.oRequest = this.AjaxRequest("init.php", sQuery, "", "");
			}.bindAsEventListener(this)
		);

		Event.stopObserving(sBtn, "click");
		$(sBtn).observe('click',
			function(){
				if($F(sDiv) === sLabel){
					$(sDiv).value = "";
				}
				var sQuery = "iAction=8&sSearch=" + encodeURIComponent($F(sDiv));
				this.oRequest = this.AjaxRequest("init.php", sQuery, "", "");
			}.bindAsEventListener(this)
		);

		Event.stopObserving(sBtn, "mouseover");
		$(sBtn).observe("mouseover", function(){$(sBtn).addClassName('hover');});
		Event.stopObserving(sBtn, "mouseout");
		$(sBtn).observe("mouseout", function(){$(sBtn).removeClassName('hover');});
	},

	CreateButtonImage : function (sIdButton){
		var iTotalClass = $$("." + sIdButton).length;
		if(parseInt(iTotalClass,10) === 0){
			if($(sIdButton)){
				Event.stopObserving(sIdButton, "mouseover");
				$(sIdButton).observe('mouseover', function(){$(sIdButton).src = $(sIdButton).src.replace("off", "on");});
				Event.stopObserving(sIdButton, "mouseout");
				$(sIdButton).observe('mouseout', function(){
					$(sIdButton).src = $(sIdButton).src.replace("on", "off");
					if(arguments.length > 1){
						$$("." + sIdButton).each(
							function (oBtn) {
								if(oBtn.hasClassName(arguments[1])){
									$(oBtn.id).src = $(oBtn.id).src.replace("off", "on");
								}
							}
						);
					}
				});
			}
		}else{
			$$("." + sIdButton).each(
				function (oBtn){
					Event.stopObserving(oBtn.id, "mouseover");
					$(oBtn.id).observe('mouseover', function(){$(oBtn.id).src = $(oBtn.id).src.replace("off", "on");});
					Event.stopObserving(oBtn.id, "mouseout");
					$(oBtn.id).observe('mouseout', function(){
						if(!oBtn.hasClassName("select")){
							$(oBtn.id).src = $(oBtn.id).src.replace("on", "off");
						}
					});
				}
			);
		}
	},

	GeneratePreviews : function (sClassName) {
		$$("." + sClassName).each(
			function (oElement) {
				Event.stopObserving(oElement, "click");
				oElement.observe("click",
					function(){
						var aIdProduit = oElement.id.split("|");
						if(aIdProduit[3] == 1) {
							var sIdPreview = "flashPreviews" + aIdProduit[1];
							$(sIdPreview).height = $("flash|" + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3]).height + "px";
							if($F(aIdProduit[0] + '_Value|' + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3]) !== ""){
								$(sIdPreview).clonePosition($(oElement.id));
								$(sIdPreview).show();

								var fLoadVideo = function (){
									var aAttribute = {data:$F(aIdProduit[0] + '_Value|' + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3]),width:"620",height:"349"};
			        				var aParams = {allowfullscreen:"true",
			        							   allowscriptaccess:"always",
			        							   movie:$F(aIdProduit[0] + '_Value|' + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3])
			        							  };
			        				var oVideo = swfobject.createSWF(aAttribute, aParams, sIdPreview);
								}
		        				swfobject.addDomLoadEvent(fLoadVideo);

								oElement.hide();

								Event.stopObserving(sIdPreview, "mouseout");
								$(sIdPreview).observe("mouseout",
									function(){
										$(sIdPreview).style.visibility = "hidden";
										oElement.clonePosition($(sIdPreview));
										$(sIdPreview).style.height = "0px";
										oElement.show();
										$(sIdPreview).hide();
									}
								);
							}
						}else{
							oRequest = this.AjaxRequest("init.php", "iAction=34&iIdProduct=" + parseInt(aIdProduit[1], 10), "", "", {bOverlay:false});

							var sIdPreview = "flashPreviews" + aIdProduit[1];
							$(sIdPreview).height = $("flash|" + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3]).height + "px";
							if($F(aIdProduit[0] + '_Value|' + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3]) !== ""){
								$(sIdPreview).clonePosition($(oElement.id));
								$(sIdPreview).show();

								switch(parseInt(aIdProduit[2],10)){
									case 1 :
										//Video
										var fLoadVideo = function (){
											var aAttribute = {data:"modules/lecteurFlash/playerBig.swf?r="+ new Date().getTime(),width:"620",height:"349"};
					        				var aParams = {flashvars:"flv=" + $F(aIdProduit[0] + '_Value|' + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3]) + "&width=620&height=349&loop=0&autoplay=1&autoload=1&margin=0&bgcolor=000000&bgcolor1=000000&bgcolor2=000000&showtime=1&loadingcolor=ff0000&buffermessage=&buffercolor=000000&buffershowbg=0"};
					        				var oVideo = swfobject.createSWF(aAttribute, aParams, sIdPreview);
										}
				        				swfobject.addDomLoadEvent(fLoadVideo);
				        				break;

				        			case 2 :
				        				//Audio
				        				var fLoadAudio = function (){
											var aAttribute = {data:$F(aIdProduit[0] + '_Value|' + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3])+"?r="+ new Date().getTime(),width:"620",height:"349"};
					        				var aParams = {};
					        				var oAudio = swfobject.createSWF(aAttribute, aParams, sIdPreview);
										}
				        				swfobject.addDomLoadEvent(fLoadAudio);
				        				break;

				        			case 3 :
				        				//Pictures
										var fLoadPictures = function (){
											var aURI = $F(aIdProduit[0] + '_Value|' + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3]).split("?");
											var aAttribute = {data:$F(aIdProduit[0] + '_Value|' + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3])+"&r="+ new Date().getTime(),width:"620",height:"349"};
					        				var aParams = {flashvars:aURI[1]};
					        				var oPictures = swfobject.createSWF(aAttribute, aParams, sIdPreview);
										}
				        				swfobject.addDomLoadEvent(fLoadPictures);
				        				break;
								}

								oElement.hide();

								Event.stopObserving(sIdPreview, "mouseout");
								$(sIdPreview).observe("mouseout",
									function(){
										$(sIdPreview).style.visibility = "hidden";
										oElement.clonePosition($(sIdPreview));
										$(sIdPreview).style.height = "0px";
										oElement.show();
										$(sIdPreview).hide();
									}
								);
							}
						}
					}.bindAsEventListener(this)
				);
			}.bindAsEventListener(this)
		);
	},



	GeneratePreviewsThumb : function (sBtn, sCible) {
		$$("." + sBtn).each(
			function (oElement) {
				Event.stopObserving(oElement, "click");
				oElement.observe("click",
					function(){
						var aIdProduit = oElement.id.split("|");
						if(aIdProduit[3] == 1) {
							var sIdPreview = "flashThumbPreviews" + aIdProduit[1];
							var sIdObserver = "categoryProduit|" + aIdProduit[1];
							Event.stopObserving(sIdObserver, "mouseout");
							$(sIdObserver).observe("mouseout",
								function(){
									$(sIdPreview).hide();
									$(sIdPreview).style.visibility = "hidden";
									$(sIdPreview).style.height = "0px";
									$("background|" + aIdProduit[1]).style.opacity = 0.85;
									$("moreInformation|" + aIdProduit[1]).style.opacity = 1;
									$(sCible + "|" + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3]).show();
									$("background|" + aIdProduit[1]).hide();
									$("moreInformation|" + aIdProduit[1]).hide();
								}.bindAsEventListener(this)
							);

							$(sIdPreview).style.height = $(sCible + "|" + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3]).style.height;

							if($F('flash_Value' + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3]) !== ""){
								$(sIdPreview).clonePosition($(oElement.id));
								$(sIdPreview).show();
								var fLoadVideo = function (){
									var aAttribute = {data:$F('flash_Value' + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3]),width:"200",height:"113"};
									var aParams = {allowfullscreen:"true",
			        							   allowscriptaccess:"always",
			        							   movie:$F('flash_Value' + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3])
			        							  };
			        				var oVideo = swfobject.createSWF(aAttribute, aParams, sIdPreview);
								}
		        				swfobject.addDomLoadEvent(fLoadVideo);

		        				$("background|" + aIdProduit[1]).style.opacity = 0;
								$("moreInformation|" + aIdProduit[1]).style.opacity = 0;
								$(sCible + "|" + aIdProduit[1]+"|"+aIdProduit[2]+"|"+aIdProduit[3]).hide();
								$("background|" + aIdProduit[1]).hide();
								$(sIdPreview).setStyle("z-index:2000");
								$(sIdPreview).show();
							}
						}else{
							oRequest = this.AjaxRequest("init.php", "iAction=34&iIdProduct=" + parseInt(aIdProduit[1], 10), "", "", {bOverlay:false});
							var sIdPreview = "flashThumbPreviews" + aIdProduit[1];
							var sIdObserver = "categoryProduit|" + aIdProduit[1];
							Event.stopObserving(sIdObserver, "mouseout");
							$(sIdObserver).observe("mouseout",
								function(){
									$(sIdPreview).hide();
									$(sIdPreview).style.visibility = "hidden";
									$(sIdPreview).style.height = "0px";
									$("background|" + aIdProduit[1]).style.opacity = 0.85;
									$("moreInformation|" + aIdProduit[1]).style.opacity = 1;
									$(sCible + "|" + aIdProduit[1]+"|"+aIdProduit[2]).show();
									$("background|" + aIdProduit[1]).hide();
									$("moreInformation|" + aIdProduit[1]).hide();
								}.bindAsEventListener(this)
							);

							$(sIdPreview).style.height = $(sCible + "|" + aIdProduit[1]+"|"+aIdProduit[2]).style.height;

							if($F('flash_Value' + aIdProduit[1]+"|"+aIdProduit[2]) !== ""){
								$(sIdPreview).clonePosition($(oElement.id));
								$(sIdPreview).show();

								switch(parseInt(aIdProduit[2],10)){
									case 1 :
										//Video
										var fLoadVideo = function (){
											var aAttribute = {data:"modules/lecteurFlash/thumb.swf?r="+ new Date().getTime(),width:"200",height:"113"};
					        				var aParams = {flashvars:"flv=" + $F('flash_Value' + aIdProduit[1]+"|"+aIdProduit[2]) + "&width=200&height=113&loop=0&autoplay=1&autoload=1&margin=0&bgcolor=000000&bgcolor1=000000&bgcolor2=000000&showplayer=never&showloading=never&loadingcolor=ff0000&buffermessage=&buffercolor=000000&buffershowbg=0"};
					        				var oVideo = swfobject.createSWF(aAttribute, aParams, sIdPreview);
										}
				        				swfobject.addDomLoadEvent(fLoadVideo);
				        				break;

				        			case 2 :
				        				//Audio
				        				var fLoadAudio = function (){
											var aAttribute = {data:$F('flash_Value' + aIdProduit[1]+"|"+aIdProduit[2])+"?r="+ new Date().getTime(),width:"200",height:"113"};
					        				var aParams = {};
					        				var oAudio = swfobject.createSWF(aAttribute, aParams, sIdPreview);
										}
				        				swfobject.addDomLoadEvent(fLoadAudio);
				        				break;

				        			case 3 :
				        				//Pictures
										var fLoadPictures = function (){
											var aURI = $F('flash_Value' + aIdProduit[1]+"|"+aIdProduit[2]).split("?");
											var aAttribute = {data:$F('flash_Value' + aIdProduit[1]+"|"+aIdProduit[2])+"&r="+ new Date().getTime(),width:"200",height:"113"};
					        				var aParams = {flashvars:aURI[1]};
					        				var oPictures = swfobject.createSWF(aAttribute, aParams, sIdPreview);
										}
				        				swfobject.addDomLoadEvent(fLoadPictures);
				        				break;
								}

								$("background|" + aIdProduit[1]).style.opacity = 0;
								$("moreInformation|" + aIdProduit[1]).style.opacity = 0;
								$(sCible + "|" + aIdProduit[1]+"|"+aIdProduit[2]).hide();
								$("background|" + aIdProduit[1]).hide();
								$(sIdPreview).setStyle("z-index:2000");
								$(sIdPreview).show();
							}
						}
					}.bindAsEventListener(this)
				);
			}.bindAsEventListener(this)
		);
	},

	Sleep : function (iMillisecondes) {
		var start = new Date().getTime();
		while(true) {
			if ((new Date().getTime() - start) > iMillisecondes){
				break;
			}
		}
	},

	initCategories : function (sClassName, sContainer){
		$$("." + sClassName).each(
			function (oElement){
				Event.stopObserving(oElement, "click");
				oElement.observe("click",
					function(){
						var aIdProduit = oElement.id.split("|");
						var sQuery = "iAction=7&iMode=" + parseInt(aIdProduit[2],10) + "&iIdCategoriesProduits=" + parseInt(aIdProduit[1],10);
						this.oRequest = this.AjaxRequest("init.php", sQuery, "", "");
					}.bindAsEventListener(this)
				);
			}.bindAsEventListener(this)
		);

		$$("#" + sContainer + " li").each(
			function(oCategory){
				Event.stopObserving(oCategory, "mouseover");
				oCategory.observe("mouseover", function(){oCategory.addClassName("hover");});
				Event.stopObserving(oCategory, "mouseout");
				oCategory.observe("mouseout", function(){oCategory.removeClassName("hover");});
			}
		);
	},

	ListProducts : function (sContainer, sClassNameMaster, sClassNameSlave){
		$$("." + sContainer).each(
			function (oProduct){
				var aId = oProduct.id.split("|");
				$("background|" + aId[1]).hide();
				$(sClassNameSlave + "|" + aId[1]).hide();

				Event.stopObserving(oProduct, "mouseover");
				oProduct.observe("mouseover",
					function (){
						var oDimensions = $(sClassNameMaster + "|" + aId[1]).getDimensions();
						$("background|" + aId[1]).clonePosition($(sClassNameMaster + "|" + aId[1]));
						$("background|" + aId[1]).setStyle("height:" + (oDimensions.height-25) + "px");
						$(sClassNameSlave + "|" + aId[1]).clonePosition($(sClassNameMaster + "|" + aId[1]));
						$(sClassNameSlave + "|" + aId[1]).setStyle("height:" + (oDimensions.height-20) + "px");
						$("background|" + aId[1]).show();
						$(sClassNameSlave + "|" + aId[1]).show();
					}
				);

				Event.stopObserving(oProduct, "mouseout");
				oProduct.observe("mouseout",
					function (){
						$("background|" + aId[1]).hide();
						$(sClassNameSlave + "|" + aId[1]).hide();
					}
				);
			}
		);
	},

	ListNavigation : function (sClass) {
		$$("." + sClass).each(
			function (oElement) {
				Event.stopObserving(oElement, "mouseover");
				oElement.observe("mouseover", function(){oElement.src = oElement.src.replace("_off", "_on");});
				Event.stopObserving(oElement, "mouseout");
				oElement.observe("mouseout", function(){oElement.src = oElement.src.replace("_on", "_off");});
			}
		);
	},

	hover : function (sClassName, sAddClassName){
		var iTotal = $$("." + sClassName).length;

		if(iTotal > 0){
			$$("." + sClassName).each(
				function (oElement){
					Event.stopObserving(oElement, "mouseover");
					oElement.observe("mouseover",
						function(){
							oElement.addClassName(sAddClassName);
							if($$("." + sClassName + " > img")){
								var oImg = oElement.firstDescendant();
								if(oImg !== null && oImg !== undefined){
									if(oImg.src !== undefined){
										oImg.src = oImg.src.replace("off", "on");
									}
								}
							}
						}
					);
					Event.stopObserving(oElement, "mouseout");
					oElement.observe("mouseout",
						function(){
							oElement.removeClassName(sAddClassName);
							if(!(oElement.hasClassName("select"))){
								if($$("." + sClassName + " > img")){
									var oImg = oElement.firstDescendant();
									if(oImg !== null && oImg !== undefined){
										if(oImg.src !== undefined){
											oImg.src = oImg.src.replace("on", "off");
										}
									}
								}
							}
						}
					);
				}
			);
		}else{
			if($(sClassName)){
				Event.stopObserving($(sClassName), "mouseover");
				$(sClassName).observe("mouseover",
					function(){
						$(sClassName).addClassName(sAddClassName);
						if($$("." + sClassName + " > img")){
							var oImg = $(sClassName).firstDescendant();
							if(oImg !== null && oImg !== undefined){
								if(oImg.src !== undefined){
									oImg.src = oImg.src.replace("off", "on");
								}
							}
						}
					}
				);
				Event.stopObserving($(sClassName), "mouseout");
				$(sClassName).observe("mouseout",
					function(){
						$(sClassName).removeClassName(sAddClassName);
						if(!($(sClassName).hasClassName("select"))){
							if($$("." + sClassName + " > img")){
								var oImg = $(sClassName).firstDescendant();
								if(oImg !== null && oImg !== undefined){
									if(oImg.src !== undefined){
										oImg.src = oImg.src.replace("on", "off");
									}
								}
							}
						}
					}
				);
			}
		}
	}
});
