

var messages = new JMessage();

function JMessage() {
    this.init;
    this.messages;
    
    this.get = function(id, args) {
                   if (!this.init) {
                       this.messages = new Array();
                       this.messages["M053"] = "Please enter the {0} field.";
                       this.messages["M054"] = "Valid length of the {0} field is between {1} and {2}.";
                       this.messages["M055"] = "Valid size of the {0} field is between {1} and {2}.";
                       this.messages["M056"] = "You can use only numbers in the {0} field.";
                       this.messages["M057"] = "Select a value of {0} field.";
                       this.messages["M058"] = "{0} Field: Invalid Email Address.";
                       this.init = true;
                   }
                   var message = this.messages[id];
                   if (!message) {
                       return id;
                   }
                   if (args) {
                       if (typeof args == "object" && args.length) {
                           for (var i = 0; i < args.length; i++) {
                               var pattern = new RegExp("\\{" + i + "\\}", "g"); 
                               message = message.replace(pattern, args[i]);
                           }
                       } else {
                           message = message.replace(/\{0\}/g, args);
                       }
                   }
                   return message;
               };

    this.alert = function(id, args) {
                     alert(this.get(id, args));
                 }
}
