String.prototype.wrap = function(maxWidth) {
    var SBC_PIXEL = 14;
    var DBC_PIXEL = 8;
    //check parameter
    if (this.length == 0) return this;
    if (typeof(maxWidth) != "number" || maxWidth == NaN || maxWidth < 1) return this;
    
    //calculate character length
    var temp = [];
    for (var i=0; i < this.length; i++) {
        var chr = this.substr(i,1);
        var len = (escape(chr).length > 3 ? SBC_PIXEL : DBC_PIXEL) + ((i==0) ? 0 : temp[i-1].l);
        temp.push({c:chr, l:len });
    }
    
    //if (temp[temp.length-1].l <= byteLength) return this;
    var line = 1;
    for (var i=0; i < temp.length ;i++) {
        if (temp[i].l >= maxWidth * line) { temp[i].c = temp[i].c + "\n"; line = line + 1; }
    }
    
    var value = "";
    for (var i=0; i < temp.length ;i++) value = value + temp[i].c;
    
    return value;
};
//取得字符串总长度
//temp function,should be changed
function getStringLength (str)
{
    var length = 0;
    for(var i=0;i<str.length;i++)
    {
        length += getCharLength(str.substr(i,1));
    }
    return length;
}

//取得字符长度
//temp function,should be changed
function getCharLength (chr)
{
    //是全角文字的 
    if(chr.match(/[ -~｡-ﾟ]/) == null)
    {
        return 14;
    }
    //是半角文字的 
    else
    {
        //半角数字 
        if(chr>="0" && chr<="9")
        {
            return 7.9;
        }
        //半角小写英文 
        if(chr>="a" && chr<="z")
        {
            if(chr == "i" || chr == "l")
            {
                return 3.02;
            }
            if(chr == "w" || chr == "m")
            {
                return 10.9;
            }
            return 6.86;
        }
        //半角大写英文
        if(chr>="A" && chr<="Z")
        {
            if(chr == "I")
            {
                return 5;
            }
            if(chr == "W")
            {
                return 14;
            }
            if(chr == "M")
            {
                return 13;
            }
            return 11;
        }
        if(chr == ":" || chr == "|" || chr == ".")
        {
            return 3;
        }
        return 7.8;
    }
}
function Length(str, len){
    var outStr = '';
    if(str.length > len){
        outStr = str.substring(0,len) + '……';
    }
    else{
        outStr = str;
    }
    return outStr;
}
