$(document).ready(function(){
    $('.toggle').click(function() { 
        $(this).closest('.main-nav').toggleClass( "menu-active" );
        $('.backdrop').show();
    });
    $('.backdrop').click(function() {
        $('.main-nav').removeClass( "menu-active" );
        $(this).hide(); 
    });
    $(window).resize(function(){
        $('.main-nav').removeClass( "menu-active" );
     });
    
    $("#country").change(function () {        
        var id = $("#country").val();
        // Intially load the Location option alone in the Region Dropdown
        var html = '';
        var i;
        var location_text = lang['country'];
        html += '<option value="">'+location_text+'</option>';
        $('#region').html(html);
        
        $.ajax({
            url : application.url+'region/list/'+id+'/'+true,
            method : "GET",
            async : true,
            dataType : 'json',
            success: function(data){
                var html = '';
                var i;
                var location_text = lang['country'];
                html += '<option value="">'+location_text+'</option>';
                for(i=0; i<data.length; i++){
                    html += '<option value='+data[i].region_id+'>'+data[i].name+'</option>';
                }
                $('#region').html(html);

            }
        });
        return false;
    });
})
