 var base_url='http://auto.e-inzert.cz/';
 var etax_js_change = false;
 
$(document).ready(function() {
    
    $('#makes_opener').click(function() {
      $('#makes_opener').toggle(); 
      $('#makes_hide').toggle(); 
      $('#makes_closer').toggle(); 
      
   });
   
   $('#makes_closer').click(function() {
      $('#makes_hide').toggle(); 
      $('#makes_opener').toggle(); 
      $('#makes_closer').toggle(); 
   });
   
   $('#equip_other_opener').click(function() {
      $('#equip_other_opener').toggle(); 
      $('#equip_other').toggle(); 
      $('#equip_other_closer').toggle(); 
      
   });
   
   $('#equip_other_closer').click(function() {
      $('#equip_other_closer').toggle(); 
      $('#equip_other').toggle(); 
      $('#equip_other_opener').toggle();    
   });
   
   //otevirani vybavy na detailu vozidla
   $('#all_equip_opener').click(function() {
      $('#all_equip_opener').toggle(); 
      $('#all_equip').toggle(); 
      $('#all_equip_closer').toggle(); 
      
   });
   
   $('#all_equip_closer').click(function() {
      $('#all_equip_closer').toggle(); 
      $('#all_equip').toggle(); 
      $('#all_equip_opener').toggle();    
   });
   // END - otevirani vybavy na detailu vozidla
   
   $('#carBodies_opener').click(function() {
      $('#carBodies_opener').toggle(); 
      $('#carBodies_hide').toggle(); 
      $('#carBodies_closer').toggle(); 
      
   });
   
   
   //Otevirani vsech znacek
   $('#hidden_make_opener').click(function() {
      $('#hidden_make_opener').hide(); 
      $('#hidden_make').show(); 
      $('#hidden_make_closer').show(); 
   });
   
    $('#hidden_make_closer').click(function() {
      $('#hidden_make_closer').hide(); 
      $('#hidden_make').hide(); 
      $('#hidden_make_opener').show(); 
   });
   //END otevirani vsech znacek
   
   
   $('#carBodies_opener').click(function() {
      $('#carBodies_opener').toggle(); 
      $('#carBodies_hide').toggle(); 
      $('#carBodies_closer').toggle(); 
      
   });
   
   $('#carBodies_closer').click(function() {
      $('#carBodies_hide').toggle(); 
      $('#carBodies_opener').toggle(); 
      $('#carBodies_closer').toggle(); 
   });
   
   
   
   /* JQuery na Eurotax */
    $('#month_prod').change(function() {
      $('#year_prod').change();
    });
    
    $('#year_prod').change(function() {
         //flobu.enable();
         var year = $(this).val();
      	    
      if(year > 0) {
	      if($("#make").val() != 0 ) {
          $("#make").change();
        } else {     
          $('#make').attr("disabled","");
  	      $('#make').selectOptions("0");
  	      if($('#make').val() == 0 ) {
            $("#make").selectedOptions().html('- vyberte -'); 
          }       
        }
	    } else {
        $('#make').attr("disabled","disabled");
	      $('#make').selectOptions("0");
	      if($('#make').val() == 0 ) {
          $("#make").selectedOptions().html('- Vyberte rok výroby -'); 
        } 
      }
	    
	    $('#fuel').selectOptions("0");
	 //   $("#fuel").selectedOptions().html('- Vyberte značku -'); 
   //   $('#fuel').attr("disabled","disabled");
      
	    $('#model').selectOptions("0");
	 //   $("#model").selectedOptions().html('- Vyberte palivo -'); 
      $('#model').attr("disabled","disabled");
      
	    $('#type').selectOptions("0");
	 //   $("#type").selectedOptions().html('- Vyberte model -'); 
	    $('#type').attr("disabled","disabled");
	    
	  });//znacka
	  
    $('#make').change(function() {
         //flobu.enable();
      var make = $(this).val();
      var year = $('#year_prod').val();
      var month = $('#month_prod').val();
     
      if(make == 0) {
        $('#fuel').attr("disabled","disabled");
	    } else {
	      $('#fuel').attr("disabled","");
      }
	    
	    $('#model').selectOptions("0");
      $('#model').attr("disabled","disabled");
	    $('#type').selectOptions("0");
	    $('#type').attr("disabled","disabled");
	    
	    if($('#eurotax_inf').val()==1) {
  	    $.get(base_url + 'jquery_php/fuel.php', 
  	      {znacka: make, rok: year, mesic: month},
  	      function(data) {
  	        $('#fuel').html(data);
       
            if(!data && make > 0 && year > 0) {
              etax_js_change = true;
              $('#msg_no_etax').show();
              $('#change2no_etax_click').click();
            } 
  	      //  $('#fuel').selectOptions("0");
  	      }      
  	    );
	    } else {
        if(etax_js_change) {
          $.get(base_url + 'jquery_php/fuel.php', 
  	      {znacka: make, rok: year, mesic: month},
  	      function(data) {
  	        $('#fuel').html(data);
    	        if(data && make > 0) {
                etax_js_change = false;
                $('#msg_no_etax').hide();
                $('#change2etax_click').click();
              } else {
                $.get(base_url + 'jquery_php/fuel_all.php', 
          	      {},
          	      function(data) {
          	        $('#fuel').html(data);
          	      //  $('#fuel').selectOptions("0");
          	      }      
          	    );              
              } //else
  	        }  //datra
  	      );
        } else { //etax_js_cahnge      
          $.get(base_url + 'jquery_php/fuel_all.php', 
    	      {},
    	      function(data) {
    	        $('#fuel').html(data);
    	      //  $('#fuel').selectOptions("0");
    	      }      
    	    );
    	  }
	    }
	    
	  });//znacka
	  
	  $('#fuel').change(function() {
	    var make = $('#make').val();
      var palivo = $(this).val();    
      var year = $('#year_prod').val();
      var month = $('#month_prod').val();
      
  	  $('#model').attr("disabled","");
  	  
  	   $('#type').selectOptions("0");
	    $('#type').attr("disabled","disabled");
	    
	    if($('#eurotax_inf').val()==1) {
	      $.get(base_url + 'jquery_php/model.php', 
  	      {znacka: make, palivo: palivo, rok: year, mesic: month},
  	      function(data) {
  	        $('#model').html(data);
  	        if(!data && make > 0 && palivo > 0 && year > 0) {
               $('#msg_no_etax').show();
               $('#change2no_etax_click').click();
            }
  	    //    $('#model').selectOptions("0");
  	      }      
  	    );   
	    } else {
        $.get(base_url + 'jquery_php/model.php', 
  	      {znacka: make, palivo: palivo, all_group: true},
  	      function(data) {
  	        $('#model').html(data);
  	      }      
  	    );   
      }
        
    });//fuel  
    
    $('#model').change(function() {
	    var model = $(this).val();
      var make = $('#make').val();    
      var palivo = $('#fuel').val(); 
      var year = $('#year_prod').val();
      var month = $('#month_prod').val();
      
      if($('#eurotax_inf').val() == 1) {
    	    $('#type').attr("disabled","");
          $.get(base_url + 'jquery_php/type.php', 
    	      {znacka: make, palivo: palivo, model: model, rok: year, mesic: month},
    	      function(data) {
    	        $('#type').html(data);
    	        if(!data && make > 0 && palivo > 0 && model > 0 && year > 0) {
                 $('#msg_no_etax').show();
                 $('#change2no_etax_click').click();
              }
    	    //    $('#model').selectOptions("0");
    	      }      
    	    );   
  	  } else {
        if(model == -1) {
          $('#model_text_row').show();
        } else {
          $('#model_text_row').hide();
        }
      }
  	    
    });//model
      
    
    $('#type').change(function() {
      var type=$(this).val();
      $.get(base_url + 'jquery_php/type_change.php', 
  	      {type: type},
  	      function(data) {
  	         var pole=unserialize(data);
             if(pole.car_body) {
               $('#car_body').selectOptions(pole.car_body);
             }
             
             if(pole.cubature) {
               $('#cubature').val(pole.cubature);
             }
             
             if(pole.power) {
               $('#power').val(pole.power);
             }
             
             if(pole.hp) {
               $('#hp').val(pole.hp);
             }
             
             if(pole.weight) {
               $('#weight').val(pole.weight);
             }
             
             if(pole.typdoor) {
               $('#door').selectOptions(pole.typdoor);
             }
             
             if(pole.gear) {
               $('#gear').selectOptions(pole.gear);
             }
           
             if(pole.drive) {
              $('#drive').selectOptions(pole.drive);
             }
             
             if(pole.tyres) {
              $('#tyres').val(pole.tyres);
             }
             
             if(pole.urban_consumption) {
               $('#urban_consumption').val(pole.urban_consumption);
             }
             
             if(pole.overland_consumption) {
               $('#overland_consumption').val(pole.overland_consumption);
             }
             
             if(pole.overall_consumption) {
               $('#overall_consumption').val(pole.overall_consumption);
             }
             
  	      }      
  	    );   
    });//type  
    
    $('#b_compensation').click(function() {
      $('#leasing_div').toggle(); 
   });
   
   //vlastni zadani auta
   $('#change2no_etax_click2').click(function() {
     $('#change2no_etax_click').click();
     return false;
   });
   
   $('#change2no_etax_click').click(function() {
      $('#change2no_etax').toggle(); 
      $('#change2etax').toggle(); 
      $('#change2no_etax2').toggle(); 
      $('#change2etax2').toggle(); 
      
      $('#eurotax_inf').val('0');
    
      $('#fuel').selectOptions("0");
      $('#model').selectOptions("0");
      $('#type').selectOptions("0");
      
      $('#make').change();
  	  $('#type').toggle(); 
  	  $('#type_text').toggle();
  	  $('#type_text_help').toggle();
  	  
  	  return false;
   });
   
   //auto zadane cez eurotax
   $('#change2etax_click2').click(function() {
     $('#change2etax_click').click();
     return false;
   });
   
   $('#change2etax_click').click(function() {
      $('#change2etax').toggle(); 
      $('#change2no_etax').toggle(); 
      $('#change2etax2').toggle(); 
      $('#change2no_etax2').toggle(); 
      
      $('#eurotax_inf').val('1');
      $('#model_text_row').hide();
      $('#msg_no_etax').hide();
      
      
      $('#type_text').toggle(); 
      $('#type_text_help').toggle();
      $('#type').toggle(); 
      
      $('#make').change();
      //$('#year_prod').selectOptions("0");
     // $('#year_prod').change();
     // $('#make').selectOptions("0");
    //  
      
    //  $('#type').selectOptions("0");
    //  $('#model').selectOptions("0");
     
      // 
     // 
   //    
    //  $('#fuel').selectOptions("0");
     
     
      
      return false;
   });
   
    
})






