/*!
 * SharePointFormSubmit
 *
 * 2009 Alex Dinnouti
 * licensed under GPL licenses.
 * 
 * http://code.google.com/p/jquerysharepointform/
 * 
 * Date: 2009-04-16
 * Revision: 1
 *
 * *
 *
 * Allow to send a form within a form in sharepoint
 * 
 * parameters:
 * 	element - the element that contains the form
 * 	method  - post / get
 * 	action  - url
 * 
 * see a example at:
 * http://code.google.com/p/jquerysharepointform/
 * 
*/

function SharePointFormSubmit (element) {
		var e; // new input element
		var f = document.createElement("form"); // form
			f.method = element.method;
			f.action = element.action;			
			f.setAttribute("style","display:none");
		var myDiv = '#' + element.element;

		// some jquery requirement form chain several commands I don't think it is necessary
			// this piece will be optimized better
			$(myDiv).find("input, select, textarea").each(function(){
				e = document.createElement("input")
				e.setAttribute("type", $(this).attr("type"));
				e.setAttribute("id", $(this).attr("id"));
				e.setAttribute("name", $(this).attr("name"));
				e.setAttribute("value", $(this).val());
				e.setAttribute("checked", $(this).attr("checked"));
				e.setAttribute("multiple", $(this).attr("multiple"));
				f.appendChild(e);
			});
			
			// submit the form
			// add the form to the document between </form> and </html>
			// if you put a breakpoint before the submit you will be able to see it
			var s = document.body.appendChild(f);
			s.submit();
};
