function ajax_maj_sous_famille(value, el, form)
{
    (function($){
        alea = Math.round(Math.random() * 10000);

        uniquementFamille = 0;
        if(value == "") {
            uniquementFamille = 1;
        }

        // appel ajax
        $.ajax({
            type: "POST",
            url: "ajax-recup-sousfamilles.php",
            data: "parent_id=" + value + "&uniquementFamille=" + uniquementFamille + "&nocache=" + alea,
            dataType: "xml",
            success: function(xml){
                $(xml).find('sousfamilles').each(function()
                {
                    //console.log($("form[name=" + form + "] #" + el));
                    // init select
                    $("form[name=" + form + "] #" + el).empty();
                    $("form[name=" + form + "] #" + el).append('<option value="">Sous-famille</option>');

                    $(xml).find('sousfamille').each(function()
                    {
                        $("form[name=" + form + "] #" + el).append(
                            '<option value="' + $(this).find('familles_id').text() + '">' + $(this).find('familles_name').text() + '</option>'
                            );
                    });

                });
            }

        });
    })(jQuery)
}

function ajax_maj_date(value, elt){
    (function($){
        // appel ajax
        $.ajax({
            type: "POST",
            url: "ajax-recup-date-recherche.php",
            data: {
                parent_id: value
            },
            dataType: "json",
            success: function(response){
                var filtre_date = $(elt);
                filtre_date.find('option[value!=""]').remove();
                for(var i=0;i <  response.length;i++){
                    filtre_date.append('<option value="'+response[i].date_activite+'">'+response[i].date_fr+'</option>');
                }
            }

        });
    })(jQuery);
}

function ajax_maj_lieu(value, elt){
    (function($){
        // appel ajax
        $.ajax({
            type: "POST",
            url: "ajax-recup-lieu-recherche.php",
            data: {
                parent_id: value
            },
            dataType: "json",
            success: function(response){
                var filtre_lieu = $(elt);
                filtre_lieu.find('option[value!=""]').remove();
                for(var i=0;i <  response.length;i++){
                    filtre_lieu.append('<option value="'+response[i].lieux_id+'">'+response[i].lieux_name+'</option>');
                }
            }

        });
    })(jQuery);
}


function afficher_video(state, url_site, video)
{
    (function($){
        if(state) {
	
            $("#slider").hide();
            $("#controls").hide();
		
            var flashvars = {
                url_video: url_site + "images/videos/" + encodeURI(video),
                id_player: 'visionneuse_video'
            };
            var params = {
                menu: "false",
                wmode: "transparent",
                scale: "noscale",
                align: "left",
                salign: "lt"
            };
            var attributes = {
            };
            swfobject.embedSWF(url_site + 'images/video.swf',
                'visionneuse_video', '716', '366', '10', 'expressInstall.swf', flashvars, params, attributes); 
	
        } else {
            $("#slider").show();
            $("#controls").show();
		
            $("#visionneuse_video").hide();
        }
    })(jQuery)
}

function changer_taille_video(id_video,largeur,hauteur){
    document.getElementById(id_video).style.width=largeur+"px";
    document.getElementById(id_video).style.height=hauteur+"px";
}

function show_search_avdanced(){
    (function($){
        $(".recherche-avancee-nav").toggle();
    })(jQuery)
}

function check_form_password_forgotten(form_name)
{
	error = false;
	form = form_name;
	error_message = "Veuillez compléter les champs suivants :\n\n";

	check_input("email_address", 1, "- Votre adresse email\n");
	if(form_name.email_address.value != "") {
		check_input_email("email_address", "- Votre adresse email n'est pas valide\n");
	}

	if (error == true) {
		alert(error_message);
		return false;
	} else {
		submitted = true;
		return true;
	}
}

function check_form_identification(form_name)
{
	error = false;
	form = form_name;
	error_message = "Veuillez compléter les champs suivants :\n\n";

	check_input("login", 1, "- Votre login\n");
	check_input("password", 1, "- Votre mot de passe\n");

	if (error == true) {
		alert(error_message);
		return false;
	} else {
		submitted = true;
		return true;
	}
}

function check_form_creation_compte(form_name)
{
	error = false;
	form = form_name;
	error_message = "Veuillez compléter les champs suivants :\n\n";

	check_radio("gender", "- Votre civilité\n");
	check_input("lastname", 1, "- Votre nom\n");
	check_input("firstname", 1, "- Votre prénom\n");
	check_date("jour", "mois", "annee", "- Votre date de naissance");
	check_input("email_address", 1, "- Votre adresse email\n");
	if(form_name.email_address.value != "") {
		check_input_email("email_address", "- Votre adresse email n'est pas valide\n");
	}
	check_radio("type", "- Votre type\n");
	check_input("street_address", 1, "- Votre adresse\n");
	check_input("postcode", 1, "- Votre code postal\n");
	check_input("city", 1, "- Votre ville\n");
	check_input("country", 1, "- Votre pays\n");
	check_input("telephone", 1, "- Votre téléphone principal\n");
	check_input("login", 1, "- Votre identifiant\n");
	check_input("password", 1, "- Votre mot de passe\n");
	check_input("confirmation", 1, "- Votre confirmation de mot de passe\n");
        check_radio('newsletter', '- Inscription à la Newsletter\n');
	
	if(form_name.password.value != form_name.confirmation.value) {
		error = true;
		error_message = error_message + "- Votre mot de passe et votre confirmation de mot de passe doivent être les mêmes\n";
	}

	if (error == true) {
		alert(error_message);
		return false;
	} else {
		submitted = true;
		return true;
	}
}

