var last_msg = new Object();
var jAlert = {
   show: function(title, text, class_name)
         {
            if(!title)
            {
               return;
            }

            if(!$('#ajax_alert').attr('id'))
            {
               $('<div id="ajax_alert"></div>').appendTo(document.body);
            }

            $('<div class="item ' + class_name + '"><h2>' + title + '</h2>' + text + '</div>')
               .prependTo($("#ajax_alert"))
               .fadeIn("slow", function()
               {
                  $(this).animate({opacity: 0.9}, 4000, "linear", function()
                  {
                     $(this).fadeOut("slow");
                  });
               })
               .click(function()
                           {
                              $(this).stop();
                              $(this).fadeOut("slow");
                           })

            last_msg = {title: title, text: text, class_name: class_name};

            if(!$("#alert_history_id").text())
            {

               $("(<a href='javascript:Alert.history()' class='ajax_alert'>Show Last Message</a>)")
                  .appendTo("#alert_history_id");
            }
         },

   history: function()
         {
            jAlert.show(last_msg.title, last_msg.text, last_msg.class_name);
         },

   Result: function(nObj)
   {
      if(nObj.link)
      {
         return window.location.href = nObj.link;
      }

      if(!nObj.msg || nObj.msg.length < 1)
      {
         return;
      }

      if(nObj.level == "error")
      {
         jAlert.show("Error", nObj.msg, "error");
      }
      else if(nObj.level == "notice")
      {
         jAlert.show("Notice", nObj.msg, "notice");
      }
      else if(nObj.level == "success")
      {
         jAlert.show("Success", nObj.msg, "message");
      }
   }
}

function GetBack(nUrl)
{
   window.location.href = nUrl;
   return false;
}