
var U={
	D:document,
	W:window,
	N:navigator,
	NU:navigator.userAgent
};

var UJS={
	B:{
		IE:!!(U.W.attachEvent&&!U.W.opera),
		Opera:!!U.W.opera,
		WebKit:U.NU.indexOf('AppleWebKit/')>-1,
		Gecko:U.NU.indexOf('Gecko')>-1&&U.NU.indexOf('KHTML')==-1
	},
	BF:{
		XPath:!!U.D.evaluate,
		ElementExtensions:!!U.W.HTMLElement,
		SpecificElementExtensions:(U.D.createElement('div').__proto__!==U.D.createElement('form').__proto__)
	},
	EF:function(){},
	SF:'<script[^>]*>([\u0001-\uFFFF]*?)</script>',
	JF:/^\/\*-secure-\s*(.*)\s*\*\/\s*$/,
	K:function(x){return x;},
	DN:"ujs-",
	DI:0,
	bug:function(s,b){
		if(!UJS._d) UJS._d=U.D.createElement('div');
		if(b){
			UJS._d.innerHTML=s;
		}else{
			var o=document.createElement("li");
			UJS._d.appendChild(o);
			o.innerHTML=s;
		}
	},
	time:function(s){
		var t=new Date().getTime()-startTime;
		var o=document.createElement("li");
		if(!UJS._t) UJS._t=U.D.createElement('div');
		UJS._t.appendChild(o);
		o.innerHTML=s+":"+t;
	},
	sTime:new Date().getTime()
};


var Class={
	create:function(){
		return function(){
			this.initialize.apply(this,arguments);
		}
	}
};

var Abstract=new Object();

Object.extend=function(d,s){
	for(var p in s){
		d[p]=s[p];
	}
	return d;
};

Object.extend(Object,{
	inspect:function(object){
		try{
			if(object===undefined) return 'undefined';
			if(object===null) return 'null';
			return object.inspect?object.inspect():object.toString();
		}catch(e){
			if(e instanceof RangeError) return '...';
			throw e;
		}
	},
	toJSON:function(o){
		var t=typeof o;
		switch(t){
			case 'undefined':
			case 'function':
			case 'unknown':return;
			case 'boolean':return o.toString();
		}
		if(o===null) return 'null';
		if(o.toJSON) return o.toJSON();
		if(o.ownerDocument===document) return;
		var r=[];
		for(var p in o){
			var v=Object.toJSON(o[p]);
			if(v!==undefined)
			r.push(p.toJSON()+':'+v);
		}
		return '{'+r.join(',')+'}';
	},
	keys:function(o){
		var k=[];
		for(var p in o)
			k.push(p);
		return k;
	},
	values:function(o){
		var v=[];
		for(var p in o)
			v.push(o[p]);
		return v;
	},
	clone:function(o){
		return Object.extend({},o);
	}
});

Function.prototype.bind=function(){
	var m=this,a=$A(arguments),o=a.shift();
	return function(){
		return m.apply(o,a.concat($A(arguments)));
	}
};
Function.prototype.bindAsEventListener=function(){
	var m=this,a=$A(arguments),o=a.shift();
	return function(e){
		return m.apply(o,[e||U.W.event].concat(a));
	}
};
Function.prototype.defer=function(t){
	U.W.setTimeout(this,t);
};

Object.extend(Number.prototype,{
	toColorPart:function(){
		return this.toPaddedString(2,16);
	},
	succ:function(){
		return this+1;
	},
	times:function(a){
		$R(0,this,true).each(a);
		return this;
	},
	toPaddedString:function(l,r){
		var s=this.toString(r||10);
		return '0'.times(l-s.length)+s;
	},
	toJSON:function(){
		return isFinite(this)?this.toString():'null';
	}
});

Date.prototype.toJSON=function(){
	return '"'+this.getFullYear()+'-'+
		(this.getMonth()+1).toPaddedString(2)+'-'+
		this.getDate().toPaddedString(2)+'T'+
		this.getHours().toPaddedString(2)+':'+
		this.getMinutes().toPaddedString(2)+':'+
		this.getSeconds().toPaddedString(2)+'"';
};

var Try={
	these:function(){
		var v;
		for(var i=0,l=arguments.length;i<l;i++){
			var f=arguments[i];
			try{
				v=f();
				break;
			}catch(e){}
		}
		return v;
	}
};


var PeriodicalExecuter=Class.create();
PeriodicalExecuter.prototype={
	initialize:function(c,f){
		this.callback=c;
		this.frequency=f;
		this.currentlyExecuting=false;
		this.registerCallback();
	},
	registerCallback:function(){
		this.timer=setInterval(this.onTimerEvent.bind(this),this.frequency*1000);
	},
	stop:function(){
		if(!this.timer) return;
		clearInterval(this.timer);
		this.timer=null;
	},
	onTimerEvent:function(){
		if(!this.currentlyExecuting){
			try{
				this.currentlyExecuting=true;
				this.callback(this);
			} finally{
				this.currentlyExecuting=false;
			}
		}
	}
};

