﻿function ToggleComment() {
    $('#divComment').toggle();
}
function ShowAllComments() {
    $('#aShowAllComments').remove();
    $('#divAllComments').toggle();
}

function Comment(id) {

    $.ajax({
        url: '/service/productservice.aspx?action=2',
        data: { intId: id, strName: $('#txtCommentName').val(), strText: $('#txtCommentText').val() },
        type: 'POST',
        success: function (data) {
            ToggleComment();
            alert('Takk for din kommentar!');

        } 
    });

}
$(window).bind('beforeunload', function () { SaveProductSession(); });
$(document).ready(function () {

    $(function () { $('#rateit6').rateit({ max: 10, step: 1, backingfld: '#backing6' }); });
    $('#rateit6').bind('rated reset', function (e) {
        var ri = $(this);
        var value = ri.rateit('value');
        var productID = ri.data('productid');
        //$('#rateit9').rateit('value',1);


        $.ajax({
            url: '/service/productservice.aspx',
            data: { action: 1, intId: productID, rating: value, rnd: Math.random() },
            type: 'GET',
            success: function (data) {
                if (parseInt(data) == 1) {
                    alert('Takk for din stemme!');
                    ri.rateit('readonly', true);
                }
                else {
                    alert('Du har allerede stemt på dette bladet');
                }

            },
            error: function (jxhr, msg, err) {
            }
        });
    });

    $('#txtCommentText').keyup(function () {
        if ($('#txtCommentText').val().length > 300)
            $('#txtCommentText').html($('#txtCommentText').val().substring(0, 300));
        $('#chars').html(300 - $('#txtCommentText').val().length);
    });

    $('a.lightbox').lightBox({ imageBtnClose: '/images/lightbox/closelabel.gif', imageLoading: '/images/lightbox/loading.gif' });

});

function SaveProductSession() {
    $.ajax({
        url: '/service/productservice.aspx?action=3',
        data: { intId: $('#hfPid').val(), strDate: $('#hfTime').val() },
        type: 'POST',
        async: false,
        success: function (data) {
        }
    });
}

