var url = window.location.host;    

function clearAddComment()
{
    $("#nameComment").val('');
    $("#textComment").val('');
    $("#captcha").val('');
    $("#viewAddComment").empty();
    
    //refreshimg();
}

function viewComments(module, object_id)
{
    $.post(
        "http://"+url+"/index.php",
        { 
            s:          "ajax",
            ajax:       "comments",  
            func:       "viewObjectComments",
            module:     module,
            object_id:  object_id
        },
        function ( data_view )
        {
            $("#viewComments").html(data_view);
        }
    );
    return false;
}

function viewAddComment( module, object_id )
{
    $.post(
        "http://"+url+"/index.php",
        { 
            s:          "ajax",
            ajax:       "comments",  
            func:       "addComment",
            module:     module,
            object_id:  object_id
        },
        function ( data )
        {
            $("#viewAddComment").html(data);
            updateCaptcha();
        }
    );  
    
    return false;  
}

function addComment( module, object_id )
{
    if( $("#form_addComment").validate({
        rules: {
            imgcode: {
                remote: ("http://"+url+"/check_captcha.php")
            }
        }
    }).form() )
    {
        $.post(
            "http://"+url+"/index.php",
            { 
                s:          "ajax",
                ajax:       "comments",  
                func:       "addComment",
                module:     module,
                object_id:  object_id,
                name:       $("#nameComment").val(),
                text:       $("#textComment").val() 
            },
            function ( data )
            {
                clearAddComment();
                viewComments(module, object_id);
            }
            );
    } 
     else
    {
        $("#errors").html(translates['fill_correctly']);
    }   
}