/**
 * An autosuggest textbox control.
 * @class
 * @scope public
 */

function AutoSuggestControl(oTextbox /*:HTMLInputElement*/, 
                            oProvider /*:SuggestionProvider*/) {
    
    /**
     * The currently selected suggestions.
     * @scope private
     */   
    this.cur /*:int*/ = -1;

    /**
     * The dropdown list layer.
     * @scope private
     */
    this.layer = null;
    
    /**
     * Suggestion provider for the autosuggest feature.
     * @scope private.
     */
    this.provider /*:SuggestionProvider*/ = oProvider;
    
    /**
     * The textbox to capture.
     * @scope private
     */
    this.textbox /*:HTMLInputElement*/ = oTextbox;
    
    //initialize the control
    this.init();
	
	
    
}

/**
 * Autosuggests one or more suggestions for what the user has typed.
 * If no suggestions are passed in, then no autosuggest occurs.
 * @scope private
 * @param aSuggestions An array of suggestion strings.
 * @param bTypeAhead If the control should provide a type ahead suggestion.
 */
AutoSuggestControl.prototype.autosuggest = function (aSuggestions /*:Array*/,
                                                     bTypeAhead /*:boolean*/) {
	
		//make sure there's at least one suggestion
		if (aSuggestions.length > 0) {
			if (bTypeAhead) {
			   this.typeAhead(aSuggestions[0]);
			}        
			this.showSuggestions(aSuggestions);
			
		} else {
			this.hideSuggestions(); 
		}
	
};


/**
 * Creates the dropdown layer to display multiple suggestions.
 * @scope private
 */
AutoSuggestControl.prototype.createDropDown = function () {
	var oThis = this; 
	var secondNode=null;
	   
	//create the layer and assign styles
	if(!document.getElementById("autoSuggestDiv")) {
		this.layer = document.createElement("div");
		this.layer.className = "suggestions";
		this.layer.id = "autoSuggestDiv";
		this.layer.style.visibility = "hidden";
		this.layer.style.width = this.textbox.offsetWidth;
	} else {
		this.layer = document.getElementById("autoSuggestDiv");
		this.layer.style.visibility = "hidden";
		this.layer.style.width = this.textbox.offsetWidth;
	}
    //when the user clicks on the a suggestion, get the text (innerHTML)
    //and place it into a textbox
    this.layer.onmousedown = 
    this.layer.onmouseup = 
    this.layer.onmouseover = function (oEvent) {
	    oEvent = oEvent || window.event;
        oTarget = oEvent.target || oEvent.srcElement;
        if (oEvent.type == "mousedown")
		{	
			
			var id = ipTxt; // added to get the current text box ID 
			id=id.substring(0,id.lastIndexOf('_'));			
			if(oTarget.firstChild.nodeValue!=noMethodFound &&  oTarget.firstChild.nodeValue!=null)
			{
				secondNode=oTarget.firstChild.nextSibling;
				document.getElementById(ipTxt).value = oTarget.firstChild.nodeValue + secondNode.firstChild.nodeValue + secondNode.nextSibling.nodeValue; 
				selectedContent[selectedContent.length]=document.getElementById(ipTxt).value;
				var toValue=document.getElementById(ipTxt).value;
				var assignTxt=getAirportCode(toValue);
				document.getElementById(id).value=assignTxt;				
				// added above line to handle making bold text changes in showSuggestions()		
				if(id.substring(0,id.length-1)=="shop_from")
				{				
					nextField=id.substring(0,id.lastIndexOf('_')+1)+"to"+ id.substring(id.length-1,id.length)+"_temp";
					setTimeout("document.getElementById(nextField).focus();",1);
				}
				if(oEvent.type == "mousedown") {
					oThis.hideSuggestions();
				} else {
					oThis.highlightSuggestion(oTarget);
				}
			}
			else 
			{
				if (oTarget.firstChild.nodeValue == null && oEvent.type == "mousedown")
				{
					document.getElementById(ipTxt).value = textEntered;
				}
				if(oTarget.firstChild.nodeValue==noMethodFound && oEvent.type == "mousedown")  {					
					document.getElementById(ipTxt).value = textEntered;
					if(id.substring(0,id.length-1)=="shop_from")
					{
						document.getElementById(id).value=document.getElementById(ipTxt).value;
						nextField=id.substring(0,id.lastIndexOf('_')+1)+"to"+ id.substring(id.length-1,id.length)+"_temp";						
						setTimeout("document.getElementById(nextField).focus();",1);
					}
					if(id.substring(0,id.length-1)=="shop_to")
					{
						document.getElementById(id).value=document.getElementById(ipTxt).value;
					}
					oThis.hideSuggestions();
				}				
			}						
        } 
		else if (oEvent.type == "mouseover") 
		{
            oThis.highlightSuggestion(oTarget);
        } else 
		{
            document.getElementById(ipTxt).focus();
        }
	};
    document.body.appendChild(this.layer);	
	if(selectedContent.length>=20)
	{
		selectedContent=[];
	}
};

