You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cd...@apache.org on 2008/12/05 21:30:21 UTC

svn commit: r723855 [16/23] - in /hadoop/core/trunk: ./ src/contrib/ src/contrib/chukwa/ src/contrib/chukwa/bin/ src/contrib/chukwa/conf/ src/contrib/chukwa/docs/ src/contrib/chukwa/docs/paper/ src/contrib/chukwa/hadoop-packaging/ src/contrib/chukwa/li...

Added: hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/json.js
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/json.js?rev=723855&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/json.js (added)
+++ hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/json.js Fri Dec  5 12:30:14 2008
@@ -0,0 +1,133 @@
+/*
+Copyright (c) 2002 JSON.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+The Software shall be used for Good, not Evil.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
+
+    json.js
+    2006-10-05
+
+    This file adds these methods to JavaScript:
+
+        object.toJSONString()
+
+            This method produces a JSON text from an object. The
+            object must not contain any cyclical references.
+
+        array.toJSONString()
+
+            This method produces a JSON text from an array. The
+            array must not contain any cyclical references.
+
+        string.parseJSON()
+
+            This method parses a JSON text to produce an object or
+            array. It will return false if there is an error.
+
+    It is expected that these methods will formally become part of the
+    JavaScript Programming Language in the Fourth Edition of the
+    ECMAScript standard.
+*/
+(function () {
+    var m = {
+            '\b': '\\b',
+            '\t': '\\t',
+            '\n': '\\n',
+            '\f': '\\f',
+            '\r': '\\r',
+            '"' : '\\"',
+            '\\': '\\\\'
+        },
+        s = {
+            array: function (x) {
+                var a = ['['], b, f, i, l = x.length, v;
+                for (i = 0; i < l; i += 1) {
+                    v = x[i];
+                    f = s[typeof v];
+                    if (f) {
+                        v = f(v);
+                        if (typeof v == 'string') {
+                            if (b) {
+                                a[a.length] = ',';
+                            }
+                            a[a.length] = v;
+                            b = true;
+                        }
+                    }
+                }
+                a[a.length] = ']';
+                return a.join('');
+            },
+            'boolean': function (x) {
+                return String(x);
+            },
+            'null': function (x) {
+                return "null";
+            },
+            number: function (x) {
+                return isFinite(x) ? String(x) : 'null';
+            },
+            object: function (x) {
+                if (x) {
+                    if (x instanceof Array) {
+                        return s.array(x);
+                    }
+                    var a = ['{'], b, f, i, v;
+                    for (i in x) {
+                        v = x[i];
+                        f = s[typeof v];
+                        if (f) {
+                            v = f(v);
+                            if (typeof v == 'string') {
+                                if (b) {
+                                    a[a.length] = ',';
+                                }
+                                a.push(s.string(i), ':', v);
+                                b = true;
+                            }
+                        }
+                    }
+                    a[a.length] = '}';
+                    return a.join('');
+                }
+                return 'null';
+            },
+            string: function (x) {
+                if (/["\\\x00-\x1f]/.test(x)) {
+                    x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
+                        var c = m[b];
+                        if (c) {
+                            return c;
+                        }
+                        c = b.charCodeAt();
+                        return '\\u00' +
+                            Math.floor(c / 16).toString(16) +
+                            (c % 16).toString(16);
+                    });
+                }
+                return '"' + x + '"';
+            }
+        };
+
+    Object.prototype.toJSONString = function () {
+        return s.object(this);
+    };
+
+    Array.prototype.toJSONString = function () {
+        return s.array(this);
+    };
+})();
+
+String.prototype.parseJSON = function () {
+    try {
+        return (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(this)) &&
+            eval('(' + this + ')');
+    } catch (e) {
+        return false;
+    }
+};

Added: hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/cookies.js
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/cookies.js?rev=723855&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/cookies.js (added)
+++ hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/cookies.js Fri Dec  5 12:30:14 2008
@@ -0,0 +1,34 @@
+/* Copyright (c) 2005 Tim Taylor Consulting (see LICENSE.txt)
+
+based on http://www.quirksmode.org/js/cookies.html
+*/
+
+ToolMan._cookieOven = {
+
+	set : function(name, value, expirationInDays) {
+		if (expirationInDays) {
+			var date = new Date()
+			date.setTime(date.getTime() + (expirationInDays * 24 * 60 * 60 * 1000))
+			var expires = "; expires=" + date.toGMTString()
+		} else {
+			var expires = ""
+		}
+		document.cookie = name + "=" + value + expires + "; path=/"
+	},
+
+	get : function(name) {
+		var namePattern = name + "="
+		var cookies = document.cookie.split(';')
+		for(var i = 0, n = cookies.length; i < n; i++) {
+			var c = cookies[i]
+			while (c.charAt(0) == ' ') c = c.substring(1, c.length)
+			if (c.indexOf(namePattern) == 0)
+				return c.substring(namePattern.length, c.length)
+		}
+		return null
+	},
+
+	eraseCookie : function(name) {
+		createCookie(name, "", -1)
+	}
+}

Added: hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/coordinates.js
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/coordinates.js?rev=723855&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/coordinates.js (added)
+++ hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/coordinates.js Fri Dec  5 12:30:14 2008
@@ -0,0 +1,154 @@
+/* Copyright (c) 2005 Tim Taylor Consulting (see LICENSE.txt) */
+
+/* FIXME: assumes position styles are specified in 'px' */
+
+ToolMan._coordinatesFactory = {
+
+	create : function(x, y) {
+		// FIXME: Safari won't parse 'throw' and aborts trying to do anything with this file
+		//if (isNaN(x) || isNaN(y)) throw "invalid x,y: " + x + "," + y
+		return new _ToolManCoordinate(this, x, y)
+	},
+
+	origin : function() {
+		return this.create(0, 0)
+	},
+
+	/*
+	 * FIXME: Safari 1.2, returns (0,0) on absolutely positioned elements
+	 */
+	topLeftPosition : function(element) {
+		var left = parseInt(ToolMan.css().readStyle(element, "left"))
+		var left = isNaN(left) ? 0 : left
+		var top = parseInt(ToolMan.css().readStyle(element, "top"))
+		var top = isNaN(top) ? 0 : top
+
+		return this.create(left, top)
+	},
+
+	bottomRightPosition : function(element) {
+		return this.topLeftPosition(element).plus(this._size(element))
+	},
+
+	topLeftOffset : function(element) {
+		var offset = this._offset(element) 
+
+		var parent = element.offsetParent
+		while (parent) {
+			offset = offset.plus(this._offset(parent))
+			parent = parent.offsetParent
+		}
+		return offset
+	},
+
+	bottomRightOffset : function(element) {
+		return this.topLeftOffset(element).plus(
+				this.create(element.offsetWidth, element.offsetHeight))
+	},
+
+	scrollOffset : function() {
+		if (window.pageXOffset) {
+			return this.create(window.pageXOffset, window.pageYOffset)
+		} else if (document.documentElement) {
+			return this.create(
+					document.body.scrollLeft + document.documentElement.scrollLeft, 
+					document.body.scrollTop + document.documentElement.scrollTop)
+		} else if (document.body.scrollLeft >= 0) {
+			return this.create(document.body.scrollLeft, document.body.scrollTop)
+		} else {
+			return this.create(0, 0)
+		}
+	},
+
+	clientSize : function() {
+		if (window.innerHeight >= 0) {
+			return this.create(window.innerWidth, window.innerHeight)
+		} else if (document.documentElement) {
+			return this.create(document.documentElement.clientWidth,
+					document.documentElement.clientHeight)
+		} else if (document.body.clientHeight >= 0) {
+			return this.create(document.body.clientWidth,
+					document.body.clientHeight)
+		} else {
+			return this.create(0, 0)
+		}
+	},
+
+	/**
+	 * mouse coordinate relative to the window (technically the
+	 * browser client area) i.e. the part showing your page
+	 *
+	 * NOTE: in Safari the coordinate is relative to the document
+	 */
+	mousePosition : function(event) {
+		event = ToolMan.events().fix(event)
+		return this.create(event.clientX, event.clientY)
+	},
+
+	/**
+	 * mouse coordinate relative to the document
+	 */
+	mouseOffset : function(event) {
+		event = ToolMan.events().fix(event)
+		if (event.pageX >= 0 || event.pageX < 0) {
+			return this.create(event.pageX, event.pageY)
+		} else if (event.clientX >= 0 || event.clientX < 0) {
+			return this.mousePosition(event).plus(this.scrollOffset())
+		}
+	},
+
+	_size : function(element) {
+	/* TODO: move to a Dimension class */
+		return this.create(element.offsetWidth, element.offsetHeight)
+	},
+
+	_offset : function(element) {
+		return this.create(element.offsetLeft, element.offsetTop)
+	}
+}
+
+function _ToolManCoordinate(factory, x, y) {
+	this.factory = factory
+	this.x = isNaN(x) ? 0 : x
+	this.y = isNaN(y) ? 0 : y
+}
+
+_ToolManCoordinate.prototype = {
+	toString : function() {
+		return "(" + this.x + "," + this.y + ")"
+	},
+
+	plus : function(that) {
+		return this.factory.create(this.x + that.x, this.y + that.y)
+	},
+
+	minus : function(that) {
+		return this.factory.create(this.x - that.x, this.y - that.y)
+	},
+
+	min : function(that) {
+		return this.factory.create(
+				Math.min(this.x , that.x), Math.min(this.y , that.y))
+	},
+
+	max : function(that) {
+		return this.factory.create(
+				Math.max(this.x , that.x), Math.max(this.y , that.y))
+	},
+
+	constrainTo : function (one, two) {
+		var min = one.min(two)
+		var max = one.max(two)
+
+		return this.max(min).min(max)
+	},
+
+	distance : function (that) {
+		return Math.sqrt(Math.pow(this.x - that.x, 2) + Math.pow(this.y - that.y, 2))
+	},
+
+	reposition : function(element) {
+		element.style["top"] = this.y + "px"
+		element.style["left"] = this.x + "px"
+	}
+}

