var SelectMode = 1;
var EditMode = 2;
function FormatMgr(DayFirstFormat, DateTimeFormat,DateTimeFormatShort,TimeFormat,NoOfDecPlace,NumSep)
{
	
	//=========================Properties=============================//
	this.DayFirstFormat			=	DayFirstFormat;
	this.DateTimeFormat			=	DateTimeFormat;
	this.DateTimeFormatShort	=	DateTimeFormatShort;
	this.TimeFormat				=	TimeFormat;
	this.NoOfDecPlace			=	NoOfDecPlace;
	this.NumSep					=	NumSep;
	//================================================================//
	
	//============================Methods=============================//
	this.GetFormattedDate	=	function GetFormattedDate(dateTime)
	{
		
		var dt = new Date(dateTime);//parseDate(dateTime);
		//alert(getDateFromFormat('2008-05-01','y-M-d'));
		if(!dt)
			return "";
		return formatDate(dt,this.DateTimeFormat);
		
		//alert("this.DateTimeFormat = " + this.DateTimeFormat);
		//alert("formatDate(dt,this.DateTimeFormat) = " + formatDate(dt,this.DateTimeFormat));
		
	}
	
	this.GetFormattedDateShort	=	function GetFormattedDateShort(dateTime)
	{
		var dt = new Date(dateTime);
		if(!dt)
			return "";
		return formatDate(dt,this.DateTimeFormatShort);
	}
	
	this.GetFormattedDateTime	=	function GetFormattedDateTime(dateTime)
	{
		dt = new Date(dateTime);
		return formatDate(dt,this.DateTimeFormat + ' ' + this.TimeFormat);
		
	}
	
	this.GetFormattedDateObj	=	function GetFormattedDateObj(dateTime)
	{
		return getDateObj(dateTime,this.DateTimeFormat);
			
	}
	
	this.GetFormattedDateShortObj	=	function GetFormattedDateShortObj(dateTime)
	{
		return getDateObj(dateTime,this.DateTimeFormatShort);
	}
	
	this.GetFormattedDateTimeObj	=	function GetFormattedDateTimeObj(dateTime)
	{
		return getDateObj(dateTime,this.DateTimeFormat + ' ' + this.TimeFormat);
	}
	
	this.GetFormattedNum	=	function GetFormattedNum(num)//Display Mode , SelectMode = 1, EditMode = 2
	{
		decpoint = ".";
		sep = this.NumSep;
		// check for missing parameters and use defaults if so
		//Display Mode , SelectMode = 1, EditMode = 2
		if (arguments.length == 2) {
			if(arguments[1] == SelectMode)
				sep = ",";
			else if(arguments[1] == EditMode)
				sep = "";
		}
		if (arguments.length == 1) {
			sep = ",";
			decpoint = ".";
		}
		//Temporary disable number seperator by TTW
		//sep = "";
		// need a string for operations
		num = num.toString();
		// separate the whole number and the fraction if possible
		a = num.split(decpoint);
		x = a[0]; // decimal
		y = a[1]; // fraction
		z = "";


		if (typeof(x) != "undefined") {
			// reverse the digits. regexp works from left to right.
			for (i=x.length-1;i>=0;i--)
			z += x.charAt(i);
			// add seperators. but undo the trailing one, if there
			z = z.replace(/(\d{3})/g, "$1" + sep);
			if (z.slice(-sep.length) == sep)
			z = z.slice(0, -sep.length);
			x = "";
			// reverse again to get back the number
			for (i=z.length-1;i>=0;i--)
			x += z.charAt(i);
			// add the fraction back in, if it was there
			if (typeof(y) != "undefined" && y.length > 0)
			x += decpoint + y;
		}
		//alert("this.NoOfDecPlace = " + this.NoOfDecPlace);
		if(x.indexOf('.') != -1)
		{
			//alert('if x = ' + x);
			strDisplay = x.substring(0,x.indexOf('.')+ new Number(this.NoOfDecPlace) + 1);
			//alert('strDisplay = ' + strDisplay);
		}
		else
		{
			strDisplay = x;
			//alert('else');
		}
		return strDisplay;
		//0123456789
		//1234567.890
			
		/*numObj = new Number(num);
		numObj.toFixed(this.NoOfDecPlace);
		return ;*/
	}
	//================================================================//
}