/**
 * Handles three keydown events.
 * @scope private
 * @param oEvent The event object for the keydown event.
 */
AutoSuggestControl.prototype.handleKeyDown = function (oEvent /*:Event*/) {	
	switch(oEvent.keyCode) {	
        case 38: //up arrow
        	if(document.getElementById('autoSuggestDiv').style.visibility != "hidden"){
        		this.textbox.focus();
        		this.previousSuggestion();
        	}
            break;
        case 40: //down arrow 
        	if(document.getElementById('autoSuggestDiv').style.visibility != "hidden"){
			this.textbox.focus();		
            this.nextSuggestion();	
        	}
            break;
        case 13: //enter	
			var id = this.textbox.id;
			var txtBoxNameOriginal=this.textbox.id;;
			id=id.substring(0,id.lastIndexOf('_'));
			var cSuggestionNodes ="";
			var oNode =null;
			if(this.textbox.value==textEntered && textEntered.length>=3 && document.getElementById('autoSuggestDiv').style.visibility!="hidden"  && isAlpha(textEntered))
				{	
					cSuggestionNodes = this.layer.childNodes;
					if (cSuggestionNodes.length > 0 && this.cur <= cSuggestionNodes.length -1) 
					{	
						if(this.cur == -1)
						{
							this.cur=0;
						}					
						
						oNode = cSuggestionNodes[this.cur];					
						var noMatch = oNode.firstChild.nodeValue;					
						if(noMatch == noMethodFound)
						{
							this.textbox.value=textEntered;								
							this.hideSuggestions();
							if(id.substring(0,id.length-1)=="shop_from")
							{	
								document.getElementById(id).value=this.textbox.value;
								nextField=id.substring(0,id.lastIndexOf('_')+1)+"to"+ id.substring(id.length-1,id.length)+"_temp";
								setTimeout("document.getElementById(nextField).focus();",1);
							}
							if(id.substring(0,id.length-1)=="shop_to")
							{	
								document.getElementById(id).value=this.textbox.value;
							}
							cSuggestionNodes=[];
							oNode.firstChild.nodeValue="";
							//ipTxt="";							
							break;
						}
						if(cSuggestionNodes.length == 1)
						{								
							oNode = cSuggestionNodes[this.cur];
							this.highlightSuggestion(oNode);
							var secondNode=oNode.firstChild.nextSibling;						
							this.textbox.value = oNode.firstChild.nodeValue + secondNode.firstChild.nodeValue + secondNode.nextSibling.nodeValue;
							selectedContent[selectedContent.length]=this.textbox.value;
							var toValue=this.textbox.value;
							var assignTxt=getAirportCode(toValue);
							document.getElementById(id).value=assignTxt;
							assignTxt="";
							this.hideSuggestions();
							curserPosition=0;
							this.cur=0;
							if(id.substring(0,id.length-1)=="shop_from")
							{				
								nextField=id.substring(0,id.lastIndexOf('_')+1)+"to"+ id.substring(id.length-1,id.length)+"_temp";
								setTimeout("document.getElementById(nextField).focus();",1);
							}
							cSuggestionNodes=[];
							oNode.firstChild.nodeValue="";
							secondNode.firstChild.nodeValue="";
							secondNode.nextSibling.nodeValue="";
							//ipTxt="";
							break;
						}
						else if(cSuggestionNodes.length >1)
						{							
							oNode = cSuggestionNodes[this.cur];
							this.highlightSuggestion(oNode);
							var secondNode=oNode.firstChild.nextSibling;						
							this.textbox.value = oNode.firstChild.nodeValue + secondNode.firstChild.nodeValue + secondNode.nextSibling.nodeValue; 
							selectedContent[selectedContent.length]=this.textbox.value;
							var toValue=this.textbox.value;
							var assignTxt=getAirportCode(toValue);
							document.getElementById(id).value=assignTxt;
							assignTxt="";
							this.hideSuggestions();
							curserPosition=0;
							this.cur=0;
							if(id.substring(0,id.length-1)=="shop_from")
							{				
								nextField=id.substring(0,id.lastIndexOf('_')+1)+"to"+ id.substring(id.length-1,id.length)+"_temp";
								setTimeout("document.getElementById(nextField).focus();",1);
							}
							cSuggestionNodes=[];
							oNode.firstChild.nodeValue="";
							secondNode.firstChild.nodeValue="";
							secondNode.nextSibling.nodeValue="";
							//ipTxt="";
							break;
						}
					}						
				}
				
		case 9://tab
			var id = this.textbox.id;
			id=id.substring(0,id.lastIndexOf('_'));			
			var cSuggestionNodes = "";
			var oNode = null;
				if(this.textbox.value==textEntered && textEntered.length>=3 && document.getElementById('autoSuggestDiv').style.visibility!="hidden" && isAlpha(textEntered))
				{
					cSuggestionNodes = this.layer.childNodes;
					if (cSuggestionNodes.length > 0 && this.cur <= cSuggestionNodes.length-1) 
					{	
						if(this.cur == -1)
						{
							this.cur=0;
						}					
						oNode = cSuggestionNodes[this.cur];					
						var noMatch = oNode.firstChild.nodeValue;					
						if(noMatch ==noMethodFound)
						{
							this.textbox.value=textEntered;
							document.getElementById(id).value=this.textbox.value;						
							this.hideSuggestions();
							//ipTxt="";							
							break;
						}
						if(cSuggestionNodes.length == 1 && noMatch !=noMethodFound )
						{	
							oNode = cSuggestionNodes[this.cur];
							this.highlightSuggestion(oNode);
							var secondNode=oNode.firstChild.nextSibling;
							this.textbox.value = oNode.firstChild.nodeValue + secondNode.firstChild.nodeValue + secondNode.nextSibling.nodeValue;
							selectedContent[selectedContent.length]=this.textbox.value;
							var toValue=this.textbox.value;
							var assignTxt=getAirportCode(toValue);
							document.getElementById(id).value=assignTxt;
							assignTxt="";
							this.hideSuggestions();
							curserPosition=0;
							this.cur=0;
							//ipTxt="";
							cSuggestionNodes=[];
							oNode.firstChild.nodeValue="";
							secondNode.firstChild.nodeValue="";
							secondNode.nextSibling.nodeValue="";
							break;
						}
						else if(cSuggestionNodes.length >1)
						{
							oNode = cSuggestionNodes[this.cur];
							this.highlightSuggestion(oNode);
							var secondNode=oNode.firstChild.nextSibling;								
							this.textbox.value = oNode.firstChild.nodeValue + secondNode.firstChild.nodeValue + secondNode.nextSibling.nodeValue; 
							selectedContent[selectedContent.length]=this.textbox.value;
							var toValue=this.textbox.value;
							var assignTxt=getAirportCode(toValue);							
							document.getElementById(id).value=assignTxt;
							assignTxt="";
							this.hideSuggestions();
							curserPosition=0;
							this.cur=0;
							//ipTxt="";
							cSuggestionNodes=[];
							oNode.firstChild.nodeValue="";
							secondNode.firstChild.nodeValue="";
							secondNode.nextSibling.nodeValue="";
							break;
						}
						
					}
				}
				else
				{
					if( document.getElementById('autoSuggestDiv').style.visibility!="hidden"){
						var assignTxt=getAirportCode(this.textbox.value);							
						document.getElementById(id).value=assignTxt;
					}
				}
		case 27://esc
			var id = this.textbox.id;
			id=id.substring(0,id.lastIndexOf('_'));		
			if( document.getElementById('autoSuggestDiv').style.visibility!="hidden" && this.textbox.length>3 && this.textbox.value== textEntered){
				var assignTxt=getAirportCode(this.textbox.value);
				
				if(assignTxt!=""){
					document.getElementById(id).value=assignTxt;
				}
				else
				{
					document.getElementById(id).value=this.textbox.value;
				}
			}
			else
			{
				var assignTxt=getAirportCode(this.textbox.value);							
				if(assignTxt!="")
				{
					document.getElementById(id).value=assignTxt;
				}
				else
				{
					document.getElementById(id).value=this.textbox.value;
				}
			}
			this.hideSuggestions();		
			break;	
	}
	if(selectedContent.length>=20)
	{
		selectedContent=[];
	}
};

