
$(function() {
	// Use this example, or...
	//$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
	// This, or...
	//$('#gallery a').lightBox(); // Select all links in object with gallery ID
	// This, or...
	$('a.lightbox').lightBox(); // Select all links with lightbox class
	// This, or...
	//$('a').lightBox(); // Select all links in the page
	// ... The possibility are many. Use your creative or choose one in the examples above
});


function addPanier(url, idadherent, idannonce)
{
	$.ajax(
	{
		url: url + '/panier/panier-add',
		type: 'post',
		data: 'idadherent=' + idadherent + '&idannonce=' + idannonce,
		success: function(msg)
		{
			if (msg != '') {
				alert('Problème : ' + msg);
			}
			else {
				alert('L\'annonce a bien été ajoutée');
			}
		},
		error: function(msg)
		{
			alert('Erreur : ' + msg);
		}
	});
}

function MiseEnRelation(url, idadherent, idannonce)
{
	
	$.ajax(
	{
		url: url + '/panier/mise-en-relation',
		type: 'post',
		data: 'idadherent=' + idadherent + '&idannonce=' + idannonce,
		success: function(msg)
		{
			if (msg != '') {
				alert('Problème : ' + msg);
			}
			else {
				alert('Votre demande de mise en relation a bien été envoyée.');
			}
		},
		error: function(msg)
		{
			alert('Erreur : ' + msg);
		}
	});
}

/**
 * Mise En Forme d'une <table>, les titres sont dans des balises <thead><tr><th>...</th></tr></thead> et ensuite <tbody>...</tbody>
 * @author Fabien Mercier
 * @since 06/12/08
 * @param ligne_paire string : couleur des lignes paires
 * @param ligne_impaire string : couleur des lignes impaires
 * @param surlignage string : couleur du surlignage avec la souris
 * @param exclue string : pour éviter d'appliquer les actions sur le tr voulu (avec une class)
 * ex: $('#liste_annonce > tbody > tr').skinTable('#F6F6F6', '#EFEFEF', '#FFFFFF', '');
 */
$.fn.skinTable = function(ligne_paire, ligne_impaire, surlignage, exclue) {
	this.each(function(index) {
		if (exclue == '' || $(this).attr('class') != exclue) {
			$(this).css({
				backgroundColor: (index % 2) ? ligne_impaire : ligne_paire
			});
			$(this).mouseover( function()
			{
				$(this).css({
					backgroundColor: surlignage,
					color: '#016FA2'
				});
			});
			$(this).mouseout( function()
			{
				$(this).css({
					backgroundColor: (index % 2) ? ligne_impaire : ligne_paire,
					color: ''
				});
			});
		}
	})
};

