/**
 * jquery.jspost
 * This jQuery library allows you post post a given set of page elements.
 * Note - any input fields named 'submit' will be executed.
 *
 * Example:
 * Grabs all form elements in the page element id "mystuff"
 * and posts it to the URL at action.
 *
 * // sends all form elements in div id mystuff to example.com/sample.php 
 * $("#mystuff").jspost({action:"http://www.example.com/sample.php","method":"get"});
 * 
 * @author eric.walker at gmail.com and dp.sunkara at gmail dot com
 */
(function($){
 $.fn.jspost = function(options) {
    
  var defaults = {
   method: "post",
   action: "#"
  };
  var options = $.extend(defaults, options);
  var n=Math.floor(Math.random()*1000000000);
  var f = $("<form>").attr({"id":"jsPost"+n,"name":"jsPost"+n});
  f.attr({"action":options.action,"method":options.method});
  f.css("display","none");
  this.find("input,textarea,select,hidden").not("[name='submit']").each(function(i, item) {
        obj = $(this);
        var el = $("<input type=\"hidden\">").attr({'name':$(item,obj).attr("name"),'value':$(item,obj).val()});
        f.append(el);
    });
  f.append($("<input type=\"submit\">").attr({"id":"mys"+n,"name":"submit","value":"submit"}));
  f.appendTo(document.body);
 	try { 
		__sfga();
	}
	catch(err) { 
	}
  $("#mys"+n).click();
  //$("#jsPost"+n).submit();
  //f.submit();
 };
})(jQuery);
