
// fonction appelée au chargement du DOM :
jQuery(function() {

	// menu "vous proposez" :
	jQuery('#mcp-proposez').mouseenter(function() { jQuery('#mcp-proposez ul.menu').slideDown(); });
	jQuery('#mcp-proposez').mouseleave(function() { jQuery('#mcp-proposez ul.menu').slideUp(); });

	// alignement du fond du menu sélectionné (violet) sur chacun des boutons :
	var a = jQuery('#menu a');
	for (var i = 0; i < a.length; i++)
		a[i].style.backgroundPosition = '-' + a[i].offsetLeft + 'px -' + a[i].offsetTop + 'px';

	// calcul de la largeur du menu "outils" déplié :
	var cible = jQuery('#outils-buzz');
	if (cible.length) {
		cible.css('width', 'auto');
		outils_buzz_width = cible[0].clientWidth;
		cible.css('width', '1px');
	}
	
	// Accordéon moteurs de recherche
	jQuery("#col-droite .recherche .contenu").accordion({
    change: function(event, ui) { init_autocomplete(ui.newContent); }
  });
	if (typeof(moteur_accordion) != 'undefined')
		jQuery("#col-droite .recherche .contenu").accordion('activate', moteur_accordion);
  else
    init_autocomplete(document.getElementById('moteur_offres'));

});

function init_autocomplete(div) {
  jQuery(div).find("#moteur_offres_lieu, #moteur_residences_lieu").autocomplete({
	appendTo: div,
    minLength: 2,
    source: '/_SITE/PHP/AJAX/liste_villes_dept.ajax.php',
    focus: function(event, ui) { return false; }
  });
}

// fonctions pour déplier et replier le menu outils :
var outils_buzz_width;
function outils_deplier() {
	var cible = jQuery('#outils-buzz');
	var img = jQuery('#outils-deplier img');
	cible.animate({ width: outils_buzz_width + 'px' }, 500);
	img[0].style.display = 'none';
	img[1].style.display = 'block';
}
function outils_replier() {
	var cible = jQuery('#outils-buzz');
	var img = jQuery('#outils-deplier img');
	cible.animate({ width: '1px' }, 500);
	img[1].style.display = 'none';
	img[0].style.display = 'block';
}

function connexion_oubli(i) {

	jQuery('#connexion .contenu:visible').fadeOut();

	switch (i) {
		case 0:
			jQuery('#connexion-form').fadeIn();
			break;
		case 1:
			jQuery('#connexion-oubli').fadeIn();
			break;
		case 2:
			jQuery('#connexion-oubli2').fadeIn();
			break;
		case 3:
			jQuery('#connexion-oubli3').fadeIn();
			break;
	}

}

// envoi du mot de passe par mail :
function connexion_envoi_password() {
	var email = jQuery("#connexion-oubli input[name='email']").val();
	var url = '/_SITE/PHP/AJAX/connexion_mail_password.ajax.php';
	var data = {
		email:	email
	};
	jQuery.get(url, data, function(data) {
		if (parseInt(data))
			connexion_oubli(2);
		else
			connexion_oubli(3);
	});
}




function check_tel(value) {

	return (value.match('^[0-9\+\ \-\.\(\)]*$') != null);
	
}
function uniqid() {
var now = new Date;
return now.getTime().toString(36);
} 

