	function AutoSuggest(_name,_inp,_ur)
	{
		var _auto_sug = _name != undefined ? _name : 'auto_sug';
		var _input = _inp != undefined ? _inp : 'first_name';
		var _url = _ur != undefined ? _ur : 'firstname.php?json=true&input=';
		var req;
		var _timer;
		var _current='';
		var _pointer;
		var _id=new Array();
		var upto = 1;
		var upli = 0;
		var _input_wide = 40;
		function get_staff(staff_num)
		{
			var _input = document.getElementById('staff_id');
			_input.value = staff_num;
			var _form = document.getElementById('staff_id_form');
			_form.submit();
		}
		function get_that(e)
		{
			e = ( e ) ? e : event;
			var el = e.target || e.srcElement;
			var val = el.value;
			var tit = el.title;
			if(val == tit)
			{
				el.value='';
			}
		}
		function get_this(e)
		{
			e = ( e ) ? e : event;
			var el = e.target || e.srcElement;
			var val = el.value;
			if(val == '')
			{
				var tit = el.title;
				el.value = tit;
			}
			
		}
		function find_input()
		{
			if(document.getElementById(_input))
			{
				var _in = document.getElementById(_input);
				_pointer=_in;
				_in.onfocus = get_that;
				_in.onkeydown = _in_key;
				_in.onkeyup = _in_focus;
				_in.onblur = get_this;
			}
		}
		function _in_focus()
		{
			if(_pointer.value.length > 1)
			{
				if(_pointer.value != _current)
				{
					_current = _pointer.value;
					var __url = _url + _current;
					quickRequest(__url,'GET',catch_check,damn_it);
				}
			} 
		}
		function _in_key(e)
		{
			e = e || window.event;
			switch(e.keyCode)
			{
				case 40:
					_toggle_select_key(1);
					return(e.keyCode);
					break;
				case 13:
					_on_enter_key();
					return(false);
					break;
				case 38:
					_toggle_select_key(-1);
					return(e.keyCode);
					break;
			}
			 
		}
		function catch_check(jsondata)
		{
			if(jsondata.results.length > 0)
			{
				_on_result(jsondata);
			}
		}
		function _on_result(thelist)
		{
			upli=-1;
			var thebod='';
			if(_timer != ''){clearTimeout(_timer);};
			if(!document.getElementById(_auto_sug))
			{
				var thediv=make_thing('div',_auto_sug,'',_auto_sug);
				
				thediv.style.width =( _pointer.offsetWidth - 2) + 'px';
				thebod = document.getElementsByTagName('body')[0];
			}
			else
			{
				var thediv= document.getElementById(_auto_sug);
				thediv.innerHTML='';
			}
			var thex = findPos(_pointer);
			var oury = thex[1] + _pointer.offsetHeight;
			var ourx = thex[0];
			thediv.style.left = ourx + "px";
			thediv.style.top = oury + "px";
			var i=0;
			var _size = thelist.results.length;
			var _ul = make_thing('ul');
			_id=new Array();
			make_clear(thediv,0.95);
			for(i=0; i<_size; i++)
			{
				_id[i] =thelist.results[i].id; 
				var val = thelist.results[i].value;
				var val = thelist.results[i].info;
				var st = val.toLowerCase().indexOf( _current.toLowerCase() );
				var output = val.substring(0,st) + "<strong>" + val.substring(st, st+_current.length) + "</strong>" + val.substring(st+_current.length);
				var _li = make_thing('li','li' + i,'','auto_rest',output);
				_li.onmouseover = _toggle_select;
				_li.onmouseout = _on_blur;
				_li.onclick = _on_click;
				_ul.appendChild(_li);
			}
			if(_size == 10)
			{
				//need to add an extra result link
				var _li = make_thing('li','li' + i,'','auto_rest','<strong>more results</strong>');
				_li.onmouseover = _toggle_select;
				_li.onmouseout = _on_blur;
				_li.onclick = _on_click_more;
				_ul.appendChild(_li);
			}
			thediv.appendChild(_ul);
			if(thebod != '')
			{
				thebod.appendChild(thediv);
			}
			_timer = setTimeout(remove_auto,10000);
			
		}
		
		function remove_auto()
		{
			if(document.getElementById(_auto_sug))
			{
				clearTimeout(_timer);
				fader();
			}
		}
		
		function _toggle_select(e)
		{
			clearTimeout(_timer);
			this.style.cursor = 'pointer';
			window.status = 'Select a Staff Member';
			e = ( e ) ? e : event;
			var el = e.target || e.srcElement;
			if(!el.getAttribute('id'))
			{
				while(!el.getAttribute('id'))
				{
					el= el.parentNode;
					//alert(el.type);
				}
			}
			//need to check its the li or go up a level
			el.setAttribute((ie ? 'className' : 'class'), 'auto_live');
			var id = el.getAttribute('id');
			id = id.substr(2,id.length);
			upli=id;
		}
		
		function _on_blur(e)
		{	
			e = ( e ) ? e : event;
			var el = e.target || e.srcElement;
			//need to move up the tree
			if(!el.getAttribute('id'))
			{
				while(!el.getAttribute('id'))
				{
					el= el.parentNode;
				}
			}
			upli=0;
			this.style.cursor = 'default';
			var id = el.getAttribute('id');
			id = id.substr(2,id.length);
			var _li = document.getElementById('li' + id);
			_li.setAttribute((ie ? 'className' : 'class'), 'auto_rest');
			_timer = setTimeout(remove_auto,5000);
		}
		
		function _toggle_select_key(id)
		{
			clearTimeout(_timer);
			upli += id;
			if(upli >= _id.length)
			{
				upli = _id.length - 1;
			}
			else if(upli < 0)
			{
				upli =0;
			}
			
			var _ul = document.getElementById(_auto_sug);
			var _li = _ul.getElementsByTagName('li');
			window.status = 'Select a Staff Member';
			var i=0;
			var _size = _li.length;
			for(i=0; i<_size; i++)
			{
				if(_li[i].getAttribute('id') == 'li' + upli)
				{
					_li[i].setAttribute((ie ? 'className' : 'class'), 'auto_live');
					_li[i].focus;
				}
				else
				{
					_li[i].setAttribute((ie ? 'className' : 'class'), 'auto_rest');
				}
			}
		}
		
		function _on_enter_key()
		{	
			if(_id[upli] && document.getElementById(_auto_sug))
			{
				get_staff(_id[upli]);
			}
			else
			{
				_on_click_more();
			}
		}
		
		function _on_click(e)
		{
			e = ( e ) ? e : event;
			var el = e.target || e.srcElement;
			if(!el.getAttribute('id'))
			{
				while(!el.getAttribute('id'))
				{
					el= el.parentNode;
				}
			}
			var id = el.getAttribute('id');
			id = id.substr(2,id.length);
			get_staff(_id[id]);
		}
		
		function _on_click_more()
		{
			//alert('on_click_1 called');
			var val1=document.getElementById("first_name").value;
			var val2=document.getElementById("surname").value;
			//var 
			var _form = document.getElementById('ajax_form');
			//alert(val1 + ' ' + val2 + ' ' + _form);
			var inn = document.createElement('input');
			inn.name = 'first_name';
			inn.type='hidden';
			inn.value=val1;
			_form.appendChild(inn);
			var inn2 = document.createElement('input');
			inn2.name= 'surname';
			inn2.type='hidden';
			inn2.value=val2;
			_form.appendChild(inn2);
			_form.submit();
		}
		
		
		function quickRequest(_url,_meth,_do,_dam)
		{
			var meth = _meth;
			if (window.XMLHttpRequest)
			{
				req = new XMLHttpRequest();
				req.onreadystatechange = function () { dealWithIt(_do,_dam) };
				req.open(meth, _url, true); //
				req.send(null);
			}
			else if (window.ActiveXObject)
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
				if (req)
				{
					req.onreadystatechange = function () { dealWithIt(_do,_dam) };
					req.open(meth, _url, true);
					req.send();
				}
			}
		}
		function dealWithIt(_do,_dam)
		{
			if (req.readyState == 4) 
			{
				if (req.status == 200)
				{
		
					var jsondata = eval('(' + req.responseText + ')');
					_do(jsondata);
				} 
				else 
				{
					var info="Ajax Error : " + req.status;
					_dam(info);
				}
			}
		}
		
		
		
		function damn_it(info)
		{
			//say nothing once live
			//alert(info);
		}
		
		
		/**
		  *makes a new thing
		  *_thing is the object you want to make
		  *_id sets an id
		  *_name sets name
		  *_class sets the class(note it requires the ie var(ask trev))
		  *probably could be made better with an array(key value)
		  */
		function make_thing(_thing,_id,_name,_class,_htm)
		{
			_thing = document.createElement(_thing);
			if(_class != '' && _class != null)
			{
				_thing.setAttribute(ie ? 'className' : 'class',_class);
			}
			if(_name != '' && _name != null)
			{
				_thing.setAttribute('name',_name);
			}
			if(_id != '' && _id != null)
			{
				_thing.setAttribute('id',_id);
			}
			if(_htm != '' && _htm != null)
			{
				_thing.innerHTML=_htm;
			}
			return(_thing);
		}
		
		function make_clear(thething,opa)
		{
			if (ie) // internet explorer
			{
				var ieupto = opa * 100;//ie does this in 100's so X 100
				try
				{
					thething.filters.item("DXImageTransform.Microsoft.Alpha").opacity = ieupto;
				} catch (e) { 
					// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet. 
					thething.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + ieupto + ')';
				}
			}
			else // other browsers
			{
				thething.style.opacity = opa;
			}
		}
		function fader()
		{
			if(document.getElementById(_auto_sug))
			{
				upto -= 0.1;//reduce the opacity setting
				var _li1 = document.getElementById(_auto_sug);//grab the new
				make_clear(_li1,upto);
				if(upto <= 0.3)//that should be enough
				{
					clearTimeout(_timer);//stop it from going again
					upto=1;//reset upto(opacity)
					var apop= document.getElementById(_auto_sug);
					apop.parentNode.removeChild(apop);
				}
				else
				{
					_timer = setTimeout(fader, 30);//do that again
				}
			}
		}
		function findPos(obj) 
		{
			var curleft = curtop = 0;
			if (obj.offsetParent) {
				curleft = obj.offsetLeft
				curtop = obj.offsetTop
				while (obj = obj.offsetParent) {
					curleft += obj.offsetLeft
					curtop += obj.offsetTop
				}
			}
			return [curleft,curtop];
		}
		
		find_input();
	}
	