﻿var clearUploadsFlag = true;
var UploadComponentID = new Array();
//This function clears the file input fields of
// the r.a.d.upload instance if the clearUploadsFlag flag is set to false
function clearUploads() {
	if (clearUploadsFlag) {
		for (var n = 0; n < UploadComponentID.length; n++) {
			var theRadUploadInstance = window[(UploadComponentID[n])];

			//Clear the file inputs
			var upload = $find(UploadComponentID[n]);
			if (upload != null) {
				var fileInputs = upload.getFileInputs();
				for (var i = 0; i < fileInputs.length; i++) {
					upload.clearFileInputAt(i);
				}
			}
		}
	}
}

//This function changes the original form submit function
// in order to clear the file upload input fields:
function changeOriginalSubmit() {
	var theForm = document.forms[0];
	var originalSubmit = theForm.submit;
	theForm.submit = function () {
		clearUploads();
		this.submit = originalSubmit;
		this.submit();
	}
	if (window.attachEvent) {
		theForm.attachEvent("onsubmit", clearUploads);
	}
	else if (window.addEventListener) {
		theForm.addEventListener("submit", clearUploads, false);
	}
}
