/* SUBMIT BUTTON MUST GO IN BLOCK ELEMENT EG TD DIV

extend the form validation using a validateForm() routine that returns an error if not OK

also requires latest version of global.css */

var submitID= "submit"; // name of submit button to add code to (can be overridden)
var formNumber = 0; // points to first form on page - can change this to access other forms on page
var uploadingDIV = "uploading";

var fb_errors = '';
var SpryValidated = true;
var validateOverride = false; // can be made true by a 'Back' button if needbe...

function startSubmit(e) // e = the event in mozilla
{ 
	if(typeof(validateForm) != "undefined") {
		fb_errors = validateForm();
	}
	if(typeof(Spry.Widget.Form) !="undefined") {
	SpryValidated = Spry.Widget.Form.validate(this);
	}
	if(SpryValidated && fb_errors=='')
	{ 
    if(typeof( document.getElementById(submitID))!="undefined") { 
	document.getElementById(submitID).disabled = true;
	}
	if(typeof( document.getElementById(uploadingDIV))!="undefined") { 
		document.getElementById(uploadingDIV).style.visibility = "visible";
		}
	} else {
		// this code doesn't seem to prevent subit action...
		if(!validateOverride) {
		if (!e) var e = window.event
			// kill submit
		e.cancelBubble = true; e.returnValue = false; // IE

		if (e.stopPropagation) { e.stopPropagation(); e.preventDefault(); } //FF
		alertText ="";
		alertText += (fb_errors) ? fb_errors+"\n" : "";
		alertText += (!SpryValidated) ? "There are highlighted problems on the page.\n\n" : "";
		alert(alertText+"Please review before submitting.");
		} else {
			this.submit(); // submit if overridden
		}
	}
 }
 
 
 function stopSubmit()
 {
	 if (navigator.appVersion.indexOf("MSIE") != -1) {
		 document.execCommand("Stop");
 } else {
		 window.stop();
	 }
	document.getElementById(submitID).disabled = false;
   document.getElementById(uploadingDIV).style.visibility='hidden';
 }
 
 
 function formUploadInit() {
	 // add form uploading HTML after submit button if it exists
	 var submitParent = document.getElementById(submitID).parentNode; 
	 append_HTML = '<span id="uploading"><a href="javascript:void(0);" onclick="stopSubmit(); return false;">Processing. Please wait...</a></span>'; // needs to be span for IE
     submitParent.innerHTML = submitParent.innerHTML + append_HTML;
	 addListener("submit", startSubmit , document.forms[formNumber]); 
 }
 
addListener("load", formUploadInit);
 

