text: // DO NOT EDIT THIS FILE.
  // This file is part of the Jax Framework.
  // If you edit this file, your changes will be lost when framework updates are applied.
  
  // Copyright (c) 2010-2011 Ronald B. Cemer
  // All rights reserved.
  // This software is released under the BSD license.
  // Please see the accompanying LICENSE.txt for details.
  
  // Replace tokens.
  // text: the template text.
  // tokenValues: an associative array of token names to corresponding values.
  // Tokens are in the format ${tokenName[|filter[|filter]...]}.
  // The following filters are supported:
  //     urlencode : URL-encode for use as a query string parameter [javascript escape()]
  //     rawurlencode : URL-encode for use as a URL path component [javascript encodeURIComponent()]
  //     htmlencode : endode HTML entities via jQuery (requires jQuery)
  //     fixednumeric(scale) : convert to a numeric value with scale being the
  //                           number of fractional digits
  //     yesno : convert any non-zero numeric value to Yes, otherwise No
  function replaceTokens(text, tokenValues) {
  	var len, idx1, idx2, j, braceCount, foundEnd, ch, pieces, val, scale;
  	var htmlencodediv = null;
  
  	idx1 = 0;
  	len = text.length;
  	while ((idx1 = text.indexOf('${', idx1)) >= 0) {
  		braceCount = 0;
  		foundEnd = false;
  		for (idx2 = idx1; idx2 < len; idx2++) {
  			ch = text.charAt(idx2);
  			if (ch == '$') {
  				if ( ((idx2+1) < len) && (text.charAt(idx2+1) == '{') ) {
  					idx2++;
  					braceCount++;
  				}
  			} else if (ch == '}') {
  				braceCount--;
  				if (braceCount <= 0) foundEnd = true;
  			}
  			if (foundEnd) break;
  		}
  		pieces = replaceTokens(text.substring(idx1+2, idx2), tokenValues).split('|');
  		if (pieces.length > 0) {
  			pieces[0] = pieces[0].replace(/^\s+|\s+$/g,"");	// trim whitespace
  			val = (pieces[0] in tokenValues) ? tokenValues[pieces[0]] : '';
  			for (j = 1; j < pieces.length; j++) {
  				pieces[j] = pieces[j].replace(/^\s+|\s+$/g,"").toLowerCase();
  				if (pieces[j] == 'urlencode') {
  					val = escape(val);
  				} else if (pieces[j] == 'rawurlencode') {
  					val = encodeURIComponent(val);
  				} else if (pieces[j] == 'htmlencode') {
  					if (htmlencodediv == null) htmlencodediv = $('<div/>');
  					htmlencodediv.text(val);
  					val = htmlencodediv.html();
  				} else if (pieces[j].indexOf('fixednumeric') == 0) {
  					scale = pieces[j].substring(12).replace(/^\s+|\s+$/g,"");	// trim whitespace
  					while (scale.charAt(0) == '(') scale = scale.substring(1);
  					while ((scale.length > 0) && (scale.substring(scale.length-1) == ')')) {
  						scale = scale.substring(0, scale.length-1);
  					}
  					scale = scale.replace(/^\s+|\s+$/g,"");	// trim whitespace
  					scale = Number(scale);
  					val = String(Number(val).toFixed(scale));
  				} else if (pieces[j] == 'yesno') {
  					val = (Number(val) != 0) ? 'Yes' : 'No';
  				}
  			}
  		} else {
  			val = '';
  		}
  		text = text.substring(0, idx1) + val + (((idx2+1) < len) ? text.substring(idx2+1) : '');
  		idx1 += val.length;
  		len = text.length;
  	}
  	return text;
  }
  