Added: hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/core.js
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/core.js?rev=723855&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/core.js (added)
+++ hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/core.js Fri Dec  5 12:30:14 2008
@@ -0,0 +1,170 @@
+/*
+Copyright (c) 2005 Tim Taylor Consulting <http://tool-man.org/>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
+*/
+
+var ToolMan = {
+	events : function() {
+		if (!ToolMan._eventsFactory) throw "ToolMan Events module isn't loaded";
+		return ToolMan._eventsFactory
+	},
+
+	css : function() {
+		if (!ToolMan._cssFactory) throw "ToolMan CSS module isn't loaded";
+		return ToolMan._cssFactory
+	},
+
+	coordinates : function() {
+		if (!ToolMan._coordinatesFactory) throw "ToolMan Coordinates module isn't loaded";
+		return ToolMan._coordinatesFactory
+	},
+
+	drag : function() {
+		if (!ToolMan._dragFactory) throw "ToolMan Drag module isn't loaded";
+		return ToolMan._dragFactory
+	},
+
+	dragsort : function() {
+		if (!ToolMan._dragsortFactory) throw "ToolMan DragSort module isn't loaded";
+		return ToolMan._dragsortFactory
+	},
+
+	helpers : function() {
+		return ToolMan._helpers
+	},
+
+	cookies : function() {
+		if (!ToolMan._cookieOven) throw "ToolMan Cookie module isn't loaded";
+		return ToolMan._cookieOven
+	},
+
+	junkdrawer : function() {
+		return ToolMan._junkdrawer
+	}
+
+}
+
+ToolMan._helpers = {
+	map : function(array, func) {
+		for (var i = 0, n = array.length; i < n; i++) func(array[i])
+	},
+
+	nextItem : function(item, nodeName) {
+		if (item == null) return
+		var next = item.nextSibling
+		while (next != null) {
+			if (next.nodeName == nodeName) return next
+			next = next.nextSibling
+		}
+		return null
+	},
+
+	previousItem : function(item, nodeName) {
+		var previous = item.previousSibling
+		while (previous != null) {
+			if (previous.nodeName == nodeName) return previous
+			previous = previous.previousSibling
+		}
+		return null
+	},
+
+	moveBefore : function(item1, item2) {
+		var parent = item1.parentNode
+		parent.removeChild(item1)
+		parent.insertBefore(item1, item2)
+	},
+
+	moveAfter : function(item1, item2) {
+		var parent = item1.parentNode
+		parent.removeChild(item1)
+		parent.insertBefore(item1, item2 ? item2.nextSibling : null)
+	}
+}
+
+/** 
+ * scripts without a proper home
+ *
+ * stuff here is subject to change unapologetically and without warning
+ */
+ToolMan._junkdrawer = {
+	serializeList : function(list) {
+		var items = list.getElementsByTagName("li")
+		var array = new Array()
+		for (var i = 0, n = items.length; i < n; i++) {
+			var item = items[i]
+
+			array.push(ToolMan.junkdrawer()._identifier(item))
+		}
+		return array.join('|')
+	},
+
+	inspectListOrder : function(id) {
+		alert(ToolMan.junkdrawer().serializeList(document.getElementById(id)))
+	},
+
+	restoreListOrder : function(listID) {
+		var list = document.getElementById(listID)
+		if (list == null) return
+
+		var cookie = ToolMan.cookies().get("list-" + listID)
+		if (!cookie) return;
+
+		var IDs = cookie.split('|')
+		var items = ToolMan.junkdrawer()._itemsByID(list)
+
+		for (var i = 0, n = IDs.length; i < n; i++) {
+			var itemID = IDs[i]
+			if (itemID in items) {
+				var item = items[itemID]
+				list.removeChild(item)
+				list.insertBefore(item, null)
+			}
+		}
+	},
+
+	_identifier : function(item) {
+		var trim = ToolMan.junkdrawer().trim
+		var identifier
+
+		identifier = trim(item.getAttribute("id"))
+		if (identifier != null && identifier.length > 0) return identifier;
+		
+		identifier = trim(item.getAttribute("itemID"))
+		if (identifier != null && identifier.length > 0) return identifier;
+		
+		// FIXME: strip out special chars or make this an MD5 hash or something
+		return trim(item.innerHTML)
+	},
+
+	_itemsByID : function(list) {
+		var array = new Array()
+		var items = list.getElementsByTagName('li')
+		for (var i = 0, n = items.length; i < n; i++) {
+			var item = items[i]
+			array[ToolMan.junkdrawer()._identifier(item)] = item
+		}
+		return array
+	},
+
+	trim : function(text) {
+		if (text == null) return null
+		return text.replace(/^(\s+)?(.*\S)(\s+)?$/, '$2')
+	}
+}

