Index: autosave.js
===================================================================
--- autosave.js	(revision 6543)
+++ autosave.js	(working copy)
@@ -2,20 +2,16 @@
 var autosavePeriodical;
 
 function autosave_start_timer() {
-	var form = $('post');
-	autosaveLast = form.post_title.value+form.content.value;
+	autosaveLast = jQuery('#post #title').val()+jQuery('#post #content').val();
 	// Keep autosave_interval in sync with edit_post().
 	autosavePeriodical = new PeriodicalExecuter(autosave, autosaveL10n.autosaveInterval);
 	//Disable autosave after the form has been submitted
-	if(form.addEventListener) {
-		form.addEventListener("submit", function () { autosavePeriodical.currentlyExecuting = true; }, false);
-	}
-	if(form.attachEvent) {
-		form.save ? form.save.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null;
-		form.submit ? form.submit.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null;
-		form.publish ? form.publish.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null;
-		form.deletepost ? form.deletepost.attachEvent("onclick", function () { autosavePeriodical.currentlyExecuting = true; }) : null;
-	}
+	jQuery("#post #submit").submit(function () { autosavePeriodical.currentlyExecuting = true; });
+	
+	jQuery("#post #save").click(function () { autosavePeriodical.currentlyExecuting = true; });
+	jQuery("#post #submit").click(function () { autosavePeriodical.currentlyExecuting = true; });
+	jQuery("#post #publish").click(function () { autosavePeriodical.currentlyExecuting = true; });
+	jQuery("#post #deletepost").click(function () { autosavePeriodical.currentlyExecuting = true; });
 }
 addLoadEvent(autosave_start_timer)
 
