﻿<!--
String.prototype.Trim = function(mode)
{
	var re;
	var str = this;
	switch(parseInt(mode))
	{
		case 1:			//去除左边空白
			re = /^\s*/g;
		break;
		case 2:			//去除右边空白
			re = /\s*$/g;
		break;
		case 3:			//修剪中间多余空白，去除左右空白
			str = str.replace(/\s+/g,' ');
			re = /(^\s*)|(\s*$)/g;
		break;
		case 4:			//去除所有空白
			re = /\s+/g;
		break;
		default:		//去除左右空白
			re = /(^\s*)|(\s*$)/g;
		break;
	}
    return str.replace(re,'');
}

String.prototype.Left = function(precision, more)
{
	var str = this;
	if(!more) more = '';
	if(str.length > precision)
		return str.substr(0, precision-more.length) + more;
	else
		return str;
}

String.prototype.IsInt = function()
{
	var Int = parseInt(this,10);
	if(isNaN(Int)) return false;
	if(Int.toString() != this) return false;
	return true;
}

String.prototype.IsFloat = function()
{
	var Float = parseFloat(this,10);
	if(isNaN(Float)) return false;
	if(Float.toString() != this) return false;
	return true;
}

String.prototype.Round = function(precision)
{
	var R = Math.pow(10, precision);
	return Math.round(this * R) / R;
}
// 重载适应更多数据类型
Object.prototype.Round = function(precision)
{
	var R = Math.pow(10, precision);
	return Math.round(this * R) / R;
}

String.prototype.ToDate = function()
{
	return this.substring(0,this.indexOf(' '));
}

function AutoTrim(object, count, more, tag)
{
	if(tag == null) tag = 'a';
	var subjects = document.getElementById(object).getElementsByTagName(tag);
	for(var i=0; i<subjects.length; i++)
	{
		subjects[i].title = subjects[i].innerText;
		subjects[i].innerText = subjects[i].innerText.Left(count, more);
	}
}
//-->
