String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g,'');
}

function numberFormat(nbr,minimum,maximum)
{
	nbr_old=parseInt(nbr.value,10);

	nbr_new=(isNaN(nbr_old) || nbr_old < 0)?0:nbr_old;

	if(nbr_new && nbr_new < minimum)
	{
		nbr_new=minimum;
	}
	else if(maximum && nbr_new > maximum)
	{
		nbr_new=maximum;
	}

	if(nbr_new.toString() != nbr.value)
	{
		nbr.value=nbr_new;
	}

	return nbr_new;
}

function substr_count(haystack,needle)
{
	var pos=cnt=0;

	var offset=-1;

	while((offset=haystack.indexOf(needle, offset+1)) != -1)
	{
		cnt++;
	}

	return cnt;
}
