$.fn.saveFormInSession = function(ajax, form, infoBox, callback) {
	var _this = $(this);
	var data = $(this).getFormData();
	if (typeof(data) != "undefined") {
		// submit using ajax post call to address /ajax/events.php
		var postData = "";
	    postData += "&action=saveOrUpdateForm";
	    postData += "&form=" + form;
	    postData += data;
		$.ajax({  
		  type: "POST",  
		  url: "/ajax/" + ajax + ".php",  
		  data: postData,  
		  success: function(txt) { 
			  // check for error
			  var status = ajaxGetParam(txt, "status");
			  if (status == "error") {
				  $(_this).setErrorForFields(txt, infoBox);
			  }
			  if (status == "success") {
				  var id = ajaxGetParam(txt, "ID");
				  $("#ID").val(id);
				  $(_this).resetErrorForFields(txt, infoBox);
				  if (typeof(callback) != "undefined") {		  
					  callback(txt);
				  }
			  }
		  }  
		});  		
	}
};

$.fn.getFormData = function() {
	$.fn.getFormData.data = "";
	this.each(function() {		
		var type = this.type, tag = this.tagName.toLowerCase();
		var name = this.name;
		if (tag == 'div') {
			$(':input', this).getFormData();
			return;
		}
		if (tag == 'form') {
			$(':input', this).getFormData();
			return;
		}
		if (type == 'text' || type == 'password' || tag == 'textarea' || type == 'hidden')
			$.fn.getFormData.data += "&" + name + "=" + this.value;
		else if (type == 'checkbox' || type == 'radio') {
			$.fn.getFormData.data += "&" + name + "=" + $(this).is(':checked');			
		} else if (tag == 'select')
			$.fn.getFormData.data += "&" + name + "=" + this.value;
	});
	if (typeof($.fn.getFormData.data) != "undefined") {
		return $.fn.getFormData.data;
	}
	return "";
};

