/* Must go after spry widget js but nothing else needed to add to page

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 fb_errors = '';
var SpryValidated = true;

function startSubmit(e) // e = the event in mozilla
{
	if(typeof(validateForm) != "undefined") {
		fb_errors = validateForm();
	}
	if(typeof(Spry) !="undefined") {
	SpryValidated = Spry.Widget.Form.validate(this);
	}
	if(SpryValidated && fb_errors=='')
	{ 
    if(typeof( document.getElementById(submitID))!="undefined") { 
	document.getElementById('submit').disabled = true;
	}
	if(typeof( document.getElementById("uploading"))!="undefined") { 
		document.getElementById("uploading").style.visibility = "visible";
		}
	} else {
		// this code doesn't seem to prevent subit action...
		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 errors on the page.\n\n" : "";
		alert(alertText+"Please correct before submitting.");
	}
 }
 
 
 function stopSubmit()
 {
	 if (navigator.appVersion.indexOf("MSIE") != -1) {
		 document.execCommand("Stop");
 } else {
		 window.stop();
	 }
	document.getElementById(submitID).disabled = false;
   document.getElementById('uploading').style.visibility='hidden';
 }
 
 
 function formUploadInit() {
	 // add form uploading HTML after submit button if it exists
	 var submitParent = document.getElementById(submitID).parentNode; 
	 append_HTML = '<div id="uploading"><a href="javascript:void(0);" onclick="stopSubmit(); return false;">Processing. Please wait...</a></div>';
     submitParent.innerHTML = submitParent.innerHTML + append_HTML;
	 addListener("submit", startSubmit , document.forms[formNumber]); 
 }
 
addListener("load", formUploadInit);
 
