


optionnal = {
	status:true,
	toggle : function(lng)  {
		var iLabel=$('#hideFields').html();

		if(this.status==true){
			this.status=false;

			$(".hideIt").slideUp();
		} else {
			this.status=true;
            $(".hideIt").slideDown();
		}
	}
}

valid = {

	init : function(lng, frmId)  {

		var vA=valid.emptyInput(lng,frmId);
		var vB=valid.emptyEmail(lng,frmId);
		var vC=valid.emptyTel(lng,frmId);

		if(vA && vB && vC){
			return true;
		}
		return valid.finall();

	},

	emptyInput : function(lng, frmId)  {

		var isError=false;

		emptyCountMax = $('#'+frmId+" .validEmpty").size();

		$('label').css("color","black"); // put back the normal color
		$(".emptyInputError").css({ display:"none"}); // Each time syou start the script it disable error display, so when you push the button a seoncd time , you have only the new error of your form
		$(".validForm").css({ display:"none"});

		for (i=0; i < emptyCountMax; i++) {

			if($('#'+frmId+' .validEmpty').eq(i).attr('value') == undefined){
				$('#'+frmId+' .validEmpty').eq(i).parent().find(".emptyInputError").css({ display:"block"});
				$(".validForm").css({ display:"block"});
				var errMess=$('#'+frmId+' .validEmpty').eq(i).parent().find(".emptyInputError");

				if(errMess.length == 0){
					divError = document.createElement('div')

					//namee = $('.validEmpty').eq(i).attr('name');

					var iLabel=$('#'+frmId+' .validEmpty').eq(i).parent().children('span:first').html();//le label du champ
					//enlève le : du label
					iLabel=iLabel.replace(':','');
					//alert(iLabel);

					$(divError).addClass('emptyInputError');
					$(divError).addClass('error');
					if(lng=='f'){
						$(divError).html("Le champ <i>"+iLabel+"</i> est requis");
					} else {
						$(divError).html("The field <i>"+iLabel+"</i> is mandatory");
					}
					$('#'+frmId+' .validEmpty').eq(i).parent().css("color","red");
					$('#formError').append(divError);
					// $('.validEmpty').eq(i).parent().append(divError) Append dans le parent du input
					//$('.validEmpty').eq(i).parent().css("color","red");
					$(divError).css({ display:"block",color:"red", clear:"both"});
				}
				isError=true;//valid.finall();
			}
		}
		return !isError;
	},

	emptyEmail : function(lng, frmId)  {
		var isError=false;
		emptyCountMax = $('#'+frmId+" .validEmail").size();
		$(".validEmailError").css({ display:"none"});
		$(".validForm").css({ display:"none"});
		var filter  = /^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/;
		for (i=0; i < emptyCountMax; i++) {


			var thisMail=$('#'+frmId+' .validEmail').eq(i).attr('value');
			//alert(thisMail);
			if(!filter.test(thisMail)){

				$('#'+frmId+' .validEmail').eq(i).parent().find(".validEmailError").css({ display:"block"})
				$(".validForm").css({ display:"block"})
				var errMess=$('#'+frmId+' .validEmail').eq(i).parent().find(".validEmailError");

				if(errMess.length == 0){

					divError = document.createElement('div');

					$(divError).addClass('validEmailError');
					$(divError).addClass('error');
                    if(lng=='f'){
						$(divError).text("* Adresse courriel non valide");
					}else {
						$(divError).text("* Invalid email address");
					}
					$('#'+frmId+' .validEmail').eq(i).parent().css("color","red");
					$('#formError').append(divError);//$('.validEmail').eq(i).parent().append(divError);
					//$('.validEmail').eq(i).parent().css("color","red");
					$(divError).css({ display:"block",color:"red"});
				}
				 isError=true;// valid.finall()
			}
		}
		return !isError;
	},

	emptyTel : function(lng, frmId)  {
		var isError=false;
		emptyCountMax = $('#'+frmId+" .validTel").size()
		$(".validTelError").css({ display:"none"})
		$(".validForm").css({ display:"none"})

		for (i=0; i < emptyCountMax; i++) {

			var filter  = /^[0-9\-\(\)]+$/;

			if(!filter.test($('#'+frmId+' .validTel').eq(i).attr('value'))){
				$('#'+frmId+' .validTel').eq(i).parent().find(".validTelError").css({ display:"block"})
				var errMess=$('#'+frmId+' .validTel').eq(i).parent().find(".validTelError");
				$(".validForm").css({ display:"block"})
				if(errMess.length == 0){

					divError = document.createElement('div')

					$(divError).addClass('validTelError');
					$(divError).addClass('error');
					if(lng=='f'){
						$(divError).text("* Téléphone non valide");
					}else {
						$(divError).text("* Invalid phone number");
					}
					$('#formError').append(divError);///$('.validTel').eq(i).parent().append(divError);
					$('#'+frmId+' .validTel').eq(i).parent().css("color","red");
					$(divError).css({ display:"block",color:"red"});
				}
				isError=true;//valid.finall();
			}
		}
		return !isError;
	},

	finall : function()  {
		topOffset = $(".error").eq(0).offset().top;
		$('html,body').animate({scrollTop:topOffset},'slow');
		return false;
	}
}


//*************************************************************************************
//*************************************************************************************
//*************************************************************************************
//validation du form de reservation (qui peut se retrouver potentiellement sur toutes les pages)

function validateReserv(lng){

	//y-a-t-il une date?
	var d=$('#calend').val();

	//la date doit etre au format 00/00/0000
	isDate=d.match(/\d{1,2}\/\d{1,2}\/\d{4}/);
	if(!isDate){
		if(lng=='f'){
			alert('Veuillez spécifier une date');
		} else {
            alert('Please enter a date');
		}
		$('#calend').focus();
		return false;
	}

	var promoCode = $('#rateCode').val();
	promoCode = promoCode.replace(/^\s+|\s+$/g, "");

	var bkp = $('#rateCode').clone();
	if ('' == promoCode || 'Inscrire votre code ici' == promoCode || 'Write your code here' == promoCode) {
		$('#rateCode').remove();
		setTimeout(function() {
			bkp.appendTo('label.promoCode');
		}, 100);
	}
}

