function deleteMessage(num) {
	if (confirm(messages.delete_forum_message)) {
		location = 'forum.php?delete=' + num;
		return true;
	}
	else {
		return false;
	}
}

function validatePost(sId) {
	try {
		var oForm = document.forms['comment_' + sId];
		if (oForm.mib.value != '') {
			return false;
		}
		var validator = new FormValidator('comment_' + sId);
		var errBuffer = new StringBuffer();
	}
	catch (e) {
		alert(e);
	}
	var timeNow = new Date();
	var theDate = timeNow.getDate();
	var theMonth = timeNow.getMonth() + 1;
	var theYear = timeNow.getFullYear();
	/*oForm.date.value = theYear + "-" + theMonth + "-" + theDate;*/
	var theHours = timeNow.getHours();
	var theMinutes = timeNow.getMinutes();
	/*oForm.hour.value = theHours + ":" + theMinutes + ":00";*/

	if (validator.isEmpty('title')) {
		errBuffer.append(messages.title_empty + '\n')
	}
	if (errBuffer.toString() != '') {
		alert (errBuffer.toString());
		return false;
	}

	var postContent = oForm.content.value
	postContent = postContent.replace (/(https?:\/\/[\S]{3,})/gi,'<a href="' + '$1' + '" target="_blank">' + "$1" + '</a>');
	postContent = postContent.replace(/\n/gi,' <br />');
	oForm.content.value = postContent;
	return true;
}

function insertAtCursor(myField, myValue) {
/* taken from: http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript */
/*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);
	}
	else {
		myField.value += myValue;
	}
}

focusOnTitle = false;
focusOnArea = true;

function toggleFocus(which) {
	if (which == 'Area') {
		focusOnTitle = false;
		focusOnArea = true;
	}
	else {
		focusOnTitle = true;
		focusOnArea = false;
	}
}


function pasteIcon(sIcon,nId) {
	var oForm = document.forms['comment_' + nId];
	var suffix = (nId == 0)?'_new':nId;
	var titleArea = oForm['title' + suffix];
	var contentArea = oForm['content' + suffix];
	var addTo;
	if (focusOnTitle) {
		addTo = titleArea;
	}
	else {
		addTo = contentArea;
	}

	insertAtCursor(addTo,' |' + sIcon + '| ');
}
