var AjaxRequest = Class.create( { initialize: function(url, options) { this.url = url || ''; this.options = options || { }; this.onSuccess = Object.isFunction(this.options.onSuccess) ? this.options.onSuccess : Prototype.emptyFunction; this.onFailure = Object.isFunction(this.options.onFailure) ? this.options.onFailure : Prototype.emptyFunction; this.parameters = this.options.parameters || { }; this.method = this.options.method || 'post'; this.caching = this.options.caching || false; this.loader = this.options.loader || null; this.user = this.options.user || null; this.password = this.options.password || null; this.async = this.options.password || true; this.send(); }, send: function() { var req = new JsHttpRequest(); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.responseJS) { this.onSuccess(req.responseJS, req.responseText); } else { this.onFailure(req); } } } var fx = req.onreadystatechange; req.onreadystatechange = fx.bind(this); req.loader = this.loader; req.caching = this.caching; req.open(this.method, this.url, this.async, this.user, this.password); req.send(this.parameters); } }); function pr(obj) { var res = ''; if (Object.isString(obj) || Object.isNumber(obj)) { res += obj; } else { $H(obj).each(function(el) { res += el.key + ' = ' + el.value + '
'; }); } var debug = $('debug'); if (!debug) { debug = new Element('div', { id: 'debug' }); $(document.body).insert(debug); } debug.update(res); } function AddToCart(productID, elm) { new AjaxRequest('/ajax.php', { parameters: {ajax: 1, action: 'AddToCart', ProductID: productID}, onSuccess: function(tr, text) { if (tr.added) { var d = new Element('div').update('добавлено в корзину'); d.addClassName('basket_notice'); d.hide(); var pos = $(elm).down().cumulativeOffset(); pos.top = pos.top + 23; pos.left = pos.left - 5; d.setStyle({position: 'absolute', top: pos.top+'px', left: pos.left + 'px'}); $(document.body).insert({bottom:d}); d.appear().fade({ queue: 'end' }); $('BasketTotalItems').update(tr.totals.Qty); $('BasketTotalSum').update(tr.totals.Sum); } }, onFailure: function(tr) { pr(tr.responseText); } }); } function CorrectTblStyles(id) { document.observe("dom:loaded", function() { $(id).select('tr').each(function (elm, ind){ if (ind % 2 == 1) elm.addClassName('even'); else elm.addClassName('odd'); }); }); } function SetValue(elm) { if (!elm.defValue) elm.defValue = elm.value; if (elm.value == elm.defValue) elm.value = ''; } function OpenPrintPage() { var re = /\?/; var sym = '?'; if (re.test(window.location.href)) sym = '&'; LinkWindow(window.location.href + sym + 'print=1', {resizable : 1}); } function LinkWindow(linkURL, options) { if (window.event) { event.cancelBubble = true; event.returnValue = false; } if (!options) options = {}; var width = options.width || null; var height = options.height || null; if (!width) { width = Math.ceil(screen.width/2); if (width < 650) width = 650; } if (!height) { var height = Math.ceil(screen.height*0.6); if (height < 400) height = 400; } var toolbar = options.toolbar || 0; var location = options.location || 0; var directories = options.directories || 0; var menubar = options.menubar || 0; var scrollbars = options.scrollbars || 1; var resizable = options.resizable || 0; var status = options.status || 0; var fullscreen = options.fullscreen || 0; var name = options.name || "Additional"; var left = options.left || Math.ceil(screen.width/4); var top = options.top || Math.ceil(screen.height*0.1); var oTarget = window.open(linkURL, name, "height="+height+",width="+width+",scrollbars="+scrollbars+",left="+left+",top="+top+",toolbar="+toolbar+",location"+location+",directories"+directories+",menubar"+menubar+",resizable"+resizable+",status"+status+",fullscreen"+fullscreen); oTarget.focus(); return false; } . .