function check_form_edition_compte(form_name)
{
	error = false;
	form = form_name;
	error_message = "Veuillez compléter les champs suivants :\n\n";

	check_radio("gender", "- Votre civilité\n");
	check_input("lastname", 1, "- Votre nom\n");
	check_input("firstname", 1, "- Votre prénom\n");
	check_date("jour", "mois", "annee", "- Votre date de naissance");
	check_input("email_address", 1, "- Votre adresse email\n");
	if(form_name.email_address.value != "") {
		check_input_email("email_address", "- Votre adresse email n'est pas valide\n");
	}
	check_radio("type", "- Votre type\n");
	check_input("street_address", 1, "- Votre adresse\n");
	check_input("postcode", 1, "- Votre code postal\n");
	check_input("city", 1, "- Votre ville\n");
	check_input("country", 1, "- Votre pays\n");
	check_input("telephone", 1, "- Votre téléphone\n");
	
	if(form_name.login.value != "" && form_name.password.value != "" && form_name.confirmation.value != "") {
		
		if(form_name.password.value != form_name.confirmation.value) {
			error = true;
			error_message = error_message + "- Votre mot de passe et votre confirmation de mot de passe doivent être les mêmes\n";
		}
		
	}
	
	if (error == true) {
		alert(error_message);
		return false;
	} else {
		submitted = true;
		return true;
	}
}

function check_form_commande_coordonnees(form_name)
{
	error = false;
	form = form_name;
	error_message = "Veuillez compléter les champs suivants :\n\n";

	check_radio("gender", "- Votre civilité\n");
	check_input("lastname", 1, "- Votre nom\n");
	check_input("firstname", 1, "- Votre prénom\n");
	check_input("email_address", 1, "- Votre adresse email\n");
	if(form_name.email_address.value != "") {
		check_input_email("email_address", "- Votre adresse email n'est pas valide\n");
	}
	check_radio("type", "- Votre type\n");
	check_input("street_address", 1, "- Votre adresse\n");
	check_input("postcode", 1, "- Votre code postal\n");
	check_input("city", 1, "- Votre ville\n");
	check_input("country", 1, "- Votre pays\n");
	check_input("telephone", 1, "- Votre téléphone\n");
	
	if (error == true) {
		alert(error_message);
		return false;
	} else {
		submitted = true;
		return true;
	}
}

function check_form_commande_paiement(form_name)
{
	error = false;
	form = form_name;
	error_message = "Veuillez compléter les champs suivants :\n\n";

	check_radio("payment", "- Votre mode de paiement\n");
	
	if(valeurradio(form_name.payment) == 'moneyorder') {
		check_input("chq_num", 1, "- Votre numéro de chèque\n");
		check_input("chq_banque", 1, "- Votre banque\n");
	}
	
	
	if (error == true) {
		alert(error_message);
		return false;
	} else {
		submitted = true;
		return true;
	}
}

function check_form_commande_recapitulatif(form_name)
{
	error = false;
	form = form_name;
	error_message = "";

	check_checkbox("conditions", "Veuillez accepter les conditions générales de ventes\n");
	
	if (error == true) {
		alert(error_message);
		return false;
	} else {
		submitted = true;
		return true;
	}
}

function raz_recherche_avancee(position){
    (function(){
        if(position == 'top'){
            var form_rech = $('#recherche_activite_top');
            
            form_rech.find('#filter-niveau').val('');
            form_rech.find('#filter-moyen').val('');
            form_rech.find('input[name="filter[motcle]"]').val('');
            form_rech.find('input[name="filter[code]"]').val('');
            form_rech.find('#filter-guide').get(0).checked = false;
            form_rech.find('#filter-handicap').get(0).checked = false;
            
        } else {
            var form_rech = $('#recherche_activite_left').val('');
            form_rech.find('#filter-niveau-left').val('');
            form_rech.find('#filter-moyen-left').val('');
            form_rech.find('input[name="filter[motcle]"]').val('');
            form_rech.find('input[name="filter[code]"]').val('');
            form_rech.find('#filter-guide-left').get(0).checked = false;
            form_rech.find('#filter-handicap-left').get(0).checked = false;
        }
    })(jQuery)
}
