<!--
// Auto-complete searchSuggest "object",methods, and instantiations
function searchSuggest(inputId, vidsDivId, uri){

	var inputBox = document.getElementById(inputId);
    var vidsDiv = document.getElementById(vidsDivId);
    var possibles;
    var current = 0;
    var searchUrl = uri;
    var divTimeout = setTimeout("",0);
    var lastSearchStr = '';    
	var isWorking=false;

	function constructUri(){
        return uri + escape(inputBox.value);
    }
    function hideNow(){
    	vidsDiv.style.visibility='hidden';
    	window.status = 'Done';
    }
	function hideAfterFive(){
		clearTimeout(divTimeout);
		var elementId = vidsDiv.id;
		divTimeout = setTimeout("document.getElementById('"+elementId+"').style.visibility='hidden';",3500);
	}
	function disregardHide(){
		clearTimeout(divTimeout);
	}
	
    function handleHttpResponse() {
      if (http.readyState == 4) {
      	
      	if(http.responseXML.documentElement){
        	response = http.responseXML.documentElement;
      	}
        
        if(response){
        	var curVid="";
        	var overall="";
        	var searchStringUsed;
        	
        	var specialSearches = response.getElementsByTagName('SpecialSearch');
        	var vidTitles = response.getElementsByTagName('PossibleVideo');
        	    
    		if( (vidTitles.length > 0) || (specialSearches.length > 0) ){		
    		//       
            //<PossibleVideo VideoKey="49" ProxyKey="the-title-dvd">
            //    <VideoTitle>The Title</VideoTitle>
            //    <VideoFormat>DVD</VideoFormat>            
            //</PossibleVideo>		
    			var vidUl=document.createElement('ul');
    	
				if(isIE){
					searchStringUsed = response.getElementsByTagName('SearchString')[0].firstChild.text;
				}else{
					searchStringUsed = response.getElementsByTagName('SearchString')[0].firstChild.textContent;
				}
				
				while(vidsDiv.firstChild){
                	vidsDiv.removeChild(vidsDiv.firstChild);
                }
                
                if(specialSearches.length > 0){
                	var specUl = document.createElement('ul');
                    for(var i = 0; i < specialSearches.length; i++){
            			if(isIE){
            				var thisText=specialSearches[i].firstChild.text;
    
            			}else{
            				var thisText=specialSearches[i].firstChild.textContent;
            			}
           				var specUrl=specialSearches[i].getAttribute("Url");
                        var specA = document.createElement('a');
                        specA.href=specUrl;
                        
                        var boldText = thisText;
						var boldElement = document.createElement('b');
						var boldTextNode = document.createTextNode(boldText);
						boldElement.appendChild(boldTextNode);
				
						specA.appendChild(boldElement);
                        
                        var specLi=document.createElement('li');
                        specLi.appendChild(specA);
                        specUl.appendChild(specLi);
                    }
                    vidsDiv.appendChild(specUl);
                }
                
            	for(var i = 0; i < vidTitles.length; i++){
        			if(isIE){
        				var thisTitle=vidTitles[i].firstChild.text;
        				var thisProxy=vidTitles[i].getAttribute("ProxyKey");
        				var thisFormat=vidTitles[i].lastChild.text;
        			}else{
        				var thisTitle=vidTitles[i].firstChild.textContent;
        				var thisProxy=vidTitles[i].getAttribute("ProxyKey");
        				var thisFormat=vidTitles[i].lastChild.textContent;
        			}
                    var vidA = document.createElement('a');
                    vidA.href='http://www.flixville.com/Movies/getDetails/flixProxy/' + thisProxy;
                    
                    var newTextElement = boldedHighlighter(thisTitle,thisFormat,searchStringUsed);
                    
                    vidA.appendChild(newTextElement);
                    var vidLi=document.createElement('li');
                    vidLi.appendChild(vidA);
                    vidUl.appendChild(vidLi);
                }
                
           		vidsDiv.appendChild(vidUl);
           		vidsDiv.style.position='absolute';
           		//vidsDiv.style.left=findPosX(inputBox);
           		//vidsDiv.style.top=findPosY(inputBox) + 22;
           		//vidsDiv.style.top=inputBox.style.top+inputBox.style.height;
           		if(inputBox.style.width > '200px'){
	           		vidsDiv.style.width=inputBox.style.width;
           		}
	           	else{
	           		vidsDiv.style.width='200px';
           		}
           		vidsDiv.style.visibility='visible';
           		
           		// Get all li elems into an array for direct reference
           		possibles = vidsDiv.getElementsByTagName("li");
           		for(var i = 0; i < possibles.length; i++){
					possibles[i].index = i;
				}
           		current = -1;
           		//possibles[current].className = 'searchSuggestSelected';
           		//window.status = possibles[current].firstChild.href;
           		
           		hideAfterFive();
            }//end if( (vidTitles.length > 0) || (specialSearches.length > 0) )
            else{
            	// No videos found to match
            	hideNow();            
            }
        }//end if(response)        
        
        isWorking=false;        
        
      }//end if(http.readyState == 4)
    }//end function handleHttpResponse

    function searchForVids(e) {
    	if(!isWorking && http && inputBox.value.length > 1){
    		if(inputBox.value != lastSearchStr){
	    		var searchStr = inputBox.value;
	        	http.open("GET", searchUrl + escape(searchStr), true);
	        	http.onreadystatechange = handleHttpResponse;
	        	isWorking=true;
	        	lastSearchStr = inputBox.value;
	        	http.send(null);
        	}//end if(inputBox.value != lastSearchStr)
      	}//end if (!isWorking && http)
      	else{
        	hideNow();
      	}
    }//end function updateCityState
    
    function boldedHighlighter(strToHighlight,strFormat,strSearchString){
    	
    	// Establish overall span element to return
		var ret = document.createElement('span');
    	
    	var strRemaining=strToHighlight;
    	var plainText;
    	var plainTextNode;
    	var boldText;
    	var boldElement
    	var boldTextNode;
    	var boldPos;
    	var boldPosEnd=-1;
    	var usedTextPtr;
    	while(strRemaining.length>0){
        	
			boldPos = strRemaining.indexOf('<b>');
			if(boldPos > -1){
			
				// Establish primary normal text node prior to establishing bold
				boldPosEnd = strRemaining.indexOf('</b>');
				
				plainText = strRemaining.substring(0,boldPos);				
				plainTextNode = document.createTextNode(plainText);
				
				// Record our place in the string and append this text
				usedTextPtr = boldPos;
				ret.appendChild(plainTextNode);				
			}
			else{
				// Establish plain text node for entire remaining string
				plainText = strRemaining;
				plainTextNode = document.createTextNode(plainText + " (" + strFormat + ")");
				usedTextPtr = strRemaining.length;
				ret.appendChild(plainTextNode);				
			}
			
			// Create a bold element and append it and its text
			if(boldPosEnd >- 1){
				boldText = strRemaining.substring(boldPos+3,boldPosEnd);
				boldElement = document.createElement('b');
				boldTextNode = document.createTextNode(boldText);
				boldElement.appendChild(boldTextNode);
				
				usedTextPtr = boldPosEnd+3
				
				ret.appendChild(boldElement);
				
				// Sometimes, the final word is bolded, so we have to append the format now.
				if(usedTextPtr == strToHighlight.length-1){
					plainTextNode = document.createTextNode(" (" + strFormat + ")");
					ret.appendChild(plainTextNode);				
				}				
			}
			
			// Regrab our remaining string contents
			strRemaining=strRemaining.substring(usedTextPtr+1);			
			
			// Wipeout our record of used text and bold position.
			boldPosEnd=-1;
			usedTextPtr=0;
		}//end while(strRemaining.length>0)
		
		// return entire span
		return ret;		    	

    }//end boldedHighlighter
    
    function handleKeyPress(e){
    	//clear lingering countdown
       	disregardHide();
       	
		//up arrow
		if(e.keyCode == 38){
	        if(current > 0){
				possibles[current].className = '';
          		current--;
          		possibles[current].className = 'searchSuggestSelected';
          		window.status = possibles[current].firstChild.href;
          		possibles[current].scrollIntoView(false);
        	}
        	if(isIE){
				event.returnValue = false;
			}
			else{
				e.preventDefault();
			}
			hideAfterFive();
		}//end if(e.keyCode == 38)
      	//down arrow
      	else if(e.keyCode == 40){
        	if(current < possibles.length - 1){
				possibles[current].className = '';
				current++;
				possibles[current].className = 'searchSuggestSelected';
          		window.status = possibles[current].firstChild.href;
				possibles[current].scrollIntoView(false);
			}
			if(isIE){
				event.returnValue = false;
			}
			else{
				e.preventDefault();
			}
			hideAfterFive();
		}//end else if(e.keyCode == 40)
		//enter or tab
		else if((e.keyCode == 13 || e.keyCode == 9) && vidsDiv.style.visibility == 'visible'){
			// Enter : Open the link.
			if(e.keyCode == 13){
				if(current > -1){
					window.location = possibles[current].firstChild.href;
					if(isIE){
						event.returnValue = false;
					}
					else{
						e.preventDefault();
					}
				}
			}
			// Tab : highlight first item in the list.
			else{
				current = 0;
				possibles[current].className = 'searchSuggestSelected';
				window.status = possibles[current].firstChild.href;
				if(isIE){
					event.returnValue = false;
				}
				else{
					e.preventDefault();
				}
				hideAfterFive();
			}
		}//end else if((e.keyCode == 13 || e.keyCode == 9) && popup.style.visibility == 'visible')
		//escape
		else if(e.keyCode == 27){
			if(vidsDiv.style.visibility=='visible'){
				hideNow();
				if(isIE){
					event.returnValue = false;
				}
				else{
					e.preventDefault();
				}
			}//end if(vidsDiv.style.visibility=='visible')
		}//end else if(e.keyCode == 27)
		else{
			hideAfterFive();
		}//end else
    }//end handleKeyPress(e)

	addKeyDownListener(inputBox, handleKeyPress);
	addListener(inputBox, 'keyup', searchForVids);
	
	addListener(vidsDiv, 'mouseover', disregardHide);
	addListener(vidsDiv, 'mouseout', hideAfterFive);
	
}//end function searchSuggest()
//-->