Added: hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/core.js.old
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/core.js.old?rev=723855&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/core.js.old (added)
+++ hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/core.js.old Fri Dec  5 12:30:14 2008
@@ -0,0 +1,797 @@
+/*
+Copyright (c) 2005 Tim Taylor Consulting <http://tool-man.org/>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
+*/
+
+var ToolMan = {
+	events : function() {
+		if (!ToolMan._eventsFactory) throw "ToolMan Events module isn't loaded";
+		return ToolMan._eventsFactory
+	},
+
+	css : function() {
+		if (!ToolMan._cssFactory) throw "ToolMan CSS module isn't loaded";
+		return ToolMan._cssFactory
+	},
+
+	coordinates : function() {
+		if (!ToolMan._coordinatesFactory) throw "ToolMan Coordinates module isn't loaded";
+		return ToolMan._coordinatesFactory
+	},
+
+	drag : function() {
+		if (!ToolMan._dragFactory) throw "ToolMan Drag module isn't loaded";
+		return ToolMan._dragFactory
+	},
+
+	dragsort : function() {
+		if (!ToolMan._dragsortFactory) throw "ToolMan DragSort module isn't loaded";
+		return ToolMan._dragsortFactory
+	},
+
+	helpers : function() {
+		return ToolMan._helpers
+	},
+
+	cookies : function() {
+		if (!ToolMan._cookieOven) throw "ToolMan Cookie module isn't loaded";
+		return ToolMan._cookieOven
+	},
+
+	junkdrawer : function() {
+		return ToolMan._junkdrawer
+	}
+
+}
+
+ToolMan._helpers = {
+	map : function(array, func) {
+		for (var i = 0, n = array.length; i < n; i++) func(array[i])
+	},
+
+	nextItem : function(item, nodeName) {
+		if (item == null) return
+		var next = item.nextSibling
+		while (next != null) {
+			if (next.nodeName == nodeName) return next
+			next = next.nextSibling
+		}
+		return null
+	},
+
+	previousItem : function(item, nodeName) {
+		var previous = item.previousSibling
+		while (previous != null) {
+			if (previous.nodeName == nodeName) return previous
+			previous = previous.previousSibling
+		}
+		return null
+	},
+
+	moveBefore : function(item1, item2) {
+		var parent = item1.parentNode
+		parent.removeChild(item1)
+		parent.insertBefore(item1, item2)
+	},
+
+	moveAfter : function(item1, item2) {
+		var parent = item1.parentNode
+		parent.removeChild(item1)
+		parent.insertBefore(item1, item2 ? item2.nextSibling : null)
+	}
+}
+
+/** 
+ * scripts without a proper home
+ *
+ * stuff here is subject to change unapologetically and without warning
+ */
+ToolMan._junkdrawer = {
+	serializeList : function(list) {
+		var items = list.getElementsByTagName("tr")
+                var newitems=new Array();
+		for (var i = 0, n = items.length; i < n; i++) {
+			var item = items[i]
+			var att=item.getAttribute("id");
+                        if ((att != null) && (att.indexOf("tablerow")==0)) {
+				newitems.push(item);
+                        }
+                }
+		items=newitems;
+		var array = new Array()
+		for (var i = 0, n = items.length; i < n; i++) {
+			var item = items[i]
+
+			array.push(ToolMan.junkdrawer()._identifier(item))
+		}
+		return array.join('|')
+	},
+
+	inspectListOrder : function(id) {
+		alert(ToolMan.junkdrawer().serializeList(document.getElementById(id)))
+	},
+
+	restoreListOrder : function(listID) {
+		var list = document.getElementById(listID)
+		if (list == null) return
+
+		var cookie = ToolMan.cookies().get("list-" + listID)
+		if (!cookie) return;
+
+		var IDs = cookie.split('|')
+		var items = ToolMan.junkdrawer()._itemsByID(list)
+
+		for (var i = 0, n = IDs.length; i < n; i++) {
+			var itemID = IDs[i]
+			if (itemID in items) {
+				var item = items[itemID]
+				list.removeChild(item)
+				list.insertBefore(item, null)
+			}
+		}
+	},
+
+	_identifier : function(item) {
+		var trim = ToolMan.junkdrawer().trim
+		var identifier
+
+		identifier = trim(item.getAttribute("id"))
+		if (identifier != null && identifier.length > 0) return identifier;
+		
+		identifier = trim(item.getAttribute("itemID"))
+		if (identifier != null && identifier.length > 0) return identifier;
+		
+		// FIXME: strip out special chars or make this an MD5 hash or something
+		return trim(item.innerHTML)
+	},
+
+	_itemsByID : function(list) {
+		var array = new Array()
+		var items = list.getElementsByTagName('li')
+		for (var i = 0, n = items.length; i < n; i++) {
+			var item = items[i]
+			array[ToolMan.junkdrawer()._identifier(item)] = item
+		}
+		return array
+	},
+
+	trim : function(text) {
+		if (text == null) return null
+		return text.replace(/^(\s+)?(.*\S)(\s+)?$/, '$2')
+	}
+}
+
+/* Copyright (c) 2005 Tim Taylor Consulting (see LICENSE.txt) */
+
+ToolMan._eventsFactory = {
+	fix : function(event) {
+		if (!event) event = window.event
+
+		if (event.target) {
+			if (event.target.nodeType == 3) event.target = event.target.parentNode
+		} else if (event.srcElement) {
+			event.target = event.srcElement
+		}
+
+		return event
+	},
+
+	register : function(element, type, func) {
+		if (element.addEventListener) {
+			element.addEventListener(type, func, false)
+		} else if (element.attachEvent) {
+			if (!element._listeners) element._listeners = new Array()
+			if (!element._listeners[type]) element._listeners[type] = new Array()
+			var workaroundFunc = function() {
+				func.apply(element, new Array())
+			}
+			element._listeners[type][func] = workaroundFunc
+			element.attachEvent('on' + type, workaroundFunc)
+		}
+	},
+
+	unregister : function(element, type, func) {
+		if (element.removeEventListener) {
+			element.removeEventListener(type, func, false)
+		} else if (element.detachEvent) {
+			if (element._listeners 
+					&& element._listeners[type] 
+					&& element._listeners[type][func]) {
+
+				element.detachEvent('on' + type, 
+						element._listeners[type][func])
+			}
+		}
+	}
+}
+
+/* Copyright (c) 2005 Tim Taylor Consulting (see LICENSE.txt) */
+
+// TODO: write unit tests
+ToolMan._cssFactory = {
+	readStyle : function(element, property) {
+		if (element.style[property]) {
+			return element.style[property]
+		} else if (element.currentStyle) {
+			return element.currentStyle[property]
+		} else if (document.defaultView && document.defaultView.getComputedStyle) {
+			var style = document.defaultView.getComputedStyle(element, null)
+			return style.getPropertyValue(property)
+		} else {
+			return null
+		}
+	}
+}
+
+
+/* Copyright (c) 2005 Tim Taylor Consulting (see LICENSE.txt) */
+
+/* FIXME: assumes position styles are specified in 'px' */
+
+ToolMan._coordinatesFactory = {
+
+	create : function(x, y) {
+		// FIXME: Safari won't parse 'throw' and aborts trying to do anything with this file
+		//if (isNaN(x) || isNaN(y)) throw "invalid x,y: " + x + "," + y
+		return new _ToolManCoordinate(this, x, y)
+	},
+
+	origin : function() {
+		return this.create(0, 0)
+	},
+
+	/*
+	 * FIXME: Safari 1.2, returns (0,0) on absolutely positioned elements
+	 */
+	topLeftPosition : function(element) {
+		var left = parseInt(ToolMan.css().readStyle(element, "left"))
+		var left = isNaN(left) ? 0 : left
+		var top = parseInt(ToolMan.css().readStyle(element, "top"))
+		var top = isNaN(top) ? 0 : top
+
+		return this.create(left, top)
+	},
+
+	bottomRightPosition : function(element) {
+		return this.topLeftPosition(element).plus(this._size(element))
+	},
+
+	topLeftOffset : function(element) {
+		var offset = this._offset(element) 
+
+		var parent = element.offsetParent
+		while (parent) {
+			offset = offset.plus(this._offset(parent))
+			parent = parent.offsetParent
+		}
+		return offset
+	},
+
+	bottomRightOffset : function(element) {
+		return this.topLeftOffset(element).plus(
+				this.create(element.offsetWidth, element.offsetHeight))
+	},
+
+	scrollOffset : function() {
+		if (window.pageXOffset) {
+			return this.create(window.pageXOffset, window.pageYOffset)
+		} else if (document.documentElement) {
+			return this.create(
+					document.body.scrollLeft + document.documentElement.scrollLeft, 
+					document.body.scrollTop + document.documentElement.scrollTop)
+		} else if (document.body.scrollLeft >= 0) {
+			return this.create(document.body.scrollLeft, document.body.scrollTop)
+		} else {
+			return this.create(0, 0)
+		}
+	},
+
+	clientSize : function() {
+		if (window.innerHeight >= 0) {
+			return this.create(window.innerWidth, window.innerHeight)
+		} else if (document.documentElement) {
+			return this.create(document.documentElement.clientWidth,
+					document.documentElement.clientHeight)
+		} else if (document.body.clientHeight >= 0) {
+			return this.create(document.body.clientWidth,
+					document.body.clientHeight)
+		} else {
+			return this.create(0, 0)
+		}
+	},
+
+	/**
+	 * mouse coordinate relative to the window (technically the
+	 * browser client area) i.e. the part showing your page
+	 *
+	 * NOTE: in Safari the coordinate is relative to the document
+	 */
+	mousePosition : function(event) {
+		event = ToolMan.events().fix(event)
+		return this.create(event.clientX, event.clientY)
+	},
+
+	/**
+	 * mouse coordinate relative to the document
+	 */
+	mouseOffset : function(event) {
+		event = ToolMan.events().fix(event)
+		if (event.pageX >= 0 || event.pageX < 0) {
+			return this.create(event.pageX, event.pageY)
+		} else if (event.clientX >= 0 || event.clientX < 0) {
+			return this.mousePosition(event).plus(this.scrollOffset())
+		}
+	},
+
+	_size : function(element) {
+	/* TODO: move to a Dimension class */
+		return this.create(element.offsetWidth, element.offsetHeight)
+	},
+
+	_offset : function(element) {
+		return this.create(element.offsetLeft, element.offsetTop)
+	}
+}
+
+function _ToolManCoordinate(factory, x, y) {
+	this.factory = factory
+	this.x = isNaN(x) ? 0 : x
+	this.y = isNaN(y) ? 0 : y
+}
+
+_ToolManCoordinate.prototype = {
+	toString : function() {
+		return "(" + this.x + "," + this.y + ")"
+	},
+
+	plus : function(that) {
+		return this.factory.create(this.x + that.x, this.y + that.y)
+	},
+
+	minus : function(that) {
+		return this.factory.create(this.x - that.x, this.y - that.y)
+	},
+
+	min : function(that) {
+		return this.factory.create(
+				Math.min(this.x , that.x), Math.min(this.y , that.y))
+	},
+
+	max : function(that) {
+		return this.factory.create(
+				Math.max(this.x , that.x), Math.max(this.y , that.y))
+	},
+
+	constrainTo : function (one, two) {
+		var min = one.min(two)
+		var max = one.max(two)
+
+		return this.max(min).min(max)
+	},
+
+	distance : function (that) {
+		return Math.sqrt(Math.pow(this.x - that.x, 2) + Math.pow(this.y - that.y, 2))
+	},
+
+	reposition : function(element) {
+		element.style["top"] = this.y + "px"
+		element.style["left"] = this.x + "px"
+	}
+}
+
+
+/* Copyright (c) 2005 Tim Taylor Consulting (see LICENSE.txt) */
+
+ToolMan._dragFactory = {
+	createSimpleGroup : function(element, handle) {
+		handle = handle ? handle : element
+		var group = this.createGroup(element)
+		group.setHandle(handle)
+		group.transparentDrag()
+		group.onTopWhileDragging()
+		return group
+	},
+
+	createGroup : function(element) {
+		var group = new _ToolManDragGroup(this, element)
+
+		var position = ToolMan.css().readStyle(element, 'position')
+		if (position == 'static') {
+ var agt=navigator.userAgent.toLowerCase();
+var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
+if (!is_ie) {
+			element.style["position"] = 'relative'
+}
+		} else if (position == 'absolute') {
+			/* for Safari 1.2 */
+			ToolMan.coordinates().topLeftOffset(element).reposition(element)
+		}
+
+		// TODO: only if ToolMan.isDebugging()
+		group.register('draginit', this._showDragEventStatus)
+		group.register('dragmove', this._showDragEventStatus)
+		group.register('dragend', this._showDragEventStatus)
+
+		return group
+	},
+
+	_showDragEventStatus : function(dragEvent) {
+		// window.status = dragEvent.toString()
+	},
+
+	constraints : function() {
+		return this._constraintFactory
+	},
+
+	_createEvent : function(type, event, group) {
+		return new _ToolManDragEvent(type, event, group)
+	}
+}
+
+function _ToolManDragGroup(factory, element) {
+	this.factory = factory
+	this.element = element
+	this._handle = null
+	this._thresholdDistance = 0
+        this._dragging=false
+	this._transforms = new Array()
+	// TODO: refactor into a helper object, move into events.js
+	this._listeners = new Array()
+	this._listeners['draginit'] = new Array()
+	this._listeners['dragstart'] = new Array()
+	this._listeners['dragmove'] = new Array()
+	this._listeners['dragend'] = new Array()
+}
+
+_ToolManDragGroup.prototype = {
+	/*
+	 * TODO:
+	 *   - unregister(type, func)
+	 *   - move custom event listener stuff into Event library
+	 *   - keyboard nudging of "selected" group
+	 */
+
+	setHandle : function(handle) {
+		var events = ToolMan.events()
+
+		handle.toolManDragGroup = this
+		events.register(handle, 'mousedown', this._dragInit)
+		handle.onmousedown = function() { return false }
+
+		if (this.element != handle)
+			events.unregister(this.element, 'mousedown', this._dragInit)
+	},
+
+	register : function(type, func) {
+		this._listeners[type].push(func)
+	},
+
+	addTransform : function(transformFunc) {
+		this._transforms.push(transformFunc)
+	},
+
+	verticalOnly : function() {
+		this.addTransform(this.factory.constraints().vertical())
+	},
+
+	horizontalOnly : function() {
+		this.addTransform(this.factory.constraints().horizontal())
+	},
+
+	setThreshold : function(thresholdDistance) {
+		this._thresholdDistance = thresholdDistance
+	},
+
+	transparentDrag : function(opacity) {
+ var agt=navigator.userAgent.toLowerCase();
+var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
+if (!is_ie) {
+		var opacity = typeof(opacity) != "undefined" ? opacity : 0.75;
+		var originalOpacity = ToolMan.css().readStyle(this.element, "opacity")
+
+		this.register('dragstart', function(dragEvent) {
+			var element = dragEvent.group.element
+			element.style.width = '100%'
+			element.style.height = '100%'
+			element.style.opacity = opacity
+			element.style.filter = 'alpha(opacity=' + (opacity * 100) + ')'
+		})
+		this.register('dragend', function(dragEvent) {
+			var element = dragEvent.group.element
+			element.style.opacity = originalOpacity
+			element.style.filter = 'alpha(opacity=100)'
+		})
+}
+	},
+
+	onTopWhileDragging : function(zIndex) {
+		var zIndex = typeof(zIndex) != "undefined" ? zIndex : 100000;
+		var originalZIndex = ToolMan.css().readStyle(this.element, "z-index")
+
+		this.register('dragstart', function(dragEvent) {
+			dragEvent.group.element.style.zIndex = zIndex
+		})
+		this.register('dragend', function(dragEvent) {
+			dragEvent.group.element.style.zIndex = originalZIndex
+		})
+	},
+
+	_dragInit : function(event) {
+		event = ToolMan.events().fix(event)
+		var group = document.toolManDragGroup = this.toolManDragGroup
+		var dragEvent = group.factory._createEvent('draginit', event, group)
+	
+		group._dragging=true
+		group._isThresholdExceeded = false
+		group._initialMouseOffset = dragEvent.mouseOffset
+		group._grabOffset = dragEvent.mouseOffset.minus(dragEvent.topLeftOffset)
+		ToolMan.events().register(document, 'mousemove', group._drag)
+		document.onmousemove = function() { return false }
+		ToolMan.events().register(document, 'mouseup', group._dragEnd)
+
+		group._notifyListeners(dragEvent)
+	},
+
+	_drag : function(event) {
+		event = ToolMan.events().fix(event)
+		var coordinates = ToolMan.coordinates()
+		var group = this.toolManDragGroup
+		if (!group) return
+		if (!group._dragging) return
+		var dragEvent = group.factory._createEvent('dragmove', event, group)
+
+		var newTopLeftOffset = dragEvent.mouseOffset.minus(group._grabOffset)
+
+		// TODO: replace with DragThreshold object
+		if (!group._isThresholdExceeded) {
+			var distance = 
+					dragEvent.mouseOffset.distance(group._initialMouseOffset)
+			if (distance < group._thresholdDistance) return
+			group._isThresholdExceeded = true
+			group._notifyListeners(
+					group.factory._createEvent('dragstart', event, group))
+		}
+
+		for (i in group._transforms) {
+			var transform = group._transforms[i]
+			newTopLeftOffset = transform(newTopLeftOffset, dragEvent)
+		}
+
+		var dragDelta = newTopLeftOffset.minus(dragEvent.topLeftOffset)
+		var newTopLeftPosition = dragEvent.topLeftPosition.plus(dragDelta)
+		newTopLeftPosition.reposition(group.element)
+		dragEvent.transformedMouseOffset = newTopLeftOffset.plus(group._grabOffset)
+
+		group._notifyListeners(dragEvent)
+
+		var errorDelta = newTopLeftOffset.minus(coordinates.topLeftOffset(group.element))
+		if (errorDelta.x != 0 || errorDelta.y != 0) {
+			coordinates.topLeftPosition(group.element).plus(errorDelta).reposition(group.element)
+		}
+	},
+
+	_dragEnd : function(event) {
+		event = ToolMan.events().fix(event)
+		var group = this.toolManDragGroup
+		var dragEvent;
+                if (group != null) {
+		group._dragging=false
+                if (group.factory != null) {
+                     dragEvent = group.factory._createEvent('dragend', event, group)
+                 } else {
+			dragEvent=new _ToolManDragEvent('dragend', event, group)
+                 }
+
+		group._notifyListeners(dragEvent)
+
+		this.toolManDragGroup = null
+		ToolMan.events().unregister(document, 'mousemove', group._drag)
+		document.onmousemove = null
+		ToolMan.events().unregister(document, 'mouseup', group._dragEnd)
+		}
+	},
+
+	_notifyListeners : function(dragEvent) {
+		var listeners = this._listeners[dragEvent.type]
+		for (i in listeners) {
+			listeners[i](dragEvent)
+		}
+	}
+}
+
+function _ToolManDragEvent(type, event, group) {
+	this.type = type
+	this.group = group
+	this.mousePosition = ToolMan.coordinates().mousePosition(event)
+	this.mouseOffset = ToolMan.coordinates().mouseOffset(event)
+	this.transformedMouseOffset = this.mouseOffset
+	this.topLeftPosition = ToolMan.coordinates().topLeftPosition(group.element)
+	this.topLeftOffset = ToolMan.coordinates().topLeftOffset(group.element)
+}
+
+_ToolManDragEvent.prototype = {
+	toString : function() {
+		return "mouse: " + this.mousePosition + this.mouseOffset + "    " +
+				"xmouse: " + this.transformedMouseOffset + "    " +
+				"left,top: " + this.topLeftPosition + this.topLeftOffset
+	}
+}
+
+ToolMan._dragFactory._constraintFactory = {
+	vertical : function() {
+		return function(coordinate, dragEvent) {
+			var x = dragEvent.topLeftOffset.x
+			return coordinate.x != x
+					? coordinate.factory.create(x, coordinate.y) 
+					: coordinate
+		}
+	},
+
+	horizontal : function() {
+		return function(coordinate, dragEvent) {
+			var y = dragEvent.topLeftOffset.y
+			return coordinate.y != y
+					? coordinate.factory.create(coordinate.x, y) 
+					: coordinate
+		}
+	}
+}
+
+
+/* Copyright (c) 2005 Tim Taylor Consulting (see LICENSE.txt) */
+
+ToolMan._dragsortFactory = {
+	makeSortable : function(item) {
+		var group = ToolMan.drag().createSimpleGroup(item)
+
+		group.register('dragstart', this._onDragStart)
+		group.register('dragmove', this._onDragMove)
+		group.register('dragend', this._onDragEnd)
+
+		return group
+	},
+
+	/** 
+	 * Iterates over a list's items, making them sortable, applying
+	 * optional functions to each item.
+	 *
+	 * example: makeListSortable(myList, myFunc1, myFunc2, ... , myFuncN)
+	 */
+	makeListSortable : function(list) {
+		var helpers = ToolMan.helpers()
+		var coordinates = ToolMan.coordinates()
+		var items = list.getElementsByTagName("tr")
+                var newitems=new Array();
+		for (var i = 0, n = items.length; i < n; i++) {
+			var item = items[i]
+			var att=item.getAttribute("id");
+                        if ((att != null) && (att.indexOf("tablerow")==0)) {
+				newitems.push(item);
+                        }
+                }
+		items=newitems;
+
+		helpers.map(items, function(item) {
+			var dragGroup = dragsort.makeSortable(item)
+			dragGroup.setThreshold(4)
+			var min, max
+			dragGroup.addTransform(function(coordinate, dragEvent) {
+				return coordinate.constrainTo(min, max)
+			})
+			dragGroup.register('dragstart', function() {
+				var items = list.getElementsByTagName("tr")
+                var newitems=new Array();
+		for (var i = 0, n = items.length; i < n; i++) {
+			var item = items[i]
+			var att=item.getAttribute("id");
+                        if ((att != null) && (att.indexOf("tablerow")==0)) {
+				newitems.push(item);
+                        }
+                }
+		items=newitems;
+				min = max = coordinates.topLeftOffset(items[0])
+				for (var i = 1, n = items.length; i < n; i++) {
+					var offset = coordinates.topLeftOffset(items[i])
+					min = min.min(offset)
+					max = max.max(offset)
+				}
+			})
+		})
+		for (var i = 1, n = arguments.length; i < n; i++)
+			helpers.map(items, arguments[i])
+	},
+
+	_onDragStart : function(dragEvent) {
+	},
+
+	_onDragMove : function(dragEvent) {
+		var helpers = ToolMan.helpers()
+		var coordinates = ToolMan.coordinates()
+
+		var item = dragEvent.group.element
+		var xmouse = dragEvent.transformedMouseOffset
+		var moveTo = null
+
+		var previous = helpers.previousItem(item, item.nodeName)
+		while (previous != null) {
+			var bottomRight = coordinates.bottomRightOffset(previous)
+			if (xmouse.y <= bottomRight.y && xmouse.x <= bottomRight.x) {
+				moveTo = previous
+			}
+			previous = helpers.previousItem(previous, item.nodeName)
+		}
+		if (moveTo != null) {
+			helpers.moveBefore(item, moveTo)
+			return
+		}
+
+		var next = helpers.nextItem(item, item.nodeName)
+		while (next != null) {
+			var topLeft = coordinates.topLeftOffset(next)
+			if (topLeft.y <= xmouse.y && topLeft.x <= xmouse.x) {
+				moveTo = next
+			}
+			next = helpers.nextItem(next, item.nodeName)
+		}
+		if (moveTo != null) {
+			helpers.moveBefore(item, helpers.nextItem(moveTo, item.nodeName))
+			return
+		}
+	},
+
+	_onDragEnd : function(dragEvent) {
+		ToolMan.coordinates().create(0, 0).reposition(dragEvent.group.element)
+	}
+}
+
+/* Copyright (c) 2005 Tim Taylor Consulting (see LICENSE.txt)
+
+based on http://www.quirksmode.org/js/cookies.html
+*/
+
+ToolMan._cookieOven = {
+
+	set : function(name, value, expirationInDays) {
+		if (expirationInDays) {
+			var date = new Date()
+			date.setTime(date.getTime() + (expirationInDays * 24 * 60 * 60 * 1000))
+			var expires = "; expires=" + date.toGMTString()
+		} else {
+			var expires = ""
+		}
+		document.cookie = name + "=" + value + expires + "; path=/"
+	},
+
+	get : function(name) {
+		var namePattern = name + "="
+		var cookies = document.cookie.split(';')
+		for(var i = 0, n = cookies.length; i < n; i++) {
+			var c = cookies[i]
+			while (c.charAt(0) == ' ') c = c.substring(1, c.length)
+			if (c.indexOf(namePattern) == 0)
+				return c.substring(namePattern.length, c.length)
+		}
+		return null
+	},
+
+	eraseCookie : function(name) {
+		createCookie(name, "", -1)
+	}
+}

