﻿$(document).ready(function () {
    tick_startup();

    $.ajaxSetup({ type: "POST" });

    $("#postSrch").autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "/Home/LookupCompanies",
                data: request,
                dataType: "json",
                type: "POST",
                success: function (data) {
                    processReply(data, response);
                }
            });
        },
        select: function (event, ui) {
            updateCompany(ui.item.id);
        }
    });

});

function processReply(data, response) {
    if (data[0] == null) $("#cResp").html("No matches found");
    else $("#cResp").html("&nbsp;");
    response(data);
}

var iTickTime = 5000;

function tick_startup() {
    ttOut = setTimeout("tick_adv()", iTickTime);
}

function tick_adv() {
    $(".regticker").animate({ left: -($(".regticker div:first-child").width()+30) }, 500, 'swing', function () {
        $(".regticker div:first-child").appendTo(".regticker");
        $(".regticker").css({ left: 0 });
        ttOut = setTimeout("tick_adv()", iTickTime);
    });
}

function log(message) {
    $("<div/>").text(message).prependTo("#log");
    $("#log").attr("scrollTop", 0);
}

function updateCompany(compName) {

    $("#cDetails").load("/Home/GetCompany", { id: compName }, function () {
    });

}
