var _dCalMinDate= new Date(1800, 4, 1);
var _dCalMaxDate= new Date(2200, 11, 31);

var _sShowWeekNumbers= "1";
var iShowWeekCalWidth= 170;
var iNoWeekCalWidth  = 150;
var iCalHeight       = 173;

var HILITE_NONE= 0;
var HILITE_DAY= 1;
var HILITE_WEEK= 2;
var HILITE_MONTH= 3;

// Popup Calendar
FM.UI.PopupCalendar= function(wnd) {
	var iCalWidth= _sShowWeekNumbers == "1" ? iShowWeekCalWidth : iNoWeekCalWidth;
	if (Sys.Browser.agent == Sys.Browser.Firefox) iCalHeight= 164;
	this.Window= (!wnd) ? new FM.PopupWindow(null, null, window.document, iCalWidth, iCalHeight) : wnd;
	this._format= "d";
	this.contentDiv= this.Window.GetBodyElement();
	this.OnSelect= null;
	this.FireOnMonth= false;
	
	$addHandlers(this.contentDiv, {
		'click' : this._click
	}, this);
	
	this.dtf= Sys.CultureInfo.CurrentCulture.dateTimeFormat;
	
	this.HideDlg= Function.createDelegate(this, this.Hide);
}

FM.UI.PopupCalendar.prototype= {

	dispose : function() {
		if (!this.Window) return;
		$clearHandlers(this.contentDiv);
		this.Window.dispose();
		this.Window= null;
  },
	
	SetCurrentDate : function(oDate, format) {
		this.Date= (oDate) ? oDate : new Date();
		if (format) this._format= format;
	},
	
	Show : function(hiliteCode) {
		this.Window.SetHtml(this.DrawMonth(this.Date, (hiliteCode) ? hiliteCode : HILITE_DAY, this.Date));
		this.Window.Show();
	},
	
	ShowMonth : function(hiliteCode) {
		this.Window.SetHtml(this.DrawYear(this.Date, (hiliteCode) ? hiliteCode : HILITE_MONTH));
		this.Window.Show();
	},
	
	Hide : function() {
		this.Window.Hide();
	},	
	
	_click : function(e) {
		var o= e.target;
		e.stopPropagation();
		var d= o.getAttribute('d');
		if (!d) return;
				
		var nav= o.getAttribute('nav');
		var D= new Date(parseInt(d, 10));
		
		switch (nav) {
			case "1": //
				var m= D.getMonth();
				var d= D.getDate();
				var a= new Array(31,28,31,30,31,30,31,31,30,31,30,31);
				if (D.getYear() % 4 == 0) a[1]= 29;
				
				if (o.innerHTML == "&lt;") {
					m--;
					if ((m > 0) && (d > a[m])) {
						D.setDate(a[m]);
					}
					D.setMonth(m);
				} else if (o.innerHTML == "&gt;") {					
					m++;
					if ((m < 12) && (d > a[m])) {						
						D.setDate(a[m]);
					}
					D.setMonth(m);
				}
				if (this.FireOnMonth && this.OnSelect) { 
					this.Date= D; this.OnSelect(); 
				} else
					this.Window.SetHtml(this.DrawMonth(D, HILITE_NONE, null));
				break;

			case "2":
				if (o.innerHTML == "&lt;") {
					D.setYear(D.getFullYear() - 1);
				} else if (o.innerHTML == "&gt;") {
					D.setYear(D.getFullYear() + 1);
				}
				this.Window.SetHtml(this.DrawYear(D));
				break;
				
			case "3":
				if (o.innerHTML == "&lt;") {
					D.setYear(D.getFullYear() - 1);
				} else if (o.innerHTML == "&gt;") {
					D.setYear(D.getFullYear() + 1);
				}
				this.Window.SetHtml(this.DrawYearsArray(D));
				break;				
				
			default: 
				this.Hide();
				if (this.OnSelect) { this.Date= D; this.OnSelect(D.getFullYear(), D.getMonth(), D.getDate()); };
				break;
		}
	},

	///
	/// Renders the control to display a month using the given day
	///
	/// D        - day around which the month should be rendered
	/// hiliteCode - rules for hiliting the dates around the given day
	///            - HILITE_NONE - no 'range' is hilited
	///            - The day represented by 'hiliteDay' is hilited
	///            - The week that contains 'hiliteDay' is hilited
	/// hiliteDay  - The day to hilite
	DrawMonth : function(D, hiliteCode, hiliteDay) {
		
		// Determine hiliting range
		var dHiliteStart= null;
		var dHiliteEnd  = null;

		switch (hiliteCode) {
			case HILITE_DAY:
				dHiliteStart= new Date(hiliteDay);
				dHiliteEnd  = new Date(hiliteDay);
				break;
				
			case HILITE_WEEK:
				dHiliteStart= DT_GetFirstDayOfWeek(hiliteDay);   
				dHiliteEnd  = DT_GetLastDayOfWeek(hiliteDay); 
				break;
				
			default:
				// Do nothing-- rather than let the user get an error, emulate HILITE_NONE.
				break;
		}

		// We are stuck with a full DateTime even though we only want to
		// check at the date level.  So, adjust the hilite start/end times
		// to be at the start/end of the days, respectively.  Otherwise
		// our date comparisons won't work.
		if (dHiliteStart != null) {
			dHiliteStart.setMilliseconds(0);
			dHiliteStart.setSeconds(0);
			dHiliteStart.setMinutes(0);
			dHiliteStart.setHours(0);
		}

		if (dHiliteEnd != null) {
			dHiliteEnd.setMilliseconds(999);
			dHiliteEnd.setSeconds(59);
			dHiliteEnd.setMinutes(59);
			dHiliteEnd.setHours(23);
		}

		var tmpDate= new Date(D);
		tmpDate.setHours(0,0,0,0);

		var dToday= new Date();
		dToday.setHours(0,0,0,0);

		var iToday= dToday.valueOf();

		var dInitDate= new Date(tmpDate.valueOf());
		var iInitMonth= dInitDate.getMonth();

		tmpDate= DT_GetFirstDayInCalendar(tmpDate);

		// write out the top navigation
		//
		var sb= new Sys.StringBuilder();
		sb.append("<table class='dt_tbl' cellpadding='0' cellspacing='0' style='border-collapse: collapse;table-layout:fixed'><tr><td style='border:1px solid #7b9ebd;height:18px;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffff,EndColorStr=#cecfde);' colspan='");
		if( _sShowWeekNumbers == "1" ) {
			// 7 days + 1 week number= 8 columns
			sb.append("8");
		} else {
			sb.append("7");
		}

		sb.append("'><table cellpadding='0' cellspacing='0' style='table-layout:fixed'><tr height='18' style='cursor:pointer;'>");

		var iValue= dInitDate.valueOf();

		// previous month navigation
		//
		if (tmpDate < _dCalMinDate) {
			sb.append("<td width='22' nav='0'>&nbsp;</td>");
		} else {
			sb.append("<td width='22' d='" + iValue + "' nav='1' onmouseover='this.runtimeStyle.color= \"#e89f2e\";' onmouseout='this.runtimeStyle.color= \"\";'>&lt;</td>");
		}

		// year navigation
		//
		sb.append("<td width='104' d='" + iValue + "' nav='2' onmouseover='this.runtimeStyle.color= \"#e89f2e\";' onmouseout='this.runtimeStyle.color= \"\";'>" + this.dtf.AbbreviatedMonthNames[iInitMonth] + " " + dInitDate.getFullYear() + "</td>");

		// next month navigation
		//
		var dLastDay= new Date(tmpDate.valueOf());

		dLastDay.setDate(dLastDay.getDate() + 42);

		if (dLastDay > _dCalMaxDate) {
			sb.append("<td width='22' nav='0'>&nbsp;</td>");
		} else {
			sb.append("<td width='22' d='" + iValue + "' nav='1' onmouseover='this.runtimeStyle.color= \"#e89f2e\";' onmouseout='this.runtimeStyle.color= \"\";'>&gt;</td>");
		}

		sb.append("</tr></table></td></tr>");

		// write out the days of the week
		//
		sb.append("<tr>");

		var i= 0;
		var ii= this.dtf.FirstDayOfWeek;

		if( _sShowWeekNumbers == "1" ) {
			// Blank out area above week numbers
			sb.append("<td style='background-color:#eeeeee;border:1px solid #7b9ebd;width:20px;height:18px;' nav='0'></td>");
		}

		while (i < 7) {
			sb.append("<td style='background-color:#eeeeee;border:1px solid #7b9ebd;width:20px;height:18px;' nav='0'>" + this.dtf.ShortestDayNames[(i + this.dtf.FirstDayOfWeek) % 7] + "</td>");
			i++;
			ii++;
			if (ii > 6) ii= 0
		}

		sb.append("</tr>");

		// write out the main body of the calendar
		//
		var iDate= 0;
		var sStyle= "";

		for (i= 0; i < 6; i++) {
			sb.append("<tr style='height:18px;' onmouseover='if(event.srcElement.noHl!=1){event.srcElement.runtimeStyle.color= \"#e89f2e\";}' onmouseout='if(event.srcElement.noHl!=1){event.srcElement.runtimeStyle.color= \"\";}'>");

			if (_sShowWeekNumbers == "1") {
				// Write out week numbers; addition is to use the last day of the week to create the week number from, which is what outlook does.
				// Otherwise Jan 1 is frequently 'week 53'
				var iWeekNumber= DT_GetWeekNumber(DT_GetLastDayOfWeek( tmpDate ) );
				sb.append("<td noHl='1' style='color:#0000ff;background-color:#eeeeee;border:1px solid #7288ac;width:20px;'>" + iWeekNumber + "</td>");
			}
			for (ii= 0; ii < 7; ii++) {
				iDate= tmpDate.getDate();
				iValue= tmpDate.valueOf();

				sStyle= "border:1px solid #7288ac;width:20px;";
				
				if (iValue == iToday) {
					sStyle+= "background-color:#DE8E29;color:#ffffff;";
				}
				
				var dayIsInThisMonth= ( tmpDate.getMonth() == iInitMonth );
				
				// Hilite the selected week if appropriate
				if( ( hiliteCode == HILITE_DAY || hiliteCode == HILITE_WEEK ) &&
									( tmpDate.getTime( ) >= dHiliteStart.getTime( ) ) &&  ( tmpDate.getTime( ) <= dHiliteEnd.getTime( ) ) )
				{
					sStyle+= "background-color:#3C9DFF;color:#ffffff;";//#cccccc;";
				} else if( !dayIsInThisMonth ) {
					sStyle+= "color:#cccccc";
				}
				/*
				if (tmpDate < _dCalMinDate || tmpDate > _dCalMaxDate) {
					sb.append("<td style='" + sStyle + "' nav='0'>&nbsp;</td>");
				} else 
				*/
				if (tmpDate.getMonth() != iInitMonth) {
					sb.append("<td style='cursor:pointer;" + sStyle + "' d='" + iValue + "'>" + iDate + "</td>");
				} else {
					sb.append("<td style='cursor:pointer;" + sStyle + "' d='" + iValue + "'>" + iDate + "</td>");
				}

				tmpDate.setDate(iDate + 1);
			}
			
			sb.append("</tr>");
		}

		// 7 days + 1 week number= 8 columns
		sb.append(this.getTodayBarHtml((_sShowWeekNumbers == "1" ? "8" : "7")));
		sb.append("</table>");
		return sb.toString(); 		
	},
	
	// Build the bottom "Today" Bar
	getTodayBarHtml : function(iColSpan) {
		var dToday= new Date();
		var s= "<tr style='height:18px;'><td style='padding-top:1px;cursor:pointer;border:1px solid #7288AC;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffff,EndColorStr=#cecfde);' colspan='";
		s+= iColSpan; 
		s+= "' d='" + dToday.valueOf() + "' onmouseover='runtimeStyle.color= \"#e89f2e\";' onmouseout='runtimeStyle.color= \"\";'>";
		//s+= formatString(_sTodayMask, DT_getDisplayValue(dToday, this._format));
		s+= "Today: " + DT_getDisplayValue(dToday, this._format);
		s+= "</td></tr>";
		return s;
	},
	
	DrawYear : function(oDate, hiliteCode) {
		var tmpDate= new Date(oDate);
		tmpDate.setMonth(0);
		tmpDate.setDate(1);
		var hMonth= (hiliteCode == HILITE_MONTH) ? oDate.getMonth() : -1;

		// write out the top navigation
		//
		var sb= new Sys.StringBuilder();
		sb.append("<table class='dt_tbl' cellpadding='0' cellspacing='0' width='");
		sb.append(_sShowWeekNumbers == "1" ? iShowWeekCalWidth : iNoWeekCalWidth);
		sb.append("' style='border-collapse:collapse;table-layout:fixed'><tr><td style='border:1px solid #7b9ebd;height:18px;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffff,EndColorStr=#cecfde);' colspan='3'><table cellpadding='0' cellspacing='0' style='table-layout:fixed'><tr height='18' style='cursor:pointer;'>");

		var iValue= tmpDate.valueOf();
		var iYear= tmpDate.getFullYear();

		// previous year navigation
		//
		if (iYear <= _dCalMinDate.getFullYear())
			sb.append("<td width='22' nav='0'>&nbsp;</td>");
		else
			sb.append("<td width='22' d='" + iValue + "' nav='2' onmouseover='this.runtimeStyle.color= \"#e89f2e\";' onmouseout='this.runtimeStyle.color= \"\";'>&lt;</td>");

		// write out the year 
		sb.append("<td d='" + iValue + "' nav='3' onmouseover='this.runtimeStyle.color= \"#e89f2e\";' onmouseout='this.runtimeStyle.color= \"\";'>" + iYear + "</td>");

		// next year navigation
		//
		if (iYear >= _dCalMaxDate.getFullYear())
			sb.append("<td width='22' nav='0'>&nbsp;</td>");
		else
			sb.append("<td width='22' d='" + iValue + "' nav='2' onmouseover='this.runtimeStyle.color= \"#e89f2e\";' onmouseout='this.runtimeStyle.color= \"\";'>&gt;</td>");

		sb.append("</tr></table></td></tr>");

		// write out the months
		//
		var iMonth= 0;

		for (i= 0; i < 4; i++) {
			sb.append("<tr style='height:"+((i == 3)?"33":"32")+"px;' onmouseover='event.srcElement.runtimeStyle.color= \"#e89f2e\";' onmouseout='event.srcElement.runtimeStyle.color= \"\";'>");

			for(ii= 0; ii < 3; ii++) {
				iMonth= tmpDate.getMonth();
				iValue= tmpDate.valueOf();

				sb.append("<td style='border:1px solid #7288ac;cursor:pointer;");
				if (hiliteCode == HILITE_MONTH && iMonth == hMonth) sb.append("background-color:#3C9DFF;color:#ffffff;");
				sb.append("(' d='" + iValue + "' nav='1'>" + this.dtf.AbbreviatedMonthNames[iMonth] + "</td>");

				tmpDate.setMonth(iMonth + 1);
			}

			sb.append("</tr>");
		}

		sb.append(this.getTodayBarHtml(3));
		sb.append("</table>");

		return sb.toString();
	},
	
	DrawYearsArray : function(oDate) {
		var tmpDate= new Date(oDate);
		tmpDate.setMonth(0);
		tmpDate.setDate(1);

		// write out the top navigation
		//
		var sb= new Sys.StringBuilder();
		sb.append("<table class='dt_tbl' cellpadding='0' cellspacing='0' width='");
		sb.append(_sShowWeekNumbers == "1" ? iShowWeekCalWidth : iNoWeekCalWidth);
		sb.append("' style='border-collapse:collapse;table-layout:fixed'><tr><td style='border:1px solid #7b9ebd;height:18px;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffff,EndColorStr=#cecfde);' colspan='3'><table cellpadding='0' cellspacing='0' style='table-layout:fixed'><tr height='18' style='cursor:pointer;'>");

		var iYear= tmpDate.getFullYear();
		var iYear1= iYear - 7;
		var iYear2= iYear + 7;

		// previous year navigation
		//
		if (iYear1 <= _dCalMinDate.getFullYear())
			sb.append("<td width='22' nav='0'>&nbsp;</td>");
		else
			sb.append("<td width='22' d='" + tmpDate.setYear(iYear1).valueOf() + "' nav='3' onmouseover='this.runtimeStyle.color= \"#e89f2e\";' onmouseout='this.runtimeStyle.color= \"\";'>&lt;</td>");

		// write out the year 
		sb.append("<td nav='0'>" + iYear1  + " - " + + iYear2 + "</td>");

		// next year navigation
		//
		if (iYear2 >= _dCalMaxDate.getFullYear())
			sb.append("<td width='22' nav='0'>&nbsp;</td>");
		else
			sb.append("<td width='22' d='" + tmpDate.setYear(iYear2).valueOf() + "' nav='3' onmouseover='this.runtimeStyle.color= \"#e89f2e\";' onmouseout='this.runtimeStyle.color= \"\";'>&gt;</td>");

		sb.append("</tr></table></td></tr>");

		// write out the months
		//
		for (i= 0; i < 5; i++) {
			sb.append("<tr style='height:" + (25 + ((i+1) % 2)) + "px' onmouseover='event.srcElement.runtimeStyle.color= \"#e89f2e\";' onmouseout='event.srcElement.runtimeStyle.color= \"\";'>");

			for(ii= 0; ii < 3; ii++) {
				sb.append("<td style='border:1px solid #7288ac;cursor:pointer;' d='" + tmpDate.setYear(iYear1).valueOf() + "' nav='2'>" + (iYear1++) + "</td>");
			}

			sb.append("</tr>");
		}

		sb.append(this.getTodayBarHtml(3));
		sb.append("</table>");

		return sb.toString();
	}
}

