﻿function Post(form, callback) {
  form = $(form);
  $('.inactive', form).val('').removeClass('inactive');
  var url = form.attr('action');
  if (!url) { url = window.location.path; }
  $.post(url, form.serialize(), callback);
}

function Invoke(params, confirmation) {
  if (typeof confirmation === 'string') { if (!confirm(confirmation)) { return; } }
  var url = (params.InvokeUrl ? params.InvokeUrl : window.location.path)
  jQuery.post(url, params);
}

var Board = {

  controlerUrl: '/forum/board-controler.aspx',
  currentEditor: null,

  AddRow: function(rowId) {
    var newRowId = rowId + "-1"
    var exists = $('#' + newRowId).length

    if (exists != 1) {
      n = 100;
      var tds = '<tr id="' + newRowId + '"><td id="' + newRowId + '-2" colspan="' + n + '">&nbsp;</td></tr>';
      $('#' + rowId).after(tds)
      return '#' + newRowId + '-2'
    } else {
      $('#' + newRowId).remove()
      return '0'
    }
  },

  PostComment: function(container, params, confirmation){
    if(confirmation && !confirm(confirmation)){ return; }
    jQuery.ajax({ url: Board.controlerUrl, data: params, complete: Board.OnRequestComplete(container), type: "POST" });
  },
  
  OnRequestComplete: function(container){
    return function(transport, type){
      var contentType = transport.getResponseHeader('Content-Type');
      if(contentType && contentType.indexOf('text/javascript') == -1){
        jQuery(container).html(transport.responseText).show();
      }
    }
  },

  InitializeImageFilePopoup: function(postId, imageFile) {
    $('#image-file-popup').show();
    $('#post-imagefile-postid').val(postId);
    $('#post-imagefile').val(imageFile);
    $('#post-imagefile').focus();
  }

}
  