/**
 * Handles keyup events.
 * @scope private
 * @param oEvent The event object for the keyup event.
 */
AutoSuggestControl.prototype.handleKeyUp = function (oEvent /*:Event*/) {

	//showSelectsInScreen(); // added this to show the drop down in the screen
    var iKeyCode = oEvent.keyCode;	
	//if(this.textbox.value.length >= 3) {
		//for backspace (8) and delete (46), shows suggestions without typeahead
    	var id = this.textbox.id;
    	id=id.substring(0,id.lastIndexOf('_'));		
		if (iKeyCode == 8 || iKeyCode == 46) {		
			if(this.textbox.value.length < 3) {				
				if(this.textbox.id=="shop_from"+(flightCount-1)+"_temp" ){
					document.getElementById("shop_from"+(flightCount-1)).value=""; 
				}
				if(this.textbox.id=="shop_to"+(flightCount-1)+"_temp"){
					document.getElementById("shop_to"+(flightCount-1)).value=""; 
				}	
				this.hideSuggestions();		
			}
			else {
				document.getElementById(id).value=document.getElementById(this.textbox.id).value;
				this.provider.requestSuggestions(this, false);				
			}
			
		//make sure not to interfere with non-character keys
		} else if (iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode < 46) || (iKeyCode >= 112 && iKeyCode <= 123)) {
			//ignore
		} else {
			//request suggestions from the suggestion provider with typeahead
			document.getElementById(id).value=document.getElementById(this.textbox.id).value;
			this.provider.requestSuggestions(this, true);
		}
	//}
};