FM.UI.PopupCalendar.registerClass('FM.UI.PopupCalendar', null, Sys.IDisposable);

FM.UI.PopupCalendar.getCurrent= function () {
  if (!FM.UI.PopupCalendar._current) FM.UI.PopupCalendar._current= new FM.UI.PopupCalendar();
  return FM.UI.PopupCalendar._current;
}


// Time Table
//
FM.UI.TimeTable= function(timeformat) {
	this.format= timeformat;
	this.Window= new FM.PopupWindow(null, null, window.document, 156, 153);
	this.contentDiv= this.Window.GetBodyElement();
	//this.contentDiv.style.backgroundColor= "";
	this.OnSelect= null;
	
	this.Hours= 0;
	this.Minutes= 0;
	
	this.startHour= 8;
	this.endHour= 18;
	
	this.dtf= Sys.CultureInfo.CurrentCulture.dateTimeFormat;
	
	this.BuildContent();
	
	this.timeDiv= this.contentDiv.childNodes[1];
	$addHandlers(this.timeDiv, {
		'click' : this._click,
		'mouseover' : this._over,
		'mouseout' : this._out
	}, this);
	
	this.ok_cell= this.contentDiv.childNodes[2].firstChild.rows[0].cells[1];
	$addHandlers(this.ok_cell, {
		'click' : this.Apply
	}, this);
}

