/**
 *  Feuille de scripts Ajax (jQuery) pour la récupérations de pays, départements et villes
 */

/**
 *  Récupération des départements
 */
function getDepartements(pays_id, type_villes, script_url)
{
    $.post(
        '/script/ajax/localisation/getDepartements',
        { pays_id: pays_id, type_villes: type_villes },
        function(data){
            $('#departements').html(data);
        });
}




/**
 *  Récupération des villes
 */
function getVilles(departement_id, pays_id)
{
    $.post(
        '/script/ajax/localisation/getVilles',
        { departement_id: departement_id, pays_id: pays_id },
        function(data){
            $('#villes').html(data);
        });
}




/**
 *  Modification de l'état du champ ville pendant la recherche des villes
 */
function onChangeDepartement(select_ville)
{
    $(select_ville).html('Chargement...');
}




/**
 *  Modification du libellé "Département" selon le type de pays sélectionné
 */
function onChangePays(select_departement, select_ville, label_departement, pays_id)
{
    $(select_departement).html('Chargement...');

    switch(pays_id)
    {
        case '2':
            $('#'+label_departement).html('Province :');
            $('#'+select_ville).html('- Choisir une province -');
            break;

        case '3':
            $('#'+label_departement).html('Canton :');
            $('#'+select_ville).html('- Choisir un canton -');
            break;

        case '4':
            $('#'+label_departement).html('R&eacute;gion :');
            $('#'+select_ville).html('- Choisir une r&eacute;gion -');
            break;

        case '5':
            $('#'+label_departement).html('District :');
            $('#'+select_ville).html('- Choisir un district -');
            break;

        case '6':
            $('#'+label_departement).html('Gouvernorat :');
            $('#'+select_ville).html('- Choisir un gouvernorat -');
            break;

        case '7':
            $('#'+label_departement).html('R&eacute;gion :');
            $('#'+select_ville).html('- Choisir une r&eacute;gion -');
            break;

        case '8':
            $('#'+label_departement).html('Wilaya :');
            $('#'+select_ville).html('- Choisir une wilaya -');
            break;

        default:
            $('#'+label_departement).html('D&eacute;partement :');
            $('#'+select_ville).html('- Choisir un d&eacute;partement -');
    }
}

