//js对象增强类
function array_has(val)
{
	var i;
	for(i = 0; i < this.length; i++)
	{
		if(this[i] == val)
		{
			return true;
		}
	}
	return false;
}
Array.prototype.has = array_has;
	
function array_remove(val)
{
	var i;
	var j;
	for(i = 0; i < this.length; i++)
	{
		if(this[i] == val)
		{
			for(j = i; j < this.length - 1; j++)
			{
			this[j] = this[j + 1];
			}
			this.length = this.length - 1;
		}
	}
}
Array.prototype.remove = array_remove;
	
function array_removeAt(index)
{
	var i;
	if(index < this.length)
	{
		for(i = index; i < this.length - 1; i++)
		{
			this[i] = this[i + 1];
		}
		this.length = this.length - 1;
	}
}
Array.prototype.removeAt = array_removeAt;

// 扩展String对象的trim()方法
String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

//构造StringHelper对象
function StringHelper()
{

}
//定义StringHelper对象的Format方法
StringHelper.Format = function(format)
{
	if ( arguments.length == 0 )
	{
		return '';
	}
	if ( arguments.length == 1 )
	{
		return String(format);
	}

	var strOutput = '';
	for ( var i=0 ; i < format.length-1 ; )
	{
		if ( format.charAt(i) == '{' && format.charAt(i+1) != '{' )
		{
			var index = 0, indexStart = i+1;
			for ( var j=indexStart ; j <= format.length-2 ; ++j )
			{
				var ch = format.charAt(j);
				if ( ch < '0' || ch > '9' ) break;
			}
			if ( j > indexStart )
			{
				if ( format.charAt(j) == '}' && format.charAt(j+1) != '}' )
				{
					for ( var k=j-1 ; k >= indexStart ; k-- )
					{
						index += (format.charCodeAt(k)-48)*Math.pow(10, j-1-k);
					}  
					var swapArg = arguments[index+1];
					strOutput += swapArg;
					i += j-indexStart+2;
					continue;
				}
			}
			strOutput += format.charAt(i);
			i++;
		}
		else
		{
			if ( ( format.charAt(i) == '{' && format.charAt(i+1) == '{' )
				|| ( format.charAt(i) == '}' && format.charAt(i+1) == '}' ) )
			{
				i++
			}
			strOutput += format.charAt(i);
			i++;
		}
	}
	strOutput += format.substr(i);
	return strOutput;
}

//查询最后匹配的字串并返回结果
function GetStringLastIndexOf(strsrc,indexstr)
{
	var i = strsrc.lastIndexOf(indexstr);
	var result = new Array();
	if(i<0)
	{
		result[0] = strsrc;
		result[1] = "";
	}
	else
	{
		result[0] = strsrc.substring(0,i);
		result[1] = strsrc.substring(i+1);
		
	}
	return result;
}

//查询第一个匹配的字串并返回结果
function GetStringIndexOf(strsrc,indexstr)
{
	var i = strsrc.indexOf(indexstr);
	var result = new Array();
	if(i<0)
	{
		result[0] = strsrc;
		result[1] = "";
	}
	else
	{
		result[0] = strsrc.substring(0,i);
		result[1] = strsrc.substring(i+1);
	}
	return result;
}
