// Please note: http://docs.jquery.com/Using_jQuery_with_Other_Libraries
jQuery.noConflict();
     
// Put all your code in your document ready area
jQuery(document).ready(function($){

//  ***************************************************
//  * @purpose: load data via ajax request to update jobs found
//  * @author:  robert.leurs@cooloxygen.com
//  * @version: 1.0 / dd.25.03.2009
//  * @version: 1.1 / dd.15.04.2009 (added multiple bind events)
//  ***************************************************

    // *** bind function: when the form is loaded, also trigger my function ***
    // since the form element does not have a load event, we trigger it on window.load!
    jQuery(window).load(function () {
        // check if we have the correct element on our page
        if ( jQuery('#searchform').length > 0 ) {
            // yes, we have.., so now let's go and do something with it
            jQuery('#searchform').trigger("myCustomAjaxUpdateEvent");
        }
    });
    
    // *** bind function on multiple events: when selection changes, trigger my function ***
    jQuery('#searchform').change(function () {
        jQuery('#searchform').trigger("myCustomAjaxUpdateEvent");
    });
    jQuery('#searchform').keyup(function () {
        jQuery('#searchform').trigger("myCustomAjaxUpdateEvent");
    });
    
    // *** actual function: load data via ajax request to update jobs found ***
    jQuery('#searchform').bind("myCustomAjaxUpdateEvent", function() {

        // extract selected values
        var val_sector          = document.getElementById("sector").value;
        var val_regio           = document.getElementById("region").value;
        var val_educationlevel  = document.getElementById("educationlevel").value;
        var val_functioncat     = document.getElementById("functioncat").value;

        // concat the values in a request string
        var request_data        = '/' + val_sector + '/' + val_regio + '/' + val_educationlevel + '/' + val_functioncat + '';

        // perform ajax request        
        var request_result = $.ajax({
            url: '/vacatures/presearch_vacancies' + request_data,
            async: false
        }).responseText;

         // set value in html element
         jQuery("#numberres").html(request_result);
    });
});