﻿$(document).ready(function () {

    // select map tab as default if tab description is empty
    var tabDescription = $('.location-overview .widecolumn .tab').eq(0).text();

    if (tabDescription.trim() == '') {
        $('.location-overview .widecolumn .links li a').eq(0).removeClass('active');
        $('.location-overview .widecolumn .tab').eq(1).show();
        $('.location-overview .widecolumn .links li a').eq(1).addClass('active');
    }

    $("#addComment").click(function (e) {
        $.ajax({
            url: "/Location/AddComment",
            contentType: "application/json; charset=utf-8",
            data: {
                locationId: $("#locationId").val(),
                commentText: $("#comment").val()
            },
            success: function (data) {
                $('.toggle-comment-form').click();
                $("#comment").val("");
                $("#commentContainer").html(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //alert(errorThrown);
                $('.toggle-comment-form').click();
                $("#comment").val("");
                $("#commentContainer").html(data);
            }
        });
    });

});
