function mark_offer(id, type) {
	$.get('/mybo.php', { action: 'mark_offer', offerid: id, type: type },
		function(data) {
			if (type == 'accepted') {
				$('#offer'+id).html('<strong>Accepted</strong>');
			} else {
				$('#offer'+id).html('<strong>Declined</strong>');
			}
		}
	);
}

function last_offer() {
	var sku = $('#sku').val();
	$.get('/mybo.php', { action: 'last_offer', sku: sku },
		function(data) {
			var data_array = data.split('|');
			//var lastoffer = CurrencyFormatted(data_array[0]);
			var lastoffer = CurrencyFormatted(0);
			var remaining = parseInt(data_array[1]);
			$('#offerprice').val(lastoffer);
			var offer_str = 'offer';
			var html_string = '';
			if (remaining > 1)
				offer_str = offer_str + 's';
			if (remaining > 0) {
				html_string = '<strong>Please note:</strong> You may only place <strong>3</strong> offers per record.<br /><strong><em>You now have '+remaining+' '+offer_str+' remaining on this record.</em></strong>';
				$('#offerinput').css('margin-top', '20px');
			} else {
				html_string = '<strong><span style="font-size: 12px">Sorry.</span><br />You have already made 3 offers.';
				$('#offerstatus').css('margin-top', '25px');
				$('#offerinput').hide();
			}
			$('#offerstatus').html(html_string);
		}
	);
}

function place_offer() {
	var origprice = parseFloat($('#price').val());
	var offerprice = parseFloat($('#offerprice').val());
	var sku = $('#sku').val();
	if (offerprice > origprice) {
		$('#offerstatus').html('<strong>Your offer must be less than the asking price of &pound;'+origprice+'</strong>');
	} else if (parseFloat(offerprice) == 0 || isNaN(offerprice)) {
		$('#offerstatus').html('<strong>Please enter a price including pence e.g. 50.00</strong>');
	} else {
		$.get('/mybo.php', { action: 'place_offer', offer: offerprice, sku: sku },
			function(data) {
				var data_array = data.split('|');
				var response = data_array[0];
				var remaining = parseInt(data_array[1]);

				html_string = '<strong><span style="font-size: 12px">Please wait!</span></strong>';
				$('#offerstatus').css('margin-top', '25px');
				$('#offerstatus').html(html_string);
				$('#offerinput').hide();

				if (response == 'DUP') {
					var html_string = '';
					html_string = '<strong><span style="font-size: 12px">Sorry.</span><br />You have already made an offer for this amount.';
					$('#offerstatus').css('margin-top', '25px');
					$('#offerstatus').html(html_string);
					$('#offerinput').hide();
				} else if (response == 'OK') {
					var html_string = '';
					html_string = '<strong><span style="font-size: 12px">Thank you.</span><br />You will be emailed with our decision.';
					$('#offerstatus').css('margin-top', '25px');
					$('#offerstatus').html(html_string);
					$('#offerinput').hide();
				} else if (response == 'NOK') {
					html_string = '<strong><span style="font-size: 12px">Sorry.</span><br />You have already made 3 offers.';
					$('#offerstatus').css('margin-top', '25px');
					$('#offerstatus').html(html_string);
					$('#offerinput').hide();
				}
			}
		);
	}
}