Added: hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/css.js
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/css.js?rev=723855&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/css.js (added)
+++ hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/css.js Fri Dec  5 12:30:14 2008
@@ -0,0 +1,17 @@
+/* Copyright (c) 2005 Tim Taylor Consulting (see LICENSE.txt) */
+
+// TODO: write unit tests
+ToolMan._cssFactory = {
+	readStyle : function(element, property) {
+		if (element.style[property]) {
+			return element.style[property]
+		} else if (element.currentStyle) {
+			return element.currentStyle[property]
+		} else if (document.defaultView && document.defaultView.getComputedStyle) {
+			var style = document.defaultView.getComputedStyle(element, null)
+			return style.getPropertyValue(property)
+		} else {
+			return null
+		}
+	}
+}

Added: hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/drag.js
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/drag.js?rev=723855&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/drag.js (added)
+++ hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/drag.js Fri Dec  5 12:30:14 2008
@@ -0,0 +1,235 @@
+/* Copyright (c) 2005 Tim Taylor Consulting (see LICENSE.txt) */
+
+ToolMan._dragFactory = {
+	createSimpleGroup : function(element, handle) {
+		handle = handle ? handle : element
+		var group = this.createGroup(element)
+		group.setHandle(handle)
+		group.transparentDrag()
+		group.onTopWhileDragging()
+		return group
+	},
+
+	createGroup : function(element) {
+		var group = new _ToolManDragGroup(this, element)
+
+		var position = ToolMan.css().readStyle(element, 'position')
+		if (position == 'static') {
+			element.style["position"] = 'relative'
+		} else if (position == 'absolute') {
+			/* for Safari 1.2 */
+			ToolMan.coordinates().topLeftOffset(element).reposition(element)
+		}
+
+		// TODO: only if ToolMan.isDebugging()
+		group.register('draginit', this._showDragEventStatus)
+		group.register('dragmove', this._showDragEventStatus)
+		group.register('dragend', this._showDragEventStatus)
+
+		return group
+	},
+
+	_showDragEventStatus : function(dragEvent) {
+		window.status = dragEvent.toString()
+	},
+
+	constraints : function() {
+		return this._constraintFactory
+	},
+
+	_createEvent : function(type, event, group) {
+		return new _ToolManDragEvent(type, event, group)
+	}
+}
+
+function _ToolManDragGroup(factory, element) {
+	this.factory = factory
+	this.element = element
+	this._handle = null
+	this._thresholdDistance = 0
+	this._transforms = new Array()
+	// TODO: refactor into a helper object, move into events.js
+	this._listeners = new Array()
+	this._listeners['draginit'] = new Array()
+	this._listeners['dragstart'] = new Array()
+	this._listeners['dragmove'] = new Array()
+	this._listeners['dragend'] = new Array()
+}
+
+_ToolManDragGroup.prototype = {
+	/*
+	 * TODO:
+	 *   - unregister(type, func)
+	 *   - move custom event listener stuff into Event library
+	 *   - keyboard nudging of "selected" group
+	 */
+
+	setHandle : function(handle) {
+		var events = ToolMan.events()
+
+		handle.toolManDragGroup = this
+		events.register(handle, 'mousedown', this._dragInit)
+		handle.onmousedown = function() { return false }
+
+		if (this.element != handle)
+			events.unregister(this.element, 'mousedown', this._dragInit)
+	},
+
+	register : function(type, func) {
+		this._listeners[type].push(func)
+	},
+
+	addTransform : function(transformFunc) {
+		this._transforms.push(transformFunc)
+	},
+
+	verticalOnly : function() {
+		this.addTransform(this.factory.constraints().vertical())
+	},
+
+	horizontalOnly : function() {
+		this.addTransform(this.factory.constraints().horizontal())
+	},
+
+	setThreshold : function(thresholdDistance) {
+		this._thresholdDistance = thresholdDistance
+	},
+
+	transparentDrag : function(opacity) {
+		var opacity = typeof(opacity) != "undefined" ? opacity : 0.75;
+		var originalOpacity = ToolMan.css().readStyle(this.element, "opacity")
+
+		this.register('dragstart', function(dragEvent) {
+			var element = dragEvent.group.element
+			element.style.opacity = opacity
+			element.style.filter = 'alpha(opacity=' + (opacity * 100) + ')'
+		})
+		this.register('dragend', function(dragEvent) {
+			var element = dragEvent.group.element
+			element.style.opacity = originalOpacity
+			element.style.filter = 'alpha(opacity=100)'
+		})
+	},
+
+	onTopWhileDragging : function(zIndex) {
+		var zIndex = typeof(zIndex) != "undefined" ? zIndex : 100000;
+		var originalZIndex = ToolMan.css().readStyle(this.element, "z-index")
+
+		this.register('dragstart', function(dragEvent) {
+			dragEvent.group.element.style.zIndex = zIndex
+		})
+		this.register('dragend', function(dragEvent) {
+			dragEvent.group.element.style.zIndex = originalZIndex
+		})
+	},
+
+	_dragInit : function(event) {
+		event = ToolMan.events().fix(event)
+		var group = document.toolManDragGroup = this.toolManDragGroup
+		var dragEvent = group.factory._createEvent('draginit', event, group)
+
+		group._isThresholdExceeded = false
+		group._initialMouseOffset = dragEvent.mouseOffset
+		group._grabOffset = dragEvent.mouseOffset.minus(dragEvent.topLeftOffset)
+		ToolMan.events().register(document, 'mousemove', group._drag)
+		document.onmousemove = function() { return false }
+		ToolMan.events().register(document, 'mouseup', group._dragEnd)
+
+		group._notifyListeners(dragEvent)
+	},
+
+	_drag : function(event) {
+		event = ToolMan.events().fix(event)
+		var coordinates = ToolMan.coordinates()
+		var group = this.toolManDragGroup
+		if (!group) return
+		var dragEvent = group.factory._createEvent('dragmove', event, group)
+
+		var newTopLeftOffset = dragEvent.mouseOffset.minus(group._grabOffset)
+
+		// TODO: replace with DragThreshold object
+		if (!group._isThresholdExceeded) {
+			var distance = 
+					dragEvent.mouseOffset.distance(group._initialMouseOffset)
+			if (distance < group._thresholdDistance) return
+			group._isThresholdExceeded = true
+			group._notifyListeners(
+					group.factory._createEvent('dragstart', event, group))
+		}
+
+		for (i in group._transforms) {
+			var transform = group._transforms[i]
+			newTopLeftOffset = transform(newTopLeftOffset, dragEvent)
+		}
+
+		var dragDelta = newTopLeftOffset.minus(dragEvent.topLeftOffset)
+		var newTopLeftPosition = dragEvent.topLeftPosition.plus(dragDelta)
+		newTopLeftPosition.reposition(group.element)
+		dragEvent.transformedMouseOffset = newTopLeftOffset.plus(group._grabOffset)
+
+		group._notifyListeners(dragEvent)
+
+		var errorDelta = newTopLeftOffset.minus(coordinates.topLeftOffset(group.element))
+		if (errorDelta.x != 0 || errorDelta.y != 0) {
+			coordinates.topLeftPosition(group.element).plus(errorDelta).reposition(group.element)
+		}
+	},
+
+	_dragEnd : function(event) {
+		event = ToolMan.events().fix(event)
+		var group = this.toolManDragGroup
+		var dragEvent = group.factory._createEvent('dragend', event, group)
+
+		group._notifyListeners(dragEvent)
+
+		this.toolManDragGroup = null
+		ToolMan.events().unregister(document, 'mousemove', group._drag)
+		document.onmousemove = null
+		ToolMan.events().unregister(document, 'mouseup', group._dragEnd)
+	},
+
+	_notifyListeners : function(dragEvent) {
+		var listeners = this._listeners[dragEvent.type]
+		for (i in listeners) {
+			listeners[i](dragEvent)
+		}
+	}
+}
+
+function _ToolManDragEvent(type, event, group) {
+	this.type = type
+	this.group = group
+	this.mousePosition = ToolMan.coordinates().mousePosition(event)
+	this.mouseOffset = ToolMan.coordinates().mouseOffset(event)
+	this.transformedMouseOffset = this.mouseOffset
+	this.topLeftPosition = ToolMan.coordinates().topLeftPosition(group.element)
+	this.topLeftOffset = ToolMan.coordinates().topLeftOffset(group.element)
+}
+
+_ToolManDragEvent.prototype = {
+	toString : function() {
+		return "mouse: " + this.mousePosition + this.mouseOffset + "    " +
+				"xmouse: " + this.transformedMouseOffset + "    " +
+				"left,top: " + this.topLeftPosition + this.topLeftOffset
+	}
+}
+
+ToolMan._dragFactory._constraintFactory = {
+	vertical : function() {
+		return function(coordinate, dragEvent) {
+			var x = dragEvent.topLeftOffset.x
+			return coordinate.x != x
+					? coordinate.factory.create(x, coordinate.y) 
+					: coordinate
+		}
+	},
+
+	horizontal : function() {
+		return function(coordinate, dragEvent) {
+			var y = dragEvent.topLeftOffset.y
+			return coordinate.y != y
+					? coordinate.factory.create(coordinate.x, y) 
+					: coordinate
+		}
+	}
+}

