/**
 * Created by IOAN on 9/22/2015.
 */
$(document).ready(function(){
    $("#logo_image").fileinput({
        'showUpload':false,
        'showRemove':false,
        'allowedFileExtensions': ['jpg', 'jpeg', 'gif', 'png'],
        'allowedPreviewTypes':['image'],
        'allowedPreviewMimeTypes': ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png']
    });

    $('#dcode').on('change', function(){
        if($(this).val() != "") {
            var params = {
                'district': $(this).val(),
                'csurl': encodeURIComponent(full_uri + "amodules/common/ajax/locations_by_district.php")
            };
            $.ajax({
                url: baseurl + '/proxy.php',
                data: params,
                cache: false,
                type: 'post',
                dataType: 'json',
                success: function(r) {
                    if(typeof(r) !== undefined) {
                        $('#lcode').html('');
                        var locations = '<option value="" selected="selected">Please Select</option>';
                        $.each(r, function(i, ar){
                            locations += '<option value="'+ar.lcode+'">'+ar.location+'</option>';
                        });

                        $('#lcode').html(locations);
                    }


                }
            });
        }
        else {
            $('#lcode').html('');
            var locations = '<option value="" selected="selected">Please select</option>';
            $('#lcode').html(locations);
        }
    });
});