$(document).ready(function() {
	try {
	var tabs = $("#tabs").tabs();
	var validator = $("#signupform").validate({
		groups: {
			birthdate: "birthdateDay birthdateMonth birthdateYear"
		},
		errorPlacement: function(label, element) {
			if (/^birthdate/.test(element[0].name)) {
				label.insertAfter("#birthdateYear");
			} else {
				label.insertAfter(element);
			}
		}
	});
	
	// validate the other two selects when one changes to update the whole group
	var birthdaySelects = $("#birthdateGroup select").click(function() {
		birthdaySelects.not(this).valid();
	})
	
	// overwrite focusInvalid to activate tab with invalid elements
	validator.focusInvalid = function() {
		if( this.settings.focusInvalid ) {
			try {
				//alert("this.findLastActive() ="+this.findLastActive())
				alert("this.errorList.length ="+this.errorList.length)
				alert("this.errorList[0].element ="+this.errorList[0].element.name)
				//alert("this.findLastActive() ="+this.findLastActive())
				var focused = $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []).filter(":visible");
				alert("tabs index ="+tabs.find(">div").index(focused.parent().parent()))
				tabs.tabs("select", tabs.find(">div").index(focused.parent().parent()));
				focused.focus();
			} catch(e) {
				// ignore IE throwing errors when focusing hidden elements
			}
		}
	};
	} catch(e) {
	
	}
});