/**
 * Hides the suggestion dropdown.
 * @scope private
 */
AutoSuggestControl.prototype.hideSuggestions = function () {
    this.layer.style.visibility = "hidden";
	document.getElementById('iframe').style.display = 'none';
};

/**
 * Highlights the given node in the suggestions dropdown.
 * @scope private
 * @param oSuggestionNode The node representing a suggestion in the dropdown.
 */
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 = "";
        }		
    }	
};

/**
 * Initializes the textbox with event handlers for
 * auto suggest functionality.
 * @scope private
 */
AutoSuggestControl.prototype.init = function () {

    //save a reference to this object
    var oThis = this;
    
    //assign the onkeyup event handler
    this.textbox.onkeyup = function (oEvent) {
    
        //check for the proper location of the event object
        if (!oEvent) {
            oEvent = window.event;
        }    
        
        //call the handleKeyUp() method with the event object
        oThis.handleKeyUp(oEvent);
    };
   
    //assign onkeydown event handler
    this.textbox.onkeydown = function (oEvent) {
        //check for the proper location of the event object
        if (!oEvent) {
            oEvent = window.event;
        }    
        
        //call the handleKeyDown() method with the event object
        oThis.handleKeyDown(oEvent);
    };
    
    //assign onblur event handler (hides suggestions)    
    this.textbox.onblur = function () { 
	
	};
	this.createDropDown();
};	

	  
/**
 * Highlights the next suggestion in the dropdown and
 * places the suggestion into the textbox.
 * @scope private
 */
AutoSuggestControl.prototype.nextSuggestion = function () {	
	var cSuggestionNodes = this.layer.childNodes;
	if (cSuggestionNodes.length > 0 && this.cur < cSuggestionNodes.length-1) 
	{
		var oNode = cSuggestionNodes[++this.cur];
			this.layer.scrollTop=this.layer.childNodes[this.cur].offsetTop - this.layer.childNodes[1].offsetTop;
		this.highlightSuggestion(oNode);
		var secondNode=oNode.firstChild.nextSibling;
		highLightedSuggestion= oNode.firstChild.nodeValue + secondNode.firstChild.nodeValue + secondNode.nextSibling.nodeValue; 
		// added to handle making bold text changes in showSuggestions()
	}
	else
	{
		this.cur=0;
		var oNode = cSuggestionNodes[this.cur];
			this.layer.scrollTop=this.layer.childNodes[this.cur].offsetTop - this.layer.childNodes[1].offsetTop;
		this.highlightSuggestion(oNode);
		if(oNode.firstChild.nodeValue!=noMethodFound)
		{
			var secondNode=oNode.firstChild.nextSibling;
			highLightedSuggestion = oNode.firstChild.nodeValue + secondNode.firstChild.nodeValue + secondNode.nextSibling.nodeValue;
			// added to handle making bold text changes in showSuggestions()		
		}
		else
		{	
			this.textbox.value= textEntered;
			this.hideSuggestions();
			
		}
	}
};

