//////////// email validation script
/////////////////////////////////////////////////////////////
// Email validation script I borrowed from who knows where...

function validEmail(email) {
    invalidChars = "/:,;"

    for (i=0;i<invalidChars.length;i++) {
        badChar = invalidChars.charAt(i)
        if (email.indexOf(badChar,0) > -1) {
            return false
        }
    }
    atPos = email.indexOf("@",1)
    if (atPos == -1) {
        return false
    }
    if (email.indexOf("@",atPos+1) > -1) {
        return false
    }
    periodPos = email.indexOf(".",atPos)
    if (periodPos == -1) {
        return false
    }
    if (periodPos+3 > email.length) {
        return false
    }
    return true

}



////////////////////////////////////////////////////////////
// All of my form validation scripts



// here's the form validator for the List a Bass page
function ValidateListBassForm() {

	var the_form = document.forms['handle_listing'];
	
	if (the_form.region_id.value == "") {
		alert ("Please enter your region");
		the_form.region_id.focus();
		return false;
	}
	
	if (the_form.town.value == "") {
		alert ("Please enter your town");
		the_form.town.focus();
		return false;
	}
	
	if (the_form.zip.value == "") {
		alert ("Please enter a zip code");
		the_form.zip.focus();
		return false;
	}
	
	if (the_form.name.value == "") {
		alert ("Please enter a name");
		the_form.name.focus();
		return false;
	}
	
	if (the_form.phone.value == "") {
		alert ("Please enter a phone number");
		the_form.phone.focus();
		return false;
	}
	
	if (the_form.email1.value == "") {
		alert ("Please enter your email");
		the_form.email1.focus();
		return false;
	}
	
	if (the_form.email2.value == "") {
		alert ("Please enter your email twice");
		the_form.email2.focus();
		return false;
	}
	
	if (the_form.description.value == "") {
		alert ("Don't forget to add your description...");
		the_form.description.focus();
		return false;
	}
	
	// also check that the email is in a valid format at least...
	if (!validEmail(the_form.email1.value)) {
		alert ("Your first email entry does not look like a valid email format to me. Please double check your typing.");
		the_form.email1.focus();
		return false;
	}
	
	if (!validEmail(the_form.email2.value)) {
		alert ("Your second email entry does not look like a valid email format to me. Please double check your typing.");
		the_form.email2.focus();
		return false;
	}
	
	// make sure that the email address match each other
	if ((the_form.email1.value) != (the_form.email2.value) ) {
		alert ("The two email address that you entered do not match each other. Please check your typing.");
		the_form.email2.focus();
		return false;
	}
	

	the_form.submit();
	
}

// this one is for the bass_edit page
function ValidateEditBassForm() {

	var the_form = document.forms['bass_edit'];
	
	if (the_form.region_id.value == "") {
		alert ("Please enter your region");
		the_form.region_id.focus();
		return false;
	}
	
	if (the_form.town.value == "") {
		alert ("Please enter your town");
		the_form.town.focus();
		return false;
	}
	
	if (the_form.zip.value == "") {
		alert ("Please enter a zip code");
		the_form.zip.focus();
		return false;
	}
	
	if (the_form.name.value == "") {
		alert ("Please enter a name");
		the_form.name.focus();
		return false;
	}
	
	if (the_form.phone.value == "") {
		alert ("Please enter a phone number");
		the_form.phone.focus();
		return false;
	}
	
	if (the_form.email1.value == "") {
		alert ("Please enter your email");
		the_form.email1.focus();
		return false;
	}
	
	if (the_form.email2.value == "") {
		alert ("Please enter your email twice");
		the_form.email2.focus();
		return false;
	}
	
	if (the_form.description.value == "") {
		alert ("Don't forget to add your description...");
		the_form.description.focus();
		return false;
	}
	
	// also check that the email is in a valid format at least...
	if (!validEmail(the_form.email1.value)) {
		alert ("Your first email entry does not look like a valid email format to me. Please double check your typing.");
		the_form.email1.focus();
		return false;
	}
	
	if (!validEmail(the_form.email2.value)) {
		alert ("Your second email entry does not look like a valid email format to me. Please double check your typing.");
		the_form.email2.focus();
		return false;
	}
	
	// make sure that the email address match each other
	if ((the_form.email1.value) != (the_form.email2.value) ) {
		alert ("The two email address that you entered do not match each other. Please check your typing.");
		the_form.email2.focus();
		return false;
	}
	

	the_form.submit();
	
}




