var PathIcon = "images/icons/";
function button_over(eButton,command) {eButton.src = PathIcon + command + '_over.gif';}
function button_out(eButton,command) {eButton.src = PathIcon + command + '.gif';}

function mozWrap(txtarea, lft, rgt) {
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		if (selEnd==1 || selEnd==2) selEnd=selLength;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + lft + s2 + rgt + s3;
	}
	
	function IEWrap(txtarea, lft, rgt) {
		strSelection = document.selection.createRange().text;
		if (strSelection!="") {
		  document.selection.createRange().text = lft + strSelection + rgt;
		} else {
		  txtarea.focus()
		  strSelection = document.selection.createRange().text;
//		  document.selection.createRange().text = strSelection + lft + rgt;
		  txtarea.value = txtarea.value + lft + rgt;
		}
	}
	

	function wrapSelection(txtarea, lft, rgt) {
		if (document.all) {IEWrap(txtarea, lft, rgt);}
		else if (document.getElementById) {mozWrap(txtarea, lft, rgt);}
	}
	function wrapSelectionWithLink(txtarea) {
		var my_link =prompt("Enter URL:","http://"); //mdOpen('Enter URL:','280','150','OK','Cancel','','','','Insert Link','','row');
		if (my_link != null) {
			lft="<a href=\"" + my_link + "\">";
			rgt="</a>";
			wrapSelection(txtarea, lft, rgt);
		}
		return;
	}	
	
		
	function shortCuts(e) {
	  //start autosave
	  if (top && top.toolbar && top.toolbar.autoSaveTimer && !top.toolbar.autoSaveTimerOn) top.toolbar.autoSaveTimer();

	  if (document.all) {
		key=event.keyCode; txtarea=thisForm.T;
		if (key == 1) wrapSelectionWithLink(txtarea);
		if (key == 2) wrapSelection(txtarea,'<strong>','</strong>');
		if (key == 20) wrapSelection(txtarea,'<em>','</em>');
		if (key == 19) postFrame.post(true);
		if (key == 10) postFrame.post(false);
	  }
	  else if (document.getElementById) {
	  	ctrl=e.ctrlKey; shft=e.shiftKey; chr=e.charCode; key=e.keyCode;
	  	if (ctrl) if (shft) if (chr==65) wrapSelectionWithLink(thisForm.postBody);
	  	if (ctrl) if (shft) if (chr==66) wrapSelection(thisForm.postBody,'<strong>','</strong>');
	  	if (ctrl) if (shft) if (chr==84) wrapSelection(thisForm.postBody,'<em>','</em>');
		if (ctrl) if (shft) if (chr==83) postFrame.post(true);
		if (ctrl) if (key==13) postFrame.post(false);
	  }
	  return true;
	}
	
	// set listeners per browser
	//document.onkeypress = shortCuts;


