function content(url) {
	$("#content").html('<p class="loading"><img src="images/loader.gif" alt="" /> loading...</p>');
	$.ajax({
		type: "GET",
		url: url,
		error: function () {
			alert("failed");
			return false;
		},
		success: function(msg){
			$("#content").html(msg);
			return false;
		}
	});
}

function tools(url) {
	$("#tools").html('<p class="loading"><img src="images/loader.gif" alt="" /> loading...</p>');
	$.ajax({
		type: "GET",
		url: url,
		error: function () {
			$("#tools").html("There was a problem, please try again.");
			return false;
		},
		success: function(msg){
			$("#tools").html(msg);
			return false;
		}
	});		
}

function thunkit(theForm) {
	url = "inc/process.php?thunkwords="+theForm.thunkwords.value.replace(/\s/g,"%20");
	tools(url);
}

function searchWord(theForm) {
	var word = theForm.word.value;
	myTest = /^[a-z]+$/i;
	if(myTest.test(word))
	{
		url="inc/content.php?word="+word;
		content(url);
	}
	else
	{
		alert("Please enter a single word");
	}
}

function swap(thunk) {
	url = "inc/content.php?swap="+thunk;
	$.ajax({
		type: "GET",
		url: url,
		error: function () {
			$("#msg").html('<p>Swap failed</p>');
			return false;
		},
		success: function(msg){
			//$("#msg").html('<p>Unable to swap</p>');
			if(msg == 0) {
				$("#msg").html('<p>Unable to swap</p>');
			}
			else {
				$("#t"+thunk).html(msg);
				$("#msg").html('<p>Swapped '+msg+'</p>');
			}
			return false;
		}
	});
}