$(document).ready(function() {
	$("#vom").click(function () {
		$("#vomsubmenu").slideDown('fast');
		$("#masubmenu").slideUp('slow');
		$("#mpsubmenu").slideUp('slow');
		$("#mmasubmenu").slideUp('slow');
	});
	
	$("#ma").click(function () {
		$("#masubmenu").slideDown('fast');
		$("#vomsubmenu").slideUp('slow');
		$("#mpsubmenu").slideUp('slow');
		$("#mmasubmenu").slideUp('slow');
	});

	$("#mp").click(function () {
		$("#mpsubmenu").slideDown('fast');
		$("#masubmenu").slideUp('slow');
		$("#vomsubmenu").slideUp('slow');
		$("#mmasubmenu").slideUp('slow');
	});
	
	$("#mma").click(function () {
		$("#mmasubmenu").slideDown('fast');
		$("#masubmenu").slideUp('slow');
		$("#mpsubmenu").slideUp('slow');
		$("#vomsubmenu").slideUp('slow');
	});
	
	$("#member_list .evenrow").toggle(function() {
		$(this).next('tr').fadeIn('slow');
	}, function() {
		$(this).next('tr').fadeOut('fast');
	});

	$("#member_list .oddrow").toggle(function() {
		$(this).next('tr').fadeIn('slow');
	}, function() {
		$(this).next('tr').fadeOut('fast');
	});	
	
  $("#frm_applyformembership").submit(function() {
	if ($("#bpa_join_title").val() == "0")
	{
		alert("You must enter your Title before submitting this form.");
		$("#bpa_join_title").focus();
		return false;
	}
	
	if ($("#bpa_join_name").val() < " ")
	{
		alert("You must enter your Name before submitting this form.");
		$("#bpa_join_name").focus();
		return false;
	}	

	if ($("#bpa_join_jobtitle").val() < " ")
	{
		alert("You must enter your Job Title before submitting this form.");
		$("#bpa_join_jobtitle").focus();
		return false;
	}	
	
	if ($("#bpa_join_email").val() < " ")
	{
		alert("You must enter your Email Address before submitting this form.");
		$("#bpa_join_email").focus();
		return false;
	}

	if ($("#bpa_join_password").val() < " ")
	{
		alert("You must enter a Password before submitting this form.");
		$("#bpa_join_password").focus();
		return false;
	}

	if ($("#bpa_join_orgname").val() < " ")
	{
		alert("You must enter your Organisations Name before submitting this form.");
		$("#bpa_join_orgname").focus();
		return false;
	}

	if ($("#bpa_join_orgadd").val() < " ")
	{
		alert("You must enter your Organisations Address before submitting this form.");
		$("#bpa_join_orgadd").focus();
		return false;
	}

	if ($("#bpa_join_orgpcode").val() < " ")
	{
		alert("You must enter your Organisations Postcode before submitting this form.");
		$("#bpa_join_orgpcode").focus();
		return false;
	}
	
	if ($("#bpa_join_orgtel").val() < " ")
	{
		alert("You must enter your Organisations Telephone before submitting this form.");
		$("#bpa_join_orgtel").focus();
		return false;
	}
	
	  $.ajax({
		type: "POST",
		url : "apply_for_membership_db.asp",
		data: $("#frm_applyformembership").serialize(),
		success:
			function(data)
			{
				if (data == "BadEmail")
				{
					alert("Your Email address does not appear to be valid. Please correct it before submitting this form.");
					$("#bpa_join_email").focus();
				}
				else if (data == "BadOrgEmail")
				{
					alert("Your Organisations Email address does now appear to be valid. Please correct it before submitting this form.");
					
					$("#bpa_join_orgemail").focus();
				}
				else if (data == "BadCaptcha")
				{
					alert("I'm afraid that the two words do not match.");
					$("#recaptcha_response_field").focus();
				}
				else
				{
					$("#afmcontent").html("<p>Thank you for applying to join BPA Retail.</p><p>Your application form has been successfully sent.</p>");
				}
			}
		});
		return false;
	});
	
  $("#frm_contactus").submit(function() {
	if ($("#contact_name").val() < " ")
	{
		alert("You must enter your Name before submitting your enquiry.");
		$("#contact_name").focus();
		return false;
	}
	
	if ($("#contact_email").val() < " ")
	{
		alert("You must enter your Email Address before submitting your enquiry.");
		$("#contact_email").focus();
		return false;
	}	

	if ($("#contact_message").val() < " ")
	{
		alert("You must enter your Message before submitting your enquiry.");
		$("#contact_message").focus();
		return false;
	}	
	
	  $.ajax({
		type: "POST",
		url : "contact_db.asp",
		data: $("#frm_contactus").serialize(),
		success:
			function(data)
			{
				if (data == "BadEmail")
				{
					alert("Your Email address does not appear to be valid. Please correct it before submitting this form.");
					$("#bpa_join_email").focus();
				}
				else if (data == "BadCaptcha")
				{
					alert("I'm afraid that the two words do not match.");
					$("#recaptcha_response_field").focus();
				}
				else
				{
					$("#cucontent").html("<p>Thank you. Your enquiry has been successfully sent.</p>");
				}
			}
		});
		return false;
	});

  $("#frm_Documents").submit(function() {
  if ($("#doc_name").val() < " ")
	{
		alert("You must enter your Name before submitting your enquiry.");
		$("#doc_name").focus();
		return false;
	}

	if ($("#doc_email").val() < " ")
	{
		alert("You must enter your Email Address before submitting your enquiry.");
		$("#doc_email").focus();
		return false;
	}
	
	var docchecked = $("input:checked").length;

	if (docchecked == 0)
	{
		alert("You must select at least one document before submitting your enquiry.");
	}
	
	  $.ajax({
		type: "POST",
		url : "documents_db.asp",
		data: $("#frm_Documents").serialize(),
		success:
			function(data)
			{
				if (data == "BadEmail")
				{
					alert("Your Email address does not appear to be valid. Please correct it before submitting this form.");
					$("#bpa_join_email").focus();
				}
				else if (data == "BadCaptcha")
				{
					alert("I'm afraid that the two words do not match.");
					$("#recaptcha_response_field").focus();
				}
				else
				{
					$("#dcontent").html("<p>Thank you. Your enquiry has been successfully sent.</p>");
				}
			}
		});
		return false;
	});
	
	$("#frm_memberlogin").submit(function() {
	if ($("#login_email").val() < " ")
	{
		alert("You must enter your Email Address before logging in.");
		$("#login_email").focus();
		return false;
	}

	if ($("#login_password").val() < " ")
	{
		alert("You must enter your Password before logging in.");
		$("#login_password").focus();
		return false;
	}
	
	  $.ajax({
		type: "POST",
		url : "dologin_db.asp",
		data: $("#frm_memberlogin").serialize(),
		success:
			function(data)
			{
				if (data == "BadEmail")
				{
					alert("Your Email address does not appear to be valid. Please correct it before submitting this form.");
					$("#login_email").focus();
					return false;
				}
				else if (data == "BadLogin")
				{
					alert("Unknown Email Address or Password");
					$("#login_email").focus();
					return false;
				}
				else
				{
					$("#frm_memberlogin").slideUp("slow");
					$("#loggedin").fadeIn("slow");
				}
			}
		});

		return false;
	});

  $("#frm_EditDetails").submit(function() {
	if ($("#member_title").val() == "0")
	{
		alert("You must enter your Title before submitting this form.");
		$("#member_title").focus();
		return false;
	}

	if ($("#member_forename").val() < " ")
	{
		alert("You must enter your Forename before submitting this form.");
		$("#member_forename").focus();
		return false;
	}	

	if ($("#member_surname").val() < " ")
	{
		alert("You must enter your Surname before submitting this form.");
		$("#member_surname").focus();
		return false;
	}

	if ($("#member_jobtitle").val() < " ")
	{
		alert("You must enter your Job Title before submitting this form.");
		$("#member_jobtitle").focus();
		return false;
	}	

	if ($("#member_login").val() < " ")
	{
		alert("You must enter your Login Email Address before submitting this form.");
		$("#member_login").focus();
		return false;
	}

	if ($("#member_pword").val() < " ")
	{
		alert("You must enter a Password before submitting this form.");
		$("#member_pword").focus();
		return false;
	}

	if ($("#member_address1").val() < " ")
	{
		alert("You must enter your Address before submitting this form.");
		$("#member_address1").focus();
		return false;
	}

	if ($("#member_county").val() < " ")
	{
		alert("You must enter your County before submitting this form.");
		$("#member_county").focus();
		return false;
	}

	if ($("#member_postcode").val() < " ")
	{
		alert("You must enter your Postcode before submitting this form.");
		$("#member_postcode").focus();
		return false;
	}
	
	if ($("#member_tel").val() < " ")
	{
		alert("You must enter your Telephone before submitting this form.");
		$("#member_tel").focus();
		return false;
	}
	
	  $.ajax({
		type: "POST",
		url : "edit_details_db.asp",
		data: $("#frm_EditDetails").serialize(),
		success:
			function(data)
			{
				if (data == "BadEmail")
				{
					alert("Your Email address does not appear to be valid. Please correct it before submitting this form.");
					$("#bpa_join_email").focus();
				}
				else if (data == "BadCaptcha")
				{
					alert("I'm afraid that the two words do not match.");
					$("#recaptcha_response_field").focus();
				}
				else
				{
					$("#edcontent").html("<p>Thank you.</p><p>Your details have been successfully amended.</p>");
				}
				
			}
		});
		return false;
	});
	
});
