$().ready(function() {
	$("#signupForm").validate({
		rules: {
			username: {
				required: true,
				minlength: 3,
				maxlength: 20,
				remote: "ajax/users.php"
			},
			password: {
				required: true,
				minLength: 5,
				maxLength: 20
			},
			confirm_password: {
				required: true,
				minLength: 5,
				maxLength: 20,
				equalTo: "#password"
			},
			title: "required",
			firstname: {
				required: true,
				minlength: 3,
				maxlength: 40
			},
			surname: {
				required: true,
				minlength: 3,
				maxlength: 40
			},
			company: {
				required: true,
				minlength: 3,
				maxlength: 40
			},
			business_sector: "required",
			email: {
				required: true,
				email: true,
				remote: "ajax/emails.php"
			},
			confirm_email: {
				required: true,
				email: true,
				equalTo: "#email"
			},
			phone: "required",
			house_number: "required",
			address1: {
				required: true,
				minlength: 3,
				maxlength: 50
			},
			address2: {
				minlength: 3,
				maxlength: 50
			},
			town_city: {
				required: true,
				minlength: 3,
				maxlength: 50
			},
			county: {
				required: true,
				minlength: 3,
				maxlength: 50
			},
			postcode: {
				required: true,
				minlength: 6,
				maxlength: 8
			},
			country: {
				required: true,
				minlength: 2,
				maxlength: 50
			},
			privacy: "required",
			terms: "required"		
		},
		messages: {
			username: {
				required: "Please enter a username",
				minlength: "Your username must consist of at least 3 characters",
				maxlength: "Your username must not exceed 20 characters in length",
				remote: jQuery.format("'{0}' is already registered. Please try a different username.")
			},
			password: {
				required: "Please provide a password",
				minlength: "Your password must be at least 5 characters long",
				maxlength: "Your password must not exceed 20 characters in length"
			},
			confirm_password: {
				required: "Please provide a password",
				minlength: "Your password must be at least 5 characters long",
				maxlength: "Your password must not exceed 20 characters in length",
				equalTo: "Please enter the same password as above"
			},
			title: "Please select a title",
			firstname: {
				required: "Please enter your first name",
				minlength: "Your first name must consist of at least 3 characters",
				maxlength: "Your first name must not exceed 40 characters in length"
			},
			surname: {
				required: "Please enter a surname",
				minlength: "Your surname must consist of at least 3 characters",
				maxlength: "Your surname must not exceed 40 characters in length"
			},
			company: {
				required: "Please enter a company name",
				minlength: "Your company name must consist of at least 3 characters",
				maxlength: "Your company name must not exceed 40 characters in length"
			},
			business_sector: "Please select a business sector",
			email: {
				required: "Please enter a valid email address",
				remote: jQuery.format("'{0}' is already registered. Please log in or submit a request for a new password if you have forgotten it.")
			},
			confirm_email: {
				required: "Please confirm your email address",
				equalTo: "Please enter the same email address as above"
			},
			phone: "Please enter your phone number",
			house_number: "Please enter your house number / name",
			address1: {
				required: "Please provide the first line of your address",
				minlength: "The first line of your address must be at least 3 characters long",
				maxlength: "The first line of your address must not exceed 50 characters in length"
			},
			address2: {
				minlength: "The second line of your address must be at least 3 characters long",
				maxlength: "The second line of your address must not exceed 50 characters in length"
			},
			town_city: {
				required: "Please provide the name of your town/city",
				minlength: "The name of your town/city must be at least 3 characters long",
				maxlength: "The name of your town/city must not exceed 50 characters in length"
			},
			county: {
				required: "Please provide the name of your county",
				minlength: "The name of your county must be at least 3 characters long",
				maxlength: "The name of your county must not exceed 50 characters in length"
			},
			postcode: {
				required: "Please provide your post code",
				minlength: "Your post code must be at least 6 characters long",
				maxlength: "Your post code must not exceed 8 characters in length"
			},
			country: {
				required: "Please provide the name of your country",
				minlength: "The name of your country must be at least 2 characters long",
				maxlength: "The name of your country must not exceed 50 characters in length"
			},
			privacy: "Please agree to our privacy policy",
			terms: "Please agree to our terms and conditions"
		}
	});
	
	$("#business_sector").change(onSelectChange); 
	$("#other").hide();  
	
});

function onSelectChange(){   
    var selected = $("#business_sector option:selected");        
    var output = "";   
    if(selected.val() == "other"){   
        //output = "You Selected " + selected.text();
		//show output  
		$("#other").show(); 
    }   else {
		$("#other").hide(); 
	}
    $("#output").html(output);   
}   

