var input_color = '#222';
var instruction_color = '#999';

var error_box_color = '#fb0';
var message_box_color = '#F0E2FF';

var fade_out_time = 500;
var fade_in_time = 1500;
var message_display_time = 5000;

$(document).ready(function() {
    // Input Instruction Handling
    $(".with-instructions").css("color", instruction_color);
    $(".with-instructions").attr("value", function() {
        return $(this).attr("title");
    });
    
    $(".with-instructions").focus(function() {
        if (this.value == $(this).attr("title")) {
            this.value = '';
            this.style.color = input_color;
        }
        $(this).blur(function() {
            if (this.value == '') {
                this.style.color = instruction_color;
                this.value = $(this).attr("title");
            }
        });
    });
    
    $("form").submit(function() {
        $(".with-instructions").attr("value", function() {
            if (this.value == $(this).attr("title")) {
                return '';
            }
        });
        return false;
    });
});

function show_message(message_text) {
    $("#message").fadeOut(fade_out_time, function(){
       $("#message").css("background-color", message_box_color);
       $("#message").html(message_text);
       $("#message").fadeIn(fade_in_time).fadeTo(message_display_time, 1).fadeOut(fade_out_time);
   });
}

function show_error(error_text) {
    $("#message").fadeOut(fade_out_time, function(){
       $("#message").css("background-color", error_box_color);
       $("#message").html(error_text);
       $("#message").fadeIn(fade_in_time);
   });
}
