function doAjax(formID, submitURL) {
   var string = "";
   var dataObj = {};
   $("#" + formID).find('input').each(function(index) {
     if ($(this).attr("type").toLowerCase() === "submit") return;
     else if ($(this).attr("type").toLowerCase() === "button") return;
     else if ($(this).attr("type").toLowerCase() === "radio" && !$(this).attr("checked")) return;
     //but if a check box is checked, it should pass the value 1 along
     else if ($(this).attr("type").toLowerCase() === "checkbox" && $(this).attr("checked")){
     	dataObj[$(this).attr("name")] = "1";
     	string = string+" | "+$(this).attr("name")+": "+"1";
     }
     else if ($(this).attr("type").toLowerCase() === "checkbox" && !$(this).attr("checked")){
     	dataObj[$(this).attr("name")] = "0";
     	string = string+" | "+$(this).attr("name")+": "+"0";
     }
     //Other cases:
     else {
     	dataObj[$(this).attr("name")] = $(this).val();
     	string = string+" | "+$(this).attr("name")+": "+$(this).val();
     }
   });
   
   $("#" + formID).find('select').each(function(index) {
     if ($(this).attr("type").toLowerCase() === "submit") return;
     dataObj[$(this).attr("name")] = $(this).val();
     string = string+" | "+$(this).attr("name")+": "+$(this).val();
   });
   
   if($("#refine_search_use_distance").attr("checked")) {
   		//If this case is true, we must regrettably embark on an entirely different tangent, to a new ajax function located in application.js, and we'll not return here
		getLatLngFromLocation(dataObj);
		return;
   }

   //alert(string);
   
   $.ajax({
     type: "POST",
     url: submitURL,
     dataType: "json",
     data: dataObj,
     success: function (result, stat, xhr) {
        //$("#result").html("Success: " + stat + ", result text is: " + result.text + " heading to: " + result.destination);
         if (result.success) {
		   //alert(result.text + " (a success)");
		   //What action to take upon success is specific to each form:
		   if(formID == 'register_form') 
			 {
			 	showSignupSuccess(result.type,result.email);
		   }
		   
			if(formID == 'pnj_register_form') 
			{
				showSignupSuccess(result.type,result.email);
			 	if(result.type == 2) 
				{
			 		$("#login_header").html("Welcome <span><a href='#'>"+result.name+"</span></a>!&nbsp;&nbsp;|&nbsp;&nbsp;<a href='/index.php/login/logout'>Logout</a>");
			 		loginPostNewJob(result.name, result.email);
			 	}
			}
		  else if(formID == 'login_form') 
			{
				window.location.reload();
		   	$("#login_form_modal_window").fadeOut(100);
			}
		  else if(formID == 'trial_login_form') 
			{
			 window.location = "/search/doSearch/";
		  }
		  else if(formID == 'error_login_form') 
			{
				window.location.reload();
		  }
		  else if(formID == 'pnj-sign-in-div' || formID == 'pnj_login_form') 
			{
				//window.location = '#';
			 	//Change the header so that it displays the logged in view.
			 	//TODO: Link this generated header to the HELP page once it has been created
			 	alert('will display');
			 	$("#login_header").html("<span class='name'>Welcome back <a href='/index.php/profile'>"+result.name+"</a>!</span><span class='sep'>|</span><a href='/index.php/settings'>Help</a><span class='sep'>|</span><a href='/index.php/login/logout'>Sign out</a>");
		    	alert('will hide');
		    	$("#pnj-sign-in-div").hide();
				$("#pnj-password-div").hide();
				$("#pnj-company-name").val(result.name);
				$("#pnj-contact-email").val(result.email);
		     }
		   else if (formID == 'refine_form') 
			 {
		   	document.getElementById('results_section').innerHTML = result.resultsview;
		   	makeResultsMap(result.resultjobs);
		   }
		   else if(formID == 'delete_account_form')
			 {
		   		//You have deleted your account, so you should be logged out and moved to the landing page.
		   }
			}
      else {
           if(formID == 'pnj-sign-in-div' || formID == 'login_form' || formID == 'register_form') {
           		//special case for the login and register forms, where errors are all grouped into one top located box
           		for (var fieldName in result.errors) {
					$("#"+formID + "_top_errorReport").html("");
				   if(result.errors[fieldName] == "") {
					//If no error , hide the field
					//hideError(formID, "top");
				   }
				   else {
				   	alert(result.errors[fieldName]);
					$("#"+formID + "_top_errorReport").append(result.errors[fieldName]);
					showError(formID, "top");
				   }
			   }
           }
           else {
               //standard case for one page forms
			   for (var fieldName in result.errors) {
			   if(result.errors[fieldName] == "") {
				//If no error , hide the field
				hideError(formID, fieldName);
			   }
			   else {
				$("#"+formID + "_" + fieldName + "_errorReport").html(result.errors[fieldName]);
				showError(formID, fieldName);
			   }
			   }
           }
         }
       },
     error: function (xhr, stat, err) {
	 alert("error! " + stat + " Error: " + err + " xhr: " + xhr);
       },
	     complete: function (xhr, stat) {
      }
     });
}
