
// Blog functions
function showBlogArhive()
{
    var arhive = $("#blog_arhive").val();
    if (arhive == '0') return false;
    
   var year = arhive.substring(0, 4);
   var month = arhive.substring(5, 7);
   
   document.location.href = "/blog/"+year+"/"+month+"/";
    return true;
}

function postComment()
{
    var error = '';
    if (!trim($("#comment_name").val())) error += "Enter your name\n";
    if (!trim($("#comment_post").val())) error += "Enter you comment\n";
    if (error) {alert(error);return false;}



   $.ajax({
      type: "POST",
      dataType: "html",
      error: function(response){},
      url: "/blog/comment/add",
      data: $("#post_comment").serialize(),
      beforeSend: function()
      {
         blockStandart('comments_div');
      },
      complete: function()
      {
         $('#comments_div').unblock();
      },
      success: function(response)
      {
          $('#comment_post').val('');
          alert("Comment is wating for approval");
      }
   });
   
    return true;
}

function paginator(url, params, div)
{
    $.ajax({
        type: "POST",
        dataType: "html",
        url: url,
        data: params,
        success: function (response)
        {
            $("#"+div).html(response);
        },
        beforeSend: function()
        {
            blockStandart(div);
        },
        complete: function()
        {
            $("#"+div).unblock();
        }
    });
}

function showPopup(nWidth, url, data)
{
    $('#modalContent').html("");
    $('#modalPreloader').css('display', 'block');

    if (nWidth > 0)
    {
        //block screen
        $('#body').block({
            message: $('#modalWindow'),
            centerY: false,
            css:
            {
                top: getBodyScrollTop() + 40,
                left: ($(window).width() - nWidth) /2 + 'px',
                width: nWidth + 'px'
            }
        });
    }

    //get contents
    $.ajax({
        type: "POST",
        url: url,
        data: data,
        dataType: "html",
        complete: function(){},
        success: function(response)
        {
            $('#modalPreloader').css('display', 'none');
            $('#modalContent').html(response);
        },
        complete: function()
        {
            $(".blockOverlay").css('height',$(document).height());
        }
    });
}

function showPopupHtml(nWidth, htmlData)
{
    $('#modalContent').html("");
    $('#modalPreloader').css('display', 'block');

    if (nWidth > 0)
    {
        //block screen
        $('#body').block({
            message: $('#modalWindow'),
            centerY: false,
            css:
            {
                top: getBodyScrollTop() + 40,
                left: ($(window).width() - nWidth) /2 + 'px',
                width: nWidth + 'px'
            }
        });
    }

    $('#modalPreloader').css('display', 'none');
    $('#modalContent').html(htmlData);
    $(".blockOverlay").css('height',$(document).height());
}

function closePopup()
{
    $('#modalContent').html("");
    $('#body').unblock();
}

