var pop_window = null;
			
function winpop(page, name, x, y) {
	var this_x = (screen.width) ? (screen.width - x) / 2  : 100;
	var this_y = (screen.height) ? (screen.height - y) / 2  : 100;
	var options = "width=" + x + ",height=" + y + ",top=" + this_y + ",left=" + this_x + "," + "scrollbars=yes" + ",location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	pop_window = window.open(page, name, options);
	pop_window.focus();
}

function addcode(addcode) {
	field = document.parent.content;
	
	code = addcode;
	if (document.selection) {
		field.focus();
		sel = document.selection.createRange();
		sel.text = code;
	} else if (field.selectionStart || field.selectionStart == '0') {
		var startPos = field.selectionStart;
		var endPos = field.selectionEnd;
		field.value = field.value.substring(0, startPos)
		+ code
		+ field.value.substring(endPos, field.value.length);
	} else {
		field.value += code;
	}
}

function codeformat(value, type) {
	form = document.parent;
	
	addcode('[' + type + '=' + value + '][/' + type + ']');
	
	form.formatsize.selectedIndex = 0;
	form.formatfont.selectedIndex = 0;
	form.formatcolour.selectedIndex = 0;
}

function codeformatsingle(value, type) {
	form = document.parent;
	
	addcode('[' + type + '=' + value + ']');
	
	form.formatsize.selectedIndex = 0;
	form.formatfont.selectedIndex = 0;
	form.formatcolour.selectedIndex = 0;
}

function validate_length(element, valid_length) {
	
	our_element = document.getElementById(element);
	our_length = our_element.value.length;
	
	if (our_length < valid_length) {
		our_element.style.borderColor = '#f00';
	} else {
		our_element.style.borderColor = '#000';
	}
}

function validate(type) {
	
	if (type == 1) {
		if (document.parent.title.value == "") {
			alert("You must enter a title.");
			document.parent.title.focus();
			return false;
		}
	}
	if (document.parent.content.value == "") {
		alert("You must enter some content.");
		document.parent.content.focus();
		return false;
	}
	return true;
}

function ask_delete(url, message) {
	switch (message) {
		case 1:
			the_message = 'Are you sure?';
			break;
		case 2:
			the_message = 'Do you really want to delete this message?';
			break;
		case 3:
			the_message = 'Are you sure? This will delete all posts in this topic, too.';
			break;
	}
	
	if (confirm(the_message)) {
		window.location.href = url;
	}
}