function isEmail(who) {
	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
	return(email.test(who));
}

function getSelectedRadio(buttonGroup) {
	// returns the array number of the selected radio button or -1 if no button is selected
	if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
		for (var i=0; i<buttonGroup.length; i++) {
			if (buttonGroup[i].checked) {
				return i
			}
		}
	} else {
		if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
	}
	// if we get to this point, no radio button is selected
	return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
	// returns the value of the selected radio button or "" if no button is selected
	var i = getSelectedRadio(buttonGroup);
	if (i == -1) {
		return "";
	} else {
		if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
			return buttonGroup[i].value;
		} else { // The button group is just the one button, and it is checked
			return buttonGroup.value;
		}
	}
} // Ends the "getSelectedRadioValue" function


function enviaForm() {

	var is_valid=1;
	var error_msg='Dados do Formulário em Falta:\n';

	if ( document.form2.name.value.length == 0 ){
		is_valid=0;
		error_msg +='- O seu nome\n';
	}

	if ( ! isEmail(document.form2.email.value) ){
		is_valid=0;
		error_msg +='- O seu email não é válido\n';
	}

	if ( getSelectedRadioValue(document.form2.pais).length == 0){
		is_valid=0;
		error_msg +='- O seu país de residência\n';
	}

	if (getSelectedRadioValue(document.form2.pais) == '2'){
		if ( document.form2.ilha.value.length == 0){
			is_valid=0;
			error_msg +='- A sua ilha de residência\n';
		}
	}

	if ( is_valid ){
		document.form2.submit();
	}else{
		alert(error_msg);
		return false;
	}
}