<!--
// taghelp.js
//
// contains functions to "assist" in adding text/tags to text fields
//

function insertAtCursor(myField, myValue) {
//inserts "myValue" at the cursor position of "myField"
//NOTE: overwrites any text currently selected

  //IE supported method
  if (window.document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;

  //MOZILLA/NETSCAPE supported method
  } 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);
    } else {
      myField.value += myValue;
    }//end if
  }//end if
}//end insertAtCursor function

function getSelection(txtBox) {
//returns the selected text of a text field

	txtBox.focus();
	return document.selection.createRange().text;

}//end getSelection function

function insertTag(txtBox, tagName) {
//inserts a simple tag around selected text of a text field
 
	selected = getSelection(txtBox);
  text = "[" + tagName + "]" + selected + "[/" + tagName + "]";
  insertAtCursor(txtBox, text);

}//end addTag function

function insertLink(txtBox) {
//prompts for a url and inserts link tag around selected text of a text field

  var url = prompt("Enter URL: (Remember to include \"http://\" or \"ftp://\"!)", "");

  if((url != null) && (url != "")) {
	  selected = getSelection(txtBox);
    text = "[link=" + url + "]" + selected + "[/link]";
    insertAtCursor(txtBox, text);
	}//end if
}//end addLink function

function openImageSelect(name) {
  window.open("/src/imgselect.php", "imgwin" + name, "toolbar=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=no,width=300,height=400,left=30,top=30");

}//end insertImg function

function insertImg(strNum) {
  if(window.name == "imgwinpost") {
    window.opener.document.postform.postcontent.focus();
	} else {
    window.opener.document.editform.editcontent.focus();
  }//end if
  sel = window.opener.document.selection.createRange();
  sel.text = "[img=" + strNum + "]";
  window.close();
}//end 
-->
