﻿$(function() {
	$("select.auto-submit").bind("change", function(e) {
		$(this).parents("form").submit();
	}).hide().each(function(i) {
		var className = "temporary-magic";
		var languageName = $($(this).find("option").get(this.selectedIndex)).text();
		$(this).parent().append("<a href=\"#\" class=\"" + className + "\">" + languageName + "</a>").find("a." + className).bind("click", function(e) {
			$(this).hide().parent().find("select.auto-submit").show().focus();
			e.preventDefault();
		});
	}).parents("form").find("input").hide();

	$("legend").each(function(i) {
		$(this).html("<span>" + $(this).text() + "</span>");
	});

	$.datepicker.setDefaults({ duration: 0 });

	// Bounce status layer to give attention (and hide after 10 seconds)
	$("#status-layer div").effect("bounce", { times: 3 }, 400);

	setInterval('$("#status-layer").slideUp("slow");', 10000);

	$("label.inside").each(function() {
		var id = $(this).attr("for");
		var defaultValue = $(this).text();
		var $field = $("#" + id);

		$field.bind("focus", function(e) {
			if ($(this).val() == defaultValue) {
				$(this).removeClass("default-value");
				$(this).val("");
			}
		});

		$field.bind("blur", function(e) {
			if ($(this).val() == "") {
				$(this).addClass("default-value");
				$(this).val(defaultValue);
			}
		});

		$($field.parents("form").get(0)).bind("submit", function(e) {
			// Remove value for all fields set to the default display value
			$(".default-value", this).val("");
		});

		$field.blur();
	});

	$("form").bind("submit", function() {
		$(this).unbind("submit").bind("submit", function(e) {
			e.preventDefault();
			return false;
		});
	});

	if (typeof (tb_init) != "undefined") {
		tb_init("a.terms");
	}
});