
function processFilters() {
  $.ajax({
    type: "POST",
	url: window.location.pathname +"filter/",
	data: $("#filters-form").serialize(),
	success: function(data){
	$("tr.list-data").remove();
	$(".list table tbody").append(data);



      }
 });
}

$(document).ready( function() {
    $("#menu li.level-0").hover(
				function () {
				  $(this).find(".menu-hover").css("display", "block");
				  $(this).find("ul").css("display", "block");

				},
				function () {
				  $(this).find(".menu-hover").css("display", "none");
				  $(this).find("ul").css("display", "none");

				});






    /* filters*/

    $(".filter-semester").click(function () {
	$("#filters-form #semester-id").attr("value", $(this).attr("id"));
	$(".filter-semester").removeClass("selected");
	$(this).addClass("selected");
	processFilters();
      });

     $(".location").click(function () {
	$("#filters-form #location-id").attr("value", $(this).attr("id").split('-').slice(-1));
	$(".location").removeClass("selected");
	$(this).addClass("selected");
	processFilters();
      });


     $(".category").click(function () {
	$("#filters-form #category-id").attr("value", $(this).attr("id").split('-').slice(-1));
	$(".category").removeClass("selected");
	$(this).addClass("selected");
	processFilters();
      });

     $(".country").click(function () {
	$("#filters-form #country-id").attr("value", $(this).attr("id").split('-').slice(-1));
	$(".country").removeClass("selected");
	$(this).addClass("selected");
	processFilters();
      });

    datepicker_options = {
    dateFormat: 'yy-mm-dd',
    onClose: function(dateText, inst) { if(dateText){processFilters()}}
    }

    $("#start-date").datepicker(datepicker_options);
    $("#end-date").datepicker(datepicker_options);

    datepicker_options2 = {
    dateFormat: 'yy-mm-dd'
    }
    $("#id_id_card_date").datepicker(datepicker_options2);
    $("#id_birth_date").datepicker(datepicker_options2);
    $("#id_proffesional_experience_date_in").datepicker(datepicker_options2);
    $("#id_proffesional_experience_date_out").datepicker(datepicker_options2);


    $('#search-query').keyup(function() {
	processFilters();
      });


    /* form */
    $(".form-toggle-button").click(function () {
	$(".form").slideToggle(500);
      });

    $(".print-document").click(function (event) {
	event.preventDefault();
	window.print();

      });

    $(".list-data").livequery(function(){
        $(this).hover(function() {
	    $(this).addClass('hover');
	  }, function() {
	    $(this).removeClass('hover');
	  });

        $(this).click(function(event) {
	    event.preventDefault();
	    window.location.href = $(this).find("a").attr("href");
	    return true;
	  });

      }, function() {
        // unbind the mouseover and mouseout events
        $(this)
	  .unbind('mouseover')
	  .unbind('mouseout');
      });

    $("#contacts .tab-inner").click(function (event) {
	$(".contacts-content .city").removeClass("selected");
	$(".contacts-content ." + $(this).attr("id")).addClass("selected");
	$("#contacts .tab-inner").removeClass("selected");
	$(this).addClass("selected");
      });

    $(".contacts-content .city").removeClass("selected");
    $(".contacts-content ." + $("#contacts .tab .selected").attr("id")).addClass("selected");


    $(".area").click(function (event) {
	$(".area-list:not(:."+$(this).attr("id")+")").addClass("collapsed");
	$(".area:not(:#"+$(this).attr("id")+")").removeClass("selected");

	$("." + $(this).attr("id")).toggleClass("collapsed");
	if($("." + $(this).attr("id")).is(':visible')) {
	       $(this).addClass("selected");

	} else {
	       $(this).removeClass("selected");
	}


      });



});

