function validate_email(email) {

	var err = 0;

	if (email==null)
		err = 1;
	if (email.length==0)
		err = 1;
	if (!all_valid_chars(email))  // check to make sure all characters are valid
		err = 1;
	if (email.indexOf("@") < 1) //  must contain @, and it must not be the first character
		err = 1;
	if (email.lastIndexOf(".") <= email.indexOf("@"))  // last dot must be after the @
		err = 1;
	if (email.indexOf("@") == email.length)  // @ must not be the last character
		err = 1;
	if (email.indexOf("..") >=0) // two periods in a row is not valid
		err = 1;
	if ((email.indexOf(".")+1) == email.length) {  // . must not be the last character
		err = 1;
    }

	if (err == 1)
        return false;
	else
		return true;
}

function all_valid_chars(email) {
	var parsed = true;
	var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
	for (var i=0; i < email.length; i++) {
		var letter = email.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1)
			continue;
		parsed = false;
		break;
	}
	return parsed;
}

function get_radio_selection(radio_element) {
	for(var i = 0; i < radio_element.length; i++) {
		if(radio_element[i].checked) {
			return radio_element[i].value;
		}
	}
	return false;
}