// JavaScript Document

$().ready(function() {
	// propose username by combining first- and lastname

	$("#signInButton").click(function() {
			$("#frmLogin").submit();
	});

	
	$('#stateRow').hide();
	$('#selCountry').change ( function () {
		if ($('#selCountry').val()=="US" || $('#selCountry').val()=="CA") {
			$('#stateRow').show();
		} else {
			$('#selState').val("");
			$('#stateRow').hide();
		}
	});
	
	 if ($("#selState").val()!="" || ($("#selCountry").val()=="US" || $("#selCountry").val()=="CA")) { 
		  $('#stateRow').show();
	}

		$.validator.addMethod("checkBirthday", function(value) {
			if ($("#selDay").val()!="" && $("#selMonth").val()!="" && $("#selYear").val()!="") 
				return true; 
			else
				return false;
		}, 'Please select birthday');

		$.validator.addMethod("checkCountry", function(value) {
			if (($("#selCountry").val()==="US" || $("#selCountry").val()=="CA") && $("#selState").val()=="") 
				return false; 
			else
				return true;
		}, 'Please select state');


		$("#txtNewUserEmail").keypress(function() {
			$('#userIdResult').hide();
		});

		$("#btnRegister").click(function() {

			if ( $("#frmRegisterUser").validate()) {
				$("#frmRegisterUser").submit();
			} 
		
		});
	

					 $("#frmRegisterUser").validate({
						rules: {
							selTitle: "required",
							txtFirstName: "required",
							txtLastName: "required",
							selYear: "checkBirthday",
							txtNewUserEmail: {
								required: true,
								email: true
							},
							txtNewPassword: {
								required: true,
								minLength: 8
							},
							txtConfirmPassword: {
								required: true,
								equalTo: "#txtNewPassword"
							},
							selCountry: "required",
							selState: "checkCountry",
							txtCity: "required",
							txtOccupation: "required",
							txtURL: {
								url: true
							},
							txtCode: "required"
						},
						messages: {
							selTitle: "Please select title.",
							txtFirstName: "Please enter first name.",
							txtLastName: "Please enter last name",
							txtNewUserEmail: {
								required: "Please enter login email",
								email: "Please enter valid email"
							},
							txtNewPassword: {
								required: "Please enter password",
								minLength: "Password must consists of at least 8 characters"
							},
							txtConfirmPassword: {
								required: "Please enter confirm password",
								equalTo: "Password and confirm password must be same" 
							},
							selCountry: "Please select country",
							txtCity:  "Please enter city",
							txtOccupation: "Please enter occupation",
							txtURL: "Please enter valid URL",
							txtCode: "Please type the characters you see in the picture above"
						}
					});



});
