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(2000, function()
                     {
                        $(this).remove();
                     });
                  });
               })
               .click(function()
                           {
                              $(this).stop();
                              $(this).hide("normal");
                           })

            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.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 ClassCache()
{
   var cacheArr = new Array();

   this.Add = function(key, value)
   {
      cacheArr[key] = value;
   }

   this.Get = function(key)
   {
      if(!cacheArr[key])
      {
         alert("Variable '" + key + "' is not defined!");
      }

      if(cacheArr[key])
      {
         return cacheArr[key];
      }
   }

   this.Delete = function(key)
   {
      delete cacheArr[key];
   }

   this.Exists = function(key)
   {
      var retFlag = false;
      if(cacheArr[key])
      {
         retFlag = true;
      }

      return retFlag;
   }
}

function GetBack(nUrl)
{
   window.location.href = nUrl;
   return false;
}