// Add support for $.postJSON (jQuery doesn't have this function)
jQuery.extend({
	postJSON: function(url, data, callback) {
		return jQuery.post(url, data, callback, "json");
	}
});

// Sends POST request for ftp information check and parses result.
function test_edit_ftp_information() {
	$("div#test-ftp-results").html("<div id='alert'><img src='/images/ajax-loader.gif' alt='' /><br />Checking FTP credentials...</div>");
	$("#test-ftp-button").hide();

	$.postJSON("/sites/test", $('form#site_form').serialize(), function(data) {
		if (data.success) {
			$("div#test-ftp-results").html("<div id='flash-good'>Good FTP information!</div>");			
		} else {
			$("div#test-ftp-results").html("<div id='flash-bad'><ul>" + data.errors +"</ul></div>");
		}

		$("#test-ftp-button").show();
	});
}

function test_new_ftp_information() {
	$("div#test-ftp-results").html("<div id='alert'><img src='/images/ajax-loader.gif' alt='' /><br />Checking FTP credentials...</div>");	
	$.postJSON("/sites/test", $('form#site_form').serialize(), function(data) {
		if (data.success) {
			$("div#test-ftp-results").html("<div id='flash-good'>Good FTP information!</div>");
			$("form#site_form").submit();
		} else {
			$("div#test-ftp-results").html("<div id='flash-bad'><ul>" + data.errors +"</ul></div>");
		}
	});
	
	return false;
}

function SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}