//Used to round any number to a specified decimal place. Helps keep the code clean.
function roundNumber(num, dec) {
	var result = Math.round( num * Math.pow(10,dec) ) / Math.pow( 10, dec );
	return result;
}

//Converts the base 10 number to any base wanted through the input. 
function parseBase(number, base){
	if(base < 2 || base > 36 || number < 0)
		return -1;
		
	i = 0;
	do{}while(Math.pow(base,++i) <= number);
	i--;
	
	convert = "";
	for( ;i>0;i--){
		convert += numlist[Math.floor(number / Math.pow(base,i))];
		number = Math.floor(number % Math.pow(base,i));
	}
	return convert + numlist[number];
}

//Creates a duplicate of an object.  Function written by Andrew Sellick at www.andrewsellick.com.
function cloneObj(o) {
	if(typeof(o) != "object") return o;
	if(o == null) return o;
	
	var newO = new Object();
	
	for(var i in o) newO[i] = cloneObj(o[i]);
	return newO;
}

//Converts the inputed number to a readable string for the bank location.
function ConvertLocation(num){
	str = "";
	if(num == 0) return "00";
	if(num < 10) str += "0";
	str += num;
	return str;
}

//Sorts the given list by level, and then by name.
function SortByLvl(a, b){
	if(a.level == b.level){
		if(a.name < b.name)		return -1;
		else if(a.name > b.name)return  1;
		else					return  0;
	}else{
		return a.level - b.level;
	}
}

//Sorts the given list by name.
function SortByName(a, b){
	if(a.name < b.name)		return -1;
	else if(a.name > b.name)return  1;
	else					return  0;
}

//Adds commas to a number. Function written by Keith Jenci at www.mredkj.com.
function addCommas(nStr){
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
