/**
 *
 *
 *
 */

document.createElement("DATALIST");
document.createElement("OUTPUT");
document.write('<style type="text\/css">\
			   		DATALIST\
					{\
						margin:					0;\
						padding:				0;\
						position:				absolute;\
						display:				none;\
					}\
					DATALIST SELECT\
					{\
						margin:					0;\
						padding:				0;\
					}\
					SPAN.UI-WEBFORMS20-INPUT-SPINNER\
					{\
						width:					0.5em;\
						cursor:					pointer;\
					}\
					SPAN.UI-WEBFORMS20-INPUT-SPINNER SPAN, .UI-WEBFORMS20-INPUT-SPINNER SPAN:link \
					{\
						width:					0.5em;\
						border:					1px solid #FFF;\
						border-radius:			0.2em;\
						-moz-border-radius:		0.2em;\
						font-size:				small;\
					}\
					SPAN.UI-WEBFORMS20-INPUT-SPINNER SPAN:hover, .UI-WEBFORMS20-INPUT-SPINNER SPAN:active\
					{\
						background-color:		#667;\
						border-color:			#000;\
						color:					#FFF;\
					}\
					INPUT.UI-WEBFORMS20-CALENDAR-TODAY, INPUT.UI-WEBFORMS20-CALENDAR-NONE\
					{\
						width:					95%;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR\
					{\
						background-color:		#F1F1F1;/*#B9D2CD;*/\
						border:					2px solid #000;\
						text-align:				center;\
						position:				absolute;\
						top:					0;\
						left:					0;\
						border-radius:			5px;\
						-moz-border-radius:		5px;\
						-webkit-border-radius:	5px;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR A\
					{\
						text-decoration:		none;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR TD\
					{\
						width:					2.2em;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR TD.UI-WEBFORMS20-CALENDAR-NOTCURRENTMONTH\
					{\
						text-decoration:		none;\
						color:					#998;\
						cursor:					default;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-WEEK TR.UI-WEBFORMS20-CALENDAR-WEEKS, \
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-WEEK TR.UI-WEBFORMS20-CALENDAR-WEEKS:link\
					{\
						border:					1px solid black;\
						background-color:		white;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR TD.UI-WEBFORMS20-CALENDAR-DAY\
					{\
						border:					1px solid transparent;\
						border-radius:			2px;\
						-moz-border-radius:		2px;\
						-webkit-border-radius:	2px;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-DATE TD.UI-WEBFORMS20-CALENDAR-DAY, \
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-DATE TD.UI-WEBFORMS20-CALENDAR-DAY:link\
					{\
						border:					1px solid black;\
						background-color:		white;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-MONTH TBODY.UI-WEBFORMS20-CALENDAR-THISMONTH TD.UI-WEBFORMS20-CALENDAR-DAY,\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-WEEK TR.UI-WEBFORMS20-CALENDAR-THISWEEK,\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-DATE TD.UI-WEBFORMS20-CALENDAR-TODAY\
					{\
						background-color:		yellow;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-MONTH TBODY.UI-WEBFORMS20-CALENDAR-THISMONTH TD.UI-WEBFORMS20-CALENDAR-TODAY\
					{\
						background-color:		red;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-MONTH TBODY.UI-WEBFORMS20-CALENDAR-SELECTED TD.UI-WEBFORMS20-CALENDAR-DAY,\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-WEEK TR.UI-WEBFORMS20-CALENDAR-SELECTED,\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-DATE TD.UI-WEBFORMS20-CALENDAR-SELECTED\
					{\
						background-color:		lightblue;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-MONTH TBODY, TABLE.UI-WEBFORMS20-CALENDAR-MODE-MONTH TBODY:link\
					{}\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-WEEK TR.UI-WEBFORMS20-CALENDAR-WEEKS:hover,\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-WEEK TR.UI-WEBFORMS20-CALENDAR-WEEKS:hover TD.UI-WEBFORMS20-CALENDAR-NOTCURRENTMONTH,\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-DATE TD.UI-WEBFORMS20-CALENDAR-DAY:hover,\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-MONTH TBODY:hover TD.UI-WEBFORMS20-CALENDAR-DAY\
					{\
						background-color:		#667;\
						color:					white;\
						cursor:					pointer;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-DATE TD.UI-WEBFORMS20-CALENDAR-NOTCURRENTMONTH,\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-DATE TD.UI-WEBFORMS20-CALENDAR-NOTCURRENTMONTH:link,\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-DATE TD.UI-WEBFORMS20-CALENDAR-NOTCURRENTMONTH:hover\
					{\
						border:					none;\
						background-color:		transparent;\
						color:					#998;\
						cursor:					default;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-MONTH TBODY:hover TD.UI-WEBFORMS20-CALENDAR-NOTCURRENTMONTH\
					{\
						background-color:		#667;\
						color:					#667;\
						cursor:					pointer;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-WEEK TD.UI-WEBFORMS20-CALENDAR-WEEK\
					{\
						background-color:		#667;\
						color:					white;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR TR.UI-WEBFORMS20-CALENDAR-TIME\
					{\
						visibility:				hidden;\
					}\
					TABLE.UI-WEBFORMS20-CALENDAR-MODE-DATE.UI-WEBFORMS20-CALENDAR-MODE-TIME TR.UI-WEBFORMS20-CALENDAR-TIME\
					{\
						visibility:				visible;\
					}\
					INPUT.UI-WEBFORMS20-PLACEHOLDER\
					{\
						text-decoration:		italic;\
						color:					#CCCCCC;\
					}\
					SPAN.UI-WEBFORMS20-TIME\
					{\
						padding:				0px;\
						margin:					0px;\
						margin-left:			10px;\
					}\
					SPAN.UI-WEBFORMS20-SLIDER\
					{\
						margin-left:			10px;\
					}\
					SPAN.UI-WEBFORMS20-SLIDER-BODY\
					{\
						background-color:		#DADADA;\
						border:					1px solid #000000;\
						display:				inline-block;\
						height:					1.25em;\
						text-align:				center;\
						width:					10em;\
						padding:				1px;\
					}\
					SPAN.UI-WEBFORMS20-SLIDER-HR\
					{\
						vertical-align:			middle;\
						display:				inline-block;\
						background-color:		#000;\
						margin:					0px;\
						padding:				0px;\
						width:					9.5em;\
						height:					3px;\
					}\
					SPAN.UI-WEBFORMS20-SLIDER-HANDLE, SPAN.UI-WEBFORMS20-SLIDER-HANDLE:link\
					{\
						cursor:					default;\
						background-color:		#DADADA;\
						border:					2px outset #CCC;\
						height:					0.75em;\
						left:					-10em;\
						position:				relative;\
						width:					2em;\
					}\
					SPAN.UI-WEBFORMS20-SLIDER-HANDLE:hover, SPAN.UI-WEBFORMS20-SLIDER-HANDLE-HOVER\
					{\
						border:					2px inset #CCC;\
					}\
					DIV.UI-WEBFORMS20-MULTIFILE\
					{\
						overflow:hidden;\
						width:250px;\
						float:right;\
					}\
					DIV.UI-WEBFORMS20-INVALID-MESSAGE\
					{\
						position:				absolute;\
						top:					0px;\
						left:					0px;\
						color:					red;\
						font-weight:			bold;\
						vertical-align:			middle;\
						padding:				0px;\
					}\
					DIV.UI-WEBFORMS20-INVALID-MESSAGE SPAN\
					{\
						float:					left;\
						padding:				2px;\
					}\
					DIV.UI-WEBFORMS20-INVALID-MESSAGE DIV\
					{\
						position:				relative;\
						left:					-3px;\
						display:				inline-block;\
						width:					300px;\
						border:					2px double red;\
						background-color:		white;\
						padding:				5px;\
						margin:					0px;\
					}\
					SPAN.UI-WEBFORMS20-DELETER\
					{\
						position:				absolute;\
						top:					0px;\
						display:				none;\
						padding:				0.01em 3px;\
						border:					3px solid black;\
						background-color:		white;\
						cursor:					pointer;\
						font-weight:			bold;\
						z-index:				500;\
					}\
			   <\/style>');

/**
 *
 *
 *
 */
