jQuery(document).ready(function() {

  // Selectboxen rufen per Ajax infos aus einem php-script
  $('select').change(function() { // wird eine Selectbox verändert, starte diese Funktion
   
    var str = "";
    $(".select option:selected").each(function () {
      str += $(this).text() + ";";
    });
      
    // scannen wir noch einmal alle Checkboxen durch, damit diese auch bei Änderungen mitgenommen werden
    
    var ext = "";
    $("input:checked").each(function () {
      ext += $(this).val() + ";";
    });
    
    // AJAX zur Darstellung der Auswahl
    
    $.ajax({
      method: "get",
      url: "../ajxsrch.php",
      data: "criteria="+str+"&extras="+ext,
      beforeSend: function(){
        $(".row1col2").hide("fast");
      }, //show loading just when link is clicked
      complete: function(){ $("#loading").hide("fast");}, //hide loading when the process is complete
      success: function(mails){ //so, if data is retrieved, store it in mails
        $(".row1col2").show("fast"); // show the div
        $(".row1col2").html(mails); //show the html inside the div


      } // Ajax: success
    }); //close $.ajax(
  }); //close change / click(


  // Checkboxen rufen per Ajax infos aus einem php-script
  $(':checkbox').click(function() { // wird eine Checkbox verändert, starte diese Funktion

    var ext = "";
    $("input:checked").each(function () {
      ext += $(this).val() + ";";
    });

    // scannen wir noch einmal alle Selectboxen durch, damit diese auch bei Änderungen mitgenommen werden

    var str = "";
    $(".select option:selected").each(function () {
      str += $(this).text() + ";";
    });
      
    // AJAX zur Darstellung der Auswahl
    
    $.ajax({
      method: "get",
      url: "../ajxsrch.php",
      data: "criteria="+str+"&extras="+ext,
      beforeSend: function(){
        $(".row1col2").hide("fast");
      }, //show loading just when link is clicked
      complete: function(){ $("#loading").hide("fast");}, //hide loading when the process is complete
      success: function(mails){ //so, if data is retrieved, store it in mails
        $(".row1col2").show("fast"); // show the div
        $(".row1col2").html(mails); //show the html inside the div


      } // Ajax: success
    }); //close $.ajax(
  }); //close checkbox(


});