// This validator is for the create_user.php page

// this one is for the bass_edit page
function ValidateCreateUserForm() {

	var the_form = document.forms['create_user'];
	
	
	if (the_form.first_name.value == "") {
		alert ("Please enter your first name");
		the_form.first_name.focus();
		return false;
	}
	
	if (the_form.last_name.value == "") {
		alert ("Please enter your last name");
		the_form.last_name.focus();
		return false;
	}
	
	
	if (the_form.email1.value == "") {
		alert ("Please enter your email");
		the_form.email1.focus();
		return false;
	}
	
	if (the_form.email2.value == "") {
		alert ("Please enter your email twice");
		the_form.email2.focus();
		return false;
	}
	
	if (the_form.password1.value == "") {
		alert ("Please enter your password");
		the_form.password1.focus();
		return false;
	}
	
	if (the_form.password2.value == "") {
		alert ("Please enter your password twice");
		the_form.password1.focus();
		return false;
	}
	
	// also check that the email is in a valid format at least...
	if (!validEmail(the_form.email1.value)) {
		alert ("Your first email entry does not look like a valid email format to me. Please double check your typing.");
		the_form.email1.focus();
		return false;
	}
	
	if (!validEmail(the_form.email2.value)) {
		alert ("Your second email entry does not look like a valid email format to me. Please double check your typing.");
		the_form.email2.focus();
		return false;
	}
	
	// make sure that the email address match each other
	if ((the_form.email1.value) != (the_form.email2.value) ) {
		alert ("The two email address that you entered do not match each other. Please check your typing.");
		the_form.email2.focus();
		return false;
	}
	
		// make sure that the passwords match each other
	if ((the_form.password1.value) != (the_form.password2.value) ) {
		alert ("The two passwords that you entered do not match each other. Please check your typing.");
		the_form.password2.focus();
		return false;
	}

	the_form.submit();
	
}


///// Finally, this is the form for the contact.php page


// This validator is for the create_user.php page

// this one is for the bass_edit page
function ValidateContactForm() {

	var the_form = document.forms['contact'];
	
	
	if (the_form.first_name.value == "") {
		alert ("Please enter your first name");
		the_form.first_name.focus();
		return false;
	}
	
	if (the_form.last_name.value == "") {
		alert ("Please enter your last name");
		the_form.last_name.focus();
		return false;
	}
		
	if (the_form.email1.value == "") {
		alert ("Please enter your email");
		the_form.email1.focus();
		return false;
	}
	
	if (the_form.email2.value == "") {
		alert ("Please enter your email twice");
		the_form.email2.focus();
		return false;
	}
	
	if (the_form.body.value == "") {
		alert ("Don't forget to enter your message");
		the_form.body.focus();
		return false;
	}
	
	
	// also check that the email is in a valid format at least...
	if (!validEmail(the_form.email1.value)) {
		alert ("Your first email entry does not look like a valid email format to me. Please double check your typing.");
		the_form.email1.focus();
		return false;
	}
	
	if (!validEmail(the_form.email2.value)) {
		alert ("Your second email entry does not look like a valid email format to me. Please double check your typing.");
		the_form.email2.focus();
		return false;
	}
	
	// make sure that the email address match each other
	if ((the_form.email1.value) != (the_form.email2.value) ) {
		alert ("The two email address that you entered do not match each other. Please check your typing.");
		the_form.email2.focus();
		return false;
	}


	the_form.submit();
	
}



// a small check to make sure that the user selects a region on the find a bass page

function ValidatePickARegion() {

	var the_form = document.forms['pick_a_region'];
	
	
	if (the_form.region_id.value == "") {
		alert ("Don't forget to pick a region");
		the_form.region_id.focus();
		return false;
	}
	

	the_form.submit();
	
}
	
	
	
	
	
	
	
	
	
	
	
	
	
