focusedFormControl = '';

    if (document.getElementsByTagName) onload = function () {
      var e, i = 0;
      while (e = document.getElementsByTagName ('INPUT')[i++]) {
        if (e.type == 'text') e.onfocus = function () {focusedFormControl = this}
      }
      
      i = 0;
    }
	
function insertChar(x) {
      c = String.fromCharCode(x);
      
      if ( focusedFormControl ) {
        //IE support
        if (document.selection) {
          focusedFormControl.focus();
          sel = document.selection.createRange();
          sel.text = c;
        }
        
        //MOZILLA/NETSCAPE support
        else if (focusedFormControl.selectionStart || focusedFormControl.selectionStart == '0') {
          var startPos = focusedFormControl.selectionStart;
          var endPos = focusedFormControl.selectionEnd;
          focusedFormControl.value = focusedFormControl.value.substring(0, startPos)
          + c
          + focusedFormControl.value.substring(endPos, focusedFormControl.value.length);
        }
        
        else {
          focusedFormControl.value += c;
        }
      }
	  
	  else {
	    alert("Select a text box to insert special characters.");
	  }
    }
	