/**
 * A handful of global support functions.
 *
 * These are available to any template that inherits from base.mako.
 */

/**
 * Provide a function for trimming whitespace.
 */
String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g, "");
}

/**
 * Create a string interpolater.  I saw this on the internet.
 *
 * Example usage:
 *   // Gotta create the vMap closure every time.
 *   var vMap = function ( _x_ ) { return eval( _x_ ); };
 *   var var1 = "SomeValue";
 *   "My string {var1}".interp(vMap) -> 'My string SomeValue'.
 */
String.prototype.interp = function ( vMap ) {
   return this.replace( /\{([^}]+)\}/g,
       function ( dummy, v ) {
                 return vMap( v );
       } );
};

/**
 * Allows arrays to be appended to.
 */
Array.prototype.append = function(val) {
    this[this.length] = val;
}

/**
 * Navigate to url.
 */
function goto_url(url) {
  location.href = url;
}
