$(document).ready(function(){
    if(typeof(functions_to_call) != 'undefined')
    {
        callFunctions(functions_to_call)
    }

    var tabs = $(jqid('tabs'));
    if(tabs.val() != undefined)
    {
        $(jqid('tabs')).tabs();
    }


    var alternate_rows = $('.alternate_rows');
    if(alternate_rows.val() != undefined)
    {
        $(".alternate_rows:odd").css("background-color", "#FFFFFF");
        $(".alternate_rows:even").css("background-color", "#D9D9D9");
    }

    var tablesorter = $('.tablesort');

	if(tablesorter.val() != undefined)
	{
	    tablesorter.tablesorter({widgets: ['zebra']});
	}

    $("#lastname").autocomplete("ajax.server.php", {
		highlight: false,
		scroll: true,
		scrollHeight: 300,
		element_id: 'lastname'
	});

    $('.tooltip').each(function(){
       $(this).qtip({
           content:
           {
               title: $(this).attr('title'),
               ajax:
               {
                  method: 'get',
                  url: $(this).attr("rel")
               }
           },
           position: {
              my: 'right top',
              at: 'top left',
              adjust: {y: 5, screen: true}
           },
           style:
           {
               tip:
               {
                   corner: true,
                   size: {x: 20, y: 8}
               },
               classes: 'ui-tooltip-dark action_qtip'
           }
       });
   });

    $('.quicksearch_field').example('Quicksearch');
    $('.quicksearch_from').example('Datum von');
    $('.quicksearch_until').example('Datum bis');

	/* Table actions */
	$('.table .choose').each(function(){
        $(this).click(function(event){
            if(!$(this).hasClass("selected"))
            {
                $(this).addClass("selected");
                $(this).parent().parent().addClass("selected");
            }
            else
            {
                $(this).removeClass("selected");
                $(this).parent().parent().removeClass("selected");
            }

            event.stopPropagation();
        });
    });

    $('.table .choose:checked').each(function(){
        $(this).addClass("selected");
        $(this).parent().parent().addClass("selected");
    });

	$('.table .img_check_all').each(function(){
	   $(this).click(function(){
	       $("input[name*='" + $(this).attr("value") + "']:not(:checked)").click();
	   });
	});

	$('.table .img_uncheck_all').each(function(){
	   $(this).click(function(){
	       $("input[name*='" + $(this).attr("value") + "']:checked").click();
	   });
	});

	$('.table tr').each(function(){
	   $(this).click(function(){
            $(this).children().children('.choose').click();
        });
    });


    // Kalender (live wegen der Möglichkeit des Auftretens in
    // kopierten Blöcken)
	$(".datepicker").live('focus', function(){
        $(this).datepicker({
            changeMonth: true,
            changeYear: true,
            showWeek: true,
            numberOfMonths: 3,
            regional: $.datepicker.regional['de']
        });
    });


});
