if (PREVIEW) {
    jQuery(function ($) {
        if(typeof Virtuemart !== "undefined") 
        {
            Virtuemart.cartEffect = function(form) {
                var $ = jQuery, datas = form.serialize();
                $.ajaxSetup({ cache: false });
                $.getJSON(vmSiteurl + 'index.php?option=com_virtuemart&nosef=1&view=cart&task=addJS&format=json' + vmLang,encodeURIComponent(datas),
                function(datas, textStatus) {
                    datas.msg = datas.msg.replace(/href=\"?([^"]*)\"/g, function(match, href) {
                        var indx = href.lastIndexOf('?');
                        return 'href="' + href + (indx === -1 ? '?' :'&') + 'template={theme}&is_preview=on' + '"';
                    });
                    
                    if(datas.stat ==1){
                        //var value = form.find('.quantity-input').val() ;
                        var txt = form.find(".pname").val()+' '+vmCartText;
                                                $.facebox.settings.closeImage = closeImage;
                                                $.facebox.settings.loadingImage = loadingImage;
                                                $.facebox.settings.faceboxHtml = faceboxHtml;
                        $.facebox({ text: datas.msg +"<H4>"+txt+"</H4>" }, 'my-groovy-style');
                    } else if(datas.stat ==2){
                        var value = form.find('.quantity-input').val() ;
                        var txt = form.find(".pname").val();
                                                $.facebox.settings.closeImage = closeImage;
                                                $.facebox.settings.loadingImage = loadingImage;
                                                $.facebox.settings.faceboxHtml = faceboxHtml;
                        $.facebox({ text: datas.msg +"<H4>"+txt+"</H4>" }, 'my-groovy-style');
                    } else {
                                                $.facebox.settings.closeImage = closeImage;
                                                $.facebox.settings.loadingImage = loadingImage;
                                                $.facebox.settings.faceboxHtml = faceboxHtml;
                        $.facebox({ text: "<H4>"+vmCartError+"</H4>"+datas.msg }, 'my-groovy-style');
                    }
                    if ($(".vmCartModule")[0]) {
                        Virtuemart.productUpdate($(".vmCartModule"));
                    }
                });
                $.ajaxSetup({ cache: true });
            }
        }
    });
}