
	function enterKeyPressed() {
		// don't do anything (since it might try to submit the form)
		return false;
	}
	function submitform(form) {
		if (!validateform(form)) {
			return false;
		}
		
		form.submit();
	}
	function trim(str) { 
		for (start=0, end=str.length; start < end; start++) 
			if (str.charAt(start) != " ") 
				break; 
		for (; end >= start; end--) 
			if (str.charAt(end-1) != " ") break; 
		if(start>end)return "";else return str.substring(start, end);
	}
	
	// This is validate that email address is of the form xxx@xxxx.com
	function validate_email(email) {
		var temp = new String(email);
		
		temp = trim(temp);

		var pChar = temp.indexOf(".");
		while (pChar != -1) {
			if (temp.charAt(pChar-1) == "@" || temp.charAt(pChar+1) == "@" ||
				temp.charAt(pChar-1) == "." || temp.charAt(pChar+1) == "." ) { 
				return false; 
			}
			pChar = temp.indexOf(".", pChar+1);
		}

		var length = temp.length;
		var atChar = temp.indexOf("@"), atChar2 = temp.indexOf("@",atChar+1);
		var periodChar = temp.lastIndexOf(".");
		var spaceChar = temp.indexOf(" ");

		//var msg = "email:" + email + "\n" +
		//	"temp:" + temp + "\n" +
		//	"length:" +  length + "\n" +
		//	"atChar:" + atChar + "\n" +
		//	"atChar2:" + atChar2 + "\n" +
		//	"periodChar:" + periodChar + "\n" +
		//	"spaceChar:" + spaceChar + "\n";
			
		//alert(msg);

		if (!(atChar > 0 && periodChar != -1 && periodChar > atChar && periodChar < length-2 &&
				atChar2 == -1 && spaceChar == -1)) { 
				return false; 
		}
		
		return true;
	}

	var msg;
	function validateform(form) {
		// spaces not allowed
		if (form.firstname.value.match(/^\s*$/)) {
			msg = "Please enter a first name!\n\n" + "This is a required field!";
			alert(msg);
			form.firstname.focus();
			return false;
		}
		if (form.lastname.value.match(/^\s*$/)) {
			msg = "Please enter a last name!\n\n" + "This is a required field!";
			alert(msg);
			form.lastname.focus();
			return false;
		}
		if (form.streetaddr.value.match(/^\s*$/)) {
			msg = "Please enter a street address!\n\n" + "This is a required field!";
			alert(msg);
			form.streetaddr.focus();
			return false;
		}
		if (form.city.value.match(/^\s*$/)) {
			msg = "Please enter a city!\n\n" + "This is a required field!";
			alert(msg);
			form.city.focus();
			return false;
		}
		if (form.state.value.match(/^\s*$/)) {
			msg = "Please enter a state!\n\n" + "This is a required field!";
			alert(msg);
			form.state.focus();
			return false;
		}
		if (form.zip.value.match(/^\s*$/)) {
			msg = "Please enter a zip code!\n\n" + "This is a required field!";
			alert(msg);
			form.zip.focus();
			return false;
		}
		if (form.country.value.match(/^\s*$/)) {
			msg = "Please enter a country!\n\n" + "This is a required field!";
			alert(msg);
			form.country.focus();
			return false;
		}
		if (form.email.value.match(/^\s*$/)) {
			msg = "Please enter an email address!\n\n" + "This is a required field!";
			alert(msg);
			form.email.focus();
			return false;
		}
		if (form.confirm_email.value.match(/^\s*$/)) {
			msg = "Please confirm the above email address!\n\n" + "This is a required field!";
			alert(msg);
			form.confirm_email.focus();
			return false;
		}

		if (!validate_email(form.email.value)) {
			msg = "The email address is not a valid email address!\n\n" +
			      "Please make sure the email is of the form xxx@xxx.com!";
			alert(msg);
			form.email.focus();
			return false;
		}
		
		// ensure that email is confirmed...
		if (form.email.value != form.confirm_email.value) {
			msg = "The email addresses have to match!\n\n" + "Please make corrections and press send again!";
			alert(msg);
			form.email.focus();
			return false;
		}
		
		return true;
	}	
