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_email_only(f) { // f is the form (passed using the this keyword)
	if(!check_email(f.email.value)){
		alert("Invalid email detected");
		// make sure the form is not submitted
		return false;
	} else {
		return true;
	}
}

function check_newlsetter(form) {
	if(!check_email(form.email.value)){
		alert("Invalid email, please enter again");
		form.email.focus(); 
		return false;
	} else {
		return true;
	}

}


function check_user_join_step_1(form) { // f is the form (passed using the this keyword)
	if(!check_email(form.uemail.value)){
		alert("Invalid email, please enter again");
		form.uemail.focus(); 
		return false;

	}else if ((form.uname.value.length < 3) || (form.uname.value.replace(/[A-Z]|[a-z]|[0-9]|_|-| /g,"") != "" ) ) {
		alert("You need to pick a username with at least 3 characters\n Alphanumeric or '_' or '-'");
		form.uname.focus();
		return false;
		
	} else if (form.upassword.value.length < 5) {
		alert("You need to enter a password with at least 5 characters");
		form.upassword.focus();
		return false;
		
	} else if (form.upassword.value!=form.repeat_upassword.value) {
		alert("Sorry! Your password fields don't match");
		form.upassword.value="";
		form.repeat_upassword.value="";
		form.upassword.focus();
		return false;
	
	}else if (form.birth_year.options[form.birth_year.selectedIndex].value == "") {
		alert("Please put your birth year");
		return false;
	
	}else if (!form.agree[0].checked == false) {
		alert("You must agree with the Usage Agreement to join");
		return false;
		
	} else {
		return true;
	}	

}


function check_user_login(form) { // f is the form (passed using the this keyword)
	if (form.login_uname.value=="") {
		alert("Please enter your username");
		form.login_uname.focus();
		return false;
		
	} else if (form.login_upassword.value=="") {
		alert("Please enter your password");
		form.login_upassword.focus();
		return false;
		
	} else {
				return true;
	}	

}

function check_user_forgot_password(form) { // f is the form (passed using the this keyword)
	if(!check_email(form.login_uemail.value)){
		alert("Invalid email, please enter again");
		form.login_uemail.focus(); 
		return false;
		
	} else {
		return true;
	}	

}


function check_user_change_password(form) { // f is the form (passed using the this keyword)
	if (form.new_upassword.value.length < 5) {
		alert("You need to enter a new password with at least 5 characters");
		form.new_upassword.focus();
		return false;
		
	} else if (form.new_upassword.value!=form.repeat_new_upassword.value) {
		alert("Sorry! Your password fields don't match");
		form.new_upassword.value="";
		form.repeat_new_upassword.value="";
		form.new_upassword.focus();
		return false;
		
	} else {
		return true;
	}	

}

function check_user_change_email(form) { // f is the form (passed using the this keyword)
	if(!check_email(form.uemail.value)){
		alert("Invalid email, please enter again");
		form.uemail.focus(); 
		return false;
		
	} else {
		return true;
	}	

}


function check_user_photos_edit(form) { // f is the form (passed using the this keyword)
	
	if (form.action.value=="add") {
		alert ("test add true");
		if (form.upload_file.value == "") {
			alert("Please select a gif or jpg file to upload");
			return false; 
		}else{
			if (!(test_for_image_file (form.upload_file.value))) {
				alert("Only gif or jpg files can be uploaded. Please try again.");
				return false; 
			}else{
				return true;
			}
		}
	} else{
		if (form.upload_file.value.length > 0) {
			if (! (test_for_image_file (form.upload_file.value)) ) {
				alert("Only gif or jpg files can be uploaded. Please try again.");
				return false; 
			}else{
				return true;
			}
		}else{
			return true;
		}
	}
}


function test_for_image_file (ext) {
  	ext = ext.substring(ext.length-3,ext.length);
 	ext = ext.toLowerCase();
	
  	if ((ext != 'jpg') && (ext != 'gif')) {
    	return false; 
	}else{
    	return true; 
	}
}


