﻿jQuery(document).ready(function() {

    var tzOffset = TimeZoneOffset();
    $("input#tzo").val(tzOffset);

    $("#addToTriBar").click(function() {
        $.ajax({
            url: "/Service/addToTriBar?userId=" + $("#userId").val() +
                        "&productId=" + $("#productId").val() +
                        "&tzo=" + $("input#tzo").val(),
            type: "GET",
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            success:
                        function(result) {
                            var obj = JSON.parse(result);
                            var msg = "<span id=\"rateMsg\"></span>";
                            if ($("div.product-status").length == 0) {
                                $("div.product-status").html(msg);
                            }
                            $("div.product-status").show();
                            if (obj.error) {
                                $("div.product-status")
                                .text(obj.error)
                                .show()
                                .fadeOut(3000);
                                // .remove();
                            } else {
                                $("div.product-status")
                                .text("Successfully added.")
                                .show()
                                .fadeOut(3000);
                                // .remove();
                            }
                        }
        });
    });
});