$().ready(function() {
    //$('#sbm_movie_search').attr('disabled', '');
    var get_movies = $('#get_movies');
    
    function show_label() {
        if ($(this).val() == '') {
            $(this).parents('li').removeClass('focus')
            label = $('[for='+$(this).attr('name')+']');
            label.show();
        }
    }
    function enable_form() {
        $('#sbm_movie_search').removeAttr('disabled');
        $('#sbm_movie_search').addClass('active');
    }
    function disable_form() {
        $('#sbm_movie_search').attr('disabled', 'disabled');
        $('#sbm_movie_search').removeClass('active');
    }
    
    $('label',get_movies).click(function() {
        $(this).hide();
        $(this).next().click();
        $(this).next().focus();
    });
    $('input[type!=submit]',get_movies).focus(function() {
        $(this).prev().hide();
        $(this).parents('li').addClass('focus')
    });
    $('input',get_movies).blur(show_label);
    
    $('#city input',get_movies).blur(function(e) {
        if ($(this).val() != '') {
            enable_form();
        } else {
            disable_form();
        }
    });

    $('#combobox_patch',get_movies).click(function(e) {
        e.preventDefault();
        e.cancelBubble = true;
        if (e.stopPropagation) e.stopPropagation();
    });
    
    var get_search = $('#get_search');
    $('label[for=cerca]', get_search).click(function(e) {
        $(this).hide();
        $(this).next().click();
        $(this).next().focus();
    });
    $('#cerca',get_search).click(function() {
        $(this).prev().hide();
        $(this).parents('li').addClass('focus')
    });
    $('#cerca',get_search).blur(show_label);
    
    $('#get_search_insala label').click(function() {
        $(this).hide();
        $(this).next().focus();
    });
    $('#get_search_insala input').blur(function() {
        if ($(this).val() == '') {
            $(this).prev().show();
        }
    });
    
});