/**
 * Highlights the previous suggestion in the dropdown and
 * places the suggestion into the textbox.
 * @scope private
 */
AutoSuggestControl.prototype.previousSuggestion = function () {
	var cSuggestionNodes = this.layer.childNodes;

	if (cSuggestionNodes.length > 1 && this.cur > 0) {
		var oNode = cSuggestionNodes[--this.cur];
		this.layer.scrollTop=this.layer.childNodes[this.cur].offsetTop - this.layer.childNodes[1].offsetTop;
		this.highlightSuggestion(oNode);
		var secondNode=oNode.firstChild.nextSibling;
		highLightedSuggestion= oNode.firstChild.nodeValue + secondNode.firstChild.nodeValue + secondNode.nextSibling.nodeValue; 
		// added to handle making bold text changes in showSuggestions()
	}
	else
	{
		this.cur = cSuggestionNodes.length-1;
		var oNode = cSuggestionNodes[this.cur];
		this.layer.scrollTop=this.layer.childNodes[this.cur].offsetTop - this.layer.childNodes[1].offsetTop;
		this.highlightSuggestion(oNode);
		if(oNode.firstChild.nodeValue!=noMethodFound)
		{
			var secondNode=oNode.firstChild.nextSibling;
			highLightedSuggestion = oNode.firstChild.nodeValue + secondNode.firstChild.nodeValue + secondNode.nextSibling.nodeValue; 
			// added to handle making bold text changes in showSuggestions()
		}
		else
		{	
			this.textbox.value= textEntered; 
			this.hideSuggestions();
		}	  		
	}
};

/**
 * Selects a range of text in the textbox.
 * @scope public
 * @param iStart The start index (base 0) of the selection.
 * @param iLength The number of characters to select.
 */
AutoSuggestControl.prototype.selectRange = function (iStart /*:int*/, iLength /*:int*/) {

    //use text ranges for Internet Explorer
    if (this.textbox.createTextRange) {
        var oRange = this.textbox.createTextRange(); 
        oRange.moveStart("character", iStart); 
        oRange.moveEnd("character", iLength - this.textbox.value.length);      
        oRange.select();
        
    //use setSelectionRange() for Mozilla
    } else if (this.textbox.setSelectionRange) {
        this.textbox.setSelectionRange(iStart, iLength);
    }     
    //set focus back to the textbox
    this.textbox.focus();      
}; 

/**
 * Builds the suggestion layer contents, moves it into position,
 * and displays the layer.
 * @scope private
 * @param aSuggestions An array of suggestions for the control.
 */
