
function valid_email(email_address) {
	if (email_address.length < 5) {
        return false
    }
    at_location = email_address.indexOf("@")
    dot_location = email_address.lastIndexOf(".")
    if (at_location == -1 || dot_location == -1 || at_location > dot_location ) {
        return false
    }
	if (at_location == 0) {
        return false
    }
    if (dot_location - at_location < 2 ) {
        return false
    }
	if (email_address.length - dot_location < 2) {
        return false
    }
	return true
}

function validate_form(donation_amount, email) {
	if (donation_amount == 0) {
		alert('Please enter an amount for your donation')
		return false
		}
	if (!valid_email(email)) {
		alert("Please enter a valid email address")
		return false
	}	
}
	
function updateForm(donation_amount) {
	donation_value = parseInt(donation_amount)
	document.getElementById("donation_nzd").innerHTML = "<input type='hidden' name='Total_NZD' value='" + parseInt(donation_value) + "'>"
	document.getElementById("donation_string").innerHTML = "<input type='hidden' name='Total_String' value='$" + donation_amount + "'>"
}	