$(document).ready(function(){
  $("#registerLightForm").validate({
  		rules: {
  			uname: {
  				remote: {
	  				url: "testnick",
	  				type: "post"
	  			}
  			},
  			email: {
  				remote: {
	  				url: "testemail",
	  				type: "post"
  				}
  			},
			passwd1: {
				notequal: "uname"
			},
  			own_question: {
  				required: "#ownQuestionRow:visible"
  			},
  			b_state2: {
  				required: "#b_state2:visible"
  			}
  		},
  		messages: {
  			uname: {
  				remote: jQuery.format("{0} is already in use")
  			},
  			email: {
  				remote: jQuery.format("{0} is already in use")
  			}
  		},
  		onkeyup: false,
		errorElement: "div",
		errorClass: "invalidComment",
		submitHandler: function(form) {
	  		if ($("#b_zip") && !checkZipMinLength('b_country', 'b_zip', 'b_zip_msg'))
	  			return false;
	  		form.submit();
  		}
  });
  
  $("#editSettingsForm").validate({
	  	ignore: ".ignore",
		rules: {
	  		email: {
				remote: {
					url: "testemail",
					type: "post"
				}
			},
	  		own_question: {
				required: "#ownQuestionRow:visible"
			},
			passwd1: {
				required: "#updatePassword:checked",
				notequal: "uname"
			}
		},
		messages: {
			email: {
				remote: jQuery.format("{0} is already in use")
			}
		},
		onkeyup: false,
		errorElement: "div",
		errorClass: "invalidComment"
  });
  
  $("#upgradeForm").validate({
	  	rules: {
	  		passwd1: {
				notequal: "uname"
			}
  		},
		onkeyup: false,
		errorElement: "div",
		errorClass: "invalidComment"
  });  
});

function showRightHint() {
	var rightHintsText = new Array();
	rightHintsText["uname"] = 'Note: Your username is used for your public community profile name and cannot be changed (not case sensitive). You may choose to use any nickname, pseudonym or avatar to be known by. This username will also be used for your profile URL. e.g. MyYogaHub.com/Username';
	rightHintsText["passwd1"] =	'Increase password security by including letters and numbers; use both upper and lower case characters. We suggest you do not use your Username.';
	rightHintsText["verif"] = 'Human requirement. By entering this code you help us prevent spam and fake registrations.';
	rightHintsText["sec_answer"] = 'Make sure your answer is memorable to you but hard for others to guess!';
	rightHintsText["interests"] = 'These will be displayed on your public profile and allow you to easily find other people in the community who share similar interests.';
	rightHintsText["description"] = 'This will be displayed on your community profile and can be updated at any time.';
	rightHintsText["sec_question"] = 'Choose an answer that is memorable, but not easy to guess. If you write your own question, do not choose a question that is common or obvious.';
	rightHintsText["timezoneoffset"] = 'Your time zone helps us provide you with content that is relevant to where you live.';

	var rightHint = $("#rightHint");
	var rightHintText = $("#rightHintText");
	rightHintText.html(rightHintsText[$(this).attr("id")]);

	// Prepare hint position
	var inputWidth = 340; 
	var offset = $(this).offset();
	var hintLeft = offset.left + inputWidth;
	rightHint.css({top:offset.top, left:hintLeft});
	rightHint.fadeIn("slow");	
}

$(document).ready(function(){
	$("#lastname, #email, #uname, #passwd1, #verif, #sec_answer").focus(showBottomHint);
	$("#uname, #passwd1, #verif, #sec_answer").focus(showRightHint);
});

$(document).ready(function(){
	$("#uname, #passwd1, #verif, #sec_answer").blur(hideRightHint);
});


$(document).ready(function(){
  $("#editProfileForm").validate({
    	onkeyup: false,
		errorElement: "div",
		errorClass: "invalidComment"
  })
});

$(document).ready(function(){
  $("#editSettingsForm").validate({
    	rules: {
  			email: {
  				remote: "testemail"
  			}
  		},
  		messages: {
  			email: {
  				remote: jQuery.format("{0} is already in use")
  			}
  		},
  		onkeyup: false,
		errorElement: "div",
		errorClass: "invalidComment"
  })
});

$(document).ready(function(){
  $("#editAddressForm").validate({
      	onkeyup: false,
		errorElement: "div",
		errorClass: "invalidComment",
		submitHandler: function(form) {
	  		if (checkZipCodes())
	  			form.submit();
  		},
		rules: {
			b_state: {
				required: "#b_state:visible"
			},	  
			b_state2: {
				required: "#b_state2:visible"
			},
			s_address: {
				required: "#ship2diff:checked"
			},
			s_city: {
				required: "#ship2diff:checked"
			},
			s_country: {
				required: "#ship2diff:checked"
			},
			s_zip: {
				required: "#ship2diff:checked"
			},
			s_state: {
				required: "#s_state:visible"
			},			
			s_state2: {
				required: "#s_state2:visible"
			}
  		}
  })
});

function refreshCaptcha()
{
	var rnd = Math.floor(Math.random()*101);
	$.get('refreshcaptcha/' + rnd, null, 
		function(data){
			$(".verifImgCont").html(data);
		}
	);
}