/*
 * pH8 Extensions of Prototype
 * (c) 2005-2008 Joris Verbogt
 */
pH8 = {};
pH8.Version = '1.0';
pH8.CompatibleWithPrototype = '1.6';

if (Prototype.Version.indexOf(pH8.CompatibleWithPrototype) !== 0 && console && console.warn)
  console.warn("This version of pH8 extensions is tested with Prototype " + pH8.CompatibleWithPrototype + 
                  " it may not work as expected with this version (" + Prototype.Version + ")");
                  
Element.addMethods({
   /**
    * Get all class parameters, i.e. class names like {prefix}-{name}={value}
    * @param Element element The element when called statically
    * @param String prefix Optional prefix, default 'param'
    * @return Array name: value hash
    */ 
   getClassParameters: function(element, prefix) {
     element = $(element);
       if (arguments.length < 2) {
           prefix = 'param';
       }
     var regex = new RegExp(prefix + '-(\\w*)=(\\S*)', 'g');
     var params = {};//new Array();
	 
     while ((result = regex.exec(element.className)) != null) {
       params[result[1]] = result[2];
     }
	 
     return params;
   },
   /**
    * Get specific class parameter, i.e. class name like {prefix}-{param}={value}
    * @param Element element The element when called statically
    * @param String param The parameter to look for
    * @param String prefix Optional prefix, default 'param'
    * @return String The parameter value
    */ 
   getClassParameter: function(element, param, prefix) {
       if (arguments.length < 3) {
           prefix = 'param';
       }
       var regex = new RegExp(prefix + '-' + param + '=(\\S*)');
       var parts = regex.exec(element.className);
       if (parts) {
           return parts[1];
       }
   }
});

Object.extend(String.prototype, {
  /**
   * Does this String represent a number?
   * @return Boolean
   */
  isNumber: function() {
    return (Number(this) !== Number.NaN);
  },
  /**
   * Does this String represent (only) numerical digits?
   * @return Boolean
   */
  isDigits: function() {
    return (this.match(/^\d+$/) !== null);
  },
  localize: function() {
    if (i18n && i18n[this]) {
      return i18n[this];
    } else {
      return this;
    }
  }
});

Object.extend(Number.prototype, {
  /**
   * Is this Number an Integer?
   * @return Boolean
   */
  isInteger: function() {
    return (Math.round(this) === this);
  }
});