

//<button>'s dont work too well in IE6
//if multiple buttons are in one form, it sends all buttons, as if they have all been click
//this function loops thru all buttons, and sets them to the same name 'submitButton'
//when clicked, they get their original name back, and only that button is sent with the form. BRILLIANT!

//also, if the class 'ignoreLock' is on the button, it sets a variable, which means it doesn't display the 'Working thing later

var ignoreLock = false;

function buttons_ie6() {

	$$('button').each(function(el) {

		var origName = el.name;

		el.name = 'submitButton';

		el.observe('click', function() {
			
			this.name = origName;

			ignoreLock = (el.className.indexOf('ignoreLock') > -1);

		});

	})

}


initAdd(buttons_ie6);






//because anything with target="_blank" does not validate, grr. So just apply class="extLink" and this will do the job.
function external_links_hack() {

	$$('.extLink').each(function(el) {

		el.target = "_blank";

	});

}

initAdd(external_links_hack);




//automatically apply zebra tables to any <table class="zebra">
function zebra_tables() {

	zebra('table', 'zebra', 'tr', 'odd, even');

}

initAdd(zebra_tables);




//When a form is submitted, it runs formSubmit (see next function)
//Also, if using GET in form, all buttons are set to 'Working...', otherwise you might get image tags in the GET url

var docSubmitted = false;

function form_busy_activity() {

	$$('form').each(function(form) {

		form.observe('submit', function(e) {

			if(form.method == 'get') {

				form.select('button').each(function(btn) {
	
					if(btn.value.length > 20) btn.value = 'Working...';

				})

			}

			if(ignoreLock) return true;

			if(docSubmitted == true) {
			
				alert('A form is currently submitting. Please be patient!');
				e.stop();
				return true;

			}

			//if we get here, its safe to submit... lets do that
			docSubmitted = true;

			//show activity in 2 seconds
			setTimeout("showActivity()", 2000);

		});

	})

}

initAdd(form_busy_activity);


//forces the 'showActivity' div to scroll with the browser

var floatActivityDivTop = 0;
function floatActivityDiv() {
	
	if(!$('showActivity')) return false;
	
	setInterval(function() {

		if (document.documentElement && document.documentElement.scrollTop) {
			scrollTop = document.documentElement.scrollTop;
		} else {
			scrollTop = document.body.scrollTop;
		}
		
		floatActivityDivTop += (scrollTop + 20 - floatActivityDivTop) / 6;
	
		$('showActivity').style.top = floatActivityDivTop + 'px';
		$('showActivity').style.right = 20 + 'px';
		

	}, 30);

}

initAdd(floatActivityDiv);
