$(function() {    
    $("#search-submit").button();
    
    // TEMP FOR NEW MAINPAGE ON MAIN VERSION
    //$("#search").autocomplete({ 
    //    source: "/__new/zend_index.php?module=ajax&action=search_context",
    //    minLength: 1
    //});
    $("#search").autocomplete({
        source: "/?module=ajax&action=s_context",
        minLength: 1
    });

//    $("#loading").ajaxStart(function(){
//        $(this).show().next('#loadimage').show();
//    }).ajaxStop(function(){
//        $(this).hide().next('#loadimage').hide();
//    });
});

function postComment(frm, _showAlert) {
    if ($('#commText').val() == '') {
        showAlert('Введите текст комментария');
        return false;
    }

    if ($('#commText').val().length < 4) {
        showAlert('Текст комментария слишком короткий');
        return false;
    }

    dataString = $(frm).serialize().replace('%5B', '[').replace('%5D', ']');
    $.post('/?module=ajax&action=addcomment', dataString, function(message){
        showAlert(message);
        frm.reset();
    });
    
    return false;
}

function showAlert(msg) {
    //alert(msg);
    if (msg !== undefined) {
        $('body').append('<div id="jsAlert" title="See.ua сообщает:"><div class="ui-state-highlight" style="margin-top: 5px; padding: 10px;"><p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span><p class="bold">'+msg+'</p></div></div>');
        $('#jsAlert').dialog({
            modal: true,
			buttons: {
				Ok: function() {
					$(this).remove();
				}
			}
        });
    }

    setTimeout(function() {$("#jsAlert").remove();}, 5000);
}