$(document).ready(function() {
	     
	$("a.confirm").click(function() {
		return confirm(this.title);
	});
	
	$(".clear-focus").focus(function() {
		if ($(this).val().substring(0, 5) == "Enter") {
			$(this).val("");
		}
	});
	
	$("body.help ol li").each(function() {
		$(this).children("div.answer").hide();
		
		$(this).children().children("a").click(function(event) {
			event.preventDefault();
			$(this).parent().next("div.answer").toggle();
		});
	});

	$("#search-type").change(function() {
        Boomster.searchBox.setMode($(this).val());
	});
	
	$("#search-form").submit(function(event) {
		if ($.trim($("#search-text").val()).substring(0, 5) == "Enter" || $.trim($("#search-text").val()) == "") {
			event.preventDefault();
			alert("Please enter a search phrase to continue.");
			$("#search-text").val("").focus();
		}
	});
	
	$("#personality-submit").click(function() {
		var checked = true;
		var group;
		
		$(".element-full").each(function() {
			group = false;
			$(this).children("input").each(function() {
				if ($(this).attr("checked") == true) {
					group = true;
				}
			});
			
			if (group == false) {
				checked = false;
			}
		});
		
		if (checked == false) {
			alert('Please answer all questions before clicking Submit.');			
			return false;
		}
	});
	
	$("form.file-upload").submit(function() {
		$(this).hide("normal");
		$(this).next().show("fast");
	});
	
	$("dd.profile-link").editInPlace({
		url: "/account/home/change_public_name",
		maxlength: "16",
		success: function(json, original_element) {
			if (json.error == 1) {
				original_element.children("span").highlightFade({
					start: "#ff8080",
					end: "#fff",
					speed: 1500
				});
			}
			else if (json.update == 1) {
				$(".update").attr("href", "http://boomster.com/people/" + json.value);
				
				$(".highlight").text(json.value).highlightFade({
					start: "#ffff80",
					end: "#fff",
					speed: 1500
				});
			}
			else {
				$(".update").attr("href", "http://boomster.com/people/" + json.value);

				original_element.children("span").text(json.value).highlightFade({
					start: "#ffff80",
					end: "#fff",
					speed: 1500
				});
			}
		}
	});
});