
$(function () {


   $("#city").change(function(){
       var city=$(this).children(":selected").attr("id");
       $.get("ajax/AJXpharmaciesByCity.php?city="+city, function(data){
           $('#pharmacy').html('<option id="0"></option>');
           $('#pharmacy').append(data);
           $('#report').html('');
       });
   });


    $(document).on('change','#region',function(){
        var regionId=$(this).children(":selected").attr("id");
        $.get("ajax/AJXprovincesByRegion.php?rId="+regionId, function(data){
            $('#province').html('<option id="0"></option>');
            $('#province').append(data);
        });
    });


    $("#pharmacy").change(function(){
        var id=$(this).children(":selected").attr("id");
        if(id==0){
            $('#report').html('');
        }
        else if(id==999){
            $("#addpharmacie")[0].click();
        }
        else {
            $.get("ajax/AJXpharmacy.php?id=" + id, function (data) {
                $('#responsable').val('');
                $('#report').html(data);
            });
        }
    });

    $(document).on('click','#valider',function(){

        var pharmacy=$("#pharmacy").children(":selected").attr("id");
        var responsable =$("#responsable").val();
        var email = $("#email").val();
        var tel = $("#tel").val();
        var province = $("#province").children(":selected").attr("id");

        $.get("ajax/AJXupdatePharmacy.php?pharmacy="+pharmacy+"&responsable="+responsable+"&email="+email+"&tel="+tel+"&province="+province, function (data) {

            $("#search").css('display','none');
            $("#questions").css('display','block');

        });
    });

    $(document).on('click','#savepharmacie',function(){

        var name=$("#newpharma").val();
        var city=$("#city").children(":selected").attr("id");
        $.get("ajax/AJXaddPharmacy.php?name="+name+"&city="+city, function (data) {

            $("#annuler")[0].click();
          //  $('#pharmacy').find('option[id=data]').attr("selected",true);

        });





    });


    $('#modal-default').on('hidden.bs.modal', function () {
        var city=$("#city").children(":selected").attr("id");
        $.get("ajax/AJXpharmaciesByCity.php?city="+city, function(data){
            $('#pharmacy').html('<option id="0"></option>');
            $('#pharmacy').append(data);
            $('#report').html('');
        });
    })



});

