
$().ready(hihi);


function make_yellow()
{
    $(this).css("background", "yellow");
}

function make_white()
{
    $(this).css("background", "white");
}

function set_highlighter(ml_selector)
{
    $(ml_selector).focus(make_yellow);
    $(ml_selector).blur(make_white);
}

function clear_value()
{
    if (this.defaultValue === this.value)
    {
        this.value = "";
    }
}

function restore_value()
{
    if ("" === this.value ){
        this.value = this.defaultValue;
    }
}

function set_clear_restore_value(selector)
{
    $(selector).focus(clear_value);
    $(selector).blur(restore_value);
}


function hihi()
{
    set_highlighter("form input[@type=text]");
    set_highlighter("form input[@type=password]");
    set_highlighter("form textarea");
    set_clear_restore_value("#year");

    jQuery.validator.addMethod("availablep", availablep, "Unavailable");

    // form_validation_rules is defined in the rules file.
    $("#form0").validate(form_validation_rules);
}


function availablep(trading_name)
{
    $.ajaxSetup({"async" : false});
    $.getJSON(
        '../new-profile/check_trading_name.php?trading_name=' + trading_name,
        function (arg0){ data = arg0; });
    $.ajaxSetup({"async" : true});

    return (1 === data["existp"]) ? false: true;
}



