// JavaScript Document

function checkEmail(f,fld) {

    var s = f.elements[fld].value;
    if (s) {
	var atsymbol = "@";
	var atoffset = s.indexOf(atsymbol);
	if (atoffset == -1) {
	    alert(s + "\nThe email address you’ve typed in seems to be invalid.\nPlease make sure to include \"@\".");
	    return false
	} else {
	    if (atoffset > s.lastIndexOf(".") || atoffset < s.lastIndexOf(atsymbol)) {
	        alert(s + "\nThe email address you’ve typed in seems to be invalid. \nIt is either the domain name is incorrect or that you have more than two \"@\".");
	        return false
	    } else {
			var re = /[^A-Za-z0-9_@\.\-]/;
			var foundArray = re.exec(s);
			if (foundArray) {
			    if (foundArray == " ") {
				alert("You cannot use \"space\" in your email address.")
			    } else {
				alert("Please enter a valid email address.")
			    }
			    return(false)
			} else {
			    return(true)
			}
	    }
	}	
    } else {
	alert("Please enter your email address.");
	return(false)
    }
}


//サンプル フォームチェック
function validatecontactForm(f) {
	var v;
	var selected = false;
	

	// 名前
	var v = f.name.value;	
	if ( v == '' ) {
		alert('Please enter your name.');
		f.name.focus();
		return false;
	}

	// Email
	var retVal = checkEmail(f,"email")
	if (!retVal) {
		f.email.focus();
		return false;
	}

return true;
}