
      //Places foucs on the first text box on the form
			function focusOnFirstTextbox() {
			if (document.forms.length > 0) {
			  var inputField = document.forms[0];
			  for (i = 0; i < inputField.length; i++) {
			  //loop through each element until first text box or textarea is found
			    if ((inputField.elements[i].type == "text") || (inputField.elements[i].type == "textarea") || (inputField.elements[i].type.toString().charAt(0) == "s")) {
			      document.forms[0].elements[i].focus(); //Give this control focus
			      break;
							}
						}
				}
			} //function focusOnFirstTextbox

		function insertAtCursor(myField, myValue) {
    //IE support
    if (document.selection) {
      myField.focus();
      sel = document.selection.createRange();
      sel.text = myValue;
    }
    //MOZILLA/NETSCAPE support
    else if (myField.selectionStart || myField.selectionStart == 0) {
      var startPos = myField.selectionStart;
      var endPos = myField.selectionEnd;
      myField.value = myField.value.substring(0, startPos)
      + myValue
      + myField.value.substring(endPos, myField.value.length);
            setCaretPosition(myField,startPos+1);
      } else {
      myField.value += myValue;

      }
      //myField.selectionStart = startPos ;
      //myField.selectionEnd = endPos;

      //setCaretPosition(myField,startPos);
      }
      
            function setCaretPosition(elem, caretPos) { //(elemId, caretPos)
    //var elem = document.getElementById(elemId);

    if(elem != null) {
        if(elem.createTextRange) {
            var range = elem.createTextRange();
            range.move('character', caretPos);
            range.select();
        }
        else {
            if(elem.selectionStart) {
                elem.focus();
                elem.setSelectionRange(caretPos, caretPos);
            }
            else
                elem.focus();
        }
    }
}