//var path = '/projects/breezy/svaciny/';
var path = '/';

function redirect(href) {
  window.location.href = href;
}

$(document).ready( function() {
    $("a.fancybox").fancybox({
      'zoomSpeedIn': 300,
      'zoomSpeedOut': 300,
      'overlayShow' :true
    });
  });
  
function select_classes(){
  var value = $('#school_id').val();

  $.ajax({                    
    url: path + 'ucet/' + 'classes/'+value,
    type: 'GET',
    dataType: 'text',
    timeout: 10000,
    error: function(){
    },
    success: function(text){
    $('#class_id').html(text)
    }
   });
 }
 
function select_schools(){
  var value = $('#town_id').val();
  var url = path + 'poptavky/towns/'+value;
 
  if($('#school_id').hasClass('inactive_only')){
    url = url + "/1";
  }
  if($('#school_id').hasClass('both')){
    url = url + "/2";
  }
  

  $.ajax({                    
    url: url,
    type: 'GET',
    dataType: 'html',
    timeout: 10000,
    error: function(){
    },
    success: function(text){
     var value = $('#school_id').val();
     $('#school_id').html(text);
     $('#school_id').val(value);
     select_classes(); 
    }
   }); 
 }
 
 function select_districts(){
  var value = $('#locations_district_id').val();
     
  $.ajax({                    
    url: path + 'poptavky/districts/'+value,
    type: 'GET',
    dataType: 'html',
    timeout: 10000,
    error: function(){
    },
    success: function(text){
     var value = $('#town_id').val();
     $('#town_id').html(text);
     $('#town_id').val(value);
     select_schools(); 
    }
   }); 
 }
 
function company_select_towns()
{
  var value = $('#company_locations_district_id').val();
  $.ajax({                    
    url: path + 'poptavky/companies_towns/'+value,
    type: 'GET',
    dataType: 'html',
    timeout: 10000,
    error: function(){
    },
    success: function(text){
     var value = $('#company_town_id').val();
     $('#company_town_id').html(text);
     $('#company_town_id').val(value);
     select_companies(); 
    }
   }); 
}

function select_companies(){
  var value = $('#company_town_id').val();
  var url = path + 'poptavky/companies/'+value;

  $.ajax({                    
    url: url,
    type: 'GET',
    dataType: 'html',
    timeout: 10000,
    error: function(){
    },
    success: function(text){
     var value = $('#company_id').val();
     $('#company_id').html(text);
     $('#company_id').val(value);
    }
   }); 
 }
 
$(window).load(function() {          
      $("select#town_id").change(function(){
       select_schools();
      });   
      $("select#locations_district_id").change(function(){
       select_districts();
      });          
      
      $("select#company_locations_district_id").change(function(){
        company_select_towns();
      });
});
  
