$(function(){
				//colorBox (ouvrir en popup)
				$(".popup").colorbox({width:300, height:250});
				
				// Datepicker
				$("#date_demenagement").datepicker({showOtherMonths: true, 
													selectOtherMonths: true, 
													dateFormat: 'dd/mm/yy', 
													dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
													monthNames: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
													nextText: 'Suivant',
													prevText: 'Précédent',
													showOn: 'both',
													buttonImage: '../../images/calendrier.jpg',
													buttonImageOnly: true,
													buttonText: 'Choisir la date du déménagement',
													minDate: 'd',
													showAnim: 'fadeIn'
													});  // fin date picker
				// Validation Formulaire									
				$('#contact').validationEngine({
												validationEventTriggers:"keyup blur",  //will validate on keyup and blur
												promptPosition: "topLeft" // OPENNING BOX POSITION, IMPLEMENTED: topLeft, topRight, bottomLeft,  centerRight, bottomRight
											})
				$('#devis_particuliers').validationEngine({
												validationEventTriggers:"keyup blur",  //will validate on keyup and blur
												promptPosition: "topLeft" // OPENNING BOX POSITION, IMPLEMENTED: topLeft, topRight, bottomLeft,  centerRight, bottomRight
											})	
				$('#devis_entreprises').validationEngine({
												validationEventTriggers:"keyup blur",  //will validate on keyup and blur
												promptPosition: "topLeft" // OPENNING BOX POSITION, IMPLEMENTED: topLeft, topRight, bottomLeft,  centerRight, bottomRight
											})
				// Fin validation formulaire
				
				// Affichage dialogue + bouton	
				$("#dialog").dialog("destroy");

		var name = $("#name"),
			email = $("#email"),
			password = $("#password"),
			password1 = $("#password1"),
			password2 = $("#password2"),
			checkbox = $("#checkbox"),
			allFields = $([]).add(name).add(email).add(password).add(password1).add(password2),
			tips = $(".validateTips");
		
		function updateTips(t) {
			tips
				.text(t)
				.addClass('ui-state-highlight');
			setTimeout(function() {
				tips.removeClass('ui-state-highlight', 1500);
			}, 500);
		}
		
		function checkLength(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips("La longueur du champs " + n + " doit être entre "+min+" et "+max+".");
				return false;
			} else {
				return true;
			}

		}
		
		function checkRegexp(o,regexp,n) {

			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}

		function checkboxSixe(groupname) {	
			if ( $("input[name='"+groupname+"']:checked").size() < 1 ) {
				checkbox.addClass('ui-state-error');
				updateTips("Veuillez choisir au moins une option.");
				return false;
			} else {
				return true;
			}
		}
		
		function verif() {
			var pass1 = $("input#password1").val();
			var pass2 = $("input#password2").val();
			if( pass1 != pass2 ){	
				updateTips("Les 2 champs ne sont pas identiques.");
				return false;
			} else{
				return true;
			}
		}
		/* ********** Choix option espace demenageur ********** */
		$("#option-form").dialog({
			autoOpen: false,
			height: 400,
			width: 800,
			modal: true,
			resizable: true,
			buttons: {
				Valider: function() {
					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkboxSixe("type_demenagement[]");
					bValid = bValid && checkboxSixe("departement[]");
					
					if (bValid) {
						document.options.submit();
						$(this).dialog('close');
					}
				},
				Annuler: function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});
		/* ********** FIN Choix option espace demenageur ********** */
		/* ********** Choix mot de passe espace demenageur ********** */
		$("#pass-form").dialog({
			autoOpen: false,
			height: 325,
			width: 350,
			modal: true,
			resizable: true,
			buttons: {
				Valider: function() {
					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(password1,"mot de passe",5,16);	
					bValid = bValid && checkLength(password2,"confirmation",5,16);				
					bValid = bValid && checkRegexp(password1,/^([0-9a-zA-Z])+$/,"Aucun caractère spécial n'est accepté");
					bValid = bValid && checkRegexp(password2,/^([0-9a-zA-Z])+$/,"Aucun caractère spécial n'est accepté");
					bValid = bValid && verif();
					
					if (bValid) {
						document.pass.submit();
						$(this).dialog('close');
					}
				},
				Annuler: function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});
		/* ********** Choix option espace demenageur ********** */
		/* ********** Login espace administrateur ********** */
		$("#admin-form").dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			resizable: false,
			buttons: {
				Valider: function() {
					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(name,"login",5,16);	
					bValid = bValid && checkLength(password,"mot de passe",5,16);	
					bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"Aucun caractère spécial n'est accepté");
					
					if (bValid) {
						document.admin.submit();
						$(this).dialog('close');
					}
				},
				Annuler: function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});
		
		$('#create-user')
			.button()
			.click(function() {
				$('#option-form').dialog('open');
			});
			
		$('#update-pass')
			.button()
			.click(function() {
				$('#pass-form').dialog('open');
			});
			
		$('#admin')
			.button({
            		icons: {
                	primary: 'ui-icon-locked'
            		},
            		text: false
        	})
			.click(function() {
				$('#admin-form').dialog('open');
			});
			
		$('#devis1').button();
		$('#devis2').button();
		$('#devis3').button();
		
		// Fin Affichage dialogue + bouton							
				
			});    // fin function principale
