function updateAmount(custom) {
	var invoiceTotal = validateCustom(custom);

	if (invoiceTotal > 0) {
		document.getElementById('amount').value = (invoiceTotal * 1.025).toFixed(2);
	}
}

function validateInvoice(invoice) {
	var invoiceNumber = invoice.value;

	if (invoiceNumber != parseInt(invoiceNumber) || invoiceNumber == 0) {
		alert('Please enter a valid invoice number.');
		return 0;
	}

	return invoiceNumber;	
}

function validateCustom(custom) {
	var invoiceTotal = custom.value;

	if (invoiceTotal != parseFloat(invoiceTotal) || invoiceTotal == 0) {
		alert('Please enter a dollar amount for the invoice total.');
		return 0;
	}

	return invoiceTotal;
}

function payment_onsubmit() {
	var business = document.getElementById('business');
	var itemNumber = document.getElementById('item_number');
	var itemName = document.getElementById('item_name');
	var invoice = document.getElementById('invoice');
	var custom = document.getElementById('custom');

	if (validateInvoice(invoice) == 0 || validateCustom(custom) == 0) {
		return false;
	}

	business.value = 'ar' + '@' + 'qbscanada' + '.' + 'com';
	itemNumber = invoice.value;
	itemName.value += invoice.value;
	updateAmount(custom);
	return true;
}

function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;

	if ((charCode != 8) && (charCode < 48 || charCode > 57)) {
		return false;
	}

	return true;
}

function isDecimalKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;

	if ((charCode != 8) && (charCode != 46) && (charCode < 48 || charCode > 57)) {
		return false;
	}

	return true;
}