/*
Using the jQuery Library handles all the 
data passing between form elements aswell as
Ajax requests.

@author: Mat Brennan, Jem Turner
*/

$(document.body).ajaxStart(function() {
	$('#amazonResult').html('<img src="images/loading.gif" alt="indicator" id="loading" />');
}).ajaxStop(function() {
	$('#loading').hide();
});
$("#amazonResult").ajaxError(function(){
  $(this).html("<p>Error: could not complete request.</p>");
});

function getAmazon(query){
	var query = $('#searchText')[0].value;
	$('#amazonResult').load("amazon.php?search="+escape(query));
}


function useValue(tochange, val){
	$(tochange)[0].value = val;
}

function changeallValues(amazonFields){
	$('#'+amazonFields).children('input').each(function(){
		sub = this.id.substr(0, this.id.length - 3)
		f = document.getElementById(sub);
		f.value = this.value;
	});
}