var text;
var lang;

function setText(lang)
{
    switch (lang)
        {
        case 'lt': text = "Jusu@e.pastas.lt"; break;
        case 'en': text = "Your@email.com"; break;
        case 'ru': text = "имя@email.ru"; break;
        case 'lv': text = "vards@epasts.lv"; break;
    }

    $('#email_text').val(text);
}

jQuery(document).ready(function(){


    lang = $('#email_text_lang').val();
    setText(lang);

    $('#email_text').blur(function(){
        if ($(this).val() == text || $(this).val().length == 0)
            setText(lang);
    });

    $('#email_text').focus(function(){
        if ($(this).val() == text)
            $(this).val('');
    });

    $('#searchField').blur(function(){
        if ($(this).val().length == 0)
            $(this).val($(this).attr('title'));
    });

    $('#searchField').focus(function(){
        if ($(this).val() == $(this).attr('title'))
            $(this).val('');
    });
    
    var l = $('#lang').val();
    $("#searchField").autocomplete("/" + l + "-search.html", {
        minChars: 3,
        max: 50,
		matchContains: true,
        formatItem: function(item) {
            return item.title;
        }
    }).result(function(event, item) {
        window.location.href = item.link;
    });
});
