       $(function(){ 
            
           if ($('select[name=country_id]').length > 0) {
               updateProvinces();
               $('select[name=country_id]').change(function(){
                   updateProvinces();
               });
           }
           
           function updateProvinces() {
               var value = $('select[name=country_id]').val();
               $('select.provinces').not('[name=province'+value+']').parents('tr').hide();
               $('select.provinces[name=province'+value+']').parents('tr').show();
               
           }
           
           if ($('select[name=pay_vat]').length > 0) {
               updateDic();
               $('select[name=country_id], select[name=pay_vat]').change(function(){
                   updateDic();
               });
           }                      
           
           function updateDic() {
               var country = $('select[name=country_id]').val();
               var payVat = $('select[name=pay_vat]').val();
               
               if ((country == 1) || (country == 2 && payVat == 1))  {
                   
                   $('input[name=dic]').parents('tr').show();
                   
               }
               else {
                   $('input[name=dic]').parents('tr').hide();
               }
               
               if (country == 1) {
                   $('select[name=pay_vat]').parents('tr').hide();
               }
               else {
                   $('select[name=pay_vat]').parents('tr').show();
               }
               
           }           
           
           if ($('select[name=deliv_country_id]').length > 0) {
               updateDelivProvinces();
               $('select[name=deliv_country_id]').change(function(){
                   updateDelivProvinces();
               });
           }
           
           function updateDelivProvinces() {
               var value = $('select[name=deliv_country_id]').val();
               $('select.deliv_provinces').not('[name=deliv_province'+value+']').parents('tr').hide();
               $('select.deliv_provinces[name=deliv_province'+value+']').parents('tr').show();
               
           }           
           
       });    