@@ -26,13 +22,7 @@
 	((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
 }
 
-function autosave_update_nonce() {
-	var response = nonceAjax.response;
-	document.getElementsByName('_wpnonce')[0].value = response;
-}
-
-function autosave_update_post_ID() {
-	var response = autosaveAjax.response;
+function autosave_update_post_ID(response) {
 	var res = parseInt(response);
 	var message;
 
@@ -40,31 +30,30 @@
 		message = autosaveL10n.errorText.replace(/%response%/g, response);
 	} else {
 		message = autosaveL10n.saveText.replace(/%time%/g, autosave_cur_time());
-		$('post_ID').name = "post_ID";
-		$('post_ID').value = res;
+		jQuery('#post_ID').attr({id: "post_ID"});
+		jQuery('#post_ID').val(res);
 		// We need new nonces
-		nonceAjax = new sack();
-		nonceAjax.element = null;
-		nonceAjax.setVar("action", "autosave-generate-nonces");
-		nonceAjax.setVar("post_ID", res);
-		nonceAjax.setVar("cookie", document.cookie);
-		nonceAjax.setVar("post_type", $('post_type').value);
-		nonceAjax.requestFile = autosaveL10n.requestFile;
-		nonceAjax.onCompletion = autosave_update_nonce;
-		nonceAjax.method = "POST";
-		nonceAjax.runAJAX();
-		$('hiddenaction').value = 'editpost';
+		jQuery.post(autosaveL10n.requestFile, {
+			data: {
+				action: "autosave-generate-nonces",
+				post_ID: res,
+				cookie: document.cookie,
+				post_type: jQuery('#post_type').val()
+			},
+		}, function(html) {
+			jQuery('#_wpnonce').val(html);
+		});
+		jQuery('#hiddenaction').val('editpost');
 	}
-	$('autosave').innerHTML = message;
+	jQuery('#autosave').html(message);
 	autosave_enable_buttons();
 }
 
 function autosave_loading() {
-	$('autosave').innerHTML = autosaveL10n.savingText;
+	jQuery('#autosave').html(autosaveL10n.savingText);
 }
 
-function autosave_saved() {
-	var response = autosaveAjax.response;
+function autosave_saved(response) {
 	var res = parseInt(response);
 	var message;
 
@@ -73,87 +62,89 @@
 	} else {
 		message = autosaveL10n.saveText.replace(/%time%/g, autosave_cur_time());
 	}
-	$('autosave').innerHTML = message;
+	jQuery('#autosave').html(message);
 	autosave_enable_buttons();
 }
 
 function autosave_disable_buttons() {
-	var form = $('post');
-	form.save ? form.save.disabled = 'disabled' : null;
-	form.submit ? form.submit.disabled = 'disabled' : null;
-	form.publish ? form.publish.disabled = 'disabled' : null;
-	form.deletepost ? form.deletepost.disabled = 'disabled' : null;
+	jQuery("#post #save:enabled").attr('disabled', 'disabled');
+	jQuery("#post #submit:enabled").attr('disabled', 'disabled');
+	jQuery("#post #publish:enabled").attr('disabled', 'disabled');
+	jQuery("#post #deletepost:enabled").attr('disabled', 'disabled');
 	setTimeout('autosave_enable_buttons();', 1000); // Re-enable 1 sec later.  Just gives autosave a head start to avoid collisions.
 }
 
 function autosave_enable_buttons() {
-	var form = $('post');
-	form.save ? form.save.disabled = '' : null;
-	form.submit ? form.submit.disabled = '' : null;
-	form.publish ? form.publish.disabled = '' : null;
-	form.deletepost ? form.deletepost.disabled = '' : null;
+	jQuery("#post #save:disabled").attr('disabled', '');
+	jQuery("#post #submit:disabled").attr('disabled', '');
+	jQuery("#post #publish:disabled").attr('disabled', '');
+	jQuery("#post #deletepost:disabled").attr('disabled', '');
 }
 
 function autosave() {
-	var form = $('post');
 	var rich = ((typeof tinyMCE != "undefined") && tinyMCE.getInstanceById('content')) ? true : false;
+	var post_data = {
+			action: "autosave",
+			post_ID:  jQuery("#post_ID").val(),
+			post_title: jQuery("#title").val(),
+			cookie: document.cookie,
+			tags_input: jQuery("#tags_input").val() || "",
+			post_type: jQuery('#post_type').val()
+		};
 
-	autosaveAjax = new sack();
-
 	/* Gotta do this up here so we can check the length when tinyMCE is in use */
 	if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 || rich == false ) {
-		autosaveAjax.setVar("content", form.content.value);
+		post_data["content"] = jQuery("#content").val();
 	} else {
 		// Don't run while the TinyMCE spellcheck is on.
 		if(tinyMCE.selectedInstance.spellcheckerOn) return;
 		tinyMCE.wpTriggerSave();
-		autosaveAjax.setVar("content", form.content.value);
+		post_data["content"] = jQuery("#content").val();
 	}
 
-	if(form.post_title.value.length==0 || form.content.value.length==0 || form.post_title.value+form.content.value == autosaveLast)
+	if(jQuery("#title").val()==null || jQuery("#content").val()==null || jQuery("#title").val()+jQuery("#content").val() == autosaveLast) {
 		return;
+	}
 
 	autosave_disable_buttons();
 
-	autosaveLast = form.post_title.value+form.content.value;
+	autosaveLast = jQuery("#title").val()+jQuery("#content").val();
 
-	cats = document.getElementsByName("post_category[]");
+	cats = jQuery("[@name='post_category[]']:checked");
 	goodcats = ([]);
 	for(i=0;i<cats.length;i++) {
 		if(cats[i].checked)
 			goodcats.push(cats[i].value);
 	}
-	catslist = goodcats.join(",");
+	post_data["catslist"] = goodcats.join(",");
 
-	autosaveAjax.setVar("action", "autosave");
-	autosaveAjax.setVar("cookie", document.cookie);
-	autosaveAjax.setVar("catslist", catslist);
-	autosaveAjax.setVar("post_ID", $("post_ID").value);
-	autosaveAjax.setVar("post_title", form.post_title.value);
-	autosaveAjax.setVar("post_type", form.post_type.value);
-	autosaveAjax.setVar("tags_input", form.tags_input.value);
-	if ( form.comment_status.checked )
-		autosaveAjax.setVar("comment_status", 'open');
-	if ( form.ping_status.checked )
-		autosaveAjax.setVar("ping_status", 'open');
-	if(form.excerpt)
-		autosaveAjax.setVar("excerpt", form.excerpt.value);
+	if ( jQuery("#comment_status").attr("checked") )
+		post_data["comment_status"] = 'open';
+	if ( jQuery("#ping_status").attr("checked") )
+		post_data["ping_status"] = 'open';
+	if( jQuery("#excerpt"))
+		post_data["excerpt"] = jQuery("#excerpt").val();
 
 	if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 || rich == false ) {
-		autosaveAjax.setVar("content", form.content.value);
+		post_data["content"] = jQuery("#content").val();
 	} else {
 		tinyMCE.wpTriggerSave();
-		autosaveAjax.setVar("content", form.content.value);
+		post_data["content"] = jQuery("#content").val();
 	}
 
-	autosaveAjax.requestFile = autosaveL10n.requestFile;
-	autosaveAjax.method = "POST";
-	autosaveAjax.element = null;
-	autosaveAjax.onLoading = autosave_loading;
-	autosaveAjax.onInteractive = autosave_loading;
-	if(parseInt($("post_ID").value) < 1)
-		autosaveAjax.onCompletion = autosave_update_post_ID;
-	else
-		autosaveAjax.onCompletion = autosave_saved;
-	autosaveAjax.runAJAX();
+	if(parseInt(jQuery("#post_ID").val()) < 1) {
+		jQuery.ajaxSetup({
+			success: function(html) { autosave_update_post_ID(html); }
+		});
+	} else {
+		jQuery.ajaxSetup({
+			success: function(html) { autosave_saved(html); }
+		});
+	}
+	jQuery.ajax({
+		data: post_data,
+		beforeSend: function() { autosave_loading() },
+		type: "POST",
+		url: autosaveL10n.requestFile
+	});
 }