Added: hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/dragsort.js
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/dragsort.js?rev=723855&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/dragsort.js (added)
+++ hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/dragsort.js Fri Dec  5 12:30:14 2008
@@ -0,0 +1,87 @@
+/* Copyright (c) 2005 Tim Taylor Consulting (see LICENSE.txt) */
+
+ToolMan._dragsortFactory = {
+	makeSortable : function(item) {
+		var group = ToolMan.drag().createSimpleGroup(item)
+
+		group.register('dragstart', this._onDragStart)
+		group.register('dragmove', this._onDragMove)
+		group.register('dragend', this._onDragEnd)
+
+		return group
+	},
+
+	/** 
+	 * Iterates over a list's items, making them sortable, applying
+	 * optional functions to each item.
+	 *
+	 * example: makeListSortable(myList, myFunc1, myFunc2, ... , myFuncN)
+	 */
+	makeListSortable : function(list) {
+		var helpers = ToolMan.helpers()
+		var coordinates = ToolMan.coordinates()
+		var items = list.getElementsByTagName("li")
+
+		helpers.map(items, function(item) {
+			var dragGroup = dragsort.makeSortable(item)
+			dragGroup.setThreshold(4)
+			var min, max
+			dragGroup.addTransform(function(coordinate, dragEvent) {
+				return coordinate.constrainTo(min, max)
+			})
+			dragGroup.register('dragstart', function() {
+				var items = list.getElementsByTagName("li")
+				min = max = coordinates.topLeftOffset(items[0])
+				for (var i = 1, n = items.length; i < n; i++) {
+					var offset = coordinates.topLeftOffset(items[i])
+					min = min.min(offset)
+					max = max.max(offset)
+				}
+			})
+		})
+		for (var i = 1, n = arguments.length; i < n; i++)
+			helpers.map(items, arguments[i])
+	},
+
+	_onDragStart : function(dragEvent) {
+	},
+
+	_onDragMove : function(dragEvent) {
+		var helpers = ToolMan.helpers()
+		var coordinates = ToolMan.coordinates()
+
+		var item = dragEvent.group.element
+		var xmouse = dragEvent.transformedMouseOffset
+		var moveTo = null
+
+		var previous = helpers.previousItem(item, item.nodeName)
+		while (previous != null) {
+			var bottomRight = coordinates.bottomRightOffset(previous)
+			if (xmouse.y <= bottomRight.y && xmouse.x <= bottomRight.x) {
+				moveTo = previous
+			}
+			previous = helpers.previousItem(previous, item.nodeName)
+		}
+		if (moveTo != null) {
+			helpers.moveBefore(item, moveTo)
+			return
+		}
+
+		var next = helpers.nextItem(item, item.nodeName)
+		while (next != null) {
+			var topLeft = coordinates.topLeftOffset(next)
+			if (topLeft.y <= xmouse.y && topLeft.x <= xmouse.x) {
+				moveTo = next
+			}
+			next = helpers.nextItem(next, item.nodeName)
+		}
+		if (moveTo != null) {
+			helpers.moveBefore(item, helpers.nextItem(moveTo, item.nodeName))
+			return
+		}
+	},
+
+	_onDragEnd : function(dragEvent) {
+		ToolMan.coordinates().create(0, 0).reposition(dragEvent.group.element)
+	}
+}

