siteTools = Class.create(communTools,{

	initLanguage : function () {
		$$(".languages img.btn").each(
			function (oElement) {
				oElement.observe("click",
					function (){
						var aInfos = oElement.id.split("|");
						this.ajaxRequest("init.php", "iAction=1&sAction="+aInfos[1]+"&iIdLanguage="+aInfos[2]);

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

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

		$(sForm).observe('submit', function(){
			console.debug(this.bWait);
			if(!this.bWait){
				this.bWait = true;
				this.closeMessage(sForm+"Msg");
				var sQuery = "iAction="+parseInt($F('iAction_'+sForm));
				var oForm = $(sForm).serialize(true);
				for (var sProperty in oForm) {
					if($(sProperty) && sProperty != "iAction_"+sForm){
						if($(sProperty).hasClassName("mandatory")){
							if ($F(sProperty) === "") {
								this.setMessage(sForm+"Msg", "error", aOptions.sFieldEmpty, {sLabel:this.getLabel(sProperty),sField:sProperty});
								return false;
							}else{
								if(!this.checkField(sProperty)){
									this.setMessage(sForm+"Msg", "error", aOptions.sFieldError, {sLabel:this.getLabel(sProperty),sField:sProperty});
									return false;
								}
							}
							$(sProperty).removeClassName("fieldError");
						}else{
							if ($F(sProperty) !== "") {
								if(!this.checkField(sProperty)){
									this.setMessage(sForm+"Msg", "error", aOptions.sFieldError, {sLabel:this.getLabel(sProperty),sField:sProperty});
									return false;
								}
							}
							$(sProperty).removeClassName("fieldError");
						}

						if(sProperty.match("sPassword")){
							$(sProperty).value = SHA1($F(sProperty));
						}
						sQuery += "&"+sProperty+"="+encodeURIComponent($F(sProperty));
					}
				}
				var oRequest = this.ajaxRequest("init.php",
												sQuery,
												"var oTools = new siteTools();oTools.setMessage('"+sForm+"Msg', 'success', oResult.sText);$('"+sForm+"').reset();oTools.closeMessageAfter('"+sForm+"Msg', 5);oTools.bWait=false;",
												"var oTools = new siteTools();oTools.setMessage('"+sForm+"Msg', 'error', oResult.sText);"
				);
			}
		}.bind(this));
	},

	initLogout : function () {
		$('logout').observe("click",
			function (){
				this.ajaxRequest("init.php", "iAction=4", "document.location.href='index.php'");
			}.bindAsEventListener(this)
		);
	},

	initSlideNavigations : function () {
		$$('ul.slideNav li').each(
			function (oNavigation) {
				oNavigation.observe("mouseover",
					function () {
						$$('.slideNavHover').each(
							function (oCurrentNav){
								oCurrentNav.removeClassName("slideNavHover");
								//new Effect.Fade(oCurrentNav);
								oCurrentNav.hide();
							}
						);

						var aInfos = oNavigation.id.split("|");
						if($('subNav|'+aInfos[1])){
							$('subNav|'+aInfos[1]).addClassName("slideNavHover");
							$('subNav|'+aInfos[1]).clonePosition(oNavigation, {offsetTop:30, setWidth:false, setHeight:false});
							//new Effect.Appear($('subNav|'+aInfos[1]));
							$('subNav|'+aInfos[1]).show();
							$('subNav|'+aInfos[1]).observe("mouseout",
								function () {
									$('subNav|'+aInfos[1]).hide();
								}
							);
						}
					}
				);

				/*
				oNavigation.observe("mouseout",
					function () {
						var aInfos = oNavigation.id.split("|");
						if($('subNav|'+aInfos[1])){
							new Effect.Fade($('subNav|'+aInfos[1]), { duration: 1});
						}
					}
				);
				*/
			}
		);
	}
});