FM.UI.TimeTable.prototype= {

	dispose : function() {
		if (!this.Window) return;
		$clearHandlers(this.timeDiv);
		$clearHandlers(this.ok_cell);
		this.Window.dispose();
		this.Window= null;
  },
	
	SetCurrentTime : function(oDate, format) {
		this.Date= (oDate) ? oDate : new Date();
		this.Hours= this.Date.getHours();
		this.Minutes= this.Date.getMinutes();
		this._format= format;
		
		this.hiliteDate();
	},
	
	Show : function() { this.Window.Show(); },
	Hide : function() { this.Window.Hide(); },	
	
	_click : function(e) {
		var o= e.target;
		e.stopPropagation();		
		if (o.tagName == "TD") {
			this.toggleCell(o, true);
			var val= o.id.substring(2);
			var tblName= o.parentNode.parentNode.parentNode.className;
			if (tblName == "dt_hours") {
				this.Hours= parseInt(val);
				this.toggleCell(this._cellH, false);
				this._cellH= o;
			} else if (tblName == "dt_mins") {
				this.Minutes= parseInt(val);
				this.toggleCell(this._cellM, false);
				this._cellM= o;
			}
		}
	},
	
	Apply : function(e) {
		if (this.OnSelect) this.OnSelect(this.Hours, this.Minutes);
	},
	
	toggleCell : function(o, fl) {
		if (!o) return;
		o.style.backgroundColor= (fl) ? "#3C9DFF" : "";
		o.style.color= (fl) ? "#FFF" : "";
	},
	
	_over : function(e) {
		var o= e.target;
		if (o.tagName == "TD" && o != this._cellH && o != this._cellM) o.style.color= "#e89f2e";
	},
	
	_out : function(e) {
		var o= e.target;
		if (o.tagName == "TD" && o != this._cellH && o != this._cellM) o.style.color= "";
	},
	
	hiliteDate : function() {
		this.toggleCell(this._cellH, false);
		this.toggleCell(this._cellM, false);
		this._cellH= $get("h_" + this.Hours, this.Window.GetBodyElement());
		this.toggleCell(this._cellH, true);
		// find near minutes from list
		var dm= (this.Minutes % 5);
		var minutes= (dm < 3) ? (this.Minutes - dm) : (this.Minutes + 5 - dm);
		this._cellM= $get("m_" + minutes, this.Window.GetBodyElement());
		this.toggleCell(this._cellM, true);
	},

	BuildContent : function() {
		var sb= new Sys.StringBuilder();
		sb.append("<div style=\"height:18px;cursor:default;border-right:#7b9ebd 1px solid;border-top:#7b9ebd 1px solid;filter:progid:dximagetransform.microsoft.gradient(gradienttype=0,startcolorstr=#ffffff,endcolorstr=#cecfde);border-left:#7b9ebd 1px solid;padding-left:3px;\">");
		sb.append("<div style=\"float:left;width:110px;padding-top:2px;\">Hours</div><div style=\"float: left;padding-top:2px;\">Minutes</div>");
		sb.append("</div>");
		sb.append("<div>");
		sb.append("<div style=\"float:left;\"><table class=\"dt_hours\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse;\">");
		// HOURS
		var h= 0;
		var hour;
		var ampm= "";
		var cs= "";
		var is_ampm= this.format.indexOf(" tt") > 0;
		sb.append("<tr>");
		while (h < 24) {
			sb.append("<td id='h_" + h + "'");
			if (h < this.startHour || h > this.endHour) sb.append(" class='na'");
			hour= "" + h;
			if (is_ampm) {
				if (h < 12) { ampm= "a"; } 
				else { ampm= "p"; hour= "" + (h - 12); }
				if (h == 0) { hour= "Mid"; ampm= ""; }
				else if (h == 12) { hour= "Noon"; ampm= ""; }
			}
			
			sb.append(">" + hour + ampm + "</td>");
			h++;
			if (h % 4 == 0 && h < 24) sb.append("</tr><tr>");			
		}
		sb.append("</tr>");
		sb.append("</table></div>");
		sb.append("<div style=\"float:left;width:4px;height:113px;border-top:solid 1px #7288AC;border-bottom:solid 1px #7288AC;\"></div>");
		sb.append("<div style=\"float:left;\"><table class=\"dt_mins\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse;\">");
		// MINUTES
		var m= 0;
		while (m < 60) {
			sb.append("<tr><td id='m_" + m + "'>:"+DT_padNumber(m)+"</td>");m+= 5;
			sb.append("<td id='m_" + m + "'>:"+DT_padNumber(m)+"</td></tr>");m+= 5;
		}
		sb.append("</table></div>");
		sb.append("</div>");
		sb.append("<div style=\"height:18px;border-right:#7b9ebd 1px solid;border-bottom:#7b9ebd 1px solid;filter:progid:dximagetransform.microsoft.gradient(gradienttype=0,startcolorstr=#ffffff,endcolorstr=#cecfde);border-left:#7b9ebd 1px solid;padding-right:3px;\">");
		sb.append("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
		sb.append("<td style=\"text-align:center;width:50%;cursor:pointer;padding-top:2px;\" onmouseover=\"this.firstChild.style.color='blue';\" onmouseout=\"this.firstChild.style.color='black';\"><label style=\"color:black;font-weight:bold;\">cancel</label></td>");
		sb.append("<td style=\"text-align:center;width:50%;cursor:pointer;padding-top:2px;\" onmouseover=\"this.firstChild.style.color='blue';\" onmouseout=\"this.firstChild.style.color='black';\"><label style=\"color:black;font-weight:bold;\">ok</label></td>");
		sb.append("</tr></table></div>");
		this.Window.SetHtml(sb.toString());
	}

}

FM.UI.TimeTable.registerClass('FM.UI.TimeTable', null, Sys.IDisposable);

FM.UI.TimeTable.getCurrent= function (timeFormat) {
  if (!FM.UI.TimeTable._current) FM.UI.TimeTable._current= new FM.UI.TimeTable(timeFormat);
  return FM.UI.TimeTable._current;
}


// UTILS
//
DT_parseDisplayValue= function(s, format) {
  var oDate= null;
  if (!s || s.length == 0) return oDate;
	
	oDate= Date.parseLocale(s, format);
	
	if (isNaN(oDate)) oDate= null;
  return oDate;
}
DT_getDisplayValue= function(oDate, format) {
  return (oDate) ? oDate.format(format) : "";
}

DT_formatUtcDate= function(D) {
	return String(D.getFullYear()) + "-" + DT_padNumber(String(D.getMonth() + 1)) + "-" + DT_padNumber(String(D.getDate())) + "T" + DT_padNumber(String(D.getHours())) + ":" + DT_padNumber(String(D.getMinutes())) + ":00";
}

DT_parseUtcValue= function(s) {
	if (s.length > 10) {
		// Date + Time
		return new Date(parseInt(s.substr(0, 4), 10), (parseInt(s.substr(5, 2), 10) - 1), parseInt(s.substr(8, 2), 10), parseInt(s.substr(11, 2), 10), parseInt(s.substr(14, 2), 10), parseInt( s.substr( 17, 2), 10 ));
	} else if (s.length > 0) {
		// date only, no time info
		return new Date(parseInt(s.substr(0, 4), 10), (parseInt(s.substr(5, 2), 10) - 1), parseInt(s.substr(8, 2), 10));
	} else return null;
}

DT_padNumber= function(s) {
	if (String(s).length == 1) return "0" + s;
	return s;
}

// Returns the first day of the week that contains the given date
DT_GetFirstDayOfWeek= function(D) {
	var firstDayOfWeek= Sys.CultureInfo.CurrentCulture.dateTimeFormat.FirstDayOfWeek;
	var daysToSubtract= (D.getDay() + 7 - firstDayOfWeek) % 7;
	return new Date(D.getTime() - (daysToSubtract * 24 * 60 * 60 * 1000));
}
// Returns the last day of the week that contains the given date
DT_GetLastDayOfWeek= function(D) {
	var firstDay= DT_GetFirstDayOfWeek(D);
	return new Date(firstDay.getTime() + ( 6 * 24 * 60 * 60 * 1000));  // Add 6 days to the first day of the week
}
DT_GetFirstDayInCalendar= function(D) {
	D.setDate(1);
	var firstDayOfWeek= Sys.CultureInfo.CurrentCulture.dateTimeFormat.FirstDayOfWeek;
	var i= D.getDay() - firstDayOfWeek;
	if (i < 0) i+= 7;
	if (i == 0) return D;

	D.setDate((i * -1) + 1);
	D.setHours(0);
	D.setMinutes(0);
	D.setSeconds(0);
	return D;
}

// Returns the week number the date falls on
// oDate - A Date Object with any given date to calculate a week number for.
DT_GetWeekNumber= function(oDate) {
	// Get the beginning of the year.
	var oYearStart= new Date(oDate.valueOf());
	oYearStart.setMonth(0, 1);  // January is month 0
	oYearStart.setHours(0, 0, 0, 0);

	var iMSSinceYearStart= oDate.valueOf() - oYearStart.valueOf();
	var fWeeksSinceYearStart= iMSSinceYearStart / 604800000;  // 1000 / 60 / 60 / 24 / 7;

	// Drop the extra decimal digits to make a whole number.
	var iWeeksSinceYearStart= Math.ceil(fWeeksSinceYearStart);

	if (iWeeksSinceYearStart == 0) {
		// Deal with case where Jan 1 is on a Monday; this formula will produce 0 because jan 1 - jan 1= 0.
		iWeeksSinceYearStart= 53;
	}
	return iWeeksSinceYearStart;
}	


Sys.Application.notifyScriptLoaded();
