function inputFocus(myfield, e)
{
    myfield.value = '';
}

function autoComplete(host, component, exec, query, url)
{
	$(function()
    {
        var cache = {}, lastXhr;

        $('#' + exec + '').autocomplete(
        {
            minLength: 3,

            source: function(request, response)
            {
                var term = request.term;

                if (term in cache)
                {
                    response(cache[term]);
                    return;
                }

                lastXhr = $.getJSON(host + '/midcom-exec-' + component + '/' + exec + '.php?' + query, request, function(data, status, xhr)
                {
                    cache[term] = data;

                    if (xhr === lastXhr)
                    {
                        response(data);
                    }
                });
            },

            select: function(event, ui)
            {
                document.getElementById(exec).value = ui.item.value.replace('/', '\\');
                var request = encodeURIComponent(document.getElementById(exec).value);
                document.location.href = url + request;
            }
        });
    });
}

$(document).ready(function()
{
    // external links
    $('a:contains(vio-blog)').addClass('target_blank');
    $('a:contains(facebook)').addClass('target_blank');
    $('a:contains(twitter)').addClass('target_blank');
    $('a:contains(youtube)').addClass('target_blank');

    // target blank compat
    $('a.target_blank').bind('click', function()
    {
        window.open(this.href);
        return false;
    });

    // readonly JS dates
    $('input.jsdate').attr('readonly', 'readonly');

    // text changer
    $('span:contains(notwendige Eingabe)').html('Pflichtfelder');
    $('a.archival').html(''); // removing archive bild links
    $('a:contains(Marketplace)').attr('onclick', 'return confirm(\'ATTENTION PLEASE! Our Marketplace section is only available in German. Do you want to proceed anyway?\');');

    // navigation
    $('#navigation > ul > li > ul').hide();

    $('#navigation > ul > li')
        .bind('mouseenter', function()
        {
	        $('ul', $(this)).slideDown();
        })
        .bind('mouseleave', function()
        {
            $('ul', $(this)).stop(true, true);
            $('#navigation > ul > li > ul').hide();
        });
});
