jQuery.iField.registerInputType('tristate',{
	get:function(){
		var value=undefined;
		var src=this.ctl[0].src;
		var i=src.lastIndexOf('/');
		if(i!=-1)
			src=src.substring(i+1);
		if(src==='tristate_true.gif'){
			value=true;
		}else if(src==='tristate_false.gif'){
			value=false;
		}
		return value;
	},
	set:function(value){
		if(typeof(value)!=='boolean')
			value=undefined;
		this.ctl[0].src='../images/tristate_'+(value===undefined?'undefined':value.toString())+'.gif';
		return value;
	},
	onInit:function(){
		var nextState=function(ev){
			var value=ev.target.field.get();
			//Determine the next state, cycling in this order: undefined -> false -> true
			if(value===undefined)
				value=false;
			else if(value==false)
				value=true;
			else
				value=undefined;
			ev.target.field.set(value);
			ev.target.field.fieldChanged();
			return false;
		}
		this.ctl.keydown(function(ev){if(ev.keycode===32)return nextState(ev);});
		//We want two close clicks (interpreted by the system as a double click) to generate two calls to nextState
		//On IE, a double click fires a single click followed by a double, so we call nextState on both.
		//On FireFox, a double click fires two clicks followed by a double, sa calling nextState on click is enough.
		this.ctl.click(nextState);
		if(jQuery.browser.msie)
			this.ctl.dblclick(nextState);
	},
	changeEvents:[]
});