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

});

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

});

//------------------------------------------------//
var Dialog = {

    setUpForm: function(formName) {
        $('#' + formName).livequery(function() {

            /****************************************************/
            var extraPar = {
                callback: function(json) {
                    if (json.returnText != ''){
                        $('#dialog').dialog('close');
                        $('#dialog').dialog('destroy');
                        Util.showSimpleMessageInDialog(json.returnText);
                    }
                }
            }

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

            $('#' + formName).ajaxForm(options);

        });
    },

    openDialog: function(formName, dialogTitle, w, h) {
        if (!w){
           w = 485;
        }
        
        if (!h){
           h = 410;
        }

        url = $(this).attr('href');

        Util.showProgressInd();

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

            var xButtons = {};

            xButtons[Lang.data.submit] = function() {
                $('#' + formName).submit();
            };

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

            var x_dialog = $('#dialog').dialog(
                $.extend(Util.dialogDefaults, {
                    width: w,
                    height: h,
                    title: dialogTitle,
                    buttons: xButtons
                })
            );
            Util.hideProgressInd();
        });
    }
}

var EmailFriend = {
    emailToFriendForm: function(e) {
        var extraPar = {
            callback: function() {
                var msg = "<div class='sysMessage'>Your message has been sent successfully.</div>";
                $('#emailToFriendForm').html(msg);
            }
        }

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


