		var formCount = 0;
		var submitTimers = new Array();
		function addFile(f) {
			if(document.createElement) {
				//alert(AIM);
				try{//alert("Starting");
				formCount++;
				//get the div to which the file upload will be added
				var master_div = document.getElementById("formDiv");
				
				//create a new div
				var div = document.createElement("div");
				div.setAttribute("id","file_div_" + formCount);
				
				//create a new form
				
				//set the form's properties
				if(BrowserDetect.browser == "Explorer") {
					var form = document.createElement('<form id="form' + formCount + '" action="upload.php" method="post" enctype="multipart/form-data" onsubmit="return AIM.submit(this, {\'onStart\' : startCallback(this), \'onComplete\' : completeCallback})">');
					
				}
				else {
					var form = document.createElement("form");
					form.setAttribute("action","upload.php");
					//form.setAttribute("target","uploadFrame");
					form.setAttribute("method","post");
					form.setAttribute("enctype", "multipart/form-data");
					form.setAttribute("id","form" + formCount);
					//form.onsubmit = new Function("","alert('it workd');return ");
				}
				//create the file form element
				var file = document.createElement("input");
				file.setAttribute("size","20");
				file.setAttribute("id","uploadFile" + formCount);
				file.setAttribute("name","uploadFile");
				file.setAttribute("type","file");
				form.appendChild(file);
				
				var button = document.createElement("input");
				button.setAttribute("type","button");
				button.value = "Upload";
				button.onclick = function() {startFileFind(formCount)};
				
				form.appendChild(button);
				//add a hidden field
				/*var hidden = document.createElement("input");
				//hidden.setAttribute("size","20");
				//hidden.setAttribute("id","sessionid" + formCount);
				hidden.setAttribute("name","sessionid");
				hidden.setAttribute("value",sessid);
				hidden.setAttribute("type","hidden");
				form.appendChild(hidden);*/
				
				
				//append the div to the master div
				div.appendChild(form);
				//alert(div.innerHTML);
				master_div.appendChild(div);
				//alert(master_div);
				}
				catch(e) {
					alert(e.toString());
				}

			}
			else {
				alert("Your browser does not support this function.");
			}
		}	
		
		function startFileFind(id) {
		
			//alert(id);
			f = document.getElementById("form" + id);
			var elem = document.getElementById('uploadFile' + id);
			//alert(elem);
			if(elem) {
				if(elem.value) {
					//submit the form
					showGlass();
					AIM.submit(f, {'onStart' : startCallback(f), 'onComplete' : completeCallback})
					f.submit();
					
				}
				else {
					//alert(submitTimers);
					//if(typeof(submitTimers[id]) == "undefined") {
					if(!submitTimers[id]) {
						//alert('settingTimers');
						//run this function again in 5 milliseconds
						submitTimers[id] = setTimeout("startFileFind(" + id + ")",5);
					}
					
				}
				
				
			}
		}
		function startCallback(f) {
			// make something useful before submit (onStart)
			
		}

		function completeCallback(response) {
			//alert(sessid);
			//hide the smoked glass
			hideGlass();
			//remove the form
			var form = document.getElementById("form" + formCount);
			if(form) {
				form.style.display = "none";	
			}
			document.getElementById("submit_files_list").innerHTML = "";
			//remove the iframe
			
			//show the waiting img
			document.getElementById("waitingFileDiv").style.display = "block";
			//alert("File Uploaded");
			//now use ajax to get a listing of all the files uploaded so far
			var queryString = "getFiles=true";
			
			var ajax = makeAjax();
			ajax.setFunctionAfter("afterFilesListed");
			ajax.getXML(queryString);
		}
		function afterFilesListed(theHTML) {
			
			document.getElementById("submit_files_list").innerHTML = theHTML;
			document.getElementById("waitingFileDiv").style.display = "none";
		}
		
		function deleteFile(id) {
			if(confirm("Are you sure you want to remove this file?")) {
				document.getElementById("submit_files_list").innerHTML = "";
			
				//show the waiting img
				document.getElementById("waitingFileDiv").style.display = "block";
				var ajax = makeAjax();
				ajax.setFunctionAfter("afterFilesListed");
				var queryString = "deleteFile=true&id=" + id;
				ajax.getXML(queryString);
			}
			
		}
		
		function makeAjax() {
			var ajax = new ajaxObj();
			ajax.setProcessing("process2.php");
			ajax.setReturnType(true);	//returns html instead of xml
			//ajax.debug = true;
			return ajax;
		}

	function showSearchForm(elem) {
		var etop = findPosY(elem);
		var eleft = findPosX(elem);
		//alert(etop + ", " + eleft);
		var div = document.getElementById("meetSearchFormDiv");
		div.style.position = "absolute";
		div.style.top = etop + "px";
		div.style.left = eleft + "px";
		div.style.width = "200px";
		div.style.height = "200px";
		div.style.display = "block";
		div.style.zIndex = "10";
	}
	function doMeetSearch(f) {
		if(f.meetStartDate.value) {
			var ajax = makeAjax();
			ajax.setFunctionAfter("afterMeetFound");
			ajax.setProcessing("findmeets.php");
			var queryString = "domeetsearch=true&startdate=" + encodeURI(f.meetStartDate.value)
			ajax.getXML(queryString);
		}
	}
	function afterMeetFound(theHTML) {
		var div = document.getElementById("searchResults");
		div.innerHTML = theHTML;
	}	
	
	function setMeet(name,start,end,sanction) {
		//alert(sanction);
		var f = document.submitform;
		f.meetname.value = name;
		f.start.value = start;
		f.end.value = end;
		f.sanction.value = sanction;
		hideSearchDiv();
	}
	
	function hideSearchDiv() {
		var div = document.getElementById("meetSearchFormDiv");
		div.style.display="none";
	}
	
	function saveSubmission(f) {
		var buttonSpan = document.getElementById("submitButtonSpan");
		buttonSpan.style.display = "none";
		var waitingSpan = document.getElementById("submitWaiting");
		waitingSpan.style.display = "inline";
		
		//check for that the fields are set
		var ajax = makeAjax();
		ajax.xmlreturntype = false;  //return xml for this part.
		ajax.setFunctionAfter("afterSaveSubmission");
		var queryString = ajax.makeQuery(f);
		queryString += "saveResults=true";
		//ajax.debug = true;
		ajax.getXML(queryString);
	}
	function afterSaveSubmission(theXML) {
		var ajax = new ajaxObj();
		//check for errors
		var errors = ajax.checkXMLError(theXML);
		if(errors.length) {
			var errmsg = errors.join("\n");
			alert(errmsg);
		}
		else {
			//then check if the file check failed
			var missing = theXML.getElementsByTagName("missing_file");
			if(missing.length) {
				//the submitted files appears to have a missing file
				//display the message and if the user confirms the that s/he has entered
				//all the files s/he can, then resubmit the form, but send a no check variable as well
				if(confirm(missing[0].firstChild.data)) {
					var f = document.submitform;
					f.nocheck.value = "true";
					saveSubmission(f);
					return;
				}
			}
			//and if not, then reload the page
			else {
				alert("The meet has been saved.");
				window.location.reload();
			}
		}
		
		var buttonSpan = document.getElementById("submitButtonSpan");
		buttonSpan.style.display = "inline";
		var waitingSpan = document.getElementById("submitWaiting");
		waitingSpan.style.display = "none";
		
	}
