﻿function gotoPredictionBoard() {
    if ($("#headerGetQuote").val() != $("#headerGetQuote")[0].title && $("#headerGetQuote").val() != "") {
        document.location = "/predictionboard.aspx?symbol=" + $("#headerGetQuote").val();
    }
}

$(document).ready(function() {

    // Make sure enter key submits the symbol input entry.
    $('#headerGetQuote').keyup(function(e) {
        if (e.keyCode == 13) {
            gotoPredictionBoard();
        }
    });

    $("#headerGetQuote").autocomplete('/services/symbol.ashx', {
        parse: function(data) {
            return $.map(eval(data), function(row) {
                return {
                    data: row,
                    value: row.symbol,
                    result: row.symbol
                }
            });
        },
        formatItem: function(item) {
            if (item.symbol.length > 0)
                return "<div style='float: left; width: 60px;'>" + item.symbol + "</div><span title='" + item.name + "'>" + item.name.substr(0, 30) + "</span>";
            else
                return item.name;
        },
        width: 285,
        scroll: false
    });

    $('#headerGetQuote').result(function(event, data, formatted) {
        document.location = "/predictionboard.aspx?symbol=" + data.symbol;
    });

    // Enable default text for the main symbol input box.
    // Uses value of the "title" attribute as the default text.
    $("#headerGetQuote").focus(function(srcc) {
        if ($(this).val() == $(this)[0].title) {
            $(this).removeClass("defaultTextActive");
            $(this).val("");
        }
    });
    $("#headerGetQuote").blur(function() {
        if ($(this).val() == "") {
            $(this).addClass("defaultTextActive");
            $(this).val($(this)[0].title);
        }
    });
    $("#headerGetQuote").blur();
    // End default text

    // Preload rollovers defined in our stylesheet(s)
    $.preloadCssImages();

});