var NB = function()
{
	var popup = {};
	popupDefaultConfig = "location=no,menubar=no,personalbar=no,resizeable=no,scrollbars=no,status=no,toolbar=no";
	openedWindows = [];
	
	return {
		Popup : function(url, width, height, config)
		{
			var index = -1;
			for(var i = 0; i < openedWindows.length; i++)
			{
				if(url == openedWindows[i])
				{
					 index = i;
					 break;
				}
			}
			
			var popupName = "";
			
			if(index > -1)
			{
				popupName = "popup_" + index;
			}
			else
			{
				popupName = "popup_" + openedWindows.length;
				openedWindows[openedWindows.length] = url;
			}
			
			xPos = Math.ceil((screen.availWidth - width) / 2);
			yPos = Math.ceil((screen.availHeight- height) / 2);
			
			config = (typeof(config) == "string") ? config : popupDefaultConfig;
			config += ",width="+width+",height="+height+",left="+xPos+",top="+yPos;
			
			var win = window.open(url, popupName, config);
			win.focus();
			
			return win;
		}	
	}
}();
NB.Math = function()
{
	return  {
		GetFloat : function(str, precision)
		{
			// if already numeric value
			if(typeof(str) == "number")
				return this.FormatFloat(str, precision);
			if(str == null || str == "")	return 0;
			
			str.indexOf(",");
			str = str.replace(",",".");
			str = str.replace(" ", "");
			re = new RegExp("([0-9.]+)");
			result = str.match(re);
			if(result != null)
				str = result[0];
			str = parseFloat(str);	
			if(isNaN(str)) str = 0;
			
			return str;
		},
		FormatFloat : function(num, precision)
		{
			num = parseFloat(num);
			if(!isNaN(num))
			{
				num *= Math.pow(10, precision);
				num  = Math.round(num);
				num /= Math.pow(10, precision);
			}
			else
				return "NaN";
			return num;
		},
		FormatNumber : function(num, decplaces, decPointChar, thousandsSepChar)
		{
			var num = (String)(num);
			num = num.replace(",", ".");
			var re = new RegExp("^([0-9]|[0-9]{2}|[0-9]{3}])?(([0-9]{3})*)(\\.[0-9]*)?$", "i");
			var matches = re.exec(num);

			var dec = 0;
			if(typeof(matches[4]) == "string")
			{
				dec = (matches[4].replace(".", ""));
			}
			
			var thousandGroups = [];
			if(typeof(matches[2]) == "string")
			{
				for(var i = 0; i < matches[2].length; i+=3)
				{
					thousandGroups[thousandGroups.length] = matches[2].substr(i, 3);
				}
			}
			
			var numberBegin = "";
			if(typeof(matches[1]) == "string")
			{
				numberBegin = matches[1];
			}
			
			var numberMiddle = thousandGroups.join(thousandsSepChar);
			
			if(numberBegin.length > 0 && numberMiddle.length > 0)
			{
				numberBegin += thousandsSepChar;
			}
			
			
			var numberEnd = "";
			if(decplaces > 0)
			{
				numberEnd += dec;
				for(var i = numberEnd.length; i < decplaces; i++)
				{
					numberEnd += "0";
				}
			}
			
			var output = numberBegin + numberMiddle + decPointChar + numberEnd;
			return output;
		}
	};
}();

