String.prototype.trim = function() {
		return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function() {
		return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");	
}
	
String.prototype.replaceAll = function(strTarget, // The substring you want to replace
								strSubString // The string you want to replace in.
){
 var strText = this;
 var intIndexOfMatch = strText.indexOf( strTarget );
  
 // Keep looping while an instance of the target string
 // still exists in the string.
 while (intIndexOfMatch != -1){
 // Relace out the current instance.
 strText = strText.replace( strTarget, strSubString );
  
 // Get the index of any next matching substring.
 intIndexOfMatch = strText.indexOf( strTarget );
 }
  
 // Return the updated string with ALL the target strings
 // replaced out with the new substring.
 return( strText );
}

String.prototype.isNumeric = function()

{
	var sText = this;
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


var numSplitItems = 0;
String.prototype.split2 = function(splitOn) {
	var strText = this;
	var output = [];
 	numSplitItems = 0;
 	var idx = strText.indexOf(splitOn);
   	while (idx != -1){
 		var strText2 = strText.substring(0, idx);
 		output[numSplitItems] = strText2;
 		numSplitItems = numSplitItems+1;
 		strText = strText.substring(idx+splitOn.length);
   		idx = strText.indexOf(splitOn);
 	}
 	if(strText != "" && strText != splitOn) {
 		output[numSplitItems] = strText;
 		numSplitItems = numSplitItems + 1;
 	}
 	return(output);
}

String.prototype.quote = function() {
	var str = this.replace(/'/g, "\\\'");
	str = str.replace(/"/g,"%22");
	return str;
}

function StringBuffer() { 
   this.buffer = []; 
 } 

 StringBuffer.prototype.append = function append(string) { 
   this.buffer.push(string); 
   return this; 
 }; 

 StringBuffer.prototype.appendBuffer = function append(stringBuff) { 
   for(var i=0; i<stringBuff.length; i++)
	   this.buffer.push(stringBuff.get(i)); 
   return this; 
 }; 
 
 StringBuffer.prototype.length = function() {
 	return this.buffer.length;
 }
 StringBuffer.prototype.toString = function toString() { 
   return this.buffer.join(""); 
 }; 
 function get(i) {
 	return this.buffer[i];
 }

  
 