(function($)
{
	var undefined;
	
	/**
	 *
	 *
	 */
	function watch(element, property, getter, setter)
	{
		if(property.constructor == Object)
		{
			var A;
			for(A in property)
			{
				watch(element, A, property[A].getter||null, property[A].setter||null);
			}
			
			return;
		}
		
		getter = getter||function(){throw "Setting property '" + property + "' that has only getter."; return false;};
		setter = setter||function(){element[property] = getter.call(element); throw "Getting property '" + property + "' that has only setter."; return false;};
		
		/*@cc_on
		   /*@if (@_jscript_version < 5.8)
			 	element[property] = getter.call(element);
			
				$(element)
					.bind("propertychange", function(event)
					{
						if(event.propertyName == property)
						{
							if(setter.call(element, element[property]) === false)
							{
								element[property] = getter.call(element);
								return;
							}
						}
					});
				return element;
		   /*@end
		@*/
		//JavaScript 1.5 standards compliant getter and setter
		if("__defineGetter__" in element)
		{
			element.__defineGetter__(property, getter);
			element.__defineSetter__(property, setter);
		}
		//IE 8
		else if("defineProperty" in Object)
		{
			Object.defineProperty(element, 
								  property, 
								  {
									  getter: getter, 
									  setter: setter
								  });
		}
		//IE < 8
		else if("ActiveXObject" in window)
		{
			element[property] = getter.call(element);
			
			$(element)
				.bind("propertychange", function(event)
				{
					if(event.propertyName == property)
					{
						if(setter.call(element, element[property]) === false)
						{
							element[property] = getter.call(element);
							return;
						}
					}
				});
		}
		//JavaScript 1.2 capable browsers
		else if("watch" in element)
		{
			element.watch(property, function(id, oldval, newval)
			{
				if(id == property && setter.call(element, newval) === false)
				{
					return oldval;
				}
				
				return newval;
			});
		}
		else
		{
			var current = element[property] = getter.call(element);
			setTimeout(function ()
			{
				if (element[property] !== current)
				{
					if(setter.call(element, element[property]) === false)
					{
						element[property] = getter.call(element);
						return;
					}
				}
			}, 100);
		}
		
		return element;
	}
	
	/**
	 *	
	 *
	 *
	 */
	function formatDate(date, type)
	{
		var A = getWeekNumber(date);
		switch((type||"").toLowerCase())
		{
			case "date":			return date.getFullYear() + "-" + 
											(((date.getMonth()+1) < 10 ? '0' : '') + (date.getMonth()+1)) + "-" + 
											((date.getDate() < 10 ? '0' : '') + date.getDate());
			case "time":			return ((date.getUTCHours() < 10 ? '0' : '') + date.getUTCHours()) + ":" + 
											((date.getUTCMinutes() < 10 ? '0' : '') + date.getUTCMinutes()) + ":00";
			//2009-01-01T12:02:30.002Z
			case "datetime":		return date.getFullYear() + "-" + 
											(((date.getUTCMonth()+1) < 10 ? '0' : '') + (date.getUTCMonth()+1)) + "-" + 
											((date.getUTCDate() < 10 ? '0' : '') + date.getUTCDate()) + "T" +
											((date.getUTCHours() < 10 ? '0' : '') + date.getUTCHours()) + ":" + 
											((date.getUTCMinutes() < 10 ? '0' : '') + date.getUTCMinutes()) + ":" +
											((date.getUTCSeconds() < 10 ? '0' : '') + date.getUTCSeconds()) + "." +
											((date.getUTCMilliseconds() < 100 ? '0' : '') + (date.getUTCMilliseconds() < 10 ? '0' : '') + date.getUTCMilliseconds()) + "Z";
			case "datetime-local":	return date.getFullYear() + "-" + 
											(((date.getMonth()+1) < 10 ? '0' : '') + (date.getMonth()+1)) + "-" + 
											((date.getDate() < 10 ? '0' : '') + date.getDate()) + "T" +
											((date.getHours() < 10 ? '0' : '') + date.getHours()) + ":" + 
											((date.getMinutes() < 10 ? '0' : '') + date.getMinutes()) + ":" +
											((date.getSeconds() < 10 ? '0' : '') + date.getSeconds()) + "." +
											((date.getMilliseconds() < 100 ? '0' : '') + (date.getMilliseconds() < 10 ? '0' : '') + date.getMilliseconds());
			case "month":			return date.getFullYear() + "-" + (((date.getUTCMonth()+1) < 10 ? '0' : '') + (date.getUTCMonth()+1));
			case "week":			return date.getFullYear() + "-W" + ((A < 10 ? '0' : '') + A);
			default:				return "";
		}
	}
		
	/**
	 *
	 *
	 */
	function isoDate(string)
	{
		var d = string.match(/(\d{4})-(\d{2})(-(\d{2})(T(\d{2}):(\d{2})(:(\d{2})(\.(\d{3}))?)?(Z|(([-+])(\d{2}):(\d{2})))?)?)?/);
		
		var date = new Date(d[1], 0, 1);
		var offset = 0/*date.getTimezoneOffset()*/, ret = new Date();
	
		date.setMonth(d[2] - 1);
		if (d[4]) { date[(d[12] != "Z" ? "setDate" : "setUTCDate")](Number(d[4])); }
		if (d[6]) { date[(d[12] != "Z" ? "setHours" : "setUTCHours")](Number(d[6])); }
		if (d[7]) { date[(d[12] != "Z" ? "setMinutes" : "setUTCHours")](Number(d[7])); }
		if (d[9]) { date[(d[12] != "Z" ? "setSeconds" : "setUTCSeconds")](Number(d[9])); }
		//if (d[10]) { date.setMilliseconds(Number("0." + d[10]) * 1000); }
		if (d[13])
		{
			offset = (Number(d[15]) * 60) + Number(d[16]);
			offset *= ((d[14] == '-') ? 1 : -1);
			offset -= date.getTimezoneOffset();
		}
		//console.log(d);
		
		ret.setTime((Number(date) + (offset * 60 * 1000)));
		return ret;
	}
		
	/**
	 *
	 *
	 */
	function hasDataListAncestor(field)
	{
		var B = field;
		while(B = B.parentNode)
		{
			if(B.tagName && B.tagName.toUpperCase() == "DATALIST")
			{
				return true;
			}
		}
		
		return false;
	}
		
	/**
	 *
	 *
	 */
	function getType(element)
	{
		return element && element.tagName == "INPUT"  ?
				($.browser.msie ? ($(element).clone(false).wrap("<div/>").parent().html().match(/type=['"]*(\w+)/)||["",""])[1] : element.getAttribute("type")||"") :
				"";
	}
		
	/**
	 *
	 *
	 *
	 */
	function getWeekNumber(date)
	{
		var A = new Date(date.getFullYear(), 0, 1),
			B = A.getDay() - 0; //the day of week the year begins on
			B = (B >= 0 ? B : B + 7);
		var C = Math.floor((date.getTime() - A.getTime() - (date.getTimezoneOffset() - A.getTimezoneOffset()) * 60000) / 86400000) + 1,
			D;
		
		if(B < 2)
		{
			D = Math.floor((C + B - 1) / 7) + 1;
			if(D > 52)
			{
				A = new Date(date.getFullYear() + 1, 0, 1);
				B = A.getDay() - 0;
				B = B >= 0 ? B : B + 7;
				/*if the next year starts before the middle of
				the week, it is week #1 of that year*/
				D = B < 4 ? 1 : 53;
			}
		}
		else
		{
			D = Math.floor((C + B - 1) / 7);
		}
		return D == 0 ? 52 : D;
	}
		
	/**
	 *
	 *
	 *
	 */
	function getDays(year, month)
	{
		var firstDay = (new Date(year, month, 1)).getDay(),
			daysThisMonth = ( 32 - (new Date(year, month, 32)).getDate() ),
			daysLastMonth = ( 32 - (new Date((month == 0 ? year - 1 : year), (month == 0 ? 12 : month - 1), 32)).getDate() ),
			ret = [],
			i = 0;
		
		for(;i < 42; i += 1)
		{
			if(i < firstDay)
			{
				ret[i] = daysLastMonth - (firstDay - 1 - i);
			}
			else if(i >= (firstDay + daysThisMonth))
			{
				ret[i] = i - (firstDay + daysThisMonth) + 1;
			}
			else
			{
				ret[i] = i - firstDay + 1;
			}
		}
		return ret;
	}
	
	/**
	 *
	 *
	 *
	 */
	function getWeeks(year, month)
	{
		for(var A = new Date(year, month, 1), B = [], C = 0;C < 6; ++C)
		{
			B[C] = getWeekNumber(A);
			if (B[C] == 52 && B[C-1] == 52)
			{
				B[C] = 53;
			}
			A.setDate(A.getDate() + 7);
		}
		
		return B;
	}
	
	/**
	 *
	 *
	 *
	 */
	function indexOf(arr, element)
	{
		element = $.trim(element).toLowerCase();
		
		if(element)
		{
			for(var B = 0, C = arr.length; B < C; B += 1)
			{
				if(arr[B].toLowerCase() == element)
				{
					return B;
				}
			}
		}
		
		return -1;
	}
	
	/**
	 *
	 *
	 *
	 */
	function daysInMonth(date)
	{
		var A = new Date(date.getFullYear(), date.getMonth(), 32);
		return ( 32 - A.getDate() );
	}
	
	/**
	 *
	 *
	 *
	 */
	$.WebForms20 = {
		
		/**
		 *
		 *
		 *
		 */
		checkValidity: function(form, unhandledInvalidControls)
		{
			unhandledInvalidControls = unhandledInvalidControls||[];
			$(form).elements(false)
				.each(function()
				{
					var $this = $(this), event;
					
					if($this.willValidate() && !$this.validity().valid)
					{
						event = $.event.fix({
									type: 				"invalid", 
									target:				this, 
									cancelBubble:		false, 
									returnValue:		true, 
									preventDefault:		function(){event.returnValue = false;}, 
									stopPropagation:	function(){event.cancelBubble = true;},
									timeStamp: 			+new Date
								});
						
						if(false !== $.event.trigger("invalid", [event], this, false) || event.returnValue !== true)
						{
							Array.prototype.push.call(unhandledInvalidControls, this);
						}
					}
				});
			
			return (unhandledInvalidControls.length < 1);
		},
		
		/**
		 *
		 *
		 *
		 */
		getPattern: function(element)
		{
			var pattern = "";
			
			if(element.hasOwnProperty && element.hasOwnProperty("pattern"))
			{
				pattern = element.pattern;
			}
			else if($(element).attr("pattern"))
			{
				pattern = $(element).attr("pattern");
			}
			else if(element.tagName == "INPUT")
			{
				switch((getType(element)||"").toLowerCase())
				{
					case "date":			pattern = "(\\d{4})\\-(\\d{2})\\-(\\d{2})"; break;
					case "time":			pattern = "(\\d{2}):(\\d{2})(:\\d{2}(\\.\\d+)?)?(Z|(\\+|\\-)\\d{2}:\\d{2})?"; break;
					case "datetime":		pattern = "(\\d{4})\\-(\\d{2})\\-(\\d{2})T(\\d{2}):(\\d{2})(:\\d{2}(\\.\\d+)?)?(Z|(\\+|\\-)\\d{2}:\\d{2})"; break;
					case "datetime-local":	pattern = "(\\d{4})\\-(\\d{2})\\-(\\d{2})T(\\d{2}):(\\d{2})(:\\d{2}(\\.\\d+)?)?(Z|(\\+|\\-)\\d{2}:\\d{2})?"; break;
					case "month":			pattern = "(\\d{4})\\-(\\d{2})"; break;
					case "week":			pattern = "(\\d{4})\\-W(\\d{2})"; break;
					case "number":
					case "range":			pattern = "\\-?\\d+(\\.\\d+)?((e|E)(\\+|\\-)?\\d+)?"; break;
					case "color":			pattern = "#[A-Fa-f\\d]{6}"; break;
					case "url":				pattern = "\\w+:(\\\/){0,3}[\\w\\-\\.]{3,}[^\\s]*"; break;
					case "email":			pattern = "[^@\\s]+@([\\w\\-\\.]{3,}|[\\d\\[\\]\\.]{7,}|[A-Fa-f\\d:]{3,})"; break;
				}
			}
			
			return pattern && $(element).multiple()
					? pattern + "(\s*,\s*" + pattern + ")+"
					: pattern;
		},
		
		/**
		 *
		 *
		 *
		 */
		getMin:function(element)
		{
			if(element.hasOwnProperty && element.hasOwnProperty("min"))
			{
				return element.min;
			}
			
			var $e = $(element), A, B, C;
				
			switch((getType(element)||"").toLowerCase())
			{
				case "date":
				case "time":
				case "datetime":
				case "datetime-local":
				case "month":			return $e.attr("min") && 
												(new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test($e.attr("min")) ? 
												Date.parse($e.attr("min")) :
												null;
												
				case "week":
					if($e.attr("min"))
					{
						A = new RegExp("^" + $.WebForms20.getPattern(element) + "$");
						B = $e.attr("min");
						if(A.test(B))
						{
							C = A.exec(B);
							B = new Date(C[1], 0, 1);
							return (new Date(C[1], 0, (C[2]*7) + (B.getDay() > 1 ? 1 : 0))).getTime();
						}
					}
					
					break;
				case "number":
				case "range":			return $e.attr("min") && 
												(new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test($e.attr("min")) ? 
												Number($e.attr("min")) :
												null;
			}
			
			return null;
		},
		
		/**
		 *
		 *
		 *
		 */
		setMin:function(element, num)
		{
			if(element.hasOwnProperty && element.hasOwnProperty("min"))
			{
				element.min = num;
				return;
			}
			
			var type = (getType(element)||"").toLowerCase();
			
			switch(type)
			{
				case "date":
				case "time":
				case "datetime":
				case "datetime-local":
				case "month":
				case "week":
					if((new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test(num.toString()))
					{
						$(element).attr("min", formatDate(new Date((isNaN(num) ? Date.parse(num) : num)), type));
					}
					break;
				case "number":
				case "range":
					if((new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test(num.toString()))
					{
						$(element).attr("min", (isNaN(num) ? Number(num) : num).toString());
					}
			}
		},
		
		/**
		 *
		 *
		 *
		 */
		getMax:function(element)
		{
			if(element.hasOwnProperty && element.hasOwnProperty("max"))
			{
				return element.max;
			}
			
			var $e = $(element), A, B, C;
				
			switch((getType(element)||"").toLowerCase())
			{
				case "date":
				case "time":
				case "datetime":
				case "datetime-local":
				case "month":			return $e.attr("max") && 
												(new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test($e.attr("max")) ? 
												Date.parse($e.attr("max")) :
												null;
												
				case "week":
					if($e.attr("max"))
					{
						A = new RegExp("^" + $.WebForms20.getPattern(element) + "$");
						B = $e.attr("max");
						if(A.test(B))
						{
							C = A.exec(B);
							B = new Date(C[1], 0, 1);
							return (new Date(C[1], 0, (C[2]*7) + (B.getDay() > 1 ? 1 : 0))).getTime();
						}
					}
					
					break;
				case "number":
				case "range":			return $e.attr("max") && 
												(new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test($e.attr("max")) ? 
												Number($e.attr("max")) :
												null;
			}
			
			return null;
		},
		
		/**
		 *
		 *
		 *
		 */
		setMax:function(element, num)
		{
			if(element.hasOwnProperty && element.hasOwnProperty("max"))
			{
				element.max = num;
				return;
			}
			
			var type = (getType(element)||"").toLowerCase();
			
			switch(type)
			{
				case "date":
				case "time":
				case "datetime":
				case "datetime-local":
				case "month":
				case "week":
					if((new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test(num.toString()))
					{
						$(element).attr("max", formatDate(new Date((isNaN(num) ? Date.parse(num) : num)), type));
					}
					break;
				case "number":
				case "range":
					if((new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test(num.toString()))
					{
						$(element).attr("max", (isNaN(num) ? Number(num) : num).toString());
					}
			}
		},
		
		/**
		 *
		 *
		 *
		 */
		getStep:function(element)
		{
			if(element.hasOwnProperty && element.hasOwnProperty("step"))
			{
				return element.step;
			}
			
			var $e = $(element), A, B, C;
				
			switch((getType(element)||"").toLowerCase())
			{
				case "time":
				case "datetime":
				case "datetime-local":	return $e.attr("step") && $e.attr("step").toLowerCase() != "any" &&
												(new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test($e.attr("step")) ? 
												Date.parse($e.attr("step")) :
												60;
				case "date":
				case "month":			return $e.attr("step") && $e.attr("step").toLowerCase() != "any" &&
												(new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test($e.attr("step")) ? 
												Date.parse($e.attr("step")) :
												1;
												
				case "week":
					if($e.attr("step") && $e.attr("step").toLowerCase() != "any")
					{
						A = new RegExp("^" + $.WebForms20.getPattern(element) + "$");
						B = $e.attr("step");
						if(A.test(B))
						{
							C = A.exec(B);
							B = new Date(C[1], 0, 1);
							return (new Date(C[1], 0, (C[2]*7) + (B.getDay() > 1 ? 1 : 0))).getTime();
						}
					}
					
					return 604800000;
				case "number":
				case "range":			return $e.attr("step") && 
												(new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test($e.attr("step")) ? 
												Number($e.attr("step")) :
												1;
			}
			
			return null;
		},
		
		/**
		 *
		 *
		 *
		 */
		getStepScaleFactor:function(element)
		{
			switch((getType(element)||"").toLowerCase())
			{
				case "time":
				case "datetime":
				case "datetime-local":	return 1000;
				case "date":			return 86400000;
				case "week":			return 604800000;
			}
			
			return 1;
		},
		
		/**
		 *
		 *
		 *
		 */
		setStep:function(element, num)
		{
			var type = (getType(element)||"").toLowerCase();
			
			switch(type)
			{
				case "date":
				case "time":
				case "datetime":
				case "datetime-local":
				case "month":
				case "week":
					if((new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test(num.toString()))
					{
						$(element).attr("step", formatDate(new Date((isNaN(num) ? Date.parse(num) : num)), type));
					}
					break;
				case "number":
				case "range":
					if((new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test(num.toString()))
					{
						$(element).attr("step", (isNaN(num) ? Number(num) : num).toString());
					}
			}
		},
		
		/**
		 *
		 *
		 *
		 */
		getValueAsDate:function(element)
		{
			var $e = $(element), A, B, C;
			
			switch((getType(element)||"").toLowerCase())
			{
				case "date":
				case "datetime":
				case "datetime-local":
				case "month":			return element.value && 
													(new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test(element.value) ? 
													isoDate(element.value) :
													new Date(1970, 0, 1);
				case "week":
					if(element.value)
					{
						A = new RegExp("^" + $.WebForms20.getPattern(element) + "$");
						if(A.test(element.value))
						{
							C = A.exec(element.value);
							B = new Date(C[1], 0, 1);
							return new Date(C[1], 0, (C[2]*7) + (B.getDay() > 1 ? 1 : 0));
						}
					}
					else
						return new Date();
				case "time":			return element.value && 
													(new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test(element.value) ? 
													new Date(Date.parse("Jan 1 1970 " + element.value + " GMT")) :
													new Date(1970, 0, 1);
			}
			
			return null;
		},
		
		/**
		 *
		 *
		 *
		 */
		setValueAsDate:function(element, value)
		{
			if(value.constructor != Date)
			{
				return null;
			}
			
			var type = (getType(element)||"").toLowerCase();
			
			switch(type)
			{
				case "date":
				case "time":
				case "datetime":
				case "datetime-local":
				case "month":
				case "week":
					$(element).val(formatDate(value, type));
			}
		},
		
		/**
		 *
		 *
		 *
		 */
		getValueAsNumber:function(element)
		{
			var $e = $(element), A, B, C;
			
			switch((getType(element)||"").toLowerCase())
			{
				case "date":
				case "datetime":
				case "datetime-local":
				case "month":			return element.value && 
												(new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test(element.value) ? 
												isoDate(element.value).getTime() :
												0;
				case "week":
					if(element.value)
					{
						A = new RegExp("^" + $.WebForms20.getPattern(element) + "$");
						if(A.test(element.value))
						{
							C = A.exec(element.value);
							B = new Date(C[1], 0, 1);
							return (new Date(C[1], 0, (C[2]*7) + (B.getDay() > 1 ? 1 : 0))).getTime();
						}
					}
					return 0;
				case "time":			return element.value && 
												(new RegExp("^" + $.WebForms20.getPattern(element) + "$")).test(element.value) ? 
												Date.parse("Jan 1, 1970 " + element.value + " GMT") :
												0;
				case "range":
				case "number":	return !isNaN(element.value) ? Number(element.value) : 0;
			}
			
			return null;
		},
		
		/**
		 *
		 *
		 *
		 */
		setValueAsNumber:function(element, value)
		{
			if(isNaN(value))
			{
				return null;
			}
			
			var type = (getType(element)||"").toLowerCase();
			
			switch(type)
			{
				case "date":
				case "time":
				case "datetime":
				case "datetime-local":
				case "month":
				case "week":
					$(element).val(formatDate(new Date(value), type));
					break;
				case "range":
				case "number":
					element.value = value.toString();
				
			}
		},
		
		/**
		 *
		 *
		 *
		 */
		step:function(element, step, multiplier)
		{
			if(element.tagName != "INPUT")
			{
				return null;
			}
			
			var A = $(element), B, C = A.valueAsNumber(), D = A.min()||-1, E = A.max()||Infinity, F = A.step()||1, G = 0, H;
			
			if(getType(element) == "month")
			{
				F = F||B.getMonth();
				
				while(--step >= 0)
				{
					B = A.valueAsDate();
					B.setMonth( + multiplier);
					A.valueAsDate(B);
				}
				return null;
			}
			
			if(C < D)
			{
				A.valueAsNumber(D);
				return;
			}
			
			B = ((F||Number($.WebForms20.getStepScaleFactor(element))) * multiplier);
			
			C = (A.valueAsNumber()||D||0);
			
			G = (
				 B.toString().substr(B.toString().indexOf(".")+1).length > C.toString().substr(C.toString().indexOf(".")+1).length ?
				 B.toString().substr(B.toString().indexOf(".")+1).length :
				 C.toString().substr(C.toString().indexOf(".")+1).length
				);
			
			G = G > 0 ? G : 0;
			
			while(--step >= 0 && (C + B) >= D && (C + B) <= E)
			{
				H = (C + B);
				A.valueAsNumber(H % 1 == 0 ? H : H.toFixed(G));
				C = A.valueAsNumber();
			}
		},
		
		/**
		 *
		 *
		 *
		 */
		indeterminate:function(element)
		{
			return (element.hasOwnProperty("indeterminate") ? element.indeterminate : (!element.value && !element.defaultValue && !element.defaultChecked && !element.checked));
		},
		
		/**
		 *
		 *
		 *
		 */
		addOption:function(element, option, position)
		{
			var callee = arguments.callee;
			
			if(option.constructor == Array)
			{
				$.each(option, function(i, opt){callee.call(element, element, opt, position);});
				return;
			}
			
			switch(element.tagName)
			{
				case "OPTION": element = element.parentNode;
				case "SELECT":
					try{
						(element.add ? element : element.options).add(option, position||null);
					}
					catch(e)
					{
						(element.add ? element : element.options).add(option);
					}
					break;
				case "OPTGROUP":
					(!isNaN(position) ? $(element).find("OPTION").eq(position).before(option) : $(element).append(option));
					break;
				case "DATALIST":
						$(element)
							.find(">SELECT")
							.each(function ()
							{
								callee.call(element, element, option, position);
							});
					break;
			}
		}
	};

	/**
	 *
	 *
	 *
	 */
	$.fn.extend({
		
		/**
		 *
		 *
		 *
		 */
		elements: function(output)
		{
			return this.filter("FORM")
						.map(function()
						{
							var ret = [];
							
							if(this.elements.length)
							{
								ret = ret.concat($.makeArray(this.elements));
							}
							
							if(output)
							{
								try{
									ret = ret.concat($.makeArray($("OUTPUT, SPAN.UI-WEBFORMS20-OUTPUT", this)));
								}
								catch(e){}
							}
							
							return ret;
						})
						//.filter(function(){return this.tagName != "SELECT" || !$(this).hasClass('UI-WEBFORMS20-TIME');});
						.filter(":not(SELECT.UI-WEBFORMS20-TIME)");
		},
		
		/**
		 *
		 *
		 *
		 */
		placeholder: function(value)
		{
			if(value === undefined)
			{
				return this.filter("INPUT").attr("placeholder");
			}
			
			return this.filter("INPUT").attr("placeholder", value).end();
		},
		
		/**
		 *
		 *
		 *
		 */
		noValidate: function(value)
		{
			if(value === undefined)
			{
				return this.is(":novalidate");
			}
			
			return (value ? this.attr("novalidate", "novalidate") : this.removeAttr("novalidate"));
		},
		
		/**
		 *
		 *
		 *
		 */
		required: function(value)
		{
			if(value === undefined)
			{
				return (this[0] && ((this[0].attributes && this[0].attributes.required) || (this[0].hasAttribute && this[0].hasAttribute("required"))));
			}
			
			return (value ? this.attr("required", "required") : this.removeAttr("required"));
		},
		
		/**
		 *
		 *
		 *
		 */
		multiple: function(value)
		{
			if(value === undefined)
			{
				this.each(function ()
				{
					if (this.tagName.match(/input|textarea|select/i))
					{
						value = this;
						return false;
					}
				});
				
				return (value && ((!!value.attributes && !!value.attributes.multiple) || (!!value.hasAttribute && value.hasAttribute("multiple"))));
			}
			
			return (value ? this.attr("multiple", "multiple") : this.removeAttr("multiple"));
		},
		
		/**
		 *
		 *
		 *
		 */
		size: function(value)
		{
			if(value === undefined)
			{
				this.each(function ()
				{
					if (this.tagName.match(/input|textarea|select/i))
					{
						value = this;
						return false;
					}
					else if (this.tagName.match(/datalist/i))
					{
						value = this.firstChild;
						return false;
					}
				});
				
				return (value && ((value.attributes && value.attributes.size) || (value.hasAttribute && value.hasAttribute("size"))));
			}
			
			return this.attr("size", value) ;
		},
		
		/**
		 *
		 *
		 *
		 */
		pattern: function(value)
		{
			if(value === undefined)
			{
				return this.filter("INPUT").attr("pattern");
			}
			
			return this.filter("INPUT").attr("pattern", value).end();
		},
		
		/**
		 *
		 *
		 *
		 */
		step: function(value)
		{
			if(value === undefined)
			{
				return this[0] && this[0].tagName == "INPUT" ? $.WebForms20.getStep(this[0]) : null;
			}
			
			return this.filter("INPUT").each(function(){$.WebForms20.setStep(this, value);}).end();
		},
		
		/**
		 *
		 *
		 *
		 */
		min: function(value)
		{
			if(value === undefined)
			{
				return this[0] && this[0].tagName == "INPUT" ? $.WebForms20.getMin(this[0]) : null;
			}
			
			return this.filter("INPUT").each(function(){$.WebForms20.setMin(this, value);}).end();
		},
		
		/**
		 *
		 *
		 *
		 */
		max: function(value)
		{
			if(value === undefined)
			{
				return this[0] && this[0].tagName == "INPUT" ? $.WebForms20.getMax(this[0]) : null;
			}
			
			return this.filter("INPUT").each(function(){$.WebForms20.setMax(this, value);}).end();
		},
		
		/**
		 *
		 *
		 *
		 */
		maxLength: function(value)
		{
			if(value === undefined)
			{
				return (this[0] && this.attr("maxlength") > -1 && Number(this.attr("maxlength"))) || Infinity;
			}
			
			return (value > 0 ? this.attr("maxlength", value) : this.removeAttr("maxlength"));
		},
		
		/**
		 *
		 *
		 *
		 */
		valueAsDate: function(value)
		{
			if(value === undefined)
			{
				return this[0] && this[0].tagName == "INPUT" ? $.WebForms20.getValueAsDate(this[0]) : null;
			}
			
			return this.filter("INPUT").each(function(){$.WebForms20.setValueAsDate(this, value);}).end();
		},
		
		/**
		 *
		 *
		 *
		 */
		valueAsNumber: function(value)
		{
			if(value === undefined)
			{
				return this[0] && this[0].tagName == "INPUT" ? $.WebForms20.getValueAsNumber(this[0]) : null;
			}
			
			return this.filter("INPUT").each(function(){$.WebForms20.setValueAsNumber(this, value);}).trigger("WEBFORMS20update").end();
		},
		
		/**
		 *
		 *
		 *
		 */
		labels: function()
		{
			return this.filter("INPUT, SELECT, TEXTAREA, BUTTON")
						.map(function()
						{
							if(this.id)
							{
								return $.makeArray($("label[for='"+this.id+"']", this.form));
							}
						})
						.end();
		},
		
		/**
		 *
		 *
		 *
		 */
		list: function()
		{
			return this.filter("INPUT").attr("list") ? $("#" + this.filter("INPUT").attr("list")).filter("DATALIST") : $();
		},
		
		/**
		 *
		 *
		 *
		 */
		validity: function()
		{
			
			if(!this.filter("input, select, textarea, button").length)
			{
				return null;
			}
			
			var K = this.filter("input, select, textarea, button"),
				A = K.placeholder(),
				B = new RegExp("^" + ($.WebForms20.getPattern(K[0])||".*") + "$"),
				C = (K.valueAsNumber()||K.val()),
				E = K.maxLength(),
				G = K.val()||"",
				H = K.min(),
				I = K.max(),
				J = K.step(),
				F = {
						valueMissing: 		K.is(":required") && (String(G).length < 1 && !K.hasClass("UI-WEBFORMS20-PLACEHOLDER")),
						typeMismatch: 		(getType(K[0])||"").match(/(date|time|month|week|number|range|url|email|color)/i) && 
											String(G).length > 0 && !K.hasClass("UI-WEBFORMS20-PLACEHOLDER") && 
											!(B).test(G),
						patternMismatch: 	!!K.pattern() && !(new RegExp("^" + K.pattern() + "$")).test(G),
						tooLong: 			E && G.length > Number(E),
						rangeUnderflow: 	H != null && C < H,
						rangeOverflow: 		I != null && C > I,
						stepMismatch: 		!(getType(K[0])||"").match(/(date|time)/i) && J != null && (C % J) > 0,
						customError: 		!!$.data(K[0], "WebForms20.customError"),
						valid: 				true
					};
					
				F.valid = !(F.valueMissing || F.typeMismatch || F.patternMismatch || F.tooLong || F.rangeUnderflow || F.rangeOverflow || F.stepMismatch || F.customError);
				
			return F;
		},
		
		/**
		 *
		 *
		 *
		 */
		willValidate: function()
		{
			var A = this[0];
			
			return (
						A.tagName == "INPUT" ||
						A.tagName == "SELECT" || 
						A.tagName == "TEXTAREA"
					)
					&&
					!(
						 this.is(":novalidate") ||
						 A.disabled || 
						 hasDataListAncestor(A) || 
						 A.tagName == "BUTTON" ||
						 (A.type.toLowerCase() == "checkbox" && !A.checked) ||
						 (A.type.toLowerCase() == "radio" 	 && !A.checked) ||
						 (A.type.toLowerCase() == "file" 	 && !A.value) ||
						 !A.name ||
						 A.type.toLowerCase() == "button" ||
						 A.type.toLowerCase() == "image"
					);
		},
		
		/**
		 *
		 *
		 *
		 */
		setCustomValidity: function(message)
		{
			return this.each(function(){(message ? $.data(this, "WebForms20.customError", message) : $.removeData(this, "WebForms20.customError"));});
		},
		
		/**
		 *
		 *
		 *
		 */
		validationMessage: function()
		{
			return this[0] && $.data(this[0], "WebForms20.customError");
		},
		
		/**
		 *
		 *
		 *
		 */
		checkValidity: function(unhandledInvalidControls)
		{
			return $.WebForms20.checkValidity(this[0], unhandledInvalidControls);
		},
		
		/**
		 *
		 *
		 *
		 */
		stepUp: function(n)
		{
			return this.each(function(){$.WebForms20.step(this, n, 1)});
		},
		
		/**
		 *
		 *
		 *
		 */
		stepDown: function(n)
		{
			return this.each(function(){$.WebForms20.step(this, n, -1)});
		},
		
		/**
		 *
		 *
		 *
		 */
		dispatchFormInput: function()
		{
			return this.trigger("forminput");
		},
		
		/**
		 *
		 *
		 *
		 */
		dispatchFormChange: function()
		{
			return this.trigger("formchange");
		},
		
		/**
		 *
		 *
		 *
		 */
		selectedOptions: function()
		{
			return this.filter("INPUT[type='file']:multiple, SELECT")
						.map(function()
						{
							if(this.tagName == "SELECT")
							{
								return $(this.options).filter(function(){return this.selected;});
							}
							else
							{
								return [this];
							}
						});
		},
		
		/**
		 *
		 *
		 *
		 */
		addOption: function(option, position)
		{
			
			return this.filter("SELECT, OPTGROUP, OPTION, DATALIST")
						.each(function()
						{
							if(!option.tagName)
							{
								$.WebForms20.addOption(this, $.makeArray(option).reverse(), position);
								return;
							}
							
							$.WebForms20.addOption(this, option, position);
						})
						.end();
		},
		
		/**
		 *
		 *
		 *
		 */
		flash: function(number)
		{
			number = number||3;
			var A = this.hide();
			
			setTimeout(function(){number-=1;A.show();if(number > 0){setTimeout(function(){A.flash(number);}, 200);}}, 200);
			
			return this;
		}
	});
	
	function suffix (num)
	{
		num = num+"";
		switch (num.charAt(num.length-1))
		{
			case '1': return num.substr(-2) != "11" ? 'st' : 'th';
			case '2': return num.substr(-2) != "12" ? 'nd' : 'th';
			case '3': return num.substr(-2) != "13" ? 'rd' : 'th';
		}
		
		return 'th';
	}

	/**
	 *
	 *
	 *
	 */
	$.extend($.expr.filters||{}, {
		"invalid": 			function(element){return $(element).validity().valid;},
		"indeterminate": 	function(element){return $.WebForms20.indeterminate(element);},
		"target": 			function(element){return element.tagName == "A" && element.name && window.location.hash.substr(1) == element.name;},
		"willvalidate": 	function(element){return $(element).willValidate();},
		"webform20":		function(element){return (getType(element)||"").match(/number|range|date|time|month|week|url|email/i);},
		"autofocus":		function(element){return !!(element.attributes.autofocus || (element.hasAttribute&&element.hasAttribute("autofocus")));},
		"required":			function(element){return !!(element.attributes.required || (element.hasAttribute&&element.hasAttribute("required")));},
		"multiple":			function(element){return !!(element.attributes.multiple || (element.hasAttribute&&element.hasAttribute("multiple")));},
		"novalidate":		function(element){return !!(element.attributes.novalidate || (element.hasAttribute&&element.hasAttribute("novalidate")));}
	});
		
	$.each({ 
		blur: 'focusout', 
		focus: 'focusin'
	}, function( orig, fix )
	{
		jQuery.event.special[ fix ] = {
			setup: function(data, namespaces)
			{
				if (this.addEventListener)
					this.addEventListener(orig, $.data(this, "handle"), true);
				else if (this.attachEvent)
					this.attachEvent("on" + fix, $.data(this, "handle"));
			},
			teardown: function()
			{
				if (this.removeEventListener)
					this.removeEventListener(type, $.data(this, "handle"), false);
				else if (this.detachEvent)
					this.detachEvent("on" + type, $.data(this, "handle"));
			}
		};			   
	});
		
	/**
	 *
	 *
	 *
	 */
	$(function()
	{
		
		/**
		 *
		 *
		 *
		 */
		function updateCalendar()
		{
			var year = dateObject.getFullYear(),
				mon = dateObject.getMonth(),
				thisMonth = year === today.getFullYear() ? today.getMonth() : -1,
				current = mon === thisMonth,
				data = $.data(calendar[0], "WEBFORMS20.currentTarget"),
				selected = !!data && data.valueAsDate(),
				selectedMonth = !!selected && mon === selected.getMonth(),
				selectedDate = !!selected && selectedMonth
								&& year === selected.getFullYear(),
				daysInThisMonth = daysInMonth(dateObject),
				day = dateObject.getDay(),
				numweeks = (
								(daysInThisMonth >= 30 && day == 6) 
							 || (daysInThisMonth == 31 && day > 4)
							) 
							? 6 : 5,
				weeks = getWeeks(year, mon),
				days = getDays(year, mon),
				mode = calendar.hasClass("UI-WEBFORMS20-CALENDAR-MODE-DATE") ? 'date' : calendar.hasClass("UI-WEBFORMS20-CALENDAR-MODE-WEEK");
				
			mon = month[mon];
			
			calendar.find("TBODY")
				.attr('title', mon + " " + year)
				[(selectedMonth ? "addClass" : "removeClass")]("UI-WEBFORMS20-CALENDAR-SELECTED")
				[(current ? "addClass" : "removeClass")]("UI-WEBFORMS20-CALENDAR-THISMONTH");
			
			
			calendar.find("TD.UI-WEBFORMS20-CALENDAR-DAY")
				.removeClass("UI-WEBFORMS20-CALENDAR-SELECTED")
				.removeClass("UI-WEBFORMS20-CALENDAR-TODAY")
				.removeClass("UI-WEBFORMS20-CALENDAR-NOTCURRENTMONTH")
				.each(function(i)
				{
					var date = mon + " " + days[i] + ", " + year,
						$this = $(this).attr('title', mode === 'date' ? date : '').html(days[i]);
					
					if((i < 7 && days[i] > 15) || (i > 20 && days[i] < 15))
					{
						$this.addClass("UI-WEBFORMS20-CALENDAR-NOTCURRENTMONTH");
					}
					else if (current && days[i] === today.getDate())
					{
						$this.addClass("UI-WEBFORMS20-CALENDAR-TODAY");
						
						if (mode === 'date')
						{
							$this.attr('title', 'Today is ' + date);
						}
					}
					else if (selectedDate && days[i] === selected.getDate())
					{
						$this.addClass("UI-WEBFORMS20-CALENDAR-SELECTED");
						
						if (mode === 'date')
						{
							$this.attr('title', 'The currently selected date is ' + date);
						}
					}
				});
				
			calendar.find("TD.UI-WEBFORMS20-CALENDAR-WEEK")
				.each(function(i)
				{
					var $this = $(this),
						parent = $this.parent(),
						cur = parent.find("TD.UI-WEBFORMS20-CALENDAR-TODAY").length,
						sel = parent.find("TD.UI-WEBFORMS20-CALENDAR-SELECTED").length,
						suffixed = weeks[i] + suffix(weeks[i]),
						title = (
									 sel 
									 ? suffixed + " is the currently selected week." 
									 : (
										  cur 
										  ? suffixed + " is the current week of the year." 
										  : "This is the " + suffixed + " week in " + year
									  )
								 );
						$this.html(weeks[i]);
						parent
							.attr('title', title)
							[(cur ? "addClass" : "removeClass")]("UI-WEBFORMS20-CALENDAR-THISWEEK")
							[(sel ? "addClass" : "removeClass")]("UI-WEBFORMS20-CALENDAR-SELECTED");
				});
				
			calendar.find("TR.UI-WEBFORMS20-CALENDAR-WEEKS").show().filter(":gt(" + numweeks + ")").hide();
			calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-MONTH").val(mon);
			
			calendar.find("SELECT.UI-WEBFORMS20-TIME-HOUR").val(dateObject.getHours() - (dateObject.getHours() > 12 ? 12 : 0));
			calendar.find("SELECT.UI-WEBFORMS20-TIME-MINUTE").val(dateObject.getMinutes());
			calendar.find("SELECT.UI-WEBFORMS20-TIME-AMPM").val((dateObject.getHours() > 12 ? "PM" : "AM"));
		}
		
		/**
		 *
		 *
		 *
		 */
		var today = new Date(),
			slider = $('<span class="UI-WEBFORMS20-SLIDER">\
					   		<span class="UI-WEBFORMS20-SLIDER-BODY">\
								<span class="UI-WEBFORMS20-SLIDER-HR">&nbsp;<\/span>\
							<\/span>\
					   		<span class="UI-WEBFORMS20-SLIDER-HANDLE">&nbsp;<\/span>\
						<\/span>')
						.bind("WEBFORMS20update", function(event, number, size)
						{
							if(isNaN(number))
							{
								number = $.data(this, "WEBFORMS20.currentTarget").valueAsNumber();
							}
							
							var Z = $(this),
								B = $.data(this, "WEBFORMS20.currentTarget"),
								A = Z.find("SPAN.UI-WEBFORMS20-SLIDER-BODY"),
								C = Z.find("SPAN.UI-WEBFORMS20-SLIDER-HANDLE")[0].offsetWidth,
								min = B.min() || 0,
								step = B.step() || 1,
								max = B.max() || !!min && min+(step*10) || 10,
								width = A.width(),
								steps = Math.ceil((Math.abs(number) - min) / step);
								steps = steps > max ? max : steps;
								size = size || Math.floor(width / (((max - min) / step) + 1)) || 1;
								step = width - Math.abs(size * steps);
							
							Z.find("SPAN.UI-WEBFORMS20-SLIDER-HANDLE")
								.css("left", -(step > C ? step : C));
						}),
			invalid = $('<div class="UI-WEBFORMS20-INVALID-MESSAGE"><div><span>'+($.browser.msie ? '&lt;' : '&#9664;')+'<\/span><\/div><\/div>').hide(),
			spinner = $('<span class="UI-WEBFORMS20-INPUT-SPINNER">\
							<span class="UI-WEBFORMS20-INPUT-SPINNER-UP" title="Up">&#9650;<\/span>\
							<span class="UI-WEBFORMS20-INPUT-SPINNER-DOWN" title="Down">&#9660;<\/span>\
						<\/span>')
							.mousedown(function(){return false})
							.each(function()
							{
								if(window.ActiveXObject)
								{
									this.onselectstart = this.ondragstart = function(){return false};
								}
							}),
			days = new Array(60),
			timer = $('<span class="UI-WEBFORMS20-TIME">&nbsp;<\/span>')
						.html('<select class="UI-WEBFORMS20-TIME UI-WEBFORMS20-TIME-HOUR" webforms20updated="true" title="Hour">\
									<option value="1">1<\/option>\
									<option value="2">2<\/option>\
									<option value="3">3<\/option>\
									<option value="4">4<\/option>\
									<option value="5">5<\/option>\
									<option value="6">6<\/option>\
									<option value="7">7<\/option>\
									<option value="8">8<\/option>\
									<option value="9">9<\/option>\
									<option value="10">10<\/option>\
									<option value="11">11<\/option>\
									<option value="0">12<\/option>\
								<\/select>:<select class="UI-WEBFORMS20-TIME UI-WEBFORMS20-TIME-MINUTE" webforms20updated="true" title="Minute">\
									' + 
									$.map(	$.each(days, function(i){days[i]=i;}), 
											function(i)
											{
												return '<option value="'+i+'">'+ (i > 9 ? i : '0' + i) +'<\/option>';
											})
											.join('') +
								'<\/select>&nbsp;<select class="UI-WEBFORMS20-TIME UI-WEBFORMS20-TIME-AMPM" webforms20updated="true" title="Morning or Evening">\
									<option value="0">AM<\/option>\
									<option value="12">PM<\/option>\
								<\/select>')
						.bind("WEBFORMS20update", function(event, number)
						{
							if(isNaN(number))
							{
								number = $.data(this, "WEBFORMS20.currentTarget").valueAsNumber();
							}
							
							number = number/1000;
							
							var P = $(this), minutes = number/60, hours = Math.round(minutes/60);
							
							P.find("SELECT.UI-WEBFORMS20-TIME-HOUR").val(hours - (hours > 11 ? 11 : 0));
							P.find("SELECT.UI-WEBFORMS20-TIME-AMPM").val((hours > 12 ? "PM" : "AM"));
							P.find("SELECT.UI-WEBFORMS20-TIME-MINUTE").val(0);
						}),
			deleter = $('<span class="UI-WEBFORMS20-DELETER">X<\/span>')
							.appendTo(document.body)
							.click(function()
							{
								var A = $.data(this, "currentTarget");
								if (A)
								{
									$(A).remove();
									$(this).hide();
								}
							}),
			dateObject = new Date(),
			month = ["January","February","March","April","May","June","July","August","September","October","November","December"],
			calendar = $('<table class="UI-WEBFORMS20-CALENDAR">\
								<thead>\
									<tr>\
										<td colspan="8">\
											<input type="button" class="UI-WEBFORMS20-CALENDAR-LASTMONTH" value="&laquo;" title="Last Month"\/>\
											<input type="text" readonly class="UI-WEBFORMS20-CALENDAR-MONTH" value="' + month[dateObject.getMonth()] + '" title="Current Month"\/>\
											<input type="button" class="UI-WEBFORMS20-CALENDAR-NEXTMONTH" value="&raquo;" title="Next Month"\/>\
											<input type="text" class="UI-WEBFORMS20-CALENDAR-YEAR" size="4" maxlength="4" \
													value="' + dateObject.getFullYear() + '" title="Current Year"\/>\
											<span class="UI-WEBFORMS20-INPUT-SPINNER">\
												<span class="UI-WEBFORMS20-INPUT-SPINNER-UP" title="Up">&#9650;<\/span>\
												<span class="UI-WEBFORMS20-INPUT-SPINNER-DOWN" title="Down">&#9660;<\/span>\
											<\/span>\
										<\/td>\
									<\/tr>\
								<\/thead>\
								<tbody>\
									<tr class="UI-WEBFORMS20-CALENDAR-WEEKHEADER">\
										<td>Week<\/td>\
										<td>Sun<\/td>\
										<td>Mon<\/td>\
										<td>Tues<\/td>\
										<td>Wed<\/td>\
										<td>Thur<\/td>\
										<td>Fri<\/td>\
										<td>Sat<\/td>\
									<\/tr>\
									<tr class="UI-WEBFORMS20-CALENDAR-WEEKS">\
										<td class="UI-WEBFORMS20-CALENDAR-WEEK">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
									<\/tr>\
									<tr class="UI-WEBFORMS20-CALENDAR-WEEKS">\
										<td class="UI-WEBFORMS20-CALENDAR-WEEK">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
									<\/tr>\
									<tr class="UI-WEBFORMS20-CALENDAR-WEEKS">\
										<td class="UI-WEBFORMS20-CALENDAR-WEEK">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
									<\/tr>\
									<tr class="UI-WEBFORMS20-CALENDAR-WEEKS">\
										<td class="UI-WEBFORMS20-CALENDAR-WEEK">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
									<\/tr>\
									<tr class="UI-WEBFORMS20-CALENDAR-WEEKS">\
										<td class="UI-WEBFORMS20-CALENDAR-WEEK">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
									<\/tr>\
									<tr class="UI-WEBFORMS20-CALENDAR-WEEKS">\
										<td class="UI-WEBFORMS20-CALENDAR-WEEK">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
										<td class="UI-WEBFORMS20-CALENDAR-DAY">&nbsp;<\/td>\
									<\/tr>\
								<\/tbody>\
								<tfoot>\
									<tr class="UI-WEBFORMS20-CALENDAR-TIME">\
										<td colspan="8">\
											' + timer.html() +
										'<\/td>\
									<\/tr>\
									<tr>\
										<td colspan="4" class="UI-WEBFORMS20-CALENDAR-BUTTONS">\
											<input type="button" class="UI-WEBFORMS20-CALENDAR-TODAY" value="Today" title="Today"\/>\
										<\/td>\
										<td colspan="4" class="UI-WEBFORMS20-CALENDAR-BUTTONS">\
											<input type="button" class="UI-WEBFORMS20-CALENDAR-NONE" value="None" title="Cancel"\/>\
										<\/td>\
									<\/tr>\
								<\/tfoot>\
							 <\/table>')
							.hide()
							.appendTo(document.body)
							.click(function(event)
							{
								$.each((event.target.className||"").split(/\s+/), function(i, className)
								{
									var A;
									switch(className)
									{
										case "UI-WEBFORMS20-CALENDAR-LASTMONTH":
											if(event.target.tagName == "INPUT")
											{
												if(dateObject.getMonth() == 0)
												{
													dateObject.setFullYear(dateObject.getFullYear() - 1);
													dateObject.setMonth(11);
													calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val(dateObject.getFullYear());
												}
												else
												{
													dateObject.setMonth(dateObject.getMonth() - 1);
												}
												
												calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-MONTH").val(month[dateObject.getMonth()]);
												updateCalendar();
											}
											break;
										case "UI-WEBFORMS20-CALENDAR-NEXTMONTH":
											if(event.target.tagName == "INPUT")
											{
												if(dateObject.getMonth() == 11)
												{
													dateObject.setFullYear(dateObject.getFullYear() + 1);
													dateObject.setMonth(0);
													calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val(dateObject.getFullYear());
												}
												else
												{
													dateObject.setMonth(dateObject.getMonth() + 1);
												}
												calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-MONTH").val(month[dateObject.getMonth()]);
												updateCalendar();
											}
											break;
										case "UI-WEBFORMS20-CALENDAR-YEAR":
											dateObject.setFullYear(event.target.value);
											calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val(dateObject.getFullYear());
											updateCalendar();
											break;
										case "UI-WEBFORMS20-CALENDAR-DAY":
											if(calendar.hasClass("UI-WEBFORMS20-CALENDAR-MODE-DATE"))
											{
												if(!$(event.target).hasClass("UI-WEBFORMS20-CALENDAR-NOTCURRENTMONTH"))
												{
													dateObject.setDate(Number($(event.target).text()));
													dateObject.setFullYear(calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val());
													dateObject.setHours(
																			Number(calendar.find("SELECT.UI-WEBFORMS20-TIME-HOUR").val())+
																			Number(calendar.find("SELECT.UI-WEBFORMS20-TIME-AMPM").val())
																		);
													dateObject.setMinutes(calendar.find("SELECT.UI-WEBFORMS20-TIME-MINUTE").val());
													var target = $.data(calendar.hide()
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-DATE")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-WEEK")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-MONTH")[0], 
																		"WEBFORMS20.currentTarget");
													target.valueAsDate(dateObject);
													$(target[0].form).trigger("formchange");
												}
											}
											else if(calendar.hasClass("UI-WEBFORMS20-CALENDAR-MODE-WEEK"))
											{
												dateObject.setDate(Number($(event.target).text()));
												dateObject.setFullYear(calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val());
												dateObject.setHours(
																		Number(calendar.find("SELECT.UI-WEBFORMS20-TIME-HOUR").val())+
																		Number(calendar.find("SELECT.UI-WEBFORMS20-TIME-AMPM").val())
																	);
												dateObject.setMinutes(calendar.find("SELECT.UI-WEBFORMS20-TIME-MINUTE").val());
												var target = $.data(calendar.hide()
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-DATE")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-WEEK")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-MONTH")[0], 
																	"WEBFORMS20.currentTarget");
													target.valueAsDate(dateObject);
													$(target[0].form).trigger("formchange");
											}
											else if(calendar.hasClass("UI-WEBFORMS20-CALENDAR-MODE-MONTH"))
											{
												dateObject.setFullYear(calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val());
												dateObject.setHours(
																		Number(calendar.find("SELECT.UI-WEBFORMS20-TIME-HOUR").val())+
																		Number(calendar.find("SELECT.UI-WEBFORMS20-TIME-AMPM").val())
																	);
												dateObject.setMinutes(calendar.find("SELECT.UI-WEBFORMS20-TIME-MINUTE").val());
												var target = $.data(calendar.hide()
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-DATE")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-WEEK")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-MONTH")[0], 
																	"WEBFORMS20.currentTarget");
													target.valueAsDate(dateObject);
													$(target[0].form).trigger("formchange");
											}
											break;
										case "UI-WEBFORMS20-CALENDAR-WEEKS":
											if(calendar.hasClass("UI-WEBFORMS20-CALENDAR-MODE-WEEK"))
											{
												dateObject.setFullYear(calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val());
												dateObject.setDate(Number($(event.target).next("TD").text()));
												dateObject.setHours(
																		Number(calendar.find("SELECT.UI-WEBFORMS20-TIME-HOUR").val())+
																		Number(calendar.find("SELECT.UI-WEBFORMS20-TIME-AMPM").val())
																	);
												dateObject.setMinutes(calendar.find("SELECT.UI-WEBFORMS20-TIME-MINUTE").val());
												var target = $.data(calendar.hide()
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-DATE")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-WEEK")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-MONTH")[0], 
																	"WEBFORMS20.currentTarget");
													target.valueAsDate(dateObject);
													$(target[0].form).trigger("formchange");
											}
											else if(calendar.hasClass("UI-WEBFORMS20-CALENDAR-MODE-MONTH"))
											{
												dateObject.setFullYear(calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val());
												dateObject.setHours(
																		Number(calendar.find("SELECT.UI-WEBFORMS20-TIME-HOUR").val())+
																		Number(calendar.find("SELECT.UI-WEBFORMS20-TIME-AMPM").val())
																	);
												dateObject.setMinutes(calendar.find("SELECT.UI-WEBFORMS20-TIME-MINUTE").val());
												var target = $.data(calendar.hide()
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-DATE")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-WEEK")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-MONTH")[0], 
																	"WEBFORMS20.currentTarget");
													target.valueAsDate(dateObject);
													$(target[0].form).trigger("formchange");
											}
											break;
										case "UI-WEBFORMS20-CALENDAR-TODAY":
											dateObject = new Date();
											dateObject.setFullYear(calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val());
											dateObject.setHours((new Date()).getHours());
											dateObject.setMinutes((new Date()).getMinutes());
											var target = $.data(calendar.hide()
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-DATE")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-WEEK")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-MONTH")[0], 
																"WEBFORMS20.currentTarget");
												target.valueAsDate(dateObject);
												$(target[0].form).trigger("formchange");
											break;
										case "UI-WEBFORMS20-CALENDAR-NONE":
											var target = $.data(calendar.hide()
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-DATE")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-WEEK")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-MONTH")[0], 
																"WEBFORMS20.currentTarget");
												target.val("");
												$(target[0].form).trigger("formchange");
											break;
										case "UI-WEBFORMS20-INPUT-SPINNER-UP":
											A = calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val();
											A = A.length == 4 ? A : 0;
											calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val(Number(A||dateObject.getFullYear()) + 1);
											dateObject.setFullYear(calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val());
											updateCalendar();
											break;
										case "UI-WEBFORMS20-INPUT-SPINNER-DOWN":
											A = calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val();
											A = A.length == 4 ? A : 0;
											calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val(Number(A||dateObject.getFullYear()) - 1);
											dateObject.setFullYear(calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val());
											updateCalendar();
											break;
										default:
											A = event.target;
											while(A.tagName != "TBODY" && A != calendar[0])
											{
												A = A.parentNode;
											}
											
											if(calendar.hasClass("UI-WEBFORMS20-CALENDAR-MODE-MONTH") && A.tagName == "TBODY")
											{
												dateObject.setFullYear(calendar.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR").val());
												dateObject.setHours(
																		Number(calendar.find("SELECT.UI-WEBFORMS20-TIME-HOUR").val())+
																		Number(calendar.find("SELECT.UI-WEBFORMS20-TIME-AMPM").val())
																	);
												dateObject.setMinutes(calendar.find("SELECT.UI-WEBFORMS20-TIME-MINUTE").val());
												var target = $.data(calendar.hide()
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-DATE")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-WEEK")
																		.removeClass("UI-WEBFORMS20-CALENDAR-MODE-MONTH")[0], 
																	"WEBFORMS20.currentTarget");
													target.valueAsDate(dateObject);
													$(target[0].form).trigger("formchange");
											}
									}
								});
								
								return false;
							})
							.mousedown(function(event)
							{
								return event.target.tagName == "INPUT";
							})
							.find("INPUT.UI-WEBFORMS20-CALENDAR-YEAR")
							.keyup(function()
							{
								if(this.value.length == 4 && !isNaN(Number(this.value)))
								{
									dateObject.setFullYear(this.value);
									updateCalendar();
								}
							})
							.end();
		
		dateObject.setDate(1);
		updateCalendar();
		
		$(document.body)
			.click(function()
			{
				calendar
					.removeClass("UI-WEBFORMS20-CALENDAR-MODE-DATE")
					.removeClass("UI-WEBFORMS20-CALENDAR-MODE-WEEK")
					.removeClass("UI-WEBFORMS20-CALENDAR-MODE-MONTH")
					.hide();
				$("DATALIST").hide();
			});
		
		
		$.WebForms20.updater = function()
		{
			
			/**
			 *	DATALIST ELEMENT
			 *
			 *
			 */
			$("DATALIST[type='application/x-webforms-2.0-datalist']")
				.each(function ()
				{
					var that = $(this),
						select = $('<select size="10">' + that.html() + '</select>');
					
					if ((select.length || select.options.length) < 10)
					{
						select.size = (select.length || select.options.length);
					}
					
					$("DATALIST" + that.attr("rel"))
						.html(select)
						.click(function ()
						{
							var target = $.data(this,"WEBFORMS20.currentTarget"),
								select = $(this).find(">SELECT");
							
							if (target)
							{
								if (target.multiple())
								{
									target.val(select.val().join(","));
								}
								else
								{
									target.val(select.val());
								}
							}
						});
						
					that.remove();
				});
			
			$("input[list]")
				.filter(":not([webforms20updated])")
				.focus(function ()
				{
					var $this = $(this),
						offset = $this.offset();
					
					$.data($("datalist#" + $this.attr("list"))
									.find(">SELECT")
									.val($this.multiple() ? $this.val().split(/\s*,\s*/) : $this.val())
									.css({
										  top:	offset.top + $this.height(),
										  left:	offset.left
									})
									.multiple($this.multiple())
									.end()
									.show()[0],
							"WEBFORMS20.currentTarget", $this);
				});
			
			/**
			 *
			 *
			 *
			 */
			$("INPUT")
				.each(function()
				{
					var C = $(this), 
						A = C.placeholder();
					
					if(A && (!C.val() || C.val() == A))
					{
						C.val(A).addClass("UI-WEBFORMS20-PLACEHOLDER");
					}
				})
				.filter(function()
				{
					return !(/(password|hidden|checkbox|radio|file)/i).test((getType(this)||""));
				})
				.filter(":not([webforms20updated])")
				.blur(function()
				{
					var B = $(this), A = B.placeholder();
					
					if(A && !B.val())
					{
						B.val(A).addClass("UI-WEBFORMS20-PLACEHOLDER");
					}
				})
				.focus(function()
				{
					var B = $(this), A = B.val();
					
					if(A && B.placeholder() == A)
					{
						B.removeClass("UI-WEBFORMS20-PLACEHOLDER").val("");
					}
				})
				.filter(function()
				{
					return (/(date|time|month|week|number|range|url|email|color)/i).test((getType(this)||""));
				})
				.each(function()
				{
					var C = $(this), 
						A,
						B = (getType(this)||"").toLowerCase(),
						mode,
						R;
					
					switch(B)
					{
						case "date":			mode = "DATE"; break;
						case "datetime":		mode = "DATE"; break;
						case "datetime-local":	mode = "DATE"; break;
						case "month":			mode = "MONTH"; break;
						case "week":			mode = "WEEK"; break;
					}
					
					if(B.match(/(date|month|week)/))
					{
						C.click(function()
						{
							$.data(
									calendar[(B.match(/time/) ? 'addClass' : 'removeClass')]("UI-WEBFORMS20-CALENDAR-MODE-TIME")
										.removeClass("UI-WEBFORMS20-CALENDAR-MODE-DATE")
										.removeClass("UI-WEBFORMS20-CALENDAR-MODE-WEEK")
										.removeClass("UI-WEBFORMS20-CALENDAR-MODE-MONTH")
										.addClass("UI-WEBFORMS20-CALENDAR-MODE-" + mode)
										.show()
										.css({top: C.offset().top + (C[0].offsetHeight||C.height()), left: C.offset().left})[0], 
									"WEBFORMS20.currentTarget", 
									C
								);
							
							if(C.val())
							{
								dateObject = C.valueAsDate();
							}
							
							updateCalendar();
							return false;
						});	
					}
					else if(B.match(/time/))
					{
						R = timer.clone(true)
								.trigger("WEBFORMS20update", [C.valueAsNumber()])
								.find("SELECT")
								.change(function()
								{
									var P = $(this.parentNode),
										V = (
												((Number(P.find(".UI-WEBFORMS20-TIME-HOUR").val()) + Number(P.find(".UI-WEBFORMS20-TIME-AMPM").val())) * 3600) + 
												(Number(P.find(".UI-WEBFORMS20-TIME-MINUTE").val()) * 60)
											) * 1000;
									
									$.WebForms20.setValueAsNumber(C[0], V);
									$(C[0].form).trigger("formchange");
								})
								.end();
						
						if(C.val())
						{
							R.trigger("WEBFORMS20update", [C.valueAsNumber()]);
						}
						else
						{
							R.trigger("WEBFORMS20update", [+new Date]);
							C.valueAsNumber(+new Date);
						}
						
						$.data(R[0], "WEBFORMS20.currentTarget", C);
						
						$.data(C.hide().before(R)[0], "WEBFORMS20.currentTarget", R);
					}
					else if(B.match(/number/))
					{
						C.css("textAlign", "right")
							.after(
								spinner.clone(true)
									.click(function(event)
									{
										if($(event.target).hasClass("UI-WEBFORMS20-INPUT-SPINNER-UP"))
										{
											C.stepUp(1);
											$(C[0].form).trigger("formchange");
										}
										else if($(event.target).hasClass("UI-WEBFORMS20-INPUT-SPINNER-DOWN"))
										{
											C.stepDown(1);
											$(C[0].form).trigger("formchange");
										}
									})
							);
					}
					else if(B.match(/range/))
					{
						R = slider.clone(true)
									.mousedown(function(event)
									{
										var step = Math.floor($(this).find("SPAN.UI-WEBFORMS20-SLIDER-BODY").width() / ((((C.max()||10) - (C.min()||0)) / (C.step()||1)) + 1))||1;
										
										if($(event.target).hasClass("UI-WEBFORMS20-SLIDER-HANDLE"))
										{
											var Q = $(event.target).addClass("UI-WEBFORMS20-SLIDER-HANDLE-HOVER"),
												A = $.extend({}, event),
												B = function(event)
												{
													if(window.ActiveXObject)
													{
														document.body.onselectstart = function(){return false};
													}
													
													var X = (event.clientX - A.clientX),
														Y = Math.abs(X),
														W = Math.floor(Y/step),
														Z = X >= 0 ? 1 : -1;
													
													if(Y > step)
													{
														A.clientX = event.clientX;
														$.WebForms20.step(C[0], W, Z);
														R.trigger("WEBFORMS20update", [C.valueAsNumber(), step])
														$(C[0].form).trigger("formchange");
													}
												},
												X = function()
												{
													if(window.ActiveXObject)
													{
														document.body.onselectstart = null;
													}
													
													Q.removeClass("UI-WEBFORMS20-SLIDER-HANDLE-HOVER");
													$(document.body).unbind("mousemove", B).unbind("mouseup", X);
												};
												
											$(document.body).mousemove(B).mouseup(X);
										}
										return false;
									});
							
						$.data(R[0], "WEBFORMS20.currentTarget", C);
						
						if(C.valueAsNumber() < C.min())
						{
							C.valueAsNumber(C.min());
						}
						
						if(C.valueAsNumber() > C.max())
						{
							C.valueAsNumber(C.max());
						}
						
						$.data(C.hide().after(R)[0], "WEBFORMS20.currentTarget", R.trigger("WEBFORMS20update", [C.valueAsNumber()]));
					}
					//Requires ColorPicker: http://www.eyecon.ro/colorpicker/
					else if(B.match(/color/) && $.fn.ColorPicker)
					{
						C.ColorPicker({
							onSubmit: function(hsb, hex, rgb)
							{
								C.val("#" + hex);
							},
							onBeforeShow: function()
							{
								C.ColorPickerSetColor(this.value);
							}
						})
						.bind('keyup', function()
						{
							C.ColorPickerSetColor(this.value);
						});
					}
				});
			
			$("INPUT[type='file']:multiple")
				.filter(":not([webforms20updated])")
				.wrap('<div class="UI-WEBFORMS20-MULTIFILE"><\/div>')
				.change(function()
				{
					if(this.value)
					{
						$(this)
							.before(
								$(this)
									.clone(true)
									.val("")
									.show()
							);	
					}
				})
				.hover(function()
				{
					if ($('input[type="file"][name="'+this.name+'"]').length > 1)
					{
						$.data(deleter[0], "currentTarget", this);
						var A = $(this).offset();
						deleter.css({top: A.top, left: A.left - (deleter.width()/2)}).show();
					}
				},
				function(e)
				{
					if (e.relatedTarget != deleter[0])
						deleter.hide();
				});
			
			$("TEXTAREA")
				.filter(":not([webforms20updated])")
				//.filter(":multiple")//.filter(function(){return !!(this.attributes.maxlength || (this.hasAttribute && this.hasAttribute("maxlength")));})
				.bind("keydown keyup keypress", function()
				{
					var maxLength = Number(this.getAttribute("maxlength"));
					
					if(maxLength > 0 && maxLength < this.value.length)
					{
						this.value = this.value.substr(0, maxLength);
					}
					
					return (maxLength < 1 || this.value.length <= maxLength);
				});
			/*
			$("INPUT, SELECT, TEXTAREA")
				.filter("[form]")
				.bind("formchange forminput", function()
				{
					var A = $.data(this, "WEBFORMS20.hiddenTarget"), B, C;
					
					if(A)
					{
						if($(this).selectedOptions().length)
						{
							B = A.attr('name');
							C = $(A[0].form);
							A.remove();
							$(this)
								.selectedOptions()
								.each(function()
								{
									C.append('<input type="hidden" name="'+B+'" value="'+this.value+'\/>');
								});
							$.data(this, "WEBFORMS20.hiddenTarget", C.find('INPUT[type="hidden"][name="'+B+'"]'));
						}
						
						A.val($(this).val());
					}
				})
				.each(function()
				{
					var A = $('form#'+$(this).attr("form")), B;
					
					if(A.length)
					{
						B = $('<input type="hidden" name="'+this.name+'" value="'+this.value+'\/>');
						$.data(this, "WEBFORMS20.hiddenTarget", B.prependTo(A));
					}
				});
			*/
			$("INPUT, TEXTAREA")
				.filter(":not([webforms20updated])")
				.keyup(function(event)
				{
					$(this.form).trigger("forminput");
				});
			
			/**
			 *
			 *
			 *
			 */
			$("FORM")
				.filter(":not([webforms20updated])")
				.attr("webforms20updated", "true")
				.submit(function(e)
				{
					$(this)
						.elements()
						.each(function()
						{
							var B = $(this), A = B.val();
					
							if(A && B.placeholder() == A)
							{
								B.removeClass("UI-WEBFORMS20-PLACEHOLDER").val("");
							}
						});
					
					if(!$(this).noValidate())
					{
						var unhandled = [],
							ret = $.WebForms20.checkValidity(this, unhandled);
						
						$.each(unhandled, function()
						{
							$.WebForms20.unhandledEvent(this);
						});
						
						return ret;
					}
				})
				.bind("forminput formchange", function(event)
				{
					$(this).elements(true);//.trigger(event.type);
				});
			
			/**
			 *
			 *
			 *
			 */
			try{
			$("OUTPUT")
				.each(function()
				{
					var A = $(
							  $(this)
									.wrap("<div\/>")
									.parent()
									.html()
									.replace(/<(\/)?output/ig,
											function(a,b)
											{
												return b ? '<\/span' : '<span';
											})
							).addClass("UI-WEBFORMS20-OUTPUT"),
						C = A.attr("value")||A.text();
					
					$(this).parent().replaceWith(A);
								
					watch(A[0], "value", function(){return $(this).text();}, function(value){$(this).text(value);});
					watch(A[0], "defaultValue", function(){return C;}, function(value){$(this).text(value);});
					watch(A[0], "form", function(){return ($(this).attr("form") ? $("form#"+$(this).attr("form")) : $(this).parent("form")).get(0)});
					watch(A[0], "htmlFor", function(){return $("#"+$(this).attr("for")).get(0);}, function(value){$(this).attr("for", value);});
					watch(A[0], "name", function(){return $(this).attr("name");}, function(value){$(this).attr("name", value);});
					watch(A[0], "type", function(){return "output";});
				});
			}catch(e){/*IE cant handle this for some absolutely insane reason that I cannot figure out*/}
			
			/**
			 *
			 *
			 *
			 */
			$("FORM")
				.elements(true)
				.filter(":not([webforms20updated])")
				.attr("webforms20updated", "true")
				.each(function()
				{
					var C = $(this),
						A = this.onformchange||C.attr("onformchange"), 
						B = this.onforminput||C.attr("onforminput");
					
					if(A)
					{
						C.bind("formchange", (typeof A == "string" ? new Function('event', A) : A)).attr('onformchange', null);
					}
					
					if(B)
					{
						C.bind("forminput", (typeof B == "string" ? new Function('event', B) : B)).attr('onforminput', null);
					}
					
					watch(this, "onforminput", function(){return null}, function(value){C.bind("forminput", value);return false;}, null);
					watch(this, "onformchange", function(){return null}, function(value){C.bind("formchange", value);return false;}, null);
				})
				.filter(":not(OUTPUT):not(SPAN.UI-WEBBFORMS20-OUTPUT)")
				.bind("keyup change click select", function(event)
				{
					if(
					   (event.type == "click" && getType(this).match(/(radio|checkbox)/i) && event.returnValue !== false) || 
					   (event.type == "change" || event.type == "select")
					)
					{
						return $(this.form).trigger("formchange");
					}
					else if(event.type == "keyup" && ($(this).attr("type")||"").match(/(file|text|search|url|email)/i))
					{
						return $(this.form).trigger("forminput") && $(this.form).trigger("formchange");
					}
				});
		};
			
		$.WebForms20.unhandledEvent = function(element)
		{
			var A,
				box = invalid.clone(),
				message = "",
				$e = $(element),
				type = (element.tagName == "INPUT" ? (getType(element)||"") : element.type).toLowerCase(),
				validity = $e.validity(),
				offset,
				top,
				left;
			
			if($e.is(":hidden"))
			{
				$e.show();
				A = true;
			}
			
			offset = $e.offset();
			top = offset.top;
			left = offset.left + (element.offsetWidth||$e.width()) - 3;
			
			if(A)
			{
				$e.hide();
			}
			
			if(validity.customError)
			{
				message += $e.validationMessage() + "\n";
			}
			
			if(validity.valueMissing)
			{
				message += "This field is required.\n";
			}
			
			if(validity.tooLong)
			{
				message += "This field cannot exceed the maximum number of characters: " + $e.maxLength() + ".\n";
			}
			
			if(validity.rangeUnderflow)
			{
				message = "This field cannot be less than the minimum value: " + $e.min() + ".\n";
			}
			
			if(validity.rangeOverflow)
			{
				message = "This field cannot be greater than the maximum value: " + $e.max() + ".\n";
			}
			
			if(validity.stepMismatch)
			{
				message = "This field must be divisible by " + $e.step() + ".\n";
			}
			
			if(validity.patternMismatch)
			{
				message = "The value of this field does not fit the desired pattern.\n";
			}
			
			if(validity.typeMismatch)
			{
				switch(type)
				{
					case "date":			message += "The value of this field must contain a valid date.\n(2000-01-01)\n"; break;
					case "datetime":		message += "The value of this field must contain a valid universal date\/time.\n(2000-01-01T00:00:00.000Z)\n"; break;
					case "datetime-local":	message += "The value of this field must contain a valid date\/time.\n(2000-01-01T00:00:00)\n"; break;
					case "month":			message += "The value of this field must contain a valid month notation.\n(2000-01)\n"; break;
					case "week":			message += "The value of this field must contain a valid week notation.\n(2000-W01)\n"; break;
					case "time":			message += "The value of this field must contain a time.\n(00:00:00)\n"; break;
					case "number":
					case "range":			message += "The value of this field must contain a valid number.\n"; break;
					case "url":				message += "The value of this field must contain a valid URL.\n(http://www.example.com/)\n"; break;
					case "email":			message += "The value of this field must contain a valid email address.\n(example@example.com)\n"; break;
					case "color":			message += "The value of this field must be a hexadecimal number representing an RGB color.\n(#RRGGBB)\n"; break;
					
					case "text":
					case "search":
					case "password":
					case "select-multiple":
					case "select-one":
					case "textarea":
					case "file":
					case "radio":
					case "checkbox":
					case "submit":
					case "button":
					case "reset":
					case "image":
					default:				throw new Error("How in the world does it not match it's type?");
				}
			}
			
			box.appendTo(document.body).children('DIV').append($.trim(message).replace("\n", "<br>"));
			box.css({
				top: top + $e.height() - (box.height()/2), 
				left:  left
			}).show().flash();
			setTimeout(function(){box.fadeOut(1000, function(){/*box.remove();*/});}, 5000);
		};
			
		$("INPUT, SELECT, BUTTON, TEXTAREA")
			.filter(":autofocus")
			.focus();
		
		$.WebForms20.updater();
	});
	
})(jQuery);

