var sLastControl = "";
var sLastValue= "";
var iNextIndex=0;
var iLastIndex=0;

function ReSetValue(selSelectObject, DisplayObject) {
	msg=selSelectObject.options[selSelectObject.selectedIndex].value
		DisplayObject.value=msg
		return true	
}

/*Resets the last and next index variables to start a new search */
function ResetLastVariable() {
				
			   iNextIndex=0;
			   iLastIndex=0;
			   return true	
	}


/* The following function perfoms a search which only finds matches 
at the beginning of the searched string */
function FindText(TextObject, selSelectObject) {
	msg1= ConvertToUpper(TextObject);

	msg1=msg1.substr(0,msg1.length);
	/* we need to reset these values so the next embedded search will start
	    at the beginning */
	iLastIndex=0;
	iNextIndex=0;
	
	for(i=0; i < (selSelectObject.options.length  ); i++)
	 {
		msg2=selSelectObject.options[i].value;

        sSubString = msg2.substr(0, msg1.length);
	    msg3 =  sSubString.search(msg1); 

	    if (msg3!== -1)
			{ 
			  selSelectObject.options(i).selected = true; 
			  sLastControl=TextObject.name;
			  /*sLastValue=TextObject.value;  */
			  sLastValue=ConvertToUpper(TextObject);
			  
			  i=selSelectObject.options.length;
			} /*IF*/
		
	  } /*FOR*/	
	  
		return true	
}/*END FUNCTION*/


/* This function will find subsequent, embedded occurrances of a string
	The function can be forced to search only at the beginning by adding 
	a % sign to the end of the entry  */
function FindNextText(TextObject, selSelectObject) {
	msg1= ConvertToUpper(TextObject);
	bBegins = -1;
	
	/* See if the user included a % sign at the end of the the string 
	     to force search only at the beginning */
	if (msg1.search("%")!== -1) 
	  {
		bBegins = "0";
		msg1=msg1.substr(0,msg1.length-1);
	  }
	  

	if (sLastControl==TextObject.name) {		
		if (sLastValue==TextObject.value) {
			if (iNextIndex==selSelectObject.options.length  ){
					iNextIndex=0;
				}
			
			 if (iNextIndex==iLastIndex){
				 	iNextIndex=0; 
				} 
					
		} /*IF*/
		else
		  {
		  	   iNextIndex=0;
			   iLastIndex=0
		  }
	  }/*IF*/
	else {
	   iNextIndex=0;
	   iLastIndex=0
	  }
	for(i=iNextIndex; i < (selSelectObject.options.length  ); i++)
	 {
		/* NOTE: this function searches the option text (the text displayed in the list) 
		  instead of the value, although it returns only the value to the text box. This
		  allows you to handle only the value while searching on a description. This can be easly
		  changed to search only the actual value by uncommenting the code assigning msgdesc shown below and 
		  removing the subsequent line. The distinction between text and value gives you a lot of flexibility
		  with regard to how you want your searches to work.
		/* msgDesc=selSelectObject.options[i].value; */
		msgDesc = selSelectObject.options(i).text;
		iLastIndex=i;
		
		/* only look at the beginning of the string if bBegins is true: */
		if (bBegins==0) 
			{
				sSubString = msgDesc.substr(0, msg1.length);
				msg3 =  sSubString.search(msg1); 
			}
		else
			{
				msg3=msgDesc.search(msg1);
			}	
	    if (msg3!== -1)
			{ 
			  selSelectObject.options(i).selected = true; 
			  sLastControl=TextObject.name;
			  /*sLastValue=TextObject.value;  */
			  sLastValue=ConvertToUpper(TextObject);
			  iNextIndex=i+1;
			  i=selSelectObject.options.length;
			} /*IF*/
		
	  } /*FOR*/	
	  
		return true	
}

function RaiseAlert(sText, sSel) 
	{
		ReSetValue(sSel, sText) 
		return true
	}

function ConvertToUpper(sText) 
	{
		retString=sText.value.toUpperCase();
		sText.value = retString;
		return retString
	}