/// <reference path="..\jquery-1.2.6.min-vsdoc.js" />
/****************************************************************************************
* Filename    : Index.js
* Description : Functions to hookup the UI on the Gallery Metadata form.
****************************************************************************************/
$(document).ready(function() {
    var url = $('#url');

    url.select();
    url.focus();

    url.focus(function() {
        url.select();
    });

    url.keydown(function(e) {
        if (e.keyCode == 13) {
            var url = $("#url").val();

            if (!validate()) {

                showError();

                return false;
            }
            else {
                $("#Form").submit();
            }
        }
    });

    $("#go").click(function() {
        if (validate()) {
            $("#Form").submit();
        } else {
            showError();
        }
    });

    $("#topRated").click(function() {

        $.get("home/top", null, function(responseText, textStatus) {
            $("#topContent").html(responseText);

            $("#topRated").parent().addClass("current");
            $("#recentSites").parent().removeClass("current");
        });

        $(this).blur();

        return false;
    });

    $("#recentSites").click(function() {

        $.get("home/recent", null, function(responseText, textStatus) {
            $("#topContent").html(responseText);

            $("#recentSites").parent().addClass("current");
            $("#topRated").parent().removeClass("current");
        });

        $(this).blur();

        return false;
    });


});

function validate() {
    var url = $("#url").val();

    if (url == "http://yoursite.com" || url == "") {
        return false;
    }
    
    return true;
}

function showError() {
    
    var hint = $(".field-message");

    if (hint.length == 0) {
        hint = $(".field-error");
    }

    hint.html("Please enter your site URL!");
}