Object.extend(String,{
	interpret:function(value){
		return value==null?'':String(value);
	},
	specialChar:{
		'\b':'\\b',
		'\t':'\\t',
		'\n':'\\n',
		'\f':'\\f',
		'\r':'\\r',
		'\\':'\\\\'
	}
});
Object.extend(String.prototype,{
	gsub:function(p,r){
		var v='',s=this,match;
		r=arguments.callee.pr(r);
		while(s.length>0){
			if(match=s.match(p)){
				v+=s.slice(0,match.index);
				v+=String.interpret(r(match));
				s=s.slice(match.index+match[0].length);
			}else{
				v+=s,s='';
			}
		}
		return v;
	},

	sub:function(p,r,c){
		r=this.gsub.pr(r);
		c=c===undefined?1:c;
		return this.gsub(p,function(match){
			if(--c<0) return match[0];
			return r(match);
		});
	},

	scan:function(p,a){
		this.gsub(p,a);
		return this;
	},

	truncate:function(l,t){
		l=l||30;
		t=t===undefined?'...':t;
		return this.length>l?this.slice(0,l-t.length)+t:this;
	},

	strip:function(){
		return this.replace(/^\s+/,'').replace(/\s+$/,'');
	},

	stripTags:function(){
		return this.replace(/<\/?[^>]+>/gi,'');
	},

	stripScripts:function(){
		return this.replace(new RegExp(UJS.SF,'img'),'');
	},

	extractScripts:function(){
		var ma=new RegExp(UJS.SF,'img');
		var mo=new RegExp(UJS.SF,'im');
		return (this.match(ma)||[]).map(function(s){
			return (s.match(mo)||['',''])[1];
		});
	},

	evalScripts:function(){
		return this.extractScripts().map(function(script){return eval(script);});
	},

	escapeHTML:function(){
		var m=arguments.callee;
		m.text.data=this;
		return m.div.innerHTML;
	},

	unescapeHTML:function(){
		var div=U.D.createElement('div');
		div.innerHTML=this.stripTags();
		return div.childNodes[0]?(div.childNodes.length>1?$A(div.childNodes).inject('',function(m,n){ return m+n.nodeValue }):
		div.childNodes[0].nodeValue):'';
	},

	toQueryParams:function(s){
		var match=this.strip().match(/([^?#]*)(#.*)?$/);
		if(!match) return{};
		return match[1].split(s||'&').inject({},function(h,p){
			if((p=p.split('='))[0]){
				var k=decodeURIComponent(p.shift());
				var v=p.length>1?p.join('='):p[0];
				if(v!=undefined) v=decodeURIComponent(v);
				if(k in h){
					if(h[k].constructor!=Array) h[k]=[h[k]];
					h[k].push(v);
				} else h[k]=v;
			}
			return h;
		});
	},

	toArray:function(){
		return this.split('');
	},

	succ:function(){
		return this.slice(0,this.length-1)+
		String.fromCharCode(this.charCodeAt(this.length-1)+1);
	},

	times:function(c){
		var r='';
		for(var i=0;i<c;i++) r+=this;
		return r;
	},

	camelize:function(){
		var p=this.split('-'),l=p.length;
		if(l==1) return p[0];
		var c=this.charAt(0)=='-'?p[0].charAt(0).toUpperCase()+p[0].substring(1):p[0];
		for(var i=1;i<l;i++)
			c+=p[i].charAt(0).toUpperCase()+p[i].substring(1);
		return c;
	},

	capitalize:function(){
		return this.charAt(0).toUpperCase()+this.substring(1).toLowerCase();
	},

	underscore:function(){
		return this.gsub(/::/,'/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase();
	},

	dasherize:function(){
		return this.gsub(/_/,'-');
	},

	inspect:function(b){
		var e=this.gsub(/[\x00-\x1f\\]/,function(match){
			var c=String.specialChar[match[0]];
			return c?c:'\\u00'+match[0].charCodeAt().toPaddedString(2,16);
		});
		if(b) return '"'+e.replace(/"/g,'\\"')+'"';
		return "'"+e.replace(/'/g,'\\\'')+"'";
	},

	toJSON:function(){
		return this.inspect(true);
	},

	unfilterJSON:function(filter){
		return this.sub(filter||UJS.JF,'#{1}');
	},

	evalJSON:function(s){
		var v=this.unfilterJSON();
		try{
			if(!s||(/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(json)))
			return eval('('+v+')');
		}catch(e){}
		throw new SyntaxError('Badly formed JSON string:'+this.inspect());
	},

	include:function(p){
		return this.indexOf(p)>-1;
	},

	startsWith:function(p){
		return this.indexOf(p)===0;
	},

	endsWith:function(p){
		var d=this.length-p.length;
		return d>=0&&this.lastIndexOf(p)===d;
	},

	empty:function(){
		return this=='';
	},

	blank:function(){
		return /^\s*$/.test(this);
	}
});

if(UJS.B.WebKit||UJS.B.IE) Object.extend(String.prototype,{
	escapeHTML:function(){
		return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
	},
	unescapeHTML:function(){
		return this.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
	}
});

String.prototype.gsub.pr=function(r){
	if(typeof r=='function') return r;
	var t=new Template(r);
	return function(match){ return t.evaluate(match) };
};
String.prototype.parseQuery=String.prototype.toQueryParams;

Object.extend(String.prototype.escapeHTML,{
	div:U.D.createElement('div'),
	text:U.D.createTextNode('')
});

with(String.prototype.escapeHTML) div.appendChild(text);

var Template=Class.create();
Template.Pattern=/(^|.|\r|\n)(#\{(.*?)\})/;
Template.prototype={
	initialize:function(t,p){
		this.template=t.toString();
		this.pattern=p||Template.Pattern;
	},

	evaluate:function(o){
		return this.template.gsub(this.pattern,function(match){
			var b=match[1];
			if(b=='\\') return match[2];
			return b+String.interpret(o[match[3]]);
		});
	}
};

var $break={},$continue=new Error('"throw $continue" is deprecated,use "return" instead');

var Enumerable={
	each:function(a){
		var k=0;
		try{
			this._each(function(v){
				a(v,k++);
			});
		}catch(e){
			if(e!=$break) throw e;
		}
		return this;
	},

	eachSlice:function(n,a){
		var k=-n,s=[],t=this.toArray();
		while((k+=n)<t.length)
			s.push(array.slice(k,index+n));
		return slices.map(a);
	},

	all:function(a){
		var r=true;
		this.each(function(v,k){
		r=r&&!!(a||UJS.K)(v,k);
		if(!r) throw $break;
		});
		return r;
	},

	any:function(iterator){
		var result=false;
		this.each(function(value,index){
		if(result=!!(iterator||UJS.K)(value,index))
		throw $break;
		});
		return result;
	},

	collect:function(iterator){
		var results=[];
		this.each(function(value,index){
		results.push((iterator||UJS.K)(value,index));
		});
		return results;
	},

	detect:function(iterator){
		var result;
		this.each(function(value,index){
		if(iterator(value,index)){
		result=value;
		throw $break;
		}
		});
		return result;
	},

	findAll:function(iterator){
		var r=[];
		this.each(function(v,k){
			if(iterator(v,k))
				r.push(v);
		});
		return r;
	},

	grep:function(p,a){
		var r=[];
		this.each(function(v,k){
			var s=v.toString();
			if(s.match(p))
				r.push((a||UJS.K)(v,k));
		})
		return r;
	},

	include:function(o){
		var f=false;
		this.each(function(v){
			if(v==o){
				f=true;
				throw $break;
			}
		});
		return f;
	},

	inGroupsOf:function(n,f){
		f=f===undefined?null:f;
		return this.eachSlice(n,function(s){
			while(s.length<n) s.push(f);
			return s;
		});
	},

	inject:function(m,a){
		this.each(function(v,k){
			m=a(m,v,k);
		});
		return m;
	},

	invoke:function(m){
		var a=$A(arguments).slice(1);
		return this.map(function(v){
			return v[m].apply(v,a);
		});
	},

	max:function(a){
		var r;
		this.each(function(v,k){
			v=(a||UJS.K)(v,k);
			if(r==undefined||v >=r)
				r=v;
		});
		return r;
	},

	min:function(a){
		var r;
		this.each(function(v,k){
			v=(a||UJS.K)(v,k);
			if(r==undefined||v<r)
				r=v;
		});
		return result;
	},

	partition:function(a){
		var t=[],f=[];
		this.each(function(v,k){
			((a||UJS.K)(v,k)?t:f).push(v);
		});
		return [t,f];
	},

	pluck:function(p){
		var r=[];
		this.each(function(v,k){
			r.push(v[p]);
		});
		return r;
	},

	reject:function(a){
		var r=[];
		this.each(function(v,k){
			if(!a(v,k))
				r.push(v);
		});
		return r;
	},

	sortBy:function(a){
		return this.map(function(v,k){
			return{v:v,criteria:iterator(v,k)};
		}).sort(function(l,r){
			var a=l.criteria,b=r.criteria;
			return a<b?-1:a>b?1:0;
		}).pluck('value');
	},

	toArray:function(){
		return this.map();
	},

	zip:function(){
		var a=UJS.K,p=$A(arguments);
		if(typeof p.last()=='function')
			a=p.pop();
		var c=[this].concat(p).map($A);
		return this.map(function(value,index){
			return a(c.pluck(index));
		});
	},

	size:function(){
		return this.toArray().length;
	},

	inspect:function(){
		return '#<Enumerable:'+this.toArray().inspect()+'>';
	}
};

Object.extend(Enumerable,{
	map:Enumerable.collect,
	find:Enumerable.detect,
	select:Enumerable.findAll,
	member:Enumerable.include,
	entries:Enumerable.toArray
});

var $A=Array.from=function(a){
	if(!a) return [];
	if(a.toArray){
		return a.toArray();
	}else{
		var r=[];
		for(var i=0,length=a.length;i<length;i++)
			r.push(a[i]);
		return r;
	}
};

if(UJS.B.WebKit){
	$A=Array.from=function(a){
		if(!a) return [];
		if(!(typeof a=='function'&&a=='[object NodeList]')&&a.toArray){
			return a.toArray();
		}else{
			var r=[];
			for(var i=0,length=a.length;i<length;i++)
				r.push(a[i]);
			return r;
		}
	}
}

Object.extend(Array.prototype,Enumerable);

if(!Array.prototype._reverse)
	Array.prototype._reverse=Array.prototype.reverse;

Object.extend(Array.prototype,{
	_each:function(a){
		for(var i=0,length=this.length;i<length;i++)
			a(this[i]);
	},

	clear:function(){
		this.length=0;
		return this;
	},

	first:function(){
		return this[0];
	},

	last:function(){
		return this[this.length-1];
	},

	compact:function(){
		return this.select(function(v){
		return v!=null;
	});
	},

	flatten:function(){
		return this.inject([],function(a,v){
			return a.concat(v&&v.constructor==Array?v.flatten():[v]);
		});
	},

	without:function(){
		var v=$A(arguments);
		return this.select(function(c){
			return !v.include(c);
		});
	},

	indexOf:function(o){
		for(var i=0,length=this.length;i<length;i++)
			if(this[i]==o) return i;
		return -1;
	},

	reverse:function(l){
		return (l!==false?this:this.toArray())._reverse();
	},

	reduce:function(){
		return this.length>1?this:this[0];
	},

	uniq:function(sorted){
		return this.inject([],function(a,v,k){
			if(0==k||(sorted?a.last()!=v:!a.include(v)))
			a.push(v);
			return a;
		});
	},

	clone:function(){
		return [].concat(this);
	},

	size:function(){
		return this.length;
	},

	inspect:function(){
		return '['+this.map(Object.inspect).join(',')+']';
	},

	toJSON:function(){
		var r=[];
		this.each(function(o){
			var v=Object.toJSON(o);
			if(v!==undefined) r.push(v);
		});
		return '['+r.join(',')+']';
	}
});

Array.prototype.toArray=Array.prototype.clone;

function $w(s){
	s=s.strip();
	return s?s.split(/\s+/):[];
}

if(UJS.B.Opera){
	Array.prototype.concat=function(){
		var a=[];
		for(var i=0,length=this.length;i<length;i++) a.push(this[i]);
			for(var i=0,length=arguments.length;i<length;i++){
				if(arguments[i].constructor==Array){
				for(var j=0,l=arguments[i].length;j<l;j++)
					a.push(arguments[i][j]);
				}else{
					a.push(arguments[i]);
				}
			}
		return a;
	};
}

var Hash=function(o){
	if(o instanceof Hash) this.merge(o);
	else Object.extend(this,o||{});
};
Object.extend(Hash,{
	toQueryString:function(o){
		var a=[];
		a.add=arguments.callee.addPair;
		this.prototype._each.call(o,function(p){
			if(!p.key) return;
			var v=p.value;
			if(v&&typeof v=='object'){
				if(v.constructor==Array) v.each(function(v){
					a.add(p.key,v);
				});
				return;
			}
			a.add(p.key,v);
		});
		return a.join('&');
	},
	toJSON:function(o){
		var r=[];
		this.prototype._each.call(o,function(p){
			var v=Object.toJSON(p.value);
			if(v!==undefined) r.push(p.key.toJSON()+':'+v);
		});
		return '{'+r.join(',')+'}';
	}
});
Hash.toQueryString.addPair=function(k,v,p){
	k=encodeURIComponent(k);
	if(v===undefined) this.push(k);
	else this.push(k+'='+(v==null?'':encodeURIComponent(v)));
}
Object.extend(Hash.prototype,Enumerable);
Object.extend(Hash.prototype,{
	_each:function(a){
		for(var k in this){
			var v=this[k];
			if(v&&v==Hash.prototype[k]) continue;
			var p=[k,v];
			p.key=k;
			p.value=v;
			a(p);
		}
	},

	keys:function(){
		return this.pluck('key');
	},

	values:function(){
		return this.pluck('value');
	},

	merge:function(h){
		return $H(h).inject(this,function(m,p){
			m[p.key]=p.value;
			return m;
		});
	},

	remove:function(){
		var r;
		for(var i=0,length=arguments.length;i<length;i++){
			var value=this[arguments[i]];
			if(value!==undefined){
				if(r===undefined) r=value;
				else{
					if(r.constructor!=Array) r=[r];
					r.push(value);
				}
			}
			delete this[arguments[i]];
		}
		return r;
	},

	toQueryString:function(){
		return Hash.toQueryString(this);
	},

	inspect:function(){
		return '#<Hash:{'+this.map(function(p){
			return p.map(Object.inspect).join(':');
		}).join(',')+'}>';
	},

	toJSON:function(){
		return Hash.toJSON(this);
	}
});

function $H(o){
	if(o instanceof Hash) return o;
	return new Hash(o);
};

if(function(){
	var i=0,T=function(v){ this.key=v };
	T.prototype.key='foo';
	for(var p in new T('bar')) i++;
	return i>1;
}()) Hash.prototype._each=function(a){
	var c=[];
	for(var k in this){
		var v=this[k];
		if((v&&v==Hash.prototype[k])||c.include(k)) continue;
		c.push(k);
		var p=[k,v];
		p.key=k;
		p.value=v;
		a(p);
	}
};

ObjectRange=Class.create();
Object.extend(ObjectRange.prototype,Enumerable);
Object.extend(ObjectRange.prototype,{
	initialize:function(s,e,c){
		this.start=s;
		this.end=e;
		this.exclusive=c;
	},
	_each:function(a){
		var v=this.start;
		while(this.include(v)){
			a(v);
			v=v.succ();
		}
	},
	include:function(v){
		if(v<this.start)
			return false;
		if(this.exclusive)
			return v<this.end;
		return v<=this.end;
	}
});

var $R=function(s,e,c){
	return new ObjectRange(s,e,c);
}


var Ajax={
	getTransport:function(){
		return Try.these(
			function(){return new XMLHttpRequest()},
			function(){return new ActiveXObject('Msxml2.XMLHTTP')},
			function(){return new ActiveXObject('Microsoft.XMLHTTP')}
		)||false;
	},
	activeRequestCount:0
}
Ajax.Responders={
	responders:[],
	_each:function(a){
		this.responders._each(a);
	},
	register:function(r){
	if(!this.include(r))
		this.responders.push(r);
	},
	unregister:function(r){
		this.responders=this.responders.without(r);
	},
	dispatch:function(c,r,t,j){
		this.each(function(d){
			if(typeof d[c]=='function'){
				try{
					d[c].apply(responder,[r,t,j]);
				}catch(e){}
			}
		});
	}
};

Object.extend(Ajax.Responders,Enumerable);

Ajax.Responders.register({
	onCreate:function(){
		Ajax.activeRequestCount++;
	},
	onComplete:function(){
		Ajax.activeRequestCount--;
	}
});

Ajax.Base=function(){};
Ajax.Base.prototype={
	setOptions:function(o){
		this.options={
			method:'post',
			asynchronous:true,
			contentType:'application/x-www-form-urlencoded',
			encoding:'UTF-8',
			parameters:''
		};
		Object.extend(this.options,o||{});
		this.options.method=this.options.method.toLowerCase();
		if(typeof this.options.parameters=='string')
		this.options.parameters=this.options.parameters.toQueryParams();
	}
};

Ajax.Request=Class.create();
Ajax.Request.Events=['Uninitialized','Loading','Loaded','Interactive','Complete'];

Ajax.Request.prototype=Object.extend(new Ajax.Base(),{
	_complete:false,

	initialize:function(u,o){
		this.transport=Ajax.getTransport();
		this.setOptions(o);
		this.request(u);
	},

	request:function(u){
		this.url=u;
		this.method=this.options.method;
		var p=Object.clone(this.options.parameters);
		if(!['get','post'].include(this.method)){
			p['_method']=this.method;
			this.method='post';
		}

		this.parameters=p;
		if(p=Hash.toQueryString(p)){
			if(this.method=='get')
				this.url+=(this.url.include('?')?'&':'?')+p;
			else if(/Konqueror|Safari|KHTML/.test(U.NU))
				p+='&_=';
		}
		try{
			if(this.options.onCreate)
				this.options.onCreate(this.transport);
			Ajax.Responders.dispatch('onCreate',this,this.transport);
			this.transport.open(this.method.toUpperCase(),this.url,
			this.options.asynchronous);
			if(this.options.asynchronous)
				setTimeout(function(){this.respondToReadyState(1)}.bind(this),10);
			this.transport.onreadystatechange=this.onStateChange.bind(this);
			this.setRequestHeaders();
			this.body=this.method=='post'?(this.options.postBody||p):null;
			this.transport.send(this.body);
			if(!this.options.asynchronous&&this.transport.overrideMimeType)
			this.onStateChange();

		}
		catch(e){
			this.dispatchException(e);
		}
	},

	onStateChange:function(){
		var r=this.transport.readyState;
		if(r>1&&!((r==4)&&this._complete))
			this.respondToReadyState(this.transport.readyState);
	},

	setRequestHeaders:function(){
		var h={
			'X-Requested-With':'XMLHttpRequest',
			'Accept':'text/javascript,text/html,application/xml,text/xml,*/*'
		};

		if(this.method=='post'){
			h['Content-type']=this.options.contentType+(this.options.encoding?';charset='+this.options.encoding:'');
			if(this.transport.overrideMimeType&&(U.NU.match(/Gecko\/(\d{4})/)||[0,2005])[1]<2005)
				h['Connection']='close';
		}

		if(typeof this.options.requestHeaders=='object'){
			var e=this.options.requestHeaders;

			if(typeof extras.push=='function')
				for(var i=0,l=e.length;i<l;i+=2)
					h[e[i]]=e[i+1];
			else
				$H(e).each(function(p){ h[p.key]=p.value });
		}

		for(var n in h)
		this.transport.setRequestHeader(n,h[n]);
	},

	success:function(){
		return !this.transport.status
		||(this.transport.status >=200&&this.transport.status<300);
	},

	respondToReadyState:function(r){
		var s=Ajax.Request.Events[r];
		var t=this.transport,j=this.evalJSON();
		if(s=='Complete'){
			try{
				this._complete=true;
				(this.options['on'+this.transport.status]||this.options['on'+(this.success()?'Success':'Failure')]||UJS.EF)(t,j);
			}catch(e){
				this.dispatchException(e);
			}
			var contentType=this.getHeader('Content-type');
			if(contentType&&contentType.strip().match(/^(text|application)\/(x-)?(java|ecma)script(;.*)?$/i))
				this.evalResponse();
		}
		try{
			(this.options['on'+s]||UJS.EF)(t,j);
			Ajax.Responders.dispatch('on'+s,this,t,j);
		}catch(e){
			this.dispatchException(e);
		}
		if(s=='Complete'){
			this.transport.onreadystatechange=UJS.EF;
		}
	},

	getHeader:function(n){
		try{
			return this.transport.getResponseHeader(n);
		}catch(e){ return null }
	},

	evalJSON:function(){
		try{
			var j=this.getHeader('X-JSON');
			return j?j.evalJSON():null;
		}catch(e){ return null }
	},

	evalResponse:function(){
		try{
			return eval((this.transport.responseText||'').unfilterJSON());
		}catch(e){
			this.dispatchException(e);
		}
	},

	dispatchException:function(e){
		(this.options.onException||UJS.EF)(this,e);
		Ajax.Responders.dispatch('onException',this,e);
	}
});

Ajax.Updater=Class.create();

Object.extend(Object.extend(Ajax.Updater.prototype,Ajax.Request.prototype),{
	initialize:function(container,url,options){
		this.container={
			success:(container.success||container),
			failure:(container.failure||(container.success?null:container))
		}

		this.transport=Ajax.getTransport();
		this.setOptions(options);

		var onComplete=this.options.onComplete||UJS.EF;
		this.options.onComplete=(function(transport,param){
			this.updateContent();
			onComplete(transport,param);
		}).bind(this);

		this.request(url);
	},

	updateContent:function(){
		var receiver=this.container[this.success()?'success':'failure'];
		var response=this.transport.responseText;

		if(!this.options.evalScripts) response=response.stripScripts();

		if(receiver=$(receiver)){
			if(this.options.insertion)
				new this.options.insertion(receiver,response);
			else
				receiver.update(response);
		}

		if(this.success()){
			if(this.onComplete)
			setTimeout(this.onComplete.bind(this),10);
		}
	}
});

Ajax.PeriodicalUpdater=Class.create();
Ajax.PeriodicalUpdater.prototype=Object.extend(new Ajax.Base(),{
	initialize:function(c,u,o){
		this.setOptions(o);
		this.onComplete=this.options.onComplete;
		this.frequency=(this.options.frequency||2);
		this.decay=(this.options.decay||1);
		this.updater={};
		this.container=c;
		this.url=u;
		this.start();
	},
	start:function(){
		this.options.onComplete=this.updateComplete.bind(this);
		this.onTimerEvent();
	},
	stop:function(){
		this.updater.options.onComplete=undefined;
		clearTimeout(this.timer);
		(this.onComplete||UJS.EF).apply(this,arguments);
	},
	updateComplete:function(r){
		if(this.options.decay){
			this.decay=(r.responseText==this.lastText?this.decay*this.options.decay:1);
			this.lastText=r.responseText;
		}
		this.timer=setTimeout(this.onTimerEvent.bind(this),
		this.decay*this.frequency*1000);
	},
	onTimerEvent:function(){
		this.updater=new Ajax.Updater(this.container,this.url,this.options);
	}
});


function $(e,s){
	if(arguments.length>1){
		for(var i=0,a=[],l=arguments.length;i<l;i++)
			a.push($(arguments[i]));
		return a;
	}
	if(typeof e=='string')
		e=U.D.getElementById(e);
	return Element.extend(e);
}

function $T(s){
	var c=document.body.getElementsByTagName(s);
	var a=[];
	for(var i=0,l=c.length;i<l;i++){
		a.push(Element.extend(c[i]));
	}
	return a;
}

if(UJS.BF.XPath){
	U.D._getElementsByXPath=function(e,p){
		var r=[];
		var q=U.D.evaluate(e,$(p)||U.D,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
		for(var i=0,l=q.snapshotLength;i<l;i++)
			r.push(q.snapshotItem(i));
		return r;
	};
	U.D.getElementsByClassName=function(c,p){
		var q=".//*[contains(concat(' ',@class,' '),' "+c+" ')]";
		return U.D._getElementsByXPath(q,p);
	}
}else U.D.getElementsByClassName=function(n,p){
	var c=($(p)||document.body).getElementsByTagName('*');
	var a=[],child;
	for(var i=0,l=c.length;i<l;i++){
		d=c[i];
	if(Element.hasClassName(d,n))
		a.push(Element.extend(d));
	}
	return a;
};
var $GC=U.D.getElementsByClassName;

if(!U.W.Element) var Element={};
Element.extend=function(e){
	var F=UJS.BF;
	if(!e||!e.tagName||e.nodeType==3||e._extended||F.SpecificElementExtensions||e==window)
		return e;

	var m={},t=e.tagName,c=Element.extend.cache,
	T=Element.Methods.ByTag;
	if(!F.ElementExtensions){
		Object.extend(m,Element.Methods),
		Object.extend(m,Element.Methods.Simulated);
	}
	if(T[t]) Object.extend(m,T[t]);
	for(var p in m){
		var v=m[p];
		if(typeof v=='function'&&!(p in e))
		e[p]=c.findOrStore(v);
	}
	e._extended=UJS.EF;
	return e;
};
Element.extend.cache={
	findOrStore:function(v){
		return this[v]=this[v]||function(){
			return v.apply(null,[this].concat($A(arguments)));
		}
	}
};
Element.Methods={
	visible:function(e){
		return $(e).style.display!='none';
	},
	toggle:function(e){
		e=$(e);
		Element[Element.visible(e)?'hide':'show'](e);
		return e;
	},
	hide:function(e){
		$(e).style.display='none';
		return e;
	},
	show:function(e,s){
		$(e).style.display=(typeof s=="undefined")?'block':s;
		return e;
	},
	remove:function(e){
		e=$(e);
		e.parentNode.removeChild(e);
		return e;
	},
	update:function(e,h){
		h=typeof h=='undefined'?'':h.toString();
		$(e).innerHTML=h.stripScripts();
		setTimeout(function(){h.evalScripts()},10);
		return e;
	},
	replace:function(e,h){
		e=$(e);
		h=typeof h=='undefined'?'':h.toString();
		if(e.outerHTML){
			e.outerHTML=h.stripScripts();
		}else{
			var r=e.ownerDocument.createRange();
			r.selectNodeContents(e);
			e.parentNode.replaceChild(r.createContextualFragment(h.stripScripts()),e);
		}
		setTimeout(function(){h.evalScripts()},10);
		return e;
	},
	inspect:function(e){
		e=$(e);
		var r='<'+e.tagName.toLowerCase();
		$H({'id':'id','className':'class'}).each(function(t){
			var p=t.first(),a=t.last();
			var value=(element[p]||'').toString();
			if(value) r+=' '+a+'='+value.inspect(true);
		});
		return r+'>';
	},
	recursivelyCollect:function(e,p){
		e=$(e);
		var a=[];
		while(e=e[p])
			if(e.nodeType==1)
				a.push(Element.extend(e));
		return a;
	},
	ancestors:function(e){
		return $(e).recursivelyCollect('parentNode');
	},
	descendants:function(e){
		return $A($(e).getElementsByTagName('*')).each(Element.extend);
	},

	firstDescendant:function(e){
		e=$(e).firstChild;
		while(e&&e.nodeType!=1) e=e.nextSibling;
		return $(e);
	},
	immediateDescendants:function(e){
		if(!(e=$(e).firstChild)) return [];
		while(e&&e.nodeType!=1) e=e.nextSibling;
		if(e) return [e].concat($(e).nextSiblings());
		return [];
	},
	previousSiblings:function(e){
		return $(e).recursivelyCollect('previousSibling');
	},
	nextSiblings:function(e){
		return $(e).recursivelyCollect('nextSibling');
	},
	siblings:function(e){
		e=$(e);
		return e.previousSiblings().reverse().concat(element.nextSiblings());
	},
	match:function(e,s){
		if(typeof s=='string')
			s=new Selector(s);
		return s.match($(e));
	},
	up:function(e,p,k){
		e=$(e);
		if(arguments.length==1) return $(e.parentNode);
		var a=e.ancestors();
		return p?Selector.findElement(a,p,k):a[k||0];
	},
	down:function(e,p,k){
		e=$(e);
		if(arguments.length==1) return e.firstDescendant();
		var d=e.descendants();
		return p?Selector.findElement(d,p,k):d[k||0];
	},
	previous:function(e,p,k){
		e=$(e);
		if(arguments.length==1) return $(Selector.handlers.previousElementSibling(e));
		var s=e.previousSiblings();
		return p?Selector.findElement(s,p,k):s[k||0];
	},
	next:function(e,p,k){
		e=$(e);
		if(arguments.length==1) return $(Selector.handlers.nextElementSibling(e));
		var n=e.nextSiblings();
		return p?Selector.findElement(n,p,k):n[k||0];
	},

	getElementsBySelector:function(){
		var a=$A(arguments),e=$(a.shift());
		return Selector.findChildElements(e,a);
	},

	getElementsByClassName:function(e,c){
		return $GC(c,e);
	},

	readAttribute:function(e,n){
		e=$(e);
		if(UJS.B.IE){
			if(!e.attributes) return null;
			var t=Element._attributeTranslations;
			if(t.values[n]) return t.values[n](e,n);
			if(t.names[n]) n=t.names[n];
			var a=e.attributes[n];
			return a?a.nodeValue:null;
		}
		return e.getAttribute(n);
	},

	getHeight:function(e){
		return $(e).getDimensions().height;
	},

	getWidth:function(e){
		return $(e).getDimensions().width;
	},

	classNames:function(e){
		return new Element.ClassNames(e);
	},

	hasClassName:function(e,c){
		if(!(e=$(e))) return;
		var n=e.className;
		if(n.length==0) return false;
		if(n==c || n.match(new RegExp("(^|\\s)"+c+"(\\s|$)")))
			return true;
		return false;
	},

	addClassName:function(e,c){
		if(!(e=$(e))) return;
		Element.classNames(e).add(c);
		return e;
	},

	removeClassName:function(e,c){
		if(!(e=$(e))) return;
		Element.classNames(e).remove(c);
		return e;
	},

	toggleClassName:function(e,c){
		if(!(e=$(e))) return;
		Element.classNames(e)[e.hasClassName(c)?'remove':'add'](c);
		return e;
	},

	observe:function(){
		Event.observe.apply(Event,arguments);
		return $A(arguments).first();
	},

	stopObserving:function(){
		Event.stopObserving.apply(Event,arguments);
		return $A(arguments).first();
	},

	cleanWhitespace:function(e){
		e=$(e);
		var n=e.firstChild;
		while(n){
			var s=n.nextSibling;
			if(n.nodeType==3&&!/\S/.test(n.nodeValue))
			e.removeChild(n);
			n=s;
		}
		return e;
	},

	empty:function(e){
		return $(e).innerHTML.blank();
	},

	descendantOf:function(e,a){
		e=$(e),a=$(a);
		while(e=e.parentNode)
			if(e==a) return true;
		return false;
	},

	scrollTo:function(e){
		e=$(e);
		var p=Position.cumulativeOffset(e);
		U.W.scrollTo(p[0],p[1]);
		return e;
	},

	getStyle:function(e,s){
		e=$(e);
		s=s=='float'?'cssFloat':s.camelize();
		var v=e.style[s];
		if(!v){
			var c=U.D.defaultView.getComputedStyle(e,null);
			v=c?c[s]:null;
		}
		if(s=='opacity') return v?parseFloat(v):1.0;
		return v=='auto'?null:v;
	},

	getOpacity:function(e){
		return $(e).getStyle('opacity');
	},

	setStyle:function(e,s,c){
		e=$(e);
		var t=e.style;
		for(var p in s)
			if(p=='opacity') e.setOpacity(s[p]);
			else t[(p=='float'||p=='cssFloat')?(t.styleFloat===undefined?'cssFloat':'styleFloat'):(c?p:p.camelize())]=s[p];
		return e;
	},

	setOpacity:function(e,v){
		e=$(e);
		e.style.opacity=(v==1||v==='')?'':(v<0.00001)?0:v;
		return e;
	},

	getDimensions:function(e){
		e=$(e);
		var d=$(e).getStyle('display');
		if(d!='none'&&d!=null)
			return{width:e.offsetWidth,height:e.offsetHeight};
		var s=e.style;
		var v=s.visibility;
		var p=s.position;
		var d=s.display;
		s.visibility='hidden';
		s.position='absolute';
		s.display='block';
		var w=e.clientWidth;
		var h=e.clientHeight;
		s.display=d;
		s.position=p;
		s.visibility=v;
		return{width:w,height:h};
	},

	makePositioned:function(e){
		e=$(e);
		var p=Element.getStyle(e,'position');
		if(p=='static'||!p){
			e._madePositioned=true;
			e.style.position='relative';
			if(U.W.opera){
				e.style.top=0;
				e.style.left=0;
			}
		}
		return e;
	},

	undoPositioned:function(e){
		e=$(e);
		if(e._madePositioned){
			e._madePositioned=undefined;
			e.style.position=e.style.top=e.style.left=e.style.bottom=e.style.right='';
		}
		return e;
	},

	makeClipping:function(e){
		e=$(e);
		if(e._overflow) return e;
		e._overflow=e.style.overflow||'auto';
		if((Element.getStyle(e,'overflow')||'visible')!='hidden')
			e.style.overflow='hidden';
		return e;
	},

	undoClipping:function(e){
		e=$(e);
		if(!e._overflow) return e;
		e.style.overflow=e._overflow=='auto'?'':e._overflow;
		e._overflow=null;
		return e;
	}
};


Object.extend(Element.Methods,{
	dom:function(e){ return e; },
	addDom:function(e,f){ e.appendChild($(f).dom()); },
	ce:function(e,s,c,a,m){
		var o=document.createElement(s);
		o=$(o);
		if(c) o.setStyle(c);
		if(a) for(var p in a) o.setAttribute(p,a[p]);
		e.appendChild(o.dom());
		if(!o.id){ o.id=UJS.DN+(++UJS.DI); }
		if(m) Object.extend(o,m);
		return $(o);
	},
	sh:function(e,s){
		e.innerHTML=s;
	},
	gh:function(e,s){
		return e.innerHTML;
	},
	gc:function(e,c,n){
		if(typeof n=="number") return $GC(c,e)[n];
		return $GC(c,e);
	},
	gt:function(e,s,n){
		var r=[],a=e.getElementsByTagName(s);
		for(var i=0,l=a.length;i<l;i++){
			r.push($(a[i]));
		}
		if(typeof n=="number") return r[n];
		return r;
	},
	setClass:function(e,s){
		e.className=s;
	},
	addClass:function(e,c){
		if(!(e=$(e))) return;
		Element.classNames(e).add(c);
	},
	delClass:function(e,c){
		if(!(e=$(e))) return;
		Element.classNames(e).remove(c);
	},
	repClass:function(e,c,p){
		if(!(e=$(e))) return;
		Element.classNames(e).remove(c);
		Element.classNames(e).add(p);
	},
	setWidth:function(e,s){
		$(e).style.width=s+"px";
	},
	setHeight:function(e,s){
		$(e).style.height=s+"px";
	},
	on:function(e,c){
		var o={};
		for(var p in c){
			Event.observe.apply(Event,[e,p,c[p]]);
			o[p]=$(e);
		}
		return o;
	},
	un:function(e,c){
		for(var p in c){
			$(e).stopObserving(p,c[p]);
		}
	},
	ls:function(e,p,c){
		Event.observe.apply(Event,[e,p,c]);
	},
	h:function(e){
		return $(e).getHeight();
	},
	w:function(e){
		return $(e).getWidth();
	},
	box:function(e,f){
		var o=$(e);
		o.width=parseInt(e.style.width||e.clientWidth||e.offsetWidth,10);
		o.height=parseInt(e.style.height||e.clientHeight||e.offsetHeight,10);
		o.left=parseInt(e.style.left||e.clientLeft||e.offsetLeft,10);
		o.top=parseInt(e.style.top||e.clientTop||e.offsetTop,10);
	},
	drag:function(o,E,C){
		var D=Event.box(E);
		B=$(o);
		B.box();
		B.dragConfig={defaultX:B.left,defaultY:B.top};
		U.D.onmouseup=function(E){
			B.drop(E);
			C&&C();
		};
		U.D.onmousemove=function(E){
			E=E||U.W.event;
			if(UJS.B.IE&&E.button!=1) return (C&&C(),B.drop());
			var mx=B.dragConfig.defaultX+(E.screenX-D.x),my=B.dragConfig.defaultY+(E.screenY-D.y),pr=B.posRange;
			o.style.left=(mx<pr.minX?pr.minX:(mx>pr.maxX?pr.maxX:mx))+"px";
			o.style.top=(my<pr.minY?pr.minY:(my>pr.maxY?pr.maxY:my))+"px";
		};
		U.D.onselectstart=function(){
			return false;
		};
	},
	drop:function(E){
		U.D.onmousemove=U.D.onselectstart=U.D.onmouseup=null;
	},
	posRange:function(){
		return {minX:-20000,maxX:20000,minY:-20000,maxY:20000};
	}
});

Object.extend(String.prototype,{
	len:function(){ return this.replace(/[^\x00-\xff]/g,"--").length; }
});

Object.extend(Element.Methods,{
	childOf:Element.Methods.descendantOf,
	childElements:Element.Methods.immediateDescendants
});

if(UJS.B.Opera){
	Element.Methods._getStyle=Element.Methods.getStyle;
	Element.Methods.getStyle=function(e,s){
		switch(s){
			case 'left':
			case 'top':
			case 'right':
			case 'bottom':
			if(Element._getStyle(e,'position')=='static') return null;
			default:return Element._getStyle(e,s);
		}
	};
}else if(UJS.B.IE){
	Element.Methods.getStyle=function(e,s){
		e=$(e);
		s=(s=='float'||s=='cssFloat')?'styleFloat':s.camelize();
		var v=e.style[s];
		if(!v&&e.currentStyle) v=e.currentStyle[s];
		if(s=='opacity'){
			if(v=(e.getStyle('filter')||'').match(/alpha\(opacity=(.*)\)/))
				if(v[1]) return parseFloat(v[1]) / 100;
			return 1.0;
		}
		if(v=='auto'){
			if((s=='width'||s=='height')&&(e.getStyle('display')!='none'))
				return e['offset'+s.capitalize()]+'px';
			return null;
		}
		return v;
	};

	Element.Methods.setOpacity=function(e,v){
		e=$(e);
		var filter=e.getStyle('filter'),s=e.style;
		if(v==1||v===''){
			s.filter=filter.replace(/alpha\([^\)]*\)/gi,'');
			return e;
		}else if(v<0.00001) v=0;
			s.filter=filter.replace(/alpha\([^\)]*\)/gi,'')+'alpha(opacity='+(v*100)+')';
		return e;
	};

	Element.Methods.update=function(e,h){
		e=$(e);
		h=typeof h=='undefined'?'':h.toString();
		var tagName=e.tagName.toUpperCase();
		if(['THEAD','TBODY','TR','TD'].include(tagName)){
			var d=U.D.createElement('div');
			switch (tagName){
				case 'THEAD':
				case 'TBODY':
					d.innerHTML='<table><tbody>'+h.stripScripts()+'</tbody></table>';
					p=2;
				break;
				case 'TR':
					d.innerHTML='<table><tbody><tr>'+h.stripScripts()+'</tr></tbody></table>';
					p=3;
				break;
				case 'TD':
					d.innerHTML='<table><tbody><tr><td>'+h.stripScripts()+'</td></tr></tbody></table>';
					p=4;
				break;
			}
			$A(e.childNodes).each(function(n){ e.removeChild(n) });
			p.times(function(){ d=d.firstChild });
			$A(d.childNodes).each(function(n){ e.appendChild(n) });
		}else{
			e.innerHTML=h.stripScripts();
		}
		setTimeout(function(){ h.evalScripts() },10);
		return e;
	}
}else if(UJS.B.Gecko){
	Element.Methods.setOpacity=function(e,v){
		e=$(e);
		e.style.opacity=(v==1)?0.999999:
		(v==='')?'':(v<0.00001)?0:v;
		return e;
	};
}

Element._attributeTranslations={
	names:{
		colspan:"colSpan",
		rowspan:"rowSpan",
		valign:"vAlign",
		datetime:"dateTime",
		accesskey:"accessKey",
		tabindex:"tabIndex",
		enctype:"encType",
		maxlength:"maxLength",
		readonly:"readOnly",
		longdesc:"longDesc"
	},
	values:{
		_getAttr:function(e,a){
			return e.getAttribute(a,2);
		},
		_flag:function(e,a){
			return $(e).hasAttribute(a)?a:null;
		},
		style:function(e){
			return e.style.cssText.toLowerCase();
		},
		title:function(e){
			var n=e.getAttributeNode('title');
			return n.specified?n.nodeValue:null;
		}
	}
};

(function(){
	Object.extend(this,{
		href:this._getAttr,
		src:this._getAttr,
		type:this._getAttr,
		disabled:this._flag,
		checked:this._flag,
		readonly:this._flag,
		multiple:this._flag
	});
}).call(Element._attributeTranslations.values);

Element.Methods.Simulated={
	hasAttribute:function(e,a){
		var t=Element._attributeTranslations,n;
		a=t.names[a]||a;
		n=$(e).getAttributeNode(a);
		return n&&n.specified;
	}
};

Element.Methods.ByTag={};

Object.extend(Element,Element.Methods);

if(!UJS.BF.ElementExtensions && U.D.createElement('div').__proto__){
	U.W.HTMLElement={};
	U.W.HTMLElement.prototype=U.D.createElement('div').__proto__;
	UJS.BF.ElementExtensions=true;
}

Element.hasAttribute=function(e,a){
	if(e.hasAttribute) return e.hasAttribute(a);
	return Element.Methods.Simulated.hasAttribute(e,a);
};

Element.addMethods=function(m){
	var F=UJS.BF,T=Element.Methods.ByTag;
	if(!m){
		Object.extend(Form,Form.Methods);
		Object.extend(Form.Element,Form.Element.Methods);
		Object.extend(Element.Methods.ByTag,{
			"FORM":Object.clone(Form.Methods),
			"INPUT":Object.clone(Form.Element.Methods),
			"SELECT":Object.clone(Form.Element.Methods),
			"TEXTAREA":Object.clone(Form.Element.Methods)
		});
	}
	if(arguments.length==2){
		var t=m;
		m=arguments[1];
	}
	if(!t) Object.extend(Element.Methods,m||{});
	else{
		if(t.constructor==Array) t.each(extend);
		else extend(t);
	}

	function extend(t){
		t=t.toUpperCase();
		if(!Element.Methods.ByTag[t])
		Element.Methods.ByTag[t]={};
		Object.extend(Element.Methods.ByTag[t],m);
	}

	function copy(m,d,o){
		o=o||false;
		var c=Element.extend.cache;
		for(var p in m){
			var value=m[p];
			if(!o||!(p in d))
			d[p]=c.findOrStore(value);
		}
	}

	function findDOMClass(t){
		var k;
		var a={
			"OPTGROUP":"OptGroup","TEXTAREA":"TextArea","P":"Paragraph",
			"FIELDSET":"FieldSet","UL":"UList","OL":"OList","DL":"DList",
			"DIR":"Directory","H1":"Heading","H2":"Heading","H3":"Heading",
			"H4":"Heading","H5":"Heading","H6":"Heading","Q":"Quote",
			"INS":"Mod","DEL":"Mod","A":"Anchor","IMG":"Image","CAPTION":
			"TableCaption","COL":"TableCol","COLGROUP":"TableCol","THEAD":
			"TableSection","TFOOT":"TableSection","TBODY":"TableSection","TR":
			"TableRow","TH":"TableCell","TD":"TableCell","FRAMESET":
			"FrameSet","IFRAME":"IFrame"
		};
		if(a[t]) k='HTML'+a[t]+'Element';
		if(U.W[k]) return U.W[k];
		k='HTML'+t+'Element';
		if(U.W[k]) return U.W[k];
		k='HTML'+t.capitalize()+'Element';
		if(U.W[k]) return U.W[k];
		U.W[k]={};
		U.W[k].prototype=U.W.createElement(t).__proto__;
		return U.W[k];
	}

	if(F.ElementExtensions){
		copy(Element.Methods,HTMLElement.prototype);
		copy(Element.Methods.Simulated,HTMLElement.prototype,true);
	}

	if(F.SpecificElementExtensions){
		for(var p in Element.Methods.ByTag){
			var k=findDOMClass(p);
			if(typeof k=="undefined") continue;
			copy(T[p],k.prototype);
		}
	}

	Object.extend(Element,Element.Methods);
	delete Element.ByTag;
};

var Toggle={display:Element.toggle};



Abstract.Insertion=function(a){
	this.adjacency=a;
}

Abstract.Insertion.prototype={
	initialize:function(e,c){
		this.element=$(e);
		this.content=c.stripScripts();
		if(this.adjacency&&this.element.insertAdjacentHTML){
			try{
				this.element.insertAdjacentHTML(this.adjacency,this.content);
			}catch(e){
				var t=this.element.tagName.toUpperCase();
				if(['TBODY','TR'].include(t)){
					this.insertContent(this.contentFromAnonymousTable());
				}else{
					throw e;
				}
			}
		}else{
			this.range=this.element.ownerDocument.createRange();
			if(this.initializeRange) this.initializeRange();
			this.insertContent([this.range.createContextualFragment(this.content)]);
		}
		setTimeout(function(){c.evalScripts()},10);
	},
	contentFromAnonymousTable:function(){
		var d=U.D.createElement('div');
		d.innerHTML='<table><tbody>'+this.content+'</tbody></table>';
		return $A(d.childNodes[0].childNodes[0].childNodes);
	}
};

var Insertion=new Object();

Insertion.Before=Class.create();
Insertion.Before.prototype=Object.extend(new Abstract.Insertion('beforeBegin'),{
	initializeRange:function(){
		this.range.setStartBefore(this.element);
	},
	insertContent:function(f){
		f.each((function(e){
			this.element.parentNode.insertBefore(e,this.element);
		}).bind(this));
	}
});

Insertion.Top=Class.create();
Insertion.Top.prototype=Object.extend(new Abstract.Insertion('afterBegin'),{
	initializeRange:function(){
		this.range.selectNodeContents(this.element);
		this.range.collapse(true);
	},
	insertContent:function(f){
		f.reverse(false).each((function(e){
			this.element.insertBefore(e,this.element.firstChild);
		}).bind(this));
	}
});

Insertion.Bottom=Class.create();
Insertion.Bottom.prototype=Object.extend(new Abstract.Insertion('beforeEnd'),{
	initializeRange:function(){
		this.range.selectNodeContents(this.element);
		this.range.collapse(this.element);
	},
	insertContent:function(f){
		f.each((function(e){
			this.element.appendChild(e);
		}).bind(this));
	}
});

Insertion.After=Class.create();
Insertion.After.prototype=Object.extend(new Abstract.Insertion('afterEnd'),{
	initializeRange:function(){
		this.range.setStartAfter(this.element);
	},

	insertContent:function(f){
		f.each((function(e){
			this.element.parentNode.insertBefore(e,this.element.nextSibling);
		}).bind(this));
	}
});



Element.ClassNames=Class.create();
Element.ClassNames.prototype={
	initialize:function(e){
		this.element=$(e);
	},
	_each:function(a){
		this.element.className.split(/\s+/).select(function(n){
			return n.length>0;
		})._each(a);
	},
	set:function(n){
		this.element.className=n;
	},
	add:function(c){
		if(this.include(c)) return;
		this.set($A(this).concat(c).join(' '));
	},
	remove:function(c){
		if(!this.include(c)) return;
		this.set($A(this).without(c).join(' '));
	},
	toString:function(){
		return $A(this).join(' ');
	}
};

Object.extend(Element.ClassNames.prototype,Enumerable);

var Selector=Class.create();
Selector.prototype={
	initialize:function(e){
		this.expression=e.strip();
		this.compileMatcher();
	},
	compileMatcher:function(){
		if(UJS.BF.XPath&&!(/\[[\w-]*?:/).test(this.expression))
			return this.compileXPathMatcher();
		var e=this.expression,ps=Selector.patterns,h=Selector.handlers,c=Selector.criteria,le,p,m;

		if(Selector._cache[e]){
			this.matcher=Selector._cache[e];return;
		}
		this.matcher=["this.matcher=function(root){","var r=root,h=Selector.handlers,c=false,n;"];
		while(e&&le!=e&&(/\S/).test(e)){
			le=e;
			for(var i in ps){
				p=ps[i];
				if(m=e.match(p)){
					this.matcher.push(typeof c[i]=='function'?c[i](m):
					new Template(c[i]).evaluate(m));
					e=e.replace(m[0],'');
					break;
				}
			}
		}
		this.matcher.push("return h.unique(n);\n}");
		eval(this.matcher.join('\n'));
		Selector._cache[this.expression]=this.matcher;
	},
	compileXPathMatcher:function(){
		var e=this.expression,ps=Selector.patterns,
		x=Selector.xpath,le, m;

		if(Selector._cache[e]){
			this.xpath=Selector._cache[e];return;
		}
		this.matcher=['.//*'];
		while(e&&le!=e&&(/\S/).test(e)){
			le=e;
			for(var i in ps){
				if(m=e.match(ps[i])){
					this.matcher.push(typeof x[i]=='function'?x[i](m):new Template(x[i]).evaluate(m));
					e=e.replace(m[0],'');
					break;
				}
			}
		}
		this.xpath=this.matcher.join('');
		Selector._cache[this.expression]=this.xpath;
	},
	findElements:function(r){
		r=r||U.D;
		if(this.xpath) return U.D._getElementsByXPath(this.xpath,r);
		return this.matcher(r);
	},
	match:function(e){
		return this.findElements(U.D).include(e);
	},
	toString:function(){
		return this.expression;
	},
	inspect:function(){
		return "#<Selector:"+this.expression.inspect()+">";
	}
};

Object.extend(Selector,{
	_cache:{},
	xpath:{
		descendant:"//*",
		child:"/*",
		adjacent:"/following-sibling::*[1]",
		laterSibling:'/following-sibling::*',
		tagName:function(m){
			if(m[1]=='*') return '';
			return "[local-name()='"+m[1].toLowerCase()+"' or local-name()='"+m[1].toUpperCase()+"']";
		},
		className:"[contains(concat(' ',@class,' '),' #{1} ')]",
		id:"[@id='#{1}']",
		attrPresence:"[@#{1}]",
		attr:function(m){
			m[3]=m[5]||m[6];
			return new Template(Selector.xpath.operators[m[2]]).evaluate(m);
		},
		pseudo:function(m){
			var h=Selector.xpath.pseudos[m[1]];
			if(!h) return '';
			if(typeof h==='function') return h(m);
			return new Template(Selector.xpath.pseudos[m[1]]).evaluate(m);
		},
		operators:{
			'=':"[@#{1}='#{3}']",
			'!=':"[@#{1}!='#{3}']",
			'^=':"[starts-with(@#{1},'#{3}')]",
			'$=':"[substring(@#{1},(string-length(@#{1})-string-length('#{3}')+1))='#{3}']",
			'*=':"[contains(@#{1},'#{3}')]",
			'~=':"[contains(concat(' ',@#{1},' '),' #{3} ')]",
			'|=':"[contains(concat('-',@#{1},'-'),'-#{3}-')]"
		},
		pseudos:{
			'first-child':'[not(preceding-sibling::*)]',
			'last-child':'[not(following-sibling::*)]',
			'only-child':'[not(preceding-sibling::* or following-sibling::*)]',
			'empty':"[count(*)=0 and (count(text())=0 or translate(text(),' \t\r\n','')='')]",
			'checked':"[@checked]",
			'disabled':"[@disabled]",
			'enabled':"[not(@disabled)]",
			'not':function(m){
				var e=m[6],p=Selector.patterns,
				x=Selector.xpath,le,m,v;

				var exclusion=[];
				while(e&&le!=e&&(/\S/).test(e)){
					le=e;
					for(var i in p){
						if(m=e.match(p[i])){
							v=typeof x[i]=='function'?x[i](m):new Template(x[i]).evaluate(m);
							exclusion.push("("+v.substring(1,v.length-1)+")");
							e=e.replace(m[0],'');
							break;
						}
					}
				}
				return "[not("+exclusion.join(" and ")+")]";
			},
			'nth-child':function(m){
				return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*)+1) ",m);
			},
			'nth-last-child':function(m){
				return Selector.xpath.pseudos.nth("(count(./following-sibling::*)+1) ",m);
			},
			'nth-of-type':function(m){
				return Selector.xpath.pseudos.nth("position() ",m);
			},
			'nth-last-of-type':function(m){
				return Selector.xpath.pseudos.nth("(last()+1-position()) ",m);
			},
			'first-of-type':function(m){
				m[6]="1";return Selector.xpath.pseudos['nth-of-type'](m);
			},
			'last-of-type':function(m){
				m[6]="1";return Selector.xpath.pseudos['nth-last-of-type'](m);
			},
			'only-of-type':function(m){
				var p=Selector.xpath.pseudos;return p['first-of-type'](m)+p['last-of-type'](m);
			},
			nth:function(f,m){
				var mm,o=m[6],p;
				if(o=='even') formula='2n+0';
				if(o=='odd') formula='2n+1';
				if(mm=o.match(/^(\d+)$/))
				return '['+f+"="+mm[1]+']';
				if(mm=o.match(/^(-?\d*)?n(([+-])(\d+))?/)){
					if(mm[1]=="-") mm[1]=-1;
					var a=mm[1]?Number(mm[1]):1;
					var b=mm[2]?Number(mm[2]):0;
					p="[((#{fragment}-#{b}) mod #{a}=0) and "+
					"((#{fragment}-#{b}) div #{a} >=0)]";
					return new Template(p).evaluate({f:f,a:a,b:b});
				}
			}
		}
	},

	criteria:{
		tagName:'n=h.tagName(n,r,"#{1}",c);c=false;',
		className:'n=h.className(n,r,"#{1}",c);c=false;',
		id:'n=h.id(n,r,"#{1}",c);c=false;',
		attrPresence:'n=h.attrPresence(n,r,"#{1}");c=false;',
		attr:function(m){
			m[3]=(m[5]||m[6]);
			return new Template('n=h.attr(n,r,"#{1}","#{3}","#{2}");c=false;').evaluate(m);
		},
		pseudo:function(m){
			if(m[6]) m[6]=m[6].replace(/"/g,'\\"');
			return new Template('n=h.pseudo(n,"#{1}","#{6}",r,c);c=false;').evaluate(m);
		},
		descendant:'c="descendant";',
		child:'c="child";',
		adjacent:'c="adjacent";',
		laterSibling:'c="laterSibling";'
	},

	patterns:{
		laterSibling:/^\s*~\s*/,
		child:/^\s*>\s*/,
		adjacent:/^\s*\+\s*/,
		descendant:/^\s/,

		tagName:/^\s*(\*|[\w\-]+)(\b|$)?/,
		id:/^#([\w\-\*]+)(\b|$)/,
		className:/^\.([\w\-\*]+)(\b|$)/,
		pseudo:/^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|\s|(?=:))/,
		attrPresence:/^\[([\w]+)\]/,
		attr:/\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\]]*?)\4|([^'"][^\]]*?)))?\]/
	},

	handlers:{
		concat:function(a,b){
			for(var i=0,node;node=b[i];i++)
				a.push(node);
			return a;
		},

		mark:function(a){
			for(var i=0,n;n=a[i];i++)
				n._counted=true;
			return a;
		},

		unmark:function(a){
			for(var i=0,n;n=a[i];i++)
				n._counted=undefined;
			return a;
		},

		index:function(p,r,o){
			p._counted=true;
			if(r){
				for(var a=p.childNodes,i=a.length-1,j=1;i >=0;i--){
					n=a[i];
					if(n.nodeType==1&&(!o||n._counted)) 
						n.nodeIndex=j++;
				}
			}else{
				for(var i=0,j=1,a=p.childNodes;n=a[i];i++)
					if(n.nodeType==1&&(!ofType||n._counted)) 
						n.nodeIndex=j++;
			}
		},

		unique:function(nodes){
			if(nodes.length==0) return nodes;
			var results=[],n;
			for(var i=0,l=nodes.length;i<l;i++)
			if(!(n=nodes[i])._counted){
				n._counted=true;
				results.push(Element.extend(n));
			}
			return Selector.handlers.unmark(results);
		},

		descendant:function(nodes){
			var h=Selector.handlers;
			for(var i=0,results=[],node;node=nodes[i];i++)
			h.concat(results,node.getElementsByTagName('*'));
			return results;
		},

		child:function(nodes){
			var h=Selector.handlers;
			for(var i=0,results=[],node;node=nodes[i];i++){
				for(var j=0,children=[],child;child=node.childNodes[j];j++)
				if(child.nodeType==1&&child.tagName!='!') results.push(child);
			}
			return results;
		},

		adjacent:function(nodes){
			for(var i=0,results=[],node;node=nodes[i];i++){
				var next=this.nextElementSibling(node);
				if(next) results.push(next);
			}
			return results;
		},

		laterSibling:function(nodes){
			var h=Selector.handlers;
			for(var i=0,results=[],node;node=nodes[i];i++)
			h.concat(results,Element.nextSiblings(node));
			return results;
		},

		nextElementSibling:function(node){
			while(node=node.nextSibling)
			if(node.nodeType==1) return node;
			return null;
		},

		previousElementSibling:function(node){
			while(node=node.previousSibling)
			if(node.nodeType==1) return node;
			return null;
		},

		tagName:function(nodes,root,tagName,combinator){
			tagName=tagName.toUpperCase();
			var results=[],h=Selector.handlers;
			if(nodes){
				if(combinator){
					if(combinator=="descendant"){
						for(var i=0,node;node=nodes[i];i++)
						h.concat(results,node.getElementsByTagName(tagName));
						return results;
					}else nodes=this[combinator](nodes);
					if(tagName=="*") return nodes;
				}
				for(var i=0,node;node=nodes[i];i++)
				if(node.tagName.toUpperCase()==tagName) results.push(node);
					return results;
			}else return root.getElementsByTagName(tagName);
		},

		id:function(nodes,root,id,combinator){
			var targetNode=$(id),h=Selector.handlers;
			if(!nodes&&root==document) return targetNode?[targetNode]:[];
			if(nodes){
				if(combinator){
					if(combinator=='child'){
						for(var i=0,node;node=nodes[i];i++)
							if(targetNode.parentNode==node) return [targetNode];
					}else if(combinator=='descendant'){
						for(var i=0,node;node=nodes[i];i++)
							if(Element.descendantOf(targetNode,node)) return [targetNode];
					}else if(combinator=='adjacent'){
						for(var i=0,node;node=nodes[i];i++)
							if(Selector.handlers.previousElementSibling(targetNode)==node)
								return [targetNode];
					}else nodes=h[combinator](nodes);
				}
				for(var i=0,node;node=nodes[i];i++)
					if(node==targetNode) return [targetNode];
				return [];
			}
			return (targetNode&&Element.descendantOf(targetNode,root))?[targetNode]:[];
		},

		className:function(nodes,root,className,combinator){
			if(nodes&&combinator) nodes=this[combinator](nodes);
			return Selector.handlers.byClassName(nodes,root,className);
		},

		byClassName:function(nodes,root,className){
			if(!nodes) nodes=Selector.handlers.descendant([root]);
			var needle=' '+className+' ';
			for(var i=0,results=[],node,nodeClassName;node=nodes[i];i++){
				nodeClassName=node.className;
				if(nodeClassName.length==0) continue;
				if(nodeClassName==className||(' '+nodeClassName+' ').include(needle))
				results.push(node);
			}
			return results;
		},

		attrPresence:function(nodes,root,attr){
			var results=[];
			for(var i=0,node;node=nodes[i];i++)
			if(Element.hasAttribute(node,attr)) results.push(node);
			return results;
		},

		attr:function(nodes,root,attr,value,operator){
			if(!nodes) nodes=root.getElementsByTagName("*");
			var handler=Selector.operators[operator],results=[];
			for(var i=0,node;node=nodes[i];i++){
				var nodeValue=Element.readAttribute(node,attr);
				if(nodeValue===null) continue;
				if(handler(nodeValue,value)) results.push(node);
			}
			return results;
		},

		pseudo:function(nodes,name,value,root,combinator){
			if(nodes&&combinator) nodes=this[combinator](nodes);
			if(!nodes) nodes=root.getElementsByTagName("*");
			return Selector.pseudos[name](nodes,value,root);
		}
	},

	pseudos:{
		'first-child':function(nodes,value,root){
			for(var i=0,results=[],node;node=nodes[i];i++){
				if(Selector.handlers.previousElementSibling(node)) continue;
				results.push(node);
			}
			return results;
		},
		'last-child':function(nodes,value,root){
			for(var i=0,results=[],node;node=nodes[i];i++){
				if(Selector.handlers.nextElementSibling(node)) continue;
				results.push(node);
			}
			return results;
		},
		'only-child':function(nodes,value,root){
			var h=Selector.handlers;
			for(var i=0,results=[],node;node=nodes[i];i++)
				if(!h.previousElementSibling(node)&&!h.nextElementSibling(node))
					results.push(node);
			return results;
		},
		'nth-child':function(nodes,formula,root){
			return Selector.pseudos.nth(nodes,formula,root);
		},
		'nth-last-child':function(nodes,formula,root){
			return Selector.pseudos.nth(nodes,formula,root,true);
		},
		'nth-of-type':function(nodes,formula,root){
			return Selector.pseudos.nth(nodes,formula,root,false,true);
		},
		'nth-last-of-type':function(nodes,formula,root){
			return Selector.pseudos.nth(nodes,formula,root,true,true);
		},
		'first-of-type':function(nodes,formula,root){
			return Selector.pseudos.nth(nodes,"1",root,false,true);
		},
		'last-of-type':function(nodes,formula,root){
			return Selector.pseudos.nth(nodes,"1",root,true,true);
		},
		'only-of-type':function(nodes,formula,root){
			var p=Selector.pseudos;
			return p['last-of-type'](p['first-of-type'](nodes,formula,root),formula,root);
		},

		getIndices:function(a,b,total){
			if(a==0) return b>0?[b]:[];
			return $R(1,total).inject([],function(memo,i){
				if(0==(i-b) % a&&(i-b) / a >=0) memo.push(i);
				return memo;
			});
		},

		nth:function(nodes,formula,root,reverse,ofType){
			if(nodes.length==0) return [];
			if(formula=='even') formula='2n+0';
			if(formula=='odd') formula='2n+1';
			var h=Selector.handlers,results=[],indexed=[],m;
			h.mark(nodes);
			for(var i=0,node;node=nodes[i];i++){
				if(!node.parentNode._counted){
					h.index(node.parentNode,reverse,ofType);
					indexed.push(node.parentNode);
				}
			}
			if(formula.match(/^\d+$/)){
				formula=Number(formula);
				for(var i=0,node;node=nodes[i];i++)
				if(node.nodeIndex==formula) results.push(node);
			}else if(m=formula.match(/^(-?\d*)?n(([+-])(\d+))?/)){
				if(m[1]=="-") m[1]=-1;
				var a=m[1]?Number(m[1]):1;
				var b=m[2]?Number(m[2]):0;
				var indices=Selector.pseudos.getIndices(a,b,nodes.length);
				for(var i=0,node,l=indices.length;node=nodes[i];i++){
					for(var j=0;j<l;j++)
					if(node.nodeIndex==indices[j]) results.push(node);
				}
			}
			h.unmark(nodes);
			h.unmark(indexed);
			return results;
		},

		'empty':function(nodes,value,root){
			for(var i=0,results=[],node;node=nodes[i];i++){
			if(node.tagName=='!'||(node.firstChild&&!node.innerHTML.match(/^\s*$/))) continue;
				results.push(node);
			}
			return results;
		},

		'not':function(nodes,selector,root){
			var h=Selector.handlers,selectorType,m;
			var exclusions=new Selector(selector).findElements(root);
			h.mark(exclusions);
			for(var i=0,results=[],node;node=nodes[i];i++)
				if(!node._counted) results.push(node);
			h.unmark(exclusions);
			return results;
		},

		'enabled':function(nodes,value,root){
			for(var i=0,results=[],node;node=nodes[i];i++)
				if(!node.disabled) results.push(node);
			return results;
		},

		'disabled':function(nodes,value,root){
			for(var i=0,results=[],node;node=nodes[i];i++)
				if(node.disabled) results.push(node);
			return results;
		},

		'checked':function(nodes,value,root){
			for(var i=0,results=[],node;node=nodes[i];i++)
				if(node.checked) results.push(node);
			return results;
		}
	},

	operators:{
		'=':function(nv,v){return nv==v;},
		'!=':function(nv,v){return nv!=v;},
		'^=':function(nv,v){return nv.startsWith(v);},
		'$=':function(nv,v){return nv.endsWith(v);},
		'*=':function(nv,v){return nv.include(v);},
		'~=':function(nv,v){return (' '+nv+' ').include(' '+v+' ');},
		'|=':function(nv,v){return ('-'+nv.toUpperCase()+'-').include('-'+v.toUpperCase()+'-');}
	},

	matchElements:function(elements,expression){
		var matches=new Selector(expression).findElements(),h=Selector.handlers;
		h.mark(matches);
		for(var i=0,results=[],element;element=elements[i];i++)
		if(element._counted) results.push(element);
		h.unmark(matches);
		return results;
	},

	findElement:function(elements,expression,index){
		if(typeof expression=='number'){
			index=expression;expression=false;
		}
		return Selector.matchElements(elements,expression||'*')[index||0];
	},

	findChildElements:function(element,expressions){
		var exprs=expressions.join(','),expressions=[];
		exprs.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/,function(m){
			expressions.push(m[1].strip());
		});
		var results=[],h=Selector.handlers;
		for(var i=0,l=expressions.length,selector;i<l;i++){
			selector=new Selector(expressions[i].strip());
			h.concat(results,selector.findElements(element));
		}
		return (l>1)?h.unique(results):results;
	}
});

function $$(){
	return Selector.findChildElements(U.D,$A(arguments));
}

var Form={
	reset:function(f){
		$(f).reset();
		return f;
	},

	serializeElements:function(a,getHash){
		var d=a.inject({},function(r,e){
			if(!e.disabled&&e.name){
				var k=e.name,v=$(e).getValue();
				if(v!=null){
					if(k in r){
						if(r[k].constructor!=Array) r[k]=[result[k]];
						r[k].push(v);
					} else r[k]=v;
				}
			}
			return r;
		});
		return getHash?d:Hash.toQueryString(d);
	}
};

Form.Methods={
	serialize:function(f,g){
		return Form.serializeElements(Form.getElements(f),g);
	},

	getElements:function(f){
		return $A($(f).getElementsByTagName('*')).inject([],
			function(e,c){
				if(Form.Element.Serializers[c.tagName.toLowerCase()])
				e.push(Element.extend(c));
				return e;
			}
		);
	},

	getInputs:function(f,t,n){
		f=$(f);
		var a=f.getElementsByTagName('input');
		if(!t&&!n) return $A(inputs).map(Element.extend);
		for(var i=0,m=[],l=a.length;i<l;i++){
			var u=a[i];
			if((t&&u.type!=t)||(n&&u.name!=n)) continue;
			m.push(Element.extend(u));
		}
		return m;
	},

	disable:function(f){
		f=$(f);
		Form.getElements(f).invoke('disable');
		return f;
	},

	enable:function(f){
		f=$(f);
		Form.getElements(f).invoke('enable');
		return f;
	},

	findFirstElement:function(f){
		return $(f).getElements().find(function(e){
			return e.type!='hidden'&&!e.disabled&&['input','select','textarea'].include(e.tagName.toLowerCase());
		});
	},

	focusFirstElement:function(f){
		f=$(f);
		f.findFirstElement().activate();
		return f;
	},

	request:function(f,o){
		f=$(f),o=Object.clone(o||{});
		var p=o.parameters;
		o.parameters=f.serialize(true);
		if(p){
			if(typeof p=='string') p=p.toQueryParams();
			Object.extend(o.parameters,p);
		}
		if(f.hasAttribute('method')&&!o.method)
		o.method=f.method;
		return new Ajax.Request(f.readAttribute('action'),o);
	}
}



Form.Element={
	focus:function(e){
		$(e).focus();
		return e;
	},
	select:function(e){
		$(e).select();
		return e;
	}
}

Form.Element.Methods={
	serialize:function(e){
		e=$(e);
		if(!e.disabled&&e.name){
			var v=e.getValue();
			if(v!=undefined){
				var pair={};
				pair[e.name]=v;
				return Hash.toQueryString(pair);
			}
		}
		return '';
	},

	getValue:function(e){
		e=$(e);
		var m=e.tagName.toLowerCase();
		return Form.Element.Serializers[m](e);
	},

	clear:function(e){
		$(e).value='';
		return e;
	},

	present:function(e){
		return $(e).value!='';
	},

	activate:function(e){
		e=$(e);
		try{
			e.focus();
			if(e.select&&(e.tagName.toLowerCase()!='input'||!['button','reset','submit'].include(e.type)))
				e.select();
		}catch(e){}
		return e;
	},

	disable:function(e){
		e=$(e);
		e.blur();
		e.disabled=true;
		return e;
	},

	enable:function(e){
		e=$(e);
		e.disabled=false;
		return e;
	}
}



var Field=Form.Element;
var $F=Form.Element.Methods.getValue;



Form.Element.Serializers={
	input:function(e){
		switch(e.type.toLowerCase()){
			case 'checkbox':
			case 'radio':
				return Form.Element.Serializers.inputSelector(e);
			break;
			default:
				return Form.Element.Serializers.textarea(e);
			break;
		}
	},

	inputSelector:function(e){
		return e.checked?e.value:null;
	},

	textarea:function(e){
		return e.value;
	},

	select:function(e){
		return this[e.type=='select-one'?'selectOne':'selectMany'](e);
	},

	selectOne:function(e){
		var k=e.selectedIndex;
		return k>=0?this.optionValue(e.options[k]):null;
	},

	selectMany:function(e){
		var v,l=e.length;
		if(!l) return null;

		for(var i=0,v=[];i<l;i++){
			var p=e.options[i];
			if(p.selected) v.push(this.optionValue(p));
		}
		return v;
	},

	optionValue:function(o){
		return Element.extend(o).hasAttribute('value')?o.value:o.text;
	}
}



Abstract.TimedObserver=function(){}
Abstract.TimedObserver.prototype={
	initialize:function(e,f,c){
		this.frequency=f;
		this.element=$(e);
		this.callback=c;
		this.lastValue=this.getValue();
		this.registerCallback();
	},

	registerCallback:function(){
		setInterval(this.onTimerEvent.bind(this),this.frequency*1000);
	},

	onTimerEvent:function(){
		var v=this.getValue();
		var c=('string'==typeof this.lastValue&&'string'==typeof v?this.lastValue!=v:String(this.lastValue)!=String(v));
		if(c){
			this.callback(this.element,v);
			this.lastValue=v;
		}
	}
}

Form.Element.Observer=Class.create();
Form.Element.Observer.prototype=Object.extend(new Abstract.TimedObserver(),{
	getValue:function(){
		return Form.Element.getValue(this.element);
	}
});

Form.Observer=Class.create();
Form.Observer.prototype=Object.extend(new Abstract.TimedObserver(),{
	getValue:function(){
		return Form.serialize(this.element);
	}
});



Abstract.EventObserver=function(){}
Abstract.EventObserver.prototype={
	initialize:function(e,c){
		this.element=$(e);
		this.callback=c;
		this.lastValue=this.getValue();
		if(this.element.tagName.toLowerCase()=='form')
			this.registerFormCallbacks();
		else
			this.registerCallback(this.element);
	},

	onElementEvent:function(){
		var v=this.getValue();
		if(this.lastValue!=v){
			this.callback(this.element,v);
			this.lastValue=v;
		}
	},

	registerFormCallbacks:function(){
		Form.getElements(this.element).each(this.registerCallback.bind(this));
	},

	registerCallback:function(element){
		if(element.type){
			switch (element.type.toLowerCase()){
				case 'checkbox':
				case 'radio':
				Event.observe(element,'click',this.onElementEvent.bind(this));
				break;
				default:
				Event.observe(element,'change',this.onElementEvent.bind(this));
				break;
			}
		}
	}
}

Form.Element.EventObserver=Class.create();
Form.Element.EventObserver.prototype=Object.extend(new Abstract.EventObserver(),{
getValue:function(){
	return Form.Element.getValue(this.element);
}
});

Form.EventObserver=Class.create();
Form.EventObserver.prototype=Object.extend(new Abstract.EventObserver(),{
getValue:function(){
	return Form.serialize(this.element);
}
});

if(!U.W.Event){
	var Event=new Object();
}
Object.extend(Event,{
	KEY_BACKSPACE:8,
	KEY_TAB:9,
	KEY_RETURN:13,
	KEY_ESC:27,
	KEY_LEFT:37,
	KEY_UP:38,
	KEY_RIGHT:39,
	KEY_DOWN:40,
	KEY_DELETE:46,
	KEY_HOME:36,
	KEY_END:35,
	KEY_PAGEUP:33,
	KEY_PAGEDOWN:34,

	element:function(e){
		return $(e.target||e.srcElement);
	},

	isLeftClick:function(e){
		return (((e.which)&&(e.which==1))||((e.button)&&(e.button==1)));
	},

	pointerX:function(e){
		return e.pageX||(e.clientX+(U.D.documentElement.scrollLeft||document.body.scrollLeft));
	},

	pointerY:function(e){
		return e.pageY||(e.clientY+(U.D.documentElement.scrollTop||document.body.scrollTop));
	},

	stop:function(e){
		if(e.preventDefault){
			e.preventDefault();
			e.stopPropagation();
		}else{
			e.returnValue=false;
			e.cancelBubble=true;
		}
	},

	findElement:function(e,t){
		var o=Event.element(e);
		while(o.parentNode&&(!o.tagName||(o.tagName.toUpperCase()!=t.toUpperCase())))
		o=o.parentNode;
		return o;
	},

	observers:false,

	_observeAndCache:function(e,n,o,b){
		if(!this.a) this.a=[];
		if(e.addEventListener){
			this.a.push([e,n,o,b]);
			e.addEventListener(n,o,b);
		}else if(e.attachEvent){
			this.a.push([e,n,o,b]);
			e.attachEvent('on'+n,o);
		}
	},

	unloadCache:function(){
		if(!Event.observers) return;
		for(var i=0,l=Event.observers.length;i<l;i++){
			Event.stopObserving.apply(this,Event.observers[i]);
			Event.observers[i][0]=null;
		}
		Event.observers=false;
	},

	observe:function(e,n,o,b){
		e=$(e);
		b=b||false;
		if(n=='keypress'&&(UJS.B.WebKit||e.attachEvent))
			n='keydown';
		Event._observeAndCache(e,n,o,b);
	},

	stopObserving:function(e,n,o,b){
		e=$(e);
		b=b||false;
		if(n=='keypress'&&(UJS.B.WebKit||e.attachEvent))
			n='keydown';
		if(e.removeEventListener){
			e.removeEventListener(n,o,b);
		}else if(e.detachEvent){
			try{
				e.detachEvent('on'+n,o);
			}catch(e){}
		}
	}
});

Object.extend(Event,{
	box:function(e){
		e=e||U.W.event;
		return {x:e.screenX,y:e.screenY,dom:Event.element(e).dom()};
	}
});

var Position={
	includeScrollOffsets:false,

	prepare:function(){
		this.deltaX=U.W.pageXOffset||U.D.documentElement.scrollLeft||document.body.scrollLeft||0;
		this.deltaY=U.W.pageYOffset||U.D.documentElement.scrollTop||document.body.scrollTop||0;
	},

	realOffset:function(element){
		var valueT=0,valueL=0;
		do{
			valueT+=element.scrollTop||0;
			valueL+=element.scrollLeft||0;
			element=element.parentNode;
		} while(element);
		return [valueL,valueT];
	},

	cumulativeOffset:function(element){
		var valueT=0,valueL=0;
		do{
			valueT+=element.offsetTop||0;
			valueL+=element.offsetLeft||0;
			element=element.offsetParent;
		} while(element);
		return [valueL,valueT];
	},

	positionedOffset:function(element){
		var valueT=0,valueL=0;
		do{
			valueT+=element.offsetTop||0;
			valueL+=element.offsetLeft||0;
			element=element.offsetParent;
			if(element){
				if(element.tagName=='BODY') break;
				var p=Element.getStyle(element,'position');
				if(p=='relative'||p=='absolute') break;
			}
		} while(element);
		return [valueL,valueT];
	},

	offsetParent:function(element){
		if(element.offsetParent) return element.offsetParent;
		if(element==document.body) return element;

		while((element=element.parentNode)&&element!=document.body)
			if(Element.getStyle(element,'position')!='static')
				return element;

		return document.body;
	},

	within:function(element,x,y){
		if(this.includeScrollOffsets)
			return this.withinIncludingScrolloffsets(element,x,y);
		this.xcomp=x;
		this.ycomp=y;
		this.offset=this.cumulativeOffset(element);

		return (y >=this.offset[1]&&y< this.offset[1]+element.offsetHeight&&x >=this.offset[0]&&x<this.offset[0]+element.offsetWidth);
	},

	withinIncludingScrolloffsets:function(element,x,y){
		var offsetcache=this.realOffset(element);

		this.xcomp=x+offsetcache[0]-this.deltaX;
		this.ycomp=y+offsetcache[1]-this.deltaY;
		this.offset=this.cumulativeOffset(element);

		return (this.ycomp>=this.offset[1]&&this.ycomp<this.offset[1]+element.offsetHeight&&this.xcomp>=this.offset[0]&&this.xcomp<this.offset[0]+element.offsetWidth);
	},

	overlap:function(mode,element){
		if(!mode) return 0;
		if(mode=='vertical')
			return ((this.offset[1]+element.offsetHeight)-this.ycomp)/element.offsetHeight;
		if(mode=='horizontal')
			return ((this.offset[0]+element.offsetWidth)-this.xcomp)/element.offsetWidth;
	},

	page:function(forElement){
		var valueT=0,valueL=0;

		var element=forElement;
		do{
			valueT+=element.offsetTop ||0;
			valueL+=element.offsetLeft||0;

			if(element.offsetParent==document.body)
			if(Element.getStyle(element,'position')=='absolute') break;

		} while(element=element.offsetParent);

		element=forElement;
		do{
			if(!document.body.opera||element.tagName=='BODY'){
				valueT -=element.scrollTop ||0;
				valueL -=element.scrollLeft||0;
			}
		} while(element=element.parentNode);

		return [valueL,valueT];
	},

	clone:function(source,target){
		var options=Object.extend({
			setLeft:true,
			setTop:true,
			setWidth:true,
			setHeight:true,
			offsetTop:0,
			offsetLeft:0
		},arguments[2]||{})

		source=$(source);
		var p=Position.page(source);

		target=$(target);
		var delta=[0,0];
		var parent=null;
		if(Element.getStyle(target,'position')=='absolute'){
			parent=Position.offsetParent(target);
			delta=Position.page(parent);
		}

		if(parent==document.body){
			delta[0]-=document.body.offsetLeft;
			delta[1]-=document.body.offsetTop;
		}

		if(options.setLeft) target.style.left=(p[0]-delta[0]+options.offsetLeft)+'px';
		if(options.setTop) target.style.top=(p[1]-delta[1]+options.offsetTop)+'px';
		if(options.setWidth) target.style.width=source.offsetWidth+'px';
		if(options.setHeight) target.style.height=source.offsetHeight+'px';
	},

	absolutize:function(element){
		element=$(element);
		if(element.style.position=='absolute') return;
		Position.prepare();

		var offsets=Position.positionedOffset(element);
		var top=offsets[1];
		var left=offsets[0];
		var width=element.clientWidth;
		var height=element.clientHeight;

		element._originalLeft=left-parseFloat(element.style.left ||0);
		element._originalTop=top -parseFloat(element.style.top||0);
		element._originalWidth=element.style.width;
		element._originalHeight=element.style.height;

		element.style.position='absolute';
		element.style.top=top+'px';
		element.style.left=left+'px';
		element.style.width=width+'px';
		element.style.height=height+'px';
	},

	relativize:function(element){
		element=$(element);
		if(element.style.position=='relative') return;
		Position.prepare();

		element.style.position='relative';
		var top=parseFloat(element.style.top ||0)-(element._originalTop||0);
		var left=parseFloat(element.style.left||0)-(element._originalLeft||0);

		element.style.top=top+'px';
		element.style.left=left+'px';
		element.style.height=element._originalHeight;
		element.style.width=element._originalWidth;
	}
}

if(UJS.B.IE) Event.observe(window,'unload',Event.unloadCache,false);

if(UJS.B.WebKit){
	Position.cumulativeOffset=function(element){
		var valueT=0,valueL=0;
		do{
			valueT+=element.offsetTop ||0;
			valueL+=element.offsetLeft||0;
			if(element.offsetParent==document.body)
			if(Element.getStyle(element,'position')=='absolute') break;

			element=element.offsetParent;
		} while(element);
		return [valueL,valueT];
	}
}

Element.addMethods();