function showLoader()
{
	var loader = document.getElementById("loader");
	var controls = document.getElementById("controls");
	var errorStr = document.getElementById("error_str");
	if (loader == null || controls == null || errorStr == null)
		return;
		
	loader.removeAttribute('style');
	controls.setAttribute('style', 'display:none;');
	errorStr.setAttribute('style', 'display:none;');
}
function showError(errorStr)
{
	if (!errorStr) var errorStr = 'File type is incorrect or file is too big';
	var loader = document.getElementById("loader");
	var controls = document.getElementById("controls");
	var errorDiv = document.getElementById("error_str");
	if (loader == null || controls == null || errorDiv == null)
		return;
		
	loader.setAttribute('style', 'display:none;');
	controls.removeAttribute('style');
	errorDiv.removeAttribute('style');
	errorDiv.innerHTML = errorStr;
}
function submitFile()
{
	var ok = true;
	var err = "";
	
	if (ok)
	{
		var fileForm = document.getElementById("file_form");
		var uploadedFile = document.getElementById("uploaded_file");
		if (fileForm == null || uploadedFile == null)
		{
			ok = false;
			err = "There is no form or file field found.";
		}
	}
	
	if (ok)
	{
		var value = uploadedFile.value;
		if (value == null || value == '')
		{
			ok = false;
			err = "No file is selected for download.";
		}
	}
	
	if (ok)
	{
		ext = value.toString().split ( '.' )[value.toString().split ( '.' ).length - 1];
		if (ext != 'txt' && ext != 'db')
		{
			ok = false;
			err = "File type is incorrect.";
		}
	}
	var filename = value.replace(/^.*\\/, '')
	if (ok && checkFileExists(filename))
	{
		var doOverwrite = confirm ("A file with name \""+filename+"\" aready exists in your storage. Would you like to overwrire it?");
		if (!doOverwrite)
		{
			return;
		}
	}
	
	if (ok)
	{
		showLoader();
		fileForm.submit();
	}
	else
	{
		showError(err);
	}
}
function checkFileExists(str)
{
/*
	if (typeof(filesArr) != 'Array')
		return false;
*/
		
	for (var i = 0; i < filesArr.length; i++) {
		var file = filesArr[i];
		if (file == str)
			return true;
	}
	
	return false;
}