// =============================================================================
// flowchart_strman.js
//
// getUniqueId()  // return value >= 0
// getUniqueId(false) // resets the counter to 0
//    Source: reported as Flanagan (Rhino) Javascript book, page 131 of the 5th edition.
//
// $(idHTMLelement)
//    returns element (e) = document.getElementById(id) if successful,
//    otherwise returns $dummy() DIV element to prevent crash.
//
// $dummy()
//    creates and returns DIV element with e.style.display='none'
//
// $show(id,fShow)
//    calls $(id).style.display=(fShow?'inline':'none');
//
// addClass(e,value)
//    safely adds value to element e
//
// $addClass(id,value)
//   calls addClass($(id),value)
//
// $$(idHTMLelement)
//    accesses e.value property
//
// $HTML(idHTMLelement)
//    accesses e.innerHTML property
//
// $call(functionName,data)
//    returns the function call functionName(data) if functionName is type 'function',
//    otherwise returns null
//
// Number.addCommas()
// String.addCommas()
//    adds commas to large numbers. returns the new string
//    Source: http://www.mredkj.com/javascript/nfbasic.html
//
// String.removeCommas() // removes all , characters
//
//
// String.endOfLine() // returns index of new line character
// String.getLine()   // returns text up to new line character

// String.advanceLine() // returns text after new line character
// String.nextLine()    // advances a line and returns it (use .advanceLine() )
//
// String.trim()        // removes leading and trailing spaces
//
// String.trimHead(keyword) // finds keyword returns it and trailing text
// String.trimTail(keyword) // finds keyword returns all text before it
//
// String.removeCarriageReturns() // removes all \r characters that MSIE inserts. returns new string
// String.removeQuotes() // removes all \' and \" characters. returns new string
// String.removeCommas() // removes all , characters. returns new string
// String.concatWords() // removes spaces inside of text. returns new string
// String.squish()      // faster call than return String.removeQuotes().removeCommas().concatWords();
// String.toVariable()  // return String.squish().toLowerCase()
// =============================================================================

// =============================================================================
// Source: reported as Flanagan (Rhino) Javascript book, page 131 of the 5th edition.
var getUniqueId = (function() {var id=0;return function() {if (arguments[0]==false)id=0;return id++;}})();
// =============================================================================
function $dummy() {var e=document.createElement("div");e.style.display='none';return e;};
function $(id)
{
  var e=document.getElementById(id);
  if(!e)
  {
    e=$dummy();
    e.id=id;
    document.body.appendChild(e);
  }
  return e;
};
function $show(id,fShow) {$(id).style.display=(fShow?'inline':'none');};
function $$(id) {var e=$(id);if(typeof arguments[1]!='undefined')e.value=arguments[1];return e.value;};
function $HTML(id) {return $(id).innerHTML;};
function $className(id,v) {var e=$(id);addClass(e,v);};
function $addClass(id,v) {addClass($(id),v);};

function addClass(e,v)
{
  if (! e.className)
    e.className = v;
  else
  {
    if (-1 == e.className.indexOf(v))
      e.className = e.className+' '+v;
  }
};

function $call(fn,data) {return ((typeof fn=='function')?fn(this.data):null)};
// =============================================================================
// Source: http://www.mredkj.com/javascript/nfbasic.html
String.prototype.addCommas = function()
{
  var x=this.split('.');
  var x1=x[0];
  var x2=(x.length>1)?('.'+x[1]):'';
  var rgx=/(\d+)(\d{3})/;
  while (rgx.test(x1))
    x1=x1.replace(rgx,'$1'+','+'$2');
  return x1+x2;
};
Number.prototype.addCommas = function() {return this.toString().addCommas();};
String.prototype.removeCommas = function() {return this.replace(/,/g,'');};
String.prototype.removeCarriageReturns = function() {return this.replace(/\r+/g,'')};
String.prototype.removeQuotes = function() {return this.replace(/\'|\"/g,'');};
String.prototype.endOfLine = function() {return this.indexOf('\n');};
String.prototype.getLine = function() {return this.substring(0,this.endOfLine());};
String.prototype.advanceLine = function() {return this.substring(this.endOfLine()+1);};
String.prototype.nextLine = function() {return this.advanceLine().getLine();};
String.prototype.trim = function() {return this.replace(/^\s+|\s+$/,'');};
String.prototype.trimHead = function(search) {return (function(text,search) {var i=text.indexOf(search);if(i!=-1)text=text.substring(i);return text;})(this,search);};
String.prototype.trimTail = function(search) {return (function(text,search) {var i=text.lastIndexOf(search);if(i!=-1)text=text.substring(0,i);return text;})(this,search);};
String.prototype.concatWords = function() {return this.replace(/\s/g,'');};
String.prototype.squish = function() {return this.replace(/\'|\"|\s|,/g,'');};
String.prototype.toVariable = function() {return this.squish().toLowerCase();};
// =============================================================================


