﻿//NOT NEEDED FOR JQ 1.4.2
//jQuery(document).bind('ajaxComplete', function (e, xhr, options) {

//  if (xhr.getResponseHeader('Content-Type').indexOf('text/javascript') !== -1) {
//    eval(xhr.responseText);
//  }

//}).ready(function () {

//});

function Post(form) {
  form = jQuery(form);
  jQuery.post(form.attr('action'), form.serialize());
}

function Invoke(params, confirmation, callback) {
  if (typeof confirmation === 'string') { if (!confirm(confirmation)) { return; } }
  var url = (params.InvokeUrl ? params.InvokeUrl : window.location.path);
  $.post(url, params, callback);
}

function SetupDefaultText() {
  var q = jQuery(this);
  var txt = q.attr('title');
  var onFocus = function () { if (q.val() == txt) { q.val('').removeClass('inactive'); } };
  var onBlur = function () { if (q.val() == '' || q.val() == txt) { q.val(txt).addClass('inactive'); } };
  q.focus(onFocus).blur(onBlur).parents('form').submit(onFocus);
  onBlur();
}

var Base = function ($) {


  // Hookup Ajax listener:
  $(document).bind('ajaxComplete', function (e, xhr, options) {
    //Eval script if text/javascript header is present:
    if (xhr.getResponseHeader('Content-Type').indexOf('text/javascript') !== -1) { eval(xhr.responseText); }
  }).bind('ajaxError', function (e, xhr, options) {
    //Display error on screen:
    $('#textblock').append(xhr.responseText);
  });


  //Public Methods:
  return {

    Post: function (form, callback) {
      form = $(form);
      $('.inactive', form).val('').removeClass('inactive');
      $.post(form.attr('action'), form.serialize(), callback);
      return false;
    },

    Invoke: function (params, confirmation) {
      if (typeof confirmation === 'string') { if (!confirm(confirmation)) { return; } }
      $.post(params.InvokeUrl ? params.InvokeUrl : window.location.path, params);
    }
  }

} (jQuery);

