var to_find = "";            // Variable that acts as keyboard buffer
var timeoutID = "";          // Process id for timer (used when stopping the timeout) 
timeoutInterval = 1000;       // Milliseconds. Shorten to cause keyboard buffer to be cleared faster 
var timeoutCtr = 0;          // Initialization of timer count down
var timeoutCtrLimit = 3 ;    // Number of times to allow timer to count down 
                             

function idle(){
  timeoutCtr += 1
  if(timeoutCtr > timeoutCtrLimit){
     to_find="";
     timeoutCtr = 0;
     window.clearInterval(timeoutID);
  }
}

function findMatch(selectBox, txtFind, objEvent) {
 if (txtFind == '' || objEvent.keyCode == 8) {
      return;
 }
 // Stop Timer
 window.clearInterval(timeoutID)
 var c = String.fromCharCode(objEvent.keyCode);
 c = c.toLowerCase(); 
 to_find += c;
 // Reset timer
 timeoutID = window.setInterval("idle()", timeoutInterval);  
 allWords = selectBox.options;
 var posLow = 0;
 var posHigh = selectBox.options.length;
 var foundIt = false;
 var st2 = new String(to_find);
 s2 = st2.toLowerCase();
 while (posLow <= posHigh) { 
      posMid = Math.floor((posLow + posHigh) / 2); 
      s = selectBox.options[posMid].text;
      st = new String(s);
      s = st.toLowerCase();
      if (s.indexOf(s2) == 0) {
           foundIt = true;
           selectBox.selectedIndex = posMid;
           // Highlight the remaining text 
           var typed_string = new String(s2);
           var total_string = new String(s);
           var t = total_string.length - (total_string.length - typed_string.length);
           end_string = total_string.substr(t, total_string.length);
           txtFind.value = s;
           if (end_string != "") {
           	var range = txtFind.createTextRange();
              	range.findText(end_string)
               	range.select();
           }
           break;
      } 
	else {
           if (s2 < s) {
                posHigh = posMid - 1;
           } 
	   else {
                posLow = posMid + 1;
           }
      }
 }

 if (!foundIt) {
      selectBox.selectedIndex = 0;
 }


} 

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

function comment_display(text_area,the_value){
	val_len=the_value.length;
	val_index= the_value.indexOf("|");
	clip_value=the_value.substring((val_index+1),val_len);
	text_area.value=clip_value;
}

