$(document).ready(function () {
	$("[task=review_delete]").click(function(){
		var thehref	= $(this).attr("rel");
		jConfirm(lblConfirmDeleteGeneral, 'Delete', function(r) {
			if(r==true) {
				window.location.href = GLOBAL_BASE_PATH+thehref;
				return true; 
			}else{
				return false;
			}
		});
	});
	$("[task=approve]").click(function()
		{
			var status		=	'active';
			var reviewID	=	$(this).attr('reviewID');
			$.ajax({
				type : "POST",
				data   : "rid="+reviewID+"&status="+status,
				url	   : GLOBAL_BASE_PATH+"product/ajaxchangereviewstatus/",	
				success : function(msg){
					location.reload();
				}
			})
	});
    $(".group1").colorbox({
        rel: 'group1'
    });

    var productTab = parseInt($("#productTab").val());
    if (productTab) {
       // setProductTab(productTab);
    } 
    $(document).on('click',"#table_listing007 .button_inline_edit1",function () {
        var curr_id = $(this).attr('id');
        var prev_id = $('#hidProductReviewID').val();
        $('#hidProductReviewID').val(curr_id);
        $('#formProductDiscussion')[0].reset();
        $('#hidProductReviewID').val(curr_id);
        if (prev_id > 0) {
            $("#hid_err_formProductDiscussion_reviewText_" + prev_id).val(0);
            $("#div_err_formProductDiscussion_reviewStatus_" + prev_id).val(0);
        }
        $(this).hide();
        $('.button_inline_edit1').show();
        $("#button_inline_edit_" + prev_id).show();
        $('#' + curr_id).hide();
    });
	
    $(document).on('click',"#cancelProductReview,.set-preority",function () {
        $('.inline_view_all').show();
        $('.inline_edit_all').hide();
        $('#rows_list_update_buttons').hide();
        $('.button_inline_edit1').show();
        var prev_id = $('#hidProductReviewID').val();
        $('#formProductDiscussion')[0].reset();
        if (prev_id > 0) {
            $("#hid_err_formProductDiscussion_reviewText_" + prev_id).val(0);
            $("#div_err_formProductDiscussion_reviewStatus_" + prev_id).val(0);
        }
        $("#button_inline_edit_" + prev_id).show();
        $(".selected_row").removeClass("selected_row");

    });
    $("#submitBulkStatus").click(function () {
        if ($(".productReviewBulkStatus:checked").size() == 0) {
            jAlert(lblSelectItem);
            return false;
        }
        var reviewStatus = $("#reviewStatus").val()

        if (reviewStatus == 'Deleted') {
            jConfirm(lblSelectDelete, 'Delete', function (r) {
                if (r == true) {
                    $('#formProductDiscussion').submit();
                }
            });
        } else if (!reviewStatus) {
            jAlert(lblSelectAction);
            return false;
        } else {
            return true;
        }

        return false;
    });
    $(document).on('blur','.inline_edit_all input',function () {
        var prev_id = $('#hidProductReviewID').val();
        var row_position = $(this).offset();
        var row_position_top = row_position.top;
        var row_position_height = $(this).closest("tr").height();
        var update_buttons_top = row_position_top + row_position_height - 20;
        $("#rows_list_update_buttons").css({
            "top": update_buttons_top + "px"
        });
    });
    $("#submitProductReview").click(function () {
        var reviewID = $('#hidProductReviewID').val();
        if (jQuery.trim($('#reviewStatus_' + reviewID).val()) == "") {
            jAlert(lblSelectAction);
            return false;
        }
        return true;
    });
});