// ==UserScript==
// @name           Tidy Quoted PM
// @namespace      tacticalgamer.com
// @description    Move quoted text to the bottom of reply textarea, and move cursor to beginning of textarea.
// @include		   http://tacticalgamer.com/private.php?do=newpm*
// @include        http://www.tacticalgamer.com/private.php?do=newpm*
// ==/UserScript==
// version 0.1 [6/12/2007 - jmaker ] Initial version


reply = document.getElementById("vB_Editor_001_textarea");

if(reply.value != "")
{
	reply.value = "\n\n\n" + reply.value;
	setCaretPosition(reply, 0);
}
else
	document.getElementById("pmrecips_txt").focus();



// these 2 functions are credited to Vishal Monpara - http://blog.vishalon.net/Post/57.aspx

function doGetCaretPosition (ctrl)
{

	var CaretPos = 0;
	// IE Support
	if (document.selection) {

		ctrl.focus ();
		var Sel = document.selection.createRange ();

		Sel.moveStart ('character', -ctrl.value.length);

		CaretPos = Sel.text.length;
	}
	// Firefox support
	else if (ctrl.selectionStart || ctrl.selectionStart == '0')
		CaretPos = ctrl.selectionStart;

	return (CaretPos);

}

function setCaretPosition(ctrl, pos)
{

	if(ctrl.setSelectionRange)
	{
		ctrl.focus();
		ctrl.setSelectionRange(pos,pos);
	}
	else if (ctrl.createTextRange) {
		var range = ctrl.createTextRange();
		range.collapse(true);
		range.moveEnd('character', pos);
		range.moveStart('character', pos);
		range.select();
	}
}

