// General Javascript Functions
// -------------------------------------------------------------------------------------------
var reWhitespace = /^\s+$/
var reFloating = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/
function round(number,X) 
{
	// rounds number to X decimal places, defaults to 2
	X = (!X ? 2 : X);
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
       
function checkcomma(tex)
{
	var invalid = ","; // Invalid character is a ','		
	if (tex.indexOf(invalid) > -1) 
	{
		return false;
	}
	else 
	{
		return true;
	}
}	       

function getRandomNum(lbound, ubound) 
{
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}

function getRandomChar(number, lower, upper, other, extra) 
{
	var numberChars = "0123456789";
	var lowerChars = "abcdefghijklmnopqrstuvwxyz";
	var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var otherChars = "";
	var charSet = extra;            
	if (number == true)
		charSet += numberChars;
	if (lower == true)
		charSet += lowerChars;
	if (upper == true)
		charSet += upperChars;
	if (other == true)
		charSet += otherChars;            
	return charSet.charAt(getRandomNum(0, charSet.length));
}

function getPassword(length) 
{
	var rc = "";
	if (length > 0)
		rc = rc + getRandomChar(1, 1, 1, 1, 'a');            
	for (var idx = 1; idx < length; ++idx) 
	{
		rc = rc + getRandomChar(1, 1, 1, 1, 'a');
	}
	return rc;
}

function trim(me)
{
	while(''+me.charAt(me.length-1)==' ')
		me = me.substring(0,me.length-1);	
	return me;
}
		
function isEmpty(s)
{
	return ((s == null) || (s.length == 0));
}

function isWhitespace(s)
{
	return (isEmpty(s) || reWhitespace.test(s));
}
	
function isDecimal(s)
{
	return reFloating.test(s);
}

function isPositive(s)
{
	if (s >= 0)
		return true;
	else
		return false;
}

function ConvertBR(input) 
{
	// Converts carriage returns 
	// to <BR> for display in HTML
	var output = "";
	for (var i = 0; i < input.length; i++) 
	{
		if ((input.charCodeAt(i) == 13) && (input.charCodeAt(i + 1) == 10)) 
		{
			i++;
			output += "<BR>";
		} 
		else 
		{
			output += input.charAt(i);
   		}
	}
	return output;
}