Added: hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/events.js
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/events.js?rev=723855&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/events.js (added)
+++ hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/org/tool-man/events.js Fri Dec  5 12:30:14 2008
@@ -0,0 +1,43 @@
+/* Copyright (c) 2005 Tim Taylor Consulting (see LICENSE.txt) */
+
+ToolMan._eventsFactory = {
+	fix : function(event) {
+		if (!event) event = window.event
+
+		if (event.target) {
+			if (event.target.nodeType == 3) event.target = event.target.parentNode
+		} else if (event.srcElement) {
+			event.target = event.srcElement
+		}
+
+		return event
+	},
+
+	register : function(element, type, func) {
+		if (element.addEventListener) {
+			element.addEventListener(type, func, false)
+		} else if (element.attachEvent) {
+			if (!element._listeners) element._listeners = new Array()
+			if (!element._listeners[type]) element._listeners[type] = new Array()
+			var workaroundFunc = function() {
+				func.apply(element, new Array())
+			}
+			element._listeners[type][func] = workaroundFunc
+			element.attachEvent('on' + type, workaroundFunc)
+		}
+	},
+
+	unregister : function(element, type, func) {
+		if (element.removeEventListener) {
+			element.removeEventListener(type, func, false)
+		} else if (element.detachEvent) {
+			if (element._listeners 
+					&& element._listeners[type] 
+					&& element._listeners[type][func]) {
+
+				element.detachEvent('on' + type, 
+						element._listeners[type][func])
+			}
+		}
+	}
+}

Added: hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/time.js
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/time.js?rev=723855&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/time.js (added)
+++ hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/time.js Fri Dec  5 12:30:14 2008
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+function save_timeframe(obj) {
+    var start = document.getElementById(obj+"start").value;
+    var end = document.getElementById(obj+"end").value;
+    var starts = start.split("-");
+    var ends = end.split("-");
+    var start_date=new Date();
+    start_date.setFullYear(starts[0]);
+    start_date.setMonth(starts[1]-1);
+    start_date.setDate(starts[2]);
+    var end_date=new Date();
+    end_date.setFullYear(ends[0]);
+    end_date.setMonth(ends[1]-1);
+    end_date.setDate(ends[2]);
+    start = start_date.getTime();
+    end = end_date.getTime();
+    var myAjax=new Ajax.Request(
+       '/hicc/jsp/session.jsp',
+       {
+           asynchronous: false,
+           method: "get",
+           parameters: "time_type=range&start="+start+"&end="+end,
+           onSuccess: function(transport) {    
+                          _currentView.getCurrentPage().refresh_all();
+                      }
+       }
+    );
+}
+
+function save_time(boxId) {
+    var time_machine="range";
+    var start=document.getElementById(boxId+"start").value;
+    var end=document.getElementById(boxId+"end").value;
+    var start_hour=document.getElementById(boxId+"start_hour").options[document.getElementById(boxId+"start_hour").selectedIndex].value;
+    var start_min=document.getElementById(boxId+"start_min").options[document.getElementById(boxId+"start_min").selectedIndex].value;
+    var end_hour=document.getElementById(boxId+"end_hour").options[document.getElementById(boxId+"end_hour").selectedIndex].value;
+    var end_min=document.getElementById(boxId+"end_min").options[document.getElementById(boxId+"end_min").selectedIndex].value;
+    var starts = start.split("-");
+    var ends = end.split("-");
+    var start_date=new Date();
+    start_date.setUTCFullYear(starts[0]);
+    start_date.setUTCMonth(starts[1]-1);
+    start_date.setUTCDate(starts[2]);
+    start_date.setUTCHours(start_hour);
+    start_date.setUTCMinutes(start_min);
+    var end_date=new Date();
+    end_date.setUTCFullYear(ends[0]);
+    end_date.setUTCMonth(ends[1]-1);
+    end_date.setUTCDate(ends[2]);
+    end_date.setUTCHours(end_hour);
+    end_date.setUTCMinutes(end_min);
+    start = start_date.getTime();
+    end = end_date.getTime();
+    
+    if(end < start) {
+        var tmp=start;
+        start=end;
+        end=tmp;
+    }
+    var myAjax=new Ajax.Request(
+        '/hicc/jsp/session.jsp',
+        {
+            asynchronous: false,
+            method: "get",
+            parameters: "time_type="+time_machine+"&start="+start+"&end="+end
+        }
+    );
+    _currentView.getCurrentPage().refresh_all();
+}
+
+function save_time_range(boxId) {
+    var time_machine="last";
+    var obj=document.getElementById(boxId+"period").options;
+    var period=obj[document.getElementById(boxId+"period").selectedIndex].value;
+    var myAjax=new Ajax.Request(
+        '/hicc/jsp/session.jsp',
+        {
+            asynchronous: false,
+            method: "get",
+            parameters: "time_type="+time_machine+"&period="+period
+        }
+    );
+    _currentView.getCurrentPage().refresh_all();
+}
+
+function save_time_slider(start, end) {
+    start=Math.round(start);
+    end=Math.round(end);
+    var myAjax = new Ajax.Request(
+         '/hicc/jsp/session.jsp',
+         {
+             method:'get',
+             parameters: {
+                 "time_type": "range",
+                 "start": start,
+                 "end": end,
+             },
+             onSuccess: function(request) {
+                 _currentView.getCurrentPage().refresh_all();
+             },
+             onException: function(error) {
+                 alert(error);
+             }
+         });
+}
+