AutoSuggestControl.prototype.showSuggestions = function (aSuggestions /*:Array*/) {
    
	resizeVariable = this.textbox;
	currentObj= this.textbox;
    var oDiv = null;
	var varBold = null;
	var displayTextPosition;
	var initialString = null;
	var middleString = null;
	var finalString = null;
    this.layer.innerHTML = "";  //clear contents of the layer
	this.layer.style.height = "";
	var lengthOfString;
	var noMatchFoundLength=false;
	var comaPosition;
	var hiphenPosition;
	var openBracePosition;
	var closeBracePosition;
	lengthOfString=aSuggestions[0].length;
	firstElementInList=aSuggestions[0];
    for (var i=0; i < aSuggestions.length; i++) 
	{
        oDiv = document.createElement("div");
		varBold = document.createElement("b");
		
		if(aSuggestions[i]!=noMethodFound)
		{
			openBracePosition=(aSuggestions[i].toUpperCase()).lastIndexOf("(");
			closeBracePosition=(aSuggestions[i].toUpperCase()).lastIndexOf(")");
			displayTextPosition = (aSuggestions[i].toUpperCase()).lastIndexOf(textEntered.toUpperCase());	
			if(displayTextPosition>=openBracePosition)
			{
				initialString = aSuggestions[i].substring(0,displayTextPosition);
				middleString =	aSuggestions[i].substring(displayTextPosition,displayTextPosition+textEntered.length);
				finalString =  aSuggestions[i].substring(displayTextPosition + textEntered.length,aSuggestions[i].length);	
			}
			else
			{
				displayTextPosition = (aSuggestions[i].toUpperCase()).indexOf(textEntered.toUpperCase());	
				initialString = aSuggestions[i].substring(0,displayTextPosition);
				middleString =	aSuggestions[i].substring(displayTextPosition,displayTextPosition+textEntered.length);
				finalString =  aSuggestions[i].substring(displayTextPosition + textEntered.length,aSuggestions[i].length);		
				
				comaPosition=(aSuggestions[i].toUpperCase()).indexOf(",");
				hiphenPosition=(aSuggestions[i].toUpperCase()).lastIndexOf("-");
				if(displayTextPosition > comaPosition && displayTextPosition < hiphenPosition)
				{	
					displayTextPosition = (aSuggestions[i].toUpperCase()).lastIndexOf(textEntered.toUpperCase());
					initialString = aSuggestions[i].substring(0,displayTextPosition);
					middleString =	aSuggestions[i].substring(displayTextPosition,displayTextPosition+textEntered.length);
					finalString =  aSuggestions[i].substring(displayTextPosition + textEntered.length,aSuggestions[i].length);	
				}		
			}
			if (aSuggestions[i].length > lengthOfString)
			{				
				lengthOfString = aSuggestions[i].length;
			}			
			oDiv.appendChild(document.createTextNode(initialString));
			varBold.appendChild(document.createTextNode(middleString));	
			oDiv.appendChild(varBold);
			oDiv.appendChild(document.createTextNode(finalString));		
			this.layer.appendChild(oDiv);
		}
		else
		{
			noMatchFoundLength=true;
			oDiv.appendChild(document.createTextNode(aSuggestions[i]));
			this.layer.appendChild(oDiv);
		}
    }
	
	try
	{
		var cSuggestionNodes = this.layer.childNodes;
		this.highlightSuggestion(cSuggestionNodes[0]);
		var secondNode=cSuggestionNodes[0].firstChild.nextSibling;
		highLightedSuggestion =  cSuggestionNodes[0].firstChild.nodeValue + secondNode.firstChild.nodeValue + secondNode.nextSibling.nodeValue; 
	}
	catch(exception){
	}
	
	var layer = document.getElementById('autoSuggestDiv');
	var iframe = document.getElementById('iframe');	
	var tmp=this.getElementPosition(this.textbox)	
	this.layer.style.left = tmp.x + "px";
	if(noMatchFoundLength==true)
	{
		this.layer.style.width = (lengthOfString*6)+50 +"px";		
    }
	else
	{
		this.layer.style.width = (lengthOfString*6)+30 + "px";		
	}	
	
	this.layer.style.top =tmp.y +this.textbox.offsetHeight + "px";	
	iframe.style.left = this.layer.style.left;
	iframe.style.top = this.layer.style.top;
	iframe.style.display = 'block';
	if(i >= 10)	
	{
		var browser=navigator.appName;
		if (browser=="Microsoft Internet Explorer"||browser=="Netscape")
		{
			iframe.style.height ="188px";	
		}
		else
		{
			iframe.style.height ="190px";	
		}
		this.layer.style.height = iframe.style.height;
		iframe.style.width = this.layer.style.width;
	}else
	{		
		if(this.layer.offsetHeight=="21"){
			this.height="19px";
			iframe.style.height = this.layer.style.height;
			iframe.style.width = this.layer.style.width;
		}else
		{
			iframe.style.height = this.layer.offsetHeight;
			this.layer.style.height=this.layer.offsetHeight;
			iframe.style.width = this.layer.style.width;
		}
	}
	divWidth=this.layer.style.width;
	divHeight=this.layer.style.height;
	divTextBoxname=this.textbox.id;	
	this.layer.style.visibility = "visible";	
	};


/**
 * Inserts a suggestion into the textbox, highlighting the 
 * suggested part of the text.
 * @scope private
 * @param sSuggestion The suggestion for the textbox.
 */
AutoSuggestControl.prototype.typeAhead = function (sSuggestion /*:String*/) {

    //check for support of typeahead functionality
    if (this.textbox.createTextRange || this.textbox.setSelectionRange){
        var iLen = this.textbox.value.length; 
        this.textbox.value = sSuggestion; 		
        this.selectRange(iLen, sSuggestion.length);
    }
};

//Gets the left & Top coordinate of the textbox.
AutoSuggestControl.prototype.getElementPosition = function(element) {
    var r = {x: element.offsetLeft, y: element.offsetTop};
    if (element.offsetParent) {
        var tmp = this.getElementPosition(element.offsetParent);
        r.x += tmp.x;
        r.y += tmp.y;
    }
    return r;
};





