var browseElementId;
var browseWindow;
var browseCallback;

/**
 * Browse for a file using FCKEditors file browser
 * 
 * elementId: ID of input element to receive the file name
 * fileType: Type of file to browse for. Default = 'Image'.
 * callback: (Optional). Function to invoke when file is picked. Takes one parameter, URL.
 */
function browseFile(elementId, fileType, callback) {
	browseElementId = elementId;
	browseCallback = callback;

	if (fileType == null)
		fileType = 'Image';

	var fileManagerPath = '/fckeditor/editor/filemanager/';
	var url = fileManagerPath + 'browser/default/browser.html?' +
				'Type=' + fileType +
				'&Connector=' + fileManagerPath + 'connectors/aspx/connector.aspx';

	var width = screen.width * 0.7;
	width = 600;
	var height = screen.height * 0.7;
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;

	var options = "toolbar=no,status=no,resizable=yes,dependent=yes";
	options += ",width=" + width;
	options += ",height=" + height;
	options += ",left=" + left;
	options += ",top=" + top;

	browseWindow = window.open(url, "BrowseWindow", options);
}

/*
function SetUrl(url, width, height, alt) {
	document.getElementById(browseElementId).value = url;
	browseWindow = null;
	if (browseCallback != null)
		browseCallback(url);
}
*/

function SetUrl(url, width, height, alt) {
	var browseElement = document.getElementById(browseElementId);
	if(browseElement!=null)
		browseElement.value = url;
	browseWindow = null;
	if (browseCallback != null)
		browseCallback(url);
}
