var PostNewItem   = new Object();
//=====================================================//
//** extending the master Util class
var Util = $.extend(Util, {

});

//------------------------------------------------//
var Comments = {
    showCommentsForm: function() {
        var url       = $(this).attr('href');
        var record_id = $(this).attr('rec_id');

        $.get(url, function(data){
            Util.initDialog();
            $('#dialog').html(data);

            var xButtons = {};

            xButtons['Submit'] = function() {
                Util.showProgressInd();
                $('#frmComment').submit();
            };

            xButtons['Cancel'] = function() {
                $(this).dialog('close');
                $(this).dialog('destroy');
            };

            var x_dialog = $('#dialog').dialog(
                $.extend(Util.dialogDefaults, {
                    title: 'Please add your comments...',
                    height: 300,
                    width: 450,
                    buttons: xButtons,
                	beforeclose:{}
                })
            );

            var extraPar = {
                callback: function(json){
                    $('#dialog').dialog('close');
                    $('#dialog').dialog('destroy');
                    Comments.reloadComments(record_id);
                }
            }

            var options = {
                success: function(json, statusText, jqFormObj) {
                    Validate.validateFormData(json, statusText, jqFormObj, extraPar);
                    Util.hideProgressInd();
                },
                beforeSubmit: function() {
                },
                dataType: 'json'
            };
            $('#frmComment').ajaxForm(options);
            Util.hideProgressInd();
        });
    },

    reloadComments: function(rec_id) {
        Util.showProgressInd();
        var url    = '/index.php?_room=comment&_spAction=list&record_id=' + rec_id + '&showHTML=0';
        var link   = $('#' + rec_id);

        $.get(url, function(data){
            var parent = $(link).closest('.commentHltBox');
            var commentsBox = $('.commentsList', parent);
            var countSpan = $('span.count', parent);
            var count = parseInt(countSpan.text());
            $(countSpan).html(count + 1);
            $(commentsBox).html(data);
            $(commentsBox).hide();
            $(commentsBox).slideDown();
            Util.hideProgressInd();
        });
    }

}

//------------------------------------------------//
var Comments1 = {
    showCommentsForm: function() {
        var url       = $(this).attr('href');
        var record_id = $(this).attr('rec_id');

        $.get(url, function(data){
            Util.initDialog();
            $('#dialog').html(data);

            var xButtons = {};

            xButtons['Submit'] = function() {
                Util.showProgressInd();
                $('#frmComment').submit();
            };

            xButtons['Cancel'] = function() {
                $(this).dialog('close');
                $(this).dialog('destroy');
            };

            var x_dialog = $('#dialog').dialog(
                $.extend(Util.dialogDefaults, {
                    title: 'Please add your comments...',
                    height: 350,
                    width: 450,
                    buttons: xButtons
                })
            );

            var extraPar = {
                callback: function(json){
                    $('#dialog').dialog('close');
                    $('#dialog').dialog('destroy');
                }
            }

            var options = {
                success: function(json, statusText, jqFormObj) {
                    Validate.validateFormData(json, statusText, jqFormObj, extraPar);
                    Util.hideProgressInd();
                },
                beforeSubmit: function() {
                },
                dataType: 'json'
            };
            $('#frmComment').ajaxForm(options);
            Util.hideProgressInd();
        });
    }
}


//------------------------------------------------//
//=====================================================//
var Validate = $.extend(Validate, {

});

