//*********************************************************************
// Method	: String.rightTrim
// Purpose	: Trims trailing whitespace chars
// Inputs	: None
// Returns	: String
//*********************************************************************
String.prototype.rightTrim = function (){
    var objRegExp = /^([\w\W]*)(\b\s*[　]*[ ]*)$/;
    if(objRegExp.test(this))
    {
        return this.replace(objRegExp,'$1');
    }
    return this;
}

//*********************************************************************
// Method	: String.leftTrim
// Purpose	: Trims leading whitespace chars
// Inputs	: None
// Returns	: String
//*********************************************************************
/*
String.prototype.leftTrim = function ()
{
    var objRegExp = /^(\s*[　]*)(\b[\w\W]*)$/;
    if(objRegExp.test(this))
    {
        return this.replace(objRegExp,'$2');
    }
    return this;
}
*/
String.prototype.leftTrim = function (){
    var objRegExp = /^(\s*[　]*)(\b[\w\W]*)$/;
    if(objRegExp.test(this))
    {
        return this.replace(objRegExp,'$2');
    }
    return this;
}

//*********************************************************************
// Method	: String.trim
// Purpose	: Removing leading and trailing space.
// Inputs	: None
// Returns	: String
//*********************************************************************
/*
String.prototype.trim = function (){
    var objRegExp = /^(\s*[　]*[ ]*)$/;
    if(objRegExp.test(this))
    {
        var strValue = this.replace(objRegExp,'');
        if( strValue.length == 0 ) return strValue;
    }

    objRegExp = /^(\s*[　]*[ ]*)([\w\W]*)(\b\s*[　]*[ ]*$)/;
    if(objRegExp.test(this))
    {
        return this.replace(objRegExp,'$2');
    }

    return this;
}
*/
String.prototype.trim = function (){
	var thisStr = ""+this;
    if(thisStr=="undefined")
        thisStr = "";
    var objRegExp = /^(\s*[　]*[ ]*)$/;
    if(objRegExp.test(thisStr))
    {
        var strValue = thisStr.replace(objRegExp,'');
        if( strValue.length == 0 ) return strValue;
    }

    objRegExp = /^(\s*[　]*[ ]*)([\w\W]*)(\b\s*[　]*[ ]*$)/;
    if(objRegExp.test(thisStr))
    {
        return thisStr.replace(objRegExp,'$2');
    }

    return thisStr;
}
//*********************************************************************
// Method	: String.trimAll
// Purpose	: Removing all space.
// Inputs	: None
// Returns	: String
//*********************************************************************
String.prototype.trimAll = function (){
    var objRegExp = /\s+|\s+$|　| /g;
    if(objRegExp.test(this))
    {
        return this.replace(objRegExp,'');
    }

    return this;
}

//*********************************************************************
// Method	: String.specialChr
// Purpose	: Special Chracter Replace
// Inputs	: None
// Returns	: String
//*********************************************************************
String.prototype.specialChr = function ()
{
    var objRegExp = /\"|\&|\+|\'|\<|\>/g;
    var retStr    = this;

    if(objRegExp.test(this))
    {
        retStr = this.replace(/\"/g,'%22');
        retStr = this.replace(/\&/g,'%26');
        retStr = this.replace(/\+/g,'%2B');
        retStr = this.replace(/\'/g,'%27');
        retStr = this.replace(/\</g,'%26lt');
        retStr = this.replace(/\>/g,'%26gt');
    }

    return retStr;
}

//*********************************************************************
// Method	: String.toInt
// Purpose	: String to Integer
// Inputs	: None
// Returns	: Integer
//*********************************************************************
String.prototype.toInt = function ()
{
    var objRegExp = /,/g;
    var retStr    = this;

    if(objRegExp.test(this))
    {
        retStr = this.replace(objRegExp,"");
    }
    return parseInt(retStr,10);
}

//*********************************************************************
// Method	: String.toFloat
// Purpose	: String to Float
// Inputs	: None
// Returns	: Float
//*********************************************************************
String.prototype.toFloat = function ()
{
    var objRegExp = /,/g;
    var retStr    = this;

    if(objRegExp.test(this))
    {
        retStr = this.replace(objRegExp,"");
    }

    return parseFloat(retStr);
}

//*********************************************************************
// Method	: String.toFloat
// Purpose	: String to Float
// Inputs	: None
// Returns	: Float
//*********************************************************************
String.prototype.nullchk = function ()
{
    if(this==null||this==undefined||this=="undefined")
        return "";
    else
        return this;
}

//*********************************************************************
// Method : var String = new StringBuffer();
// Purpose : String to StringBuffer
// Inputs : None
// Returns : StringBuffer
//*********************************************************************
var StringBuffer = function() {
 this.buffer = new Array();
}
//*********************************************************************
// Method : String.append("text");
// Purpose : add to StringBuffer
// Inputs : Text
// Returns : StringBuffer
//*********************************************************************

StringBuffer.prototype.append = function(obj) {
 this.buffer.push(obj);
}
//*********************************************************************
// Method : StringBuffer.toString()
// Purpose : StringBuffer to String
// Inputs : None
// Returns : String
//*********************************************************************
StringBuffer.prototype.toString = function() {
 return this.buffer.join("");
}

//*********************************************************************
// Method	: String.nl2br
// Purpose	: New Line To <BR /> Tag
// Inputs	: None
// Returns	: String
//*********************************************************************
String.prototype.nl2br = function ()
{
    var retStr = this;
	if(this==null||this==undefined||this=="undefined")
        return "";
        
    var objRegExp1 = /\n/g;
    var objRegExp2 = /\r/g;

    if(objRegExp1.test(this)){
        retStr = this.replace(/\n/g,'<br />');
    }else if(objRegExp2.test(this)){
    	retStr = this.replace(/\r/g,'<br />');
    }

    return retStr;
}

String.prototype.replaceAll = function(findstring, newstring){
    return this.replace(new RegExp(findstring, "gi"), newstring);
}

