var selectedVote=0;

$(function() {
            $('#picture a').lightBox({
                imageLoading: '/images/lightbox-ico-loading.gif',
                imageBtnClose: '/images/lightbox-btn-close.gif',
                imageBtnPrev: '/images/lightbox-btn-prev.gif',
                imageBtnNext: '/images/lightbox-btn-next.gif',
                imageBlank: '/images/lightbox-blank.gif',
            });
        });

function selectVote(nr){
    for(i=1;i<=nr;i++){
        thumbId = "thumb_"+i;
        j_thumbId = "#" + thumbId;
        //$(j_thumbId).addClass('vote_filled_thumb');
        $(j_thumbId).attr("src","/images/rate_on.gif");
    }
    for(i=5;i>nr;i--){
        thumbId = "thumb_"+i;
        j_thumbId = "#" + thumbId;
        //$(j_thumbId).removeClass('vote_filled_thumb');
        $(j_thumbId).attr("src","/images/rate_off.gif");
    }
}

function choseVote(nr){
    selectedVote = nr;
}

function send(prod_id){
    text='';
    if ($("#name_comment").val()==''){
        text+='You didn\'t enter a name\n';
    }
    if ($("#email_comment").val()==''){
        text+='You didn\'t enter an e-mail\n';
    }
    if ($("#comment").val()==''){
        text+='You didn\'t enter a comment';
    }
    if (text!=''){
        alert(text);
    } else {
        $.post('/send_comment.php?product_id='+prod_id+'&vote='+selectedVote, {name: $("#name_comment").val(), email: $("#email_comment").val(), comment: $("#comment").val()}, function (d){
            $("#add_comment").hide();
            $("#name_comment").val('');
            $("#email_comment").val('');
            $("#comment").val('');
            if (d=='message_not_add'){
                alert('You have added today a review for this product.');
            } else {
                //$("#user_reviews").load("/user_review.php?actions=refresh&product_id="+prod_id);
                $.getJSON("/user_review.php?actions=refresh&product_id="+prod_id, function(data){
                    $("#user_reviews").html(data.comment_div);
                    $("#vote_img").html(data.vote);
                })
            }
        })
    }
}
function add_commnet(){
    var top1=Math.round($(window).scrollTop()+200);
    $("#add_comment").css('top',top1);
    $("#add_comment").show();
}

function approve_review(comment_id){
    $("#user_reviews_"+comment_id).load("/user_review.php?actions=approve&comment_id="+comment_id);
}
function del_review(comment_id){
    $.get("/user_review.php?actions=delete&comment_id="+comment_id, function (){
        $("#user_reviews_"+comment_id).remove();
    });
}

function send_mail_request(product_id){
    top1=Math.round($(window).scrollTop()+200);
    $("#send_mail_request").css('top',top1);
    $("#send_mail_request").show();
}

function send_request(prod_id){
    text='';
    if ($("#name_request").val()==''){
        text+='You didn\'t enter a name\n';
    }
    if ($("#email_request").val()==''){
        text+='You didn\'t enter an e-mail\n';
    }
    if ($("#message_request").val()==''){
        text+='You didn\'t enter a message';
    }
    if (text!=''){
        alert(text);
    } else {
        $.post('/send_mail_request.php?product_id='+prod_id, {name: $("#name_request").val(), email: $("#email_request").val(), message: $("#message_request").val(), subject: $("#subject_request").val() }, function (data){            $("#send_mail_request").hide();
            alert(data.msg);
            //$("#user_reviews").load("/user_reviews.php?actions=refresh&product_id="+prod_id);
        }, "json")
    }
}
