
//This will find all divs with the class "inlineForm"
//All forms inside that div will be turned into ajaxForms
//Two other classes of div are hidden and shown when the form is submitted:
//inlineFormShowOnSubmit
//inlineFormHideOnSubmit


	var $ = jQuery;
        // wait for the DOM to be loaded 
	jQuery(document).ready(function($) { 
            // bind 'myForm' and provide a simple callback function 

		jQuery('div.inlineForm').each(function(el) { 

			var inlineFormDiv = jQuery(this);

			inlineFormDiv.find('form').each(function(formIndex, formElement){
				
				var theForm =jQuery(this);		
				
				
				var options = { 
				        beforeSubmit:  function(formData, jqForm, options){
						beforeSubmit(formData, jqForm, options, inlineFormDiv);
					},  // pre-submit callback 
					success:    function(responseText, statusText) { 
			        		afterSubmit(responseText, statusText, inlineFormDiv);
			    		} 
				};
				
				var firstOutput = inlineFormDiv.find('*.inlineFormOutput:first');
				if (firstOutput.size() > 0)
				{
					if ((firstOutput[0].id == null) || (firstOutput[0].id == ""))
					{
						alert('You must define an id for any element with a class of inlineFormOutput');
					}
					else
					{
						options['target']='#'+firstOutput[0].id;
					}
				}
				
				theForm.validate({
					submitHandler: function(form) {
						jQuery(form).ajaxSubmit(options);
					}
				});
				//theForm.ajaxForm(options);
			});
		});
     });

function afterSubmit(responseText, statusText, inlineFormDiv)
{
	//alert('did it' + inlineFormDiv.text());
	inlineFormDiv.find('*.inlineFormShowWhileSubmitting').each(function(){
		jQuery(this).hide();
	});
	inlineFormDiv.find('*.inlineFormHideWhileSubmitting').each(function(){
		jQuery(this).show();
	});
	inlineFormDiv.find('*.inlineFormShowOnSubmit').each(function(){
		jQuery(this).show();
	});
	inlineFormDiv.find('*.inlineFormHideOnSubmit').each(function(){
		jQuery(this).hide();
	});
	inlineFormDiv.find('*.inlineFormResponseText').each(function(){
		jQuery(this).html(responseText);
	});
	if (InlineFormAfterSubmit != null)
	{
	  alert('calling IFAS');
	  InlineFormAfterSubmit(inlineFormDiv.find('form').attr('id'));
	}
}

// pre-submit callback 
function beforeSubmit(formData, jqForm, options, inlineFormDiv) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    //var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    //alert('About to submit: \n\n' + jqForm[0].id + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 


	inlineFormDiv.find('*.inlineFormHideWhileSubmitting').each(function(){
		jQuery(this).hide();
	});

	inlineFormDiv.find('*.inlineFormShowWhileSubmitting').each(function(){
		jQuery(this).show();
	});
    return true; 
} 
 
