// Written by Ian Henderson in 2005.  Copy and modify freely, as long as this line is present and unmodified.

function uploadNeedsMore(element)
{
	var uploadTarget = document.getElementById(element);
	if (!uploadTarget) {
		return false;
	}
	if (uploadTarget.nodeName != "textarea" && uploadTarget.nodeName != "TEXTAREA") {
		return false;
	}
	return true;
}

function uploadClicked(element, path, type, more)
{
	var uploadTarget = document.getElementById(element);
	if (!uploadTarget) {
		return;
	}
	var re = new RegExp(" ","g");
	path = path.replace(re, "%20");
	if (uploadTarget.nodeName == "textarea" || uploadTarget.nodeName == "TEXTAREA") {
		var stringToInsert = "";
		if (type == "image") {
			stringToInsert = "![" + more + "](" + path + ")";
		} else if (type == "file") {
			stringToInsert = "[Download " + more + "](" + path + ")";
		}
		uploadTarget.value += stringToInsert;
	} else {
		uploadTarget.value = path;
	}
}

function uploadsWindow(elementId)
{
	var uploadsWindow = window.open("uploads.php?elementId="+elementId, "UploadedFiles", 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=250,height=400');
	if (!uploadsWindow.opener) {
		uploadsWindow.opener = self;
	}
	return false;
}