Added: hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/timeframe.js
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/timeframe.js?rev=723855&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/timeframe.js (added)
+++ hadoop/core/trunk/src/contrib/chukwa/src/web/hicc/js/timeframe.js Fri Dec  5 12:30:14 2008
@@ -0,0 +1,460 @@
+/* Timeframe, version 0.2
+ * (c) 2008 Stephen Celis
+ *
+ * Freely distributable under the terms of an MIT-style license. 
+ * ------------------------------------------------------------- */
+
+if (typeof Prototype == 'undefined' || parseFloat(Prototype.Version.substring(0, 3)) < 1.6)
+  throw 'Timeframe requires Prototype version 1.6 or greater.';
+
+// Checks for localized Datejs before defaulting to 'en-US'
+var Locale = $H({
+  format:     (typeof Date.CultureInfo == 'undefined' ? '%b %d, %Y' : Date.CultureInfo.formatPatterns.shortDate),
+  monthNames: (typeof Date.CultureInfo == 'undefined' ? $w('January February March April May June July August September October November December') : Date.CultureInfo.monthNames),
+  dayNames:   (typeof Date.CultureInfo == 'undefined' ? $w('Sunday Monday Tuesday Wednesday Thursday Friday Saturday') : Date.CultureInfo.dayNames),
+  weekOffset: (typeof Date.CultureInfo == 'undefined' ? 0 : Date.CultureInfo.firstDayOfWeek)
+});
+
+var Timeframes = [];
+
+var Timeframe = Class.create({
+  Version: '0.2',
+
+  initialize: function(element, options) {
+    Timeframes.push(this);
+
+    this.element = $(element);
+    this.element.addClassName('timeframe_calendar')
+    this.options = $H({ months: 2 }).merge(options || {});;
+    this.months = this.options.get('months');
+
+    this.weekdayNames = Locale.get('dayNames');
+    this.monthNames   = Locale.get('monthNames');
+    this.format       = this.options.get('format')     || Locale.get('format');
+    this.weekOffset   = this.options.get('weekOffset') || Locale.get('weekOffset');
+    this.maxRange = this.options.get('maxRange');
+
+    this.buttons = $H({
+      previous: $H({ label: '&larr;', element: $(this.options.get('previousButton')) }),
+      today:    $H({ label: 'T',      element: $(this.options.get('todayButton')) }),
+      reset:    $H({ label: 'R',      element: $(this.options.get('resetButton')) }),
+      next:     $H({ label: '&rarr;', element: $(this.options.get('nextButton')) })
+    })
+    this.fields = $H({ start: $(this.options.get('startField')), end: $(this.options.get('endField')) });
+
+    this.range = $H({});
+    this._buildButtons()._buildFields();
+    this.earliest = Date.parseToObject(this.options.get('earliest'));
+    this.latest   = Date.parseToObject(this.options.get('latest'));
+
+    this.calendars = [];
+    this.element.insert(new Element('div', { id: this.element.id + '_container' }));
+    this.months.times(function(month) { this.createCalendar(month) }.bind(this));
+
+    this.register().populate().refreshRange();
+  },
+
+  // Scaffolding
+
+  createCalendar: function() {
+    var calendar = new Element('table', {
+      id: this.element.id + '_calendar_' + this.calendars.length, border: 0, cellspacing: 0, cellpadding: 5
+    });
+    calendar.insert(new Element('caption'));
+
+    var head = new Element('thead');
+    var row  = new Element('tr');
+    this.weekdayNames.length.times(function(column) {
+      var weekday = this.weekdayNames[(column + this.weekOffset) % 7];
+      var cell = new Element('th', { scope: 'col', abbr: weekday }).update(weekday.substring(0,1));
+      row.insert(cell);
+    }.bind(this));
+    head.insert(row);
+    calendar.insert(head);
+
+    var body = new Element('tbody');
+    (6).times(function(rowNumber) {
+      var row = new Element('tr');
+      this.weekdayNames.length.times(function(column) {
+        var cell = new Element('td');
+        row.insert(cell);
+      });
+      body.insert(row);
+    }.bind(this));
+    calendar.insert(body);
+
+    this.element.down('div#' + this.element.id + '_container').insert(calendar);
+    this.calendars.push(calendar);
+    this.months = this.calendars.length;
+    return this;
+  },
+
+  destroyCalendar: function() {
+    this.calendars.pop().remove();
+    this.months = this.calendars.length;
+    return this;
+  },
+
+  populate: function() {
+    var month = this.date.neutral();
+    month.setDate(1);
+    this.calendars.each(function(calendar) {
+      var caption = calendar.select('caption').first();
+      caption.update(this.monthNames[month.getMonth()] + ' ' + month.getFullYear());
+
+      var iterator = new Date(month);
+      var offset = (iterator.getDay() - this.weekOffset) % 7;
+      var inactive = offset > 0 ? 'pre beyond' : false;
+      iterator.setDate(iterator.getDate() - offset);
+      if (iterator.getDate() > 1 && !inactive) {
+        iterator.setDate(iterator.getDate() - 7);
+        if (iterator.getDate() > 1) inactive = 'pre beyond';
+      }
+
+      calendar.select('td').each(function(day) {
+        day.date = new Date(iterator); // Is this expensive (we unload these later)? We could store the epoch time instead.
+        day.update(day.date.getDate()).writeAttribute('class', inactive || 'active');
+        if ((this.earliest && day.date < this.earliest) || (this.latest && day.date > this.latest))
+          day.addClassName('unselectable');
+        else
+          day.addClassName('selectable');
+        if (iterator.toString() === new Date().neutral().toString()) day.addClassName('today');
+        day.baseClass = day.readAttribute('class');
+
+        iterator.setDate(iterator.getDate() + 1);
+        if (iterator.getDate() == 1) inactive = inactive ? false : 'post beyond';
+      }.bind(this));
+
+      month.setMonth(month.getMonth() + 1);
+    }.bind(this));
+    return this;
+  },
+
+  _buildButtons: function() {
+    var buttonList = new Element('ul', { id: this.element.id + '_menu', className: 'timeframe_menu' });
+    this.buttons.each(function(pair) {
+      if (pair.value.get('element'))
+        pair.value.get('element').addClassName('timeframe_button').addClassName(pair.key);
+      else {
+        var item = new Element('li');
+        var button = new Element('a', { className: 'timeframe_button ' + pair.key, href: '#', onclick: 'return false;' }).update(pair.value.get('label'));
+        button.onclick = function() { return false; };
+        pair.value.set('element', button);
+        item.insert(button);
+        buttonList.insert(item);
+      }
+    }.bind(this))
+    if (buttonList.childNodes.length > 0) this.element.insert({ top: buttonList });
+    this.clearButton = new Element('span', { className: 'clear' }).update(new Element('span').update('X'));
+    return this;
+  },
+
+  _buildFields: function() {
+    var fieldset = new Element('div', { id: this.element.id + '_fields', className: 'timeframe_fields' });
+    this.fields.each(function(pair) {
+      if (pair.value)
+        pair.value.addClassName('timeframe_field').addClassName(pair.key);
+      else {
+        var container = new Element('div', { id: pair.key + this.element.id + '_field_container' });
+        this.fields.set(pair.key, new Element('input', { id: this.element.id + '_' + pair.key + 'field', name: pair.key + 'field', type: 'text', value: '' }));
+        container.insert(new Element('label', { 'for': pair.key + 'field' }).update(pair.key));
+        container.insert(this.fields.get(pair.key));
+        fieldset.insert(container);
+      }
+    }.bind(this));
+    if (fieldset.childNodes.length > 0) this.element.insert(fieldset);
+    this.parseField('start').refreshField('start').parseField('end').refreshField('end').initDate = new Date(this.date);
+    return this;
+  },
+
+  // Event registration
+
+  register: function() {
+    document.observe('click', this.eventClick.bind(this));
+    this.element.observe('mousedown', this.eventMouseDown.bind(this));
+    this.element.observe('mouseover', this.eventMouseOver.bind(this));
+    document.observe('mouseup', this.eventMouseUp.bind(this));
+    document.observe('unload', this.unregister.bind(this));
+    // mousemove listener for Opera in _disableTextSelection
+    return this._registerFieldObserver('start')._registerFieldObserver('end')._disableTextSelection();
+  },
+
+  unregister: function() {
+    this.element.select('td').each(function(day) { day.date = day.baseClass = null; });
+  },
+
+  _registerFieldObserver: function(fieldName) {
+    var field = this.fields.get(fieldName);
+    field.observe('focus', function() { field.hasFocus = true; this.parseField(fieldName, true); }.bind(this));
+    field.observe('blur', function() { this.refreshField(fieldName); }.bind(this));
+    new Form.Element.Observer(field, 0.2, function(element, value) { if (element.hasFocus) this.parseField(fieldName, true); }.bind(this));
+    return this;
+  },
+
+  _disableTextSelection: function() {
+    if (Prototype.Browser.IE) {
+      this.element.onselectstart = function(event) {
+        if (!/input|textarea/i.test(Event.element(event).tagName)) return false;
+      };
+    } else if (Prototype.Browser.Opera) {
+      document.observe('mousemove', this.handleMouseMove.bind(this));
+    } else {
+      this.element.onmousedown = function(event) {
+        if (!/input|textarea/i.test(Event.element(event).tagName)) return false;
+      };
+    }
+    return this;
+  },
+
+  // Fields
+
+  parseField: function(fieldName, populate) {
+    var field = this.fields.get(fieldName);
+    var date = Date.parseToObject($F(this.fields.get(fieldName)));
+    var failure = this.validateField(fieldName, date);
+    if (failure != 'hard') {
+      this.range.set(fieldName, date);
+      field.removeClassName('error');
+    } else if (field.hasFocus)
+      field.addClassName('error');
+    var date = Date.parseToObject(this.range.get(fieldName));
+    this.date = date || new Date();
+    if (populate && date) this.populate()
+    this.refreshRange();
+    return this;
+  },
+
+  refreshField: function(fieldName) {
+    var field = this.fields.get(fieldName);
+    var initValue = $F(field);
+    if (this.range.get(fieldName)) {
+      field.setValue(typeof Date.CultureInfo == 'undefined' ?
+        this.range.get(fieldName).strftime(this.format) :
+        this.range.get(fieldName).toString(this.format));
+    } else
+      field.setValue('');
+    field.hasFocus && $F(field) == '' && initValue != '' ? field.addClassName('error') : field.removeClassName('error');
+    field.hasFocus = false;
+    return this;
+  },
+
+  validateField: function(fieldName, date) {
+    if (!date) return;
+    var error;
+    if ((this.earliest && date < this.earliest) || (this.latest && date > this.latest))
+      error = 'hard';
+    else if (fieldName == 'start' && this.range.get('end') && date > this.range.get('end'))
+      error = 'soft';
+    else if (fieldName == 'end' && this.range.get('start') && date < this.range.get('start'))
+      error = 'soft';
+    return error;
+  },
+
+  // Event handling
+
+  eventClick: function(event) {
+    if (!event.element().ancestors) return;
+    var el;
+    if (el = event.findElement('a.timeframe_button'))
+      this.handleButtonClick(event, el);
+  },
+
+  eventMouseDown: function(event) {
+    if (!event.element().ancestors) return;
+    var el, em;
+    if (el = event.findElement('span.clear')) {
+      el.down('span').addClassName('active');
+      if (em = event.findElement('td.selectable'))
+        this.handleDateClick(em, true);
+    } else if (el = event.findElement('td.selectable'))
+      this.handleDateClick(el);
+    else return;
+  },
+
+  handleButtonClick: function(event, element) {
+    var el;
+    var movement = this.months > 1 ? this.months - 1 : 1;
+    if (element.hasClassName('next'))
+      this.date.setMonth(this.date.getMonth() + movement);
+    else if (element.hasClassName('previous'))
+      this.date.setMonth(this.date.getMonth() - movement);
+    else if (element.hasClassName('today'))
+      this.date = new Date();
+    else if (element.hasClassName('reset'))
+      this.reset();
+    this.populate().refreshRange();
+  },
+
+  reset: function() {
+    this.fields.get('start').setValue(this.fields.get('start').defaultValue || '');
+    this.fields.get('end').setValue(this.fields.get('end').defaultValue || '');
+    this.date = new Date(this.initDate);
+    this.parseField('start').refreshField('start').parseField('end').refreshField('end');
+  },
+
+  handleDateClick: function(element, couldClear) {
+    this.mousedown = this.dragging = true;
+    if (this.stuck) {
+      this.stuck = false;
+      return;
+    } else if (couldClear) {
+      if (!element.hasClassName('startrange')) return;
+    } else if (this.maxRange != 1) {
+      this.stuck = true;
+      setTimeout(function() { if (this.mousedown) this.stuck = false; }.bind(this), 200);
+    }
+    this.getPoint(element.date);
+  },
+
+  getPoint: function(date) {
+    if (this.range.get('start') && this.range.get('start').toString() == date && this.range.get('end'))
+      this.startdrag = this.range.get('end');
+    else {
+      this.clearButton.hide();
+      if (this.range.get('end') && this.range.get('end').toString() == date)
+        this.startdrag = this.range.get('start');
+      else
+        this.startdrag = this.range.set('start', this.range.set('end', date));
+    }
+    this.refreshRange();
+  },
+
+  eventMouseOver: function(event) {
+    var el;
+    if (!this.dragging)
+      this.toggleClearButton(event);
+    else if (event.findElement('span.clear span.active'));
+    else if (el = event.findElement('td.selectable'))
+      this.extendRange(el.date);
+    else this.toggleClearButton(event);
+  },
+
+  toggleClearButton: function(event) {
+    var el;
+    if(event.element().ancestors && event.findElement('td.selected')) {
+      if(el = this.element.select('#calendar_0 .pre.selected').first());
+      else if(el = this.element.select('.active.selected').first());
+      else if(el = this.element.select('.post.selected').first());
+      if(el) Element.insert(el, { top: this.clearButton });
+      this.clearButton.show().select('span').first().removeClassName('active');        
+    } else
+      this.clearButton.hide();
+  },
+
+  extendRange: function(date) {
+    var start, end;
+    this.clearButton.hide();
+    if (date > this.startdrag) {
+      start = this.startdrag;
+      end = date;
+    } else if (date < this.startdrag) {
+      start = date;
+      end = this.startdrag;
+    } else
+      start = end = date;
+    this.validateRange(start, end);
+    this.refreshRange();
+  },
+
+  validateRange: function(start, end) {
+    if (this.maxRange) {
+      var range = this.maxRange - 1;
+      var days = parseInt((end - start) / 86400000);
+      if (days > range) {
+        if (start == this.startdrag) {
+          end = new Date(this.startdrag);
+          end.setDate(end.getDate() + range);
+        } else {
+          start = new Date(this.startdrag);
+          start.setDate(start.getDate() - range);
+        }
+      }
+    }
+    this.range.set('start', start);
+    this.range.set('end', end);
+  },
+
+  eventMouseUp: function(event) {
+    if (!this.dragging) return;
+    if (!this.stuck) {
+      this.dragging = false;
+      if (event.findElement('span.clear span.active'))
+        this.clearRange();
+    }
+    this.mousedown = false;
+    this.refreshRange();
+  },
+
+  clearRange: function() {
+    this.clearButton.hide().select('span').first().removeClassName('active');
+    this.range.set('start', this.range.set('end', null));
+    this.refreshField('start').refreshField('end');
+  },
+
+  refreshRange: function() {
+    this.element.select('td').each(function(day) {
+      day.writeAttribute('class', day.baseClass);
+      if (this.range.get('start') && this.range.get('end') && this.range.get('start') <= day.date && day.date <= this.range.get('end')) {
+        var baseClass = day.hasClassName('beyond') ? 'beyond_' : day.hasClassName('today') ? 'today_' : null;
+        var state = this.stuck || this.mousedown ? 'stuck' : 'selected';
+        if (baseClass) day.addClassName(baseClass + state);
+        day.addClassName(state);
+        var rangeClass = '';
+        if (this.range.get('start').toString() == day.date) rangeClass += 'start';
+        if (this.range.get('end').toString() == day.date) rangeClass += 'end';
+        if (rangeClass.length > 0) day.addClassName(rangeClass + 'range');
+      }
+      if (Prototype.Browser.Opera) {
+        day.unselectable = 'on'; // Trick Opera into refreshing the selection (FIXME)
+        day.unselectable = null;
+      }
+    }.bind(this));
+    if (this.dragging) this.refreshField('start').refreshField('end');
+  },
+
+  handleMouseMove: function(event) {
+    if (event.findElement('#' + this.element.id + ' td')) window.getSelection().removeAllRanges(); // More Opera trickery
+  }
+});
+
+Object.extend(Date, {
+  parseToObject: function(string) {
+    var date = Date.parse(string);
+    if (!date) return null;
+    date = new Date(date);
+    return (date == 'Invalid Date' || date == 'NaN') ? null : date.neutral();
+  }
+});
+
+Object.extend(Date.prototype, {
+  // modified from http://alternateidea.com/blog/articles/2008/2/8/a-strftime-for-prototype
+  strftime: function(format) {
+    var day = this.getDay(), month = this.getMonth();
+    var hours = this.getHours(), minutes = this.getMinutes();
+    function pad(num) { return num.toPaddedString(2); };
+
+    return format.gsub(/\%([aAbBcdHImMpSwyY])/, function(part) {
+      switch(part[1]) {
+        case 'a': return Locale.get('dayNames').invoke('substring', 0, 3)[day].escapeHTML(); break;
+        case 'A': return Locale.get('dayNames')[day].escapeHTML(); break;
+        case 'b': return Locale.get('monthNames').invoke('substring', 0, 3)[month].escapeHTML(); break;
+        case 'B': return Locale.get('monthNames')[month].escapeHTML(); break;
+        case 'c': return this.toString(); break;
+        case 'd': return pad(this.getDate()); break;
+        case 'H': return pad(hours); break;
+        case 'I': return (hours % 12 == 0) ? 12 : pad(hours % 12); break;
+        case 'm': return pad(month + 1); break;
+        case 'M': return pad(minutes); break;
+        case 'p': return hours >= 12 ? 'PM' : 'AM'; break;
+        case 'S': return pad(this.getSeconds()); break;
+        case 'w': return day; break;
+        case 'y': return pad(this.getFullYear() % 100); break;
+        case 'Y': return this.getFullYear().toString(); break;
+      }
+    }.bind(this));
+  },
+
+  neutral: function() {
+    return new Date(this.getFullYear(), this.getMonth(), this.getDate(), 12);
+  }
+});
\ No newline at end of file