
  function close()
   {
	//this.layer.style.visibility = "hidden";
	document.getElementById("layer").style.visibility='hidden'; 
  }
		
			// AutoSuggest Control Class 
			
			
			function AutoSuggestControl(oTextbox, oProvider) {
				this.cur = -1;
				this.layer = null;
				this.provider = oProvider;
				this.textbox = oTextbox;
				this.init();
				
			};
			
			// initialise this object and assign it to the textbox
			// that we are going to put the information into.
			AutoSuggestControl.prototype.init = function () {
				var oThis = this;
				
				this.textbox.onkeyup = function (oEvent) {
					if (!oEvent) oEvent = window.event;
					oThis.handleKeyUp(oEvent);
				    //oThis.layer.scrollTop=0;	
				};
				
				this.textbox.onkeydown = function (oEvent) {
					if (!oEvent) oEvent = window.event;
					oThis.handleKeyDown(oEvent);
					//oThis.layer.scrollTop=0;
				};
				
				this.textbox.onblur = function () {
			    if((oThis.textbox.value=="")||(oThis.textbox.value==null)){
			        oThis.textbox.value="»ò¼òÆ´";
			      }
			     oThis.hideSuggestions();
				};
				
				this.textbox.onmouseover = function () {
			     oThis.textbox.focus();
			  	  
				};
				
       this.textbox.onfocus = function () {
			     oThis.textbox.select();
			  	  
				};
				
			  this.textbox.onclick = function () {
			  if (oThis.textbox.value=="»ò¼òÆ´") {
			      oThis.textbox.value="";
			  	  }
				};	

				
				
				this.textbox.onchange = function () {
		          if((oThis.textbox.value=="")||(oThis.textbox.value==null)){
			            oThis.hideSuggestions();
		           }
		      
	             };
				
				this.createDropDown();
			};
				
			// select the range of added information in the text box
			AutoSuggestControl.prototype.selectRange = function (iStart, iLength) {
				if (this.textbox.createTextRange) { // internet explorer
					var oRange = this.textbox.createTextRange();
					oRange.moveStart("character", iStart);
					oRange.moveEnd("character", iLength - this.textbox.value.length);
					oRange.select();
				} else if (this.textbox.setSelectionRange) { // mozilla
					this.textbox.setSelectionRange(iStart, iLength);
				}
				this.textbox.focus();
			};
			
			// add suggestions in only if selectRange is supported by the browser
			// by typing ahead the first of the suggestions and changing it as
			// they type in more of the possibility
			AutoSuggestControl.prototype.typeAhead = function (sSuggestion) {
				if (this.textbox.createTextRange || this.textbox.setSelectionRange) {
					var iLen = this.textbox.value.length;
					this.textbox.value = sSuggestion;
					this.selectRange(iLen, sSuggestion.length);
				}
			};
			
			// the method which triggers the type ahead and hence selectRange
			// methods - this is called by the provider with the returned suggestions
			AutoSuggestControl.prototype.autosuggest = function (aSuggestions, bTypeAhead) {
				if (aSuggestions.length > 0) {
					if (bTypeAhead) {
						this.typeAhead(aSuggestions[0]);
					}
                    this.cur=0;
					this.showSuggestions(aSuggestions);
				} else {
					this.hideSuggestions();
				}
			};
			// handling key presses on the textbox this is attached to
			// make sure they are within the range of normal characters
			// (assuming that people are typing in English only
			AutoSuggestControl.prototype.handleKeyUp = function (oEvent) {
				var iKeyCode = oEvent.keyCode;
			  					
				if (iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode <= 46) || (iKeyCode >= 112 && iKeyCode <= 123)) {
					//ignore
				} else {
					this.provider.requestSuggestions(this);
				}
			  
			   if (iKeyCode == 8 || iKeyCode == 46 || iKeyCode == 13)
			   {
			        if((this.textbox.value=="")||(this.textbox.value==null))
			          this.hideSuggestions();
			       else
				     this.provider.requestSuggestions(this, false);
		      }
		      
		      
		      
				
			 };
					
			// hide the suggestions dropdown box
			AutoSuggestControl.prototype.hideSuggestions = function () {
				this.layer.style.visibility = "hidden";
			};
			
			// select the suggestion they have highlighted
			AutoSuggestControl.prototype.highlightSuggestion = function (oSuggestionNode) {
				for (var i=0; i < this.layer.childNodes.length; i++) {
					var oNode = this.layer.childNodes[i];
					if (oNode == oSuggestionNode) 
					{
					  oNode.className = "current";
								 
					} else if (oNode.className == "current") {
						oNode.className = "";
					}
				}
			};
			
			// create the dropdown suggest box below the textbox
			AutoSuggestControl.prototype.createDropDown = function () {
				this.layer = document.createElement("div");
				this.layer.className = "suggestions";
				this.layer.style.visibility = "hidden";
				this.layer.style.overflow = "auto";
				this.layer.style.zIndex='99';
				this.layer.style.width = this.textbox.offsetWidth+80;
				this.layer.style.height = 200;
				this.layer.style.id = "layer";
				document.body.appendChild(this.layer);
				this.layer.onblur = function () {
					oThis.hideSuggestions();
				};
				// now to assign the event handlers (keyboard presses are handled separately)
				var oThis = this;
				this.layer.onmousedown = this.layer.onmouseup =
				this.layer.onmouseover = function (oEvent) {
					oEvent = oEvent || window.event;
					oTarget = oEvent.target || oEvent.srcElement;
					if (oEvent.type == "mousedown") {
							if(oTarget.firstChild.nodeValue==null)return;
							oThis.textbox.value = oTarget.firstChild.nodeValue.substring(0,6);
							//this.hideSuggestions();
					} else if (oEvent.type == "mouseover") {
							//alert(oTarget.firstChild.value);
							if(oTarget.firstChild.nodeValue==null)return;
							oThis.highlightSuggestion(oTarget);
					} else {
							if(oTarget.firstChild.nodeValue==null)return;
							oThis.textbox.focus();
					}
				};
			};
			
			// find out where the left hand side of the element is
			AutoSuggestControl.prototype.getLeft = function () {
				var oNode = this.textbox;
				var iLeft = 0;
				while(oNode.tagName != "BODY") {
					iLeft += oNode.offsetLeft+10;
					oNode = oNode.offsetParent;
				}
				return iLeft;
			};
			
			// find out where the top of the element is
			AutoSuggestControl.prototype.getTop = function () {
				var oNode = this.textbox;
				var iTop = 0;
				while(oNode.tagName != "BODY") {
					iTop += oNode.offsetTop+15;
					oNode = oNode.offsetParent;
				}
				return iTop;
			};
			
			// populate the dropdown box with the suggestions
			AutoSuggestControl.prototype.showSuggestions = function (aSuggestions) {
				var oDiv = null;
//this.layer.innerHTML = "<div><TABLE style=\"BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid\" cellSpacing=0 cellPadding=0 bgColor=#cfdef4 border=0><TBODY><TR> </TD> <TD style=\"FONT-WEIGHT: normal; FONT-SIZE: 12px; BACKGROUND-IMAGE: url(msgTopBg.gif); COLOR: #1f336b; PADDING-TOP: 4px;PADDING-left: 4px\" vAlign=center width=\"90%\"> </TD> <TD style=\"BACKGROUND-IMAGE: url(close.jpg); PADDING-TOP: 2px;PADDING-right:2px\" vAlign=center align=right width=19 height=18><span title=¹Ø±Õ style=\"CURSOR:hand;color:red;font-size:12px;font-weight:bold;margin-right:4px;\" onclick=closeDiv() ></span></TD></TR> </TBODY> </TABLE> </div>";
				this.layer.innerHTML = "";
				for (var i=0; i < aSuggestions.length; i++) {
					oDiv = document.createElement("div");
					oDiv.appendChild(document.createTextNode(aSuggestions[i]));
					this.layer.appendChild(oDiv);
				}
				
				oDiv = document.createElement("<div onclick='closeDiv()' title='¹Ø±Õ'/>"); 
				this.layer.appendChild(document.createTextNode(""));
				this.layer.appendChild(oDiv);
				
				this.layer.style.left = this.getLeft()-50 + "px";
				this.layer.style.top = (this.getTop()+this.textbox.offsetHeight-75) + "px";
				this.layer.style.visibility = "visible";
				
			};
			
			// highlight the next suggestion
			AutoSuggestControl.prototype.nextSuggestion = function () {
				var cSuggestionNodes = this.layer.childNodes;
				if (cSuggestionNodes.length > 0 && this.cur < cSuggestionNodes.length-3) {
					var oNode = cSuggestionNodes[++this.cur];
					this.highlightSuggestion(oNode);
					this.textbox.value = oNode.firstChild.nodeValue.substring(0,6);
					this.layer.scrollTop=this.cur*20;
				 }			 
				 
			};
			
			// highlight the previous suggestion
			AutoSuggestControl.prototype.previousSuggestion = function () {
				var cSuggestionNodes = this.layer.childNodes;
				if (cSuggestionNodes.length > 0 && this.cur > 0) {
					var oNode = cSuggestionNodes[--this.cur];
					this.highlightSuggestion(oNode);
					this.textbox.value = oNode.firstChild.nodeValue.substring(0,6);
					this.layer.scrollTop=this.cur*20;
				}
				
			};
			
			// handle when a user pushes a key down for up, down and enter buttons
			AutoSuggestControl.prototype.handleKeyDown = function (oEvent) {
					switch(oEvent.keyCode) {
							case 38: //up arrow
									this.previousSuggestion();
									break;
							case 40: //down arrow
									this.nextSuggestion();
									//alert(this.layer.scrollTop);
									break;
							case 13: //enter
									this.hideSuggestions();
									break;
					}
			};
			
			
		
