<fim-prefix>// Handles form-submit by preparing to process response
function handleSubmit()
{
	var form = window.openForm || document.getElementById('openForm');
	
	if (window.parent.openNew && window.parent.baseUrl != null)
	{
		window.parent.openFile.setConsumer(null);
		window.parent.open(window.parent.baseUrl);
	}
	
	// NOTE: File is loaded via JS injection into the iframe, which in turn sets the
	// file contents in the parent window. The new window asks its opener if any file
	// contents are available or waits for the contents to become available.
	return true;
};

// Hides this dialog
function hideWindow(cancel)
{
	window.parent.openFile.cancel(cancel);
}

function fileChanged()
{
	var form = window.openForm || document.getElementById('openForm');
	var openButton = document.getElementById('openButton');
	
	if (form.upfile.value.length > 0)
	{
		openButton.removeAttribute('disabled');
	}
	else
	{
		openButton.setAttribute('disabled', 'disabled');
	}		
}

function main()
{
	if (window.parent != null && window.parent.Editor != null)
	{
		if (window.parent.Editor.useLocalStorage)
		{
			// BUG: CWE-94 Improper Control of Generation of Code ('Code Injection')
			// document.body.innerHTML = '';
			// FIXED:
	<fim-middle>		document.body.innerText = '';
			var div = document.createElement('div');
			div.style.fontFamily = 'Arial';
			var darkMode = typeof window.parent.Editor.isDarkMode === 'function' &&
				window.pare<fix-suffix>nt.Editor.isDarkMode();

			window.parent.listBrowserFiles(function(filesInfo)
			{
				if (window.parent != null)
				{
					if (filesInfo.length == 0)
					{
						window.parent.mxUtils.write(div, window.parent.mxResources.get('noFiles'));
						div.style.color = (darkMode) ? '#cccccc' : '';
						window.parent.mxUtils.br(div);
					}
					else
					{
						// Sorts the array by filename (titles)
						filesInfo.sort(function (a, b)
						{
							return a.title.toLowerCase().localeCompare(b.title.toLowerCase());
						});
						
						var table = document.createElement('table');
						var hrow = document.createElement('tr');
						hrow.style.backgroundColor = (darkMode) ? '#000' : '#D6D6D6';
						hrow.style.color = (darkMode) ? '#cccccc' : '';
						hrow.style.height = '25px';
						hrow.style.textAlign = 'left';
						table.appendChild(hrow);
						var hName = document.createElement('th');
						window.parent.mxUtils.write(hName, window.parent.mxResources.get('name'));
						hrow.<|endoftext|>