/*
* This notice must be untouched at all times.

submitonlyonce.js    
The latest version is available at
http://sarat.xcelens.co.uk/2005/06/08/submit-only-once-forms/

Copyright (c) 2005 Sarat Pediredla. All rights reserved.
Last modified: 09/06/2005

This code snippet adds submit only once functionality to any forms on your site.

USAGE:
Just include the script at the end of your page before the closing </body> tag like follows (assuming the js file is in the same directory as your html file ),

<script language="javascript" src="submitonlyonce.js"></script>

LICENSE: LGPL

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License (LGPL) as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

For more details on the GNU Lesser General Public License,
see http://www.gnu.org/copyleft/lesser.html
*/

function doSubmitOnce(currentForm)
{
	// Run through elements and disable submit buttons
	for(i=0;i<currentForm.length;i++)
	{
		var currentElement = currentForm.elements[i];
		if(currentElement.type.toLowerCase() == "submit")
			currentElement.disabled = true;
	}
}


// We need to register our submit once function on all forms
if(document.all||document.getElementById) 
{	
	// Run through all forms on page
	for(i=0;i<document.forms.length;i++)
	{
		var currentForm = document.forms[i];
		// Register event handler
		// Use quirksmode idea for flexible registration by copying existing events
		var oldEventCode = (currentForm.onsubmit) ? currentForm.onsubmit : function () {};
		currentForm.onsubmit = function () {oldEventCode(); doSubmitOnce(currentForm)};
	}
}



		
	