

function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
			return (false);
		}	
	} 

	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);		
		} 
	}
}

function check_user(form) { // f is the form (passed using the this keyword)
	if (form.firstname.value == "") {
		alert("You need to enter a first name");
		form.firstname.focus();
		return false;
	
	} else if (form.lastname.value == "") {
		alert("You need to enter a last name");
		form.lastname.focus();
		return false;

	} else if(!check_email(form.email.value)){
		alert("Invalid email, please enter again");
		form.email.focus(); 
		return false;
			
	} else if (form.user_name.value == "") {
		alert("You need to enter a username");
		form.user_name.focus();
		return false;
		
	} else if (form.password1.value == "") {
		alert("You need to enter a password");
		form.password1.focus();
		return false;
		
	} else if (form.password1.value!=form.password2.value) {
		alert("Sorry! Your password fields don't match");
		form.password1.focus();
		return false;
	} else if (!form.optin.checked){
		alert("You must agree to receive occasional emails from the Silver Lake Neighborhood Council.");
		form.optin.focus();
		return false;
	
	} else {
		return true;
	}	

}

function check_user_edit(form) { // f is the form (passed using the this keyword)

	if (form.uname.value == "") {
		alert("You need to enter a username");
		form.uname.focus();
		return false;
		
	} else if(!check_email(form.uemail.value)){
		alert("Invalid email, please enter again");
		form.uemail.focus(); 
		return false;
		
	} else {
		return true;
	}	

}

function check_user_password(form) { // f is the form (passed using the this keyword)

	if (form.old_upassword.value == "") {
		alert("You need to enter your old password");
		form.upassword.focus();
		return false;
	
	} else if (form.upassword.value == "") {
		alert("You need to enter a new password");
		form.upassword.focus();
		return false;
		
	} else if (form.upassword.value!=form.repeat_upassword.value) {
		alert("Sorry! Your password fields don't match");
		form.upassword.focus();
		return false;
		
	} else {
		return true;
	}	

}

function check_topic(form) { // f is the form (passed using the this keyword)

	if (form.topic.value == "") {
		alert("You need to enter a topic");
		form.topic.focus();
		return false;
		
	} else if (form.subject.value == "") {
		alert("You need to enter a subject");
		form.subject.focus();
		return false;
		
	}else{
		return true;
	}	

}

function check_post(form) { // f is the form (passed using the this keyword)

	if (form.subject.value == "") {
		alert("You need to enter a subject");
		form.subject.focus();
		return false;
		
	}else {
		return true;
	}	

}



