// comment.js

function storeCaret (textEl) {
	if (textEl.createTextRange) 
		textEl.caretPos = document.selection.createRange().duplicate();
}

function insertComment(textE1, username) {
	var begin = '-----On ';
	var end = ' wrote:\n\n';
	var today = Date();
	var text = begin + getFormattedDate() + ', ' + username + end;
	insertAtCaret(textE1, text);
}

function insertAtCaret (textEl, text) {
	if (textEl.createTextRange && textEl.caretPos) {
		var caretPos = textEl.caretPos;
		caretPos.text =
		caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
			text + ' ' : text;
	} else
		textEl.value  = textEl.value + '\n\n' + text;
}

function getFormattedDate() {
var months=new Array(12);
months[0]="January";
months[1]="February";
months[2]="March";
months[3]="April";
months[4]="May";
months[5]="June";
months[6]="July";
months[7]="August";
months[8]="September";
months[9]="October";
months[10]="November";
months[11]="December";
var days = new Array(7);
days[0]="Sunday";
days[1]="Monday";
days[2]="Tuesday";
days[3]="Wednesday";
days[4]="Thursday";
days[5]="Friday";
days[6]="Saturday";

var time=new Date();
var lmonth=months[time.getMonth()];
var date=time.getDate();
var year=time.getYear();
var lday=days[time.getDay()];
if (year < 2000)    // Y2K Fix, Isaac Powell
year = year + 1900; // http://onyx.idbsu.edu/~ipowell
var formattedDate = lday + " " + lmonth + " " + date + ", " + year + " at " + formatNumber(time.getHours()) + ":" + formatNumber(time.getMinutes()) + ":" + formatNumber(time.getSeconds());
return formattedDate;
}

function formatNumber(number) {
	if (number <= 9)
		return "0" + number;
	else
		return number; 
}

function selectWindow(url, title) {
	window.open(url, title, 'left=20,top=20,width=750,height=680,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1');
}

function selectChildWindow(url, title, parent) {
	url = url + "&parent=" + parent
	window.open(url, title, 'left=20,top=20,width=750,height=680,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1');
}

function linkWindow(url, title) {
	window.open(url, title, 'left=20,top=20,width=750,height=400,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1');
}

function helpWindow(url, title) {
	window.open(url, title, 'left=20,top=20,width=750,height=500,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1');
}