$(function()
{

	$('#partenaire_image').cycle('fade');

	$('#v2_pulldownmenu').droppy();

// PARTIE HEADER
	$('#haut4').toggle(
		function(){
			$('#form_login').slideDown('normal');
		},
		function(){
			$('#form_login').slideUp('normal');
		}
	);

		$('#Login').focus(function() {
			if ($(this).val() == 'Identifiant') {
				$(this).val('');
			}
		})
		.blur(function() {
			if ($(this).val() == '') {
				$(this).val('Identifiant');
			}
		});

		$('#Password').focus(function() {
			if ($(this).val() == 'Mot de passe') {
				$(this).val('');
			}
		})
		.blur(function() {
			if ($(this).val() == '') {
				$(this).val('Mot de passe');
			}
		});

	$('#form_login').submit(function() {
		if ($('#Login').val() == '' && $('#Password').val() == '') {
			alert('Vous devez entrer votre login et mot de passe.');
			$('#Login').focus();
			return false;
		}
		return true;
	});

	/*$('#haut5').toggle(
		function(){
			$('#profil').slideDown('normal');
		},
		function(){
			$('#profil').slideUp('normal');
		}
	);*/
	$('#hoverCompte').bind('mouseleave',
		function(){
			$('#profil').slideUp('normal');
		}
	);
	$('#hoverCompte').bind('mouseenter',
		function(){
			$('#profil').slideDown('normal');
		}
	);
	

// PARTIE RECHERCHE AVANCEE
	$('#cedant').click(function() {
		if ($('#recherche_repreneur').css('display') != 'none') {
			$('#recherche_repreneur').css({display: 'none'})
		}
		$('#recherche_cedant').show('slide', { direction: 'up' }, 500);
	});

	$('#repreneur').click(function() {
		if ($('#recherche_cedant').css('display') != 'none') {
			$('#recherche_cedant').css({display: 'none'})
		}
		$('#recherche_repreneur').show('slide', { direction: 'up' }, 500);
	});

	
	$('#cedant_all, #repreneur_all').click(function() {
		var reg = new RegExp('_', 'g');
		var name = $(this).attr('name').split(reg);

		if ($(this).attr('checked') == true) {
			for (i = 1; i < 36; i++) {
				$('#' + name[0] + '_' + i).attr('disabled', 'disabled');
				$('#' + name[0] + '_' + i).attr('checked', false);
			}
		}
		else {
			for (i = 1; i < 36; i++) {
				$('#' + name[0] + '_' + i).removeAttr('disabled');
			}
		}
	});

	$('#cedant_35, #repreneur_35').click(function() {
		var reg = new RegExp('_', 'g');
		var name = $(this).attr('name').split(reg);

		if ($(this).attr('checked') == true) {
			for (i = 1; i < 14; i++) {
				$('#' + name[0] + '_' + i).attr('disabled', 'disabled');
				$('#' + name[0] + '_' + i).attr('checked', false);
			}
		}
		else {
			for (i = 1; i < 14; i++) {
				$('#' + name[0] + '_' + i).removeAttr('disabled');
			}
		}
	});

	$('#cedant_34, #repreneur_34').click(function() {
		var reg = new RegExp('_', 'g');
		var name = $(this).attr('name').split(reg);

		if ($(this).attr('checked') == true) {
			for (i = 14; i < 24; i++) {
				$('#' + name[0] + '_' + i).attr('disabled', 'disabled');
				$('#' + name[0] + '_' + i).attr('checked', false);
			}
		}
		else {
			for (i = 14; i < 24; i++) {
				$('#' + name[0] + '_' + i).removeAttr('disabled');
			}
		}
	});

	$('#cedant_33, #repreneur_33').click(function() {
		var reg = new RegExp('_', 'g');
		var name = $(this).attr('name').split(reg);

		if ($(this).attr('checked') == true) {
			for (i = 24; i < 33; i++) {
				$('#' + name[0] + '_' + i).attr('disabled', 'disabled');
				$('#' + name[0] + '_' + i).attr('checked', false);
			}
		}
		else {
			for (i = 24; i < 33; i++) {
				$('#' + name[0] + '_' + i).removeAttr('disabled');
			}
		}
	});

	$('#recherche_reference').submit(function() {
		var reg = new RegExp('^[0-9]{1,2}[CRcr][0-9]{1,}$');
		if ($('#reference').val() == '' || !reg.test($('#reference').val())) {
			$('#erreur_reference').html('Cette référence n\'existe pas.');
			return false;
		}else{
			$('#erreur_reference').html('&nbsp;');
		}
	});
});
/*
$(document).ready(function() {
  $('.accordeon').hide(); // on cache tous les textes (blocs ayant la classe accordeon)
  $('h2.liste_folder').click(function() { // si on clique sur un titre (ici tous les éléments contenu en les balises h2)
	if($(this).hasClass("on")){
		$('h2').removeClass("on");
		 $('.accordeon').hide(); // on deroule le div caché qui suit directement le titre
	}else{
		$('h2').removeClass("on");
		$(this).next('div:hidden').slideDown() // on deroule le div caché qui suit directement le titre
		.siblings('div:visible').slideUp(); // et on cache les div similaires qui etait visible
		$(this).addClass("on");
	}
  });
   
});
*/

//Verification du formulaire form_profil
function verif_profil(){
		var msg_err ="";
		var RegCp = new RegExp("^([0-9]{5})$");
		var RegEmail = new RegExp("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,3}");
		if(document.getElementById('nom').value==""){
			msg_err +="Le Champ Nom est obligatoire.\n";
		}
		if(document.getElementById('prenom').value==""){
			msg_err +="Le Champ Prénom est obligatoire.\n";
		}
		if(document.getElementById('code_postal').value==""){
			msg_err +="Le Champ Code Postal est obligatoire.\n";
		}else{
			if(!RegCp.test(document.getElementById('code_postal').value))   {
				msg_err += "Le Champ Code Postal doit être constitué de 5 chiffres. \n";
			}
		}
		if(document.getElementById('ville').value==""){
			msg_err +="Le Champ Ville est obligatoire.\n";
		}
		if(document.getElementById('telephone_bureau').value=="" && document.getElementById('telephone_domicile').value=="" && document.getElementById('telephone_mobile').value==""){
			msg_err += "Vous devez renseigner au moins l'un des 3 numéros de téléphones. \n";
		}
		if(document.getElementById('email').value==""){
			msg_err +="Le Champ Email est obligatoire.\n";
		}else{
			if(!RegEmail.test(document.getElementById('email').value)){
				msg_err += "Le format du Champ email n'est pas valide.";
			}
		}
		if(msg_err!=""){
			alert(msg_err);
			return false;
		}else{
			return true;
		}
		
}

