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

});

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

});

//**********************************************************************************//
Functions.changeProductNormalImage = function(imageName, mediaID){
  imgSrc   = "media/product/normal/" + imageName;
  linkTemp = "index.php?_room=media&_spAction=zoomImage&media_id=" + mediaID;
  linkSrc  = "javascript:UtilWindow.openWindow(linkTemp,'1010','800')";
  document.getElementById("productImage").src = imgSrc;
  document.getElementById("largeImage").href  = linkSrc;
}

//------------------------------------------------//
var Member = {
}

//------------------------------------------------//
var Lang = {
    data: {'close': 'close'}
}

//------------------------------------------------//
var Product = {
    getLargeImage: function(e) {
        e.preventDefault();
        var imgSrc = $(this).attr('href');

        var galleryImgDiv = $('div.pictureContainer');
        galleryImgDiv.html('').addClass('progressPicture');

        var img = new Image();
        $(img)
        .load(function() {
            $(this).hide();
            galleryImgDiv
            .removeClass('progress')
            .append(this);

            $(this).fadeIn();
        })
        .error(function () {
            alert('error loading image');
        })
        .attr('src', imgSrc);

        //*** on clicking the related images just hide the title
        $('#col3_content div.galleryInfo').hide();

    },
    
    setupEmailToFriendForm: 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);
    },

    setupEnquiryForm: function(e) {
        alert(11111)
        var extraPar = {
            callback: function() {
                var msg = "<div class='sysMessage'>Your Enquiry has been sent successfully.</div>";
                $('#enquiryForm').html(msg);
            }
        }

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

var Dialog = {

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

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

            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) {
        url = $(this).attr('href');
        Util.showProgressInd();

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

            var xButtons = {};
            xButtons.submit = function() {
                $('#' + formName).submit();
            };

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

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

}



/**
 * $('a.viewConfirmed').listHandlers('onclick', console.info);
 */
$.fn.listHandlers = function(events, outputFunction) {
    return this.each(function(i){
        var elem = this,
            dEvents = $(this).data('events');
        if (!dEvents) {return;}
        $.each(dEvents, function(name, handler){
            if((new RegExp('^(' + (events === '*' ? '.+' : events.replace(',','|').replace(/^on/i,'')) + ')$' ,'i')).test(name)) {
               $.each(handler, function(i,handler){
                   outputFunction(elem, '\n' + i + ': [' + name + '] : ' + handler );
               });
           }
        });
    });
};


