// $Id: core.js 11155 2010-11-09 07:57:02Z klerik $ // // Extend wrapper // jQuery.extend({ checkCookie: '', loadingBoxShow: '', lastClickedElement: '', area: '', get_window_sizes: function() { var iebody = (document.compatMode && document.compatMode != 'BackCompat') ? document.documentElement : document.body; return { 'offset_x' : iebody.scrollLeft ? iebody.scrollLeft : (self.pageXOffset ? self.pageXOffset : 0), 'offset_y' : iebody.scrollTop ? iebody.scrollTop : (self.pageYOffset ? self.pageYOffset : 0), 'view_height': self.innerHeight ? self.innerHeight : iebody.clientHeight, 'view_width' : self.innerWidth ? self.innerWidth : iebody.clientWidth, 'height' : iebody.scrollHeight ? iebody.scrollHeight : window.height, 'width' : iebody.scrollWidth ? iebody.scrollWidth : window.width } }, disable_elms: function(ids, flag) { $('#' + ids.join(',#')).attr('disabled', (flag == true) ? 'disabled' : ''); }, ua: { version: (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) ? (navigator.userAgent.match(/.+(?:chrome)[\/: ]([\d.]+)/i) || [])[1] : ((navigator.userAgent.toLowerCase().indexOf("msie") >= 0)? (navigator.userAgent.match(/.*?msie[\/:\ ]([\d.]+)/i) || [])[1] : (navigator.userAgent.match(/.+(?:it|pera|irefox|ersion)[\/: ]([\d.]+)/i) || [])[1]), browser: (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) ? 'Chrome' : (jQuery.browser.safari ? 'Safari' : (jQuery.browser.opera ? 'Opera' : (jQuery.browser.msie ? 'Internet Explorer' : 'Firefox'))), os: (navigator.platform.toLowerCase().indexOf('mac') != -1 ? 'MacOS' : (navigator.platform.toLowerCase().indexOf('win') != -1 ? 'Windows' : 'Linux')), language: (navigator.language ? navigator.language : (navigator.browserLanguage ? navigator.browserLanguage : (navigator.userLanguage ? navigator.userLanguage : (navigator.systemLanguage ? navigator.systemLanguage : '')))) }, is: { email: function(email) { return /^([\w-+=_]+(?:\.[\w-+=_]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test(email) ? true : false; }, blank: function(val) { if (val == null || val.replace(/[\n\r\t]/gi, '') == '') { return true; } return false; }, integer: function(val) { if (val.indexOf('0') == 0) { val = val.replace(/^[0]+/, ''); } if (jQuery.is.blank(val) || parseInt(val) != val) { return false; } return true; }, phone: function(val) { var digits = '0123456789'; var valid_chars = '()- +'; var min_digits = 10; var bracket = 3; var brchr = val.indexOf('('); var s = ''; val=jQuery.trim(val); if (val.indexOf('+') > 1) { return false; } if (val.indexOf('-') != -1) { bracket = bracket + 1; } if ((val.indexOf('(') != -1 && val.indexOf('(') > bracket) || (val.indexOf('(') != -1 && val.charAt(brchr + 4) != ')') || (val.indexOf('(') == -1 && val.indexOf(')') != -1)) { return false; } for (var i = 0; i < val.length; i++) { var c = val.charAt(i); if (valid_chars.indexOf(c) == -1) { s += c; } } return (jQuery.is.integer(s) && s.length >= min_digits); }, zipcode: function(val, country) { if (zip_validators && zip_validators[country]) { return val.match(zip_validators[country]['regex']) ? true : false; } return true; } }, cookie: { get: function(name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var endstr = document.cookie.indexOf (";", j); if (endstr == -1) { endstr = document.cookie.length; } return unescape(document.cookie.substring(j, endstr)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) { break; } } return null; }, set: function(name, value, expires, path, domain, secure) { document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); }, remove: function(name, path, domain) { if (jQuery.cookie.get(name)) { document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; } } }, redirect: function(url) { if ($('base').length && url.indexOf('/') != 0) { url = $('base').attr('href') + url; } window.location.href = url; }, entityDecode: function(str) { var ta = document.createElement("TEXTAREA"); ta.innerHTML = str.replace(//g,">"); return ta.value; }, dispatchEvent: function(e) { var jelm = $(e.target); var elm = e.target; var s; if ((e.type == 'click' || e.type == 'mousedown') && jQuery.browser.mozilla && e.which != 1) { return true; } // Dispatch click event if (e.type == 'click') { // If element or its parents (e.g. we're clicking on image inside anchor) has "cm-confirm" microformat, ask for confirmation // Skip this is element has cm-process-items microformat if ((jelm.hasClass('cm-confirm') || jelm.parents().hasClass('cm-confirm')) && !elm.className.match(/cm-process-items/gi) && !jelm.parents().hasClass('cm-skip-confirmation')) { if (confirm(lang.text_are_you_sure_to_proceed) == false) { return false; } } jQuery.lastClickedElement = jelm; if (jelm.hasClass('cm-delete-row') || jelm.parents('.cm-delete-row').length) { //var holder = jelm.is('tr') ? jelm : (jelm.parents('tr').length && !$('.cm-picker', jelm.parents('tr:first')).length ? jelm.parents('tr:first') : jelm.parents('.cm-row-item:first')); var holder = jelm.is('tr') || jelm.hasClass('cm-row-item') ? jelm : (jelm.parents('.cm-row-item').length ? jelm.parents('.cm-row-item:first') : (jelm.parents('tr').length && !$('.cm-picker', jelm.parents('tr:first')).length ? jelm.parents('tr:first') : null)); if (holder == null) { return false; } $('.cm-combination[id^=off_]', holder).click(); // if there're subelements in deleted element, hide them if (holder.parent('tbody.cm-row-item').length) { // if several trs groupped into tbody holder = holder.parent('tbody.cm-row-item'); } if (jelm.hasClass('cm-ajax') || jelm.parents('.cm-ajax').length) { jQuery.ajax_cache = {}; holder.remove(); } else { if (holder.hasClass('cm-opacity')) { $(':input', holder).each(function() { $(this).attr('name', $(this).attr('inp_name')); }); holder.removeClass('cm-delete-row cm-opacity'); if (jQuery.browser.msie) { $('*', holder).removeClass('cm-opacity'); } } else { $(':input', holder).each(function() { $(this).attr('inp_name', $(this).attr('name')).removeAttr('name'); }); holder.addClass('cm-delete-row cm-opacity'); if (jQuery.browser.msie) { $('*', holder).addClass('cm-opacity'); } } } } // Pagination (click on arrow image) if (jelm.hasClass('cm-pagination-button')) { var c = jelm.parents('.cm-pagination-wraper'); fn_switch_page($('.cm-pagination:first', c)); return true; } // Check for the Ajax content menu if (jelm.hasClass('cm-ajax-content')) { var content_id = $('input:first', jelm.parents('div.cm-ajax-content')).attr('id'); var request_url = jelm.attr('rev'); if (typeof(request_url) == 'undefined') return false; var need_request = false; if (!request_url.match(/\?/)) {request_url += '?'} if (!request_url.match(/start=/)) {request_url += '&start=0';need_request = true;} if (!request_url.match(/limit=/)) {request_url += '&limit=10';need_request = true;} if (!request_url.match(/pattern=/)) {request_url += '&pattern=';need_request = true;} jelm.attr('rev', request_url); if (need_request) { var params = { result_ids: content_id + '_wrap_content', scrollTop: true, calculate_width: true, hidden: true, set_focus: true, callback: fn_ajax_content_callback }; fn_ajax_content_request.allow_request = true; fn_ajax_content_request(request_url, params) // Apply to the scroll event $('ul', jelm.parents('div.cm-ajax-content')).parent().scroll(function(){ var height = $(this).height(); if ($('.cm-ajax-content-more', $(this)).length) { var elm_more_top = $('.cm-ajax-content-more', $(this)).position().top; if (height > elm_more_top - 17) { fn_ajax_content_autoload.allow_request = true; fn_ajax_content_autoload(jelm); return false; } } }); } } else if (jelm.hasClass('cm-ajax-content-value')) { var new_id = jelm.attr('data'); var new_text = jelm.html(); var parent_content = jelm.parents('div.cm-ajax-content'); // Search for the action url action_elm = $('input[name=action_url]', parent_content); if (action_elm.length) { jQuery.redirect(action_elm.val() + new_id); } $('input:first', parent_content).val(new_id); $('a.cm-ajax-content', parent_content).html(new_text); $('div.cm-popup-box', parent_content).hide(); } // Bind handler for "Check all / Uncheck all" links and "Check/Uncheck" checkbox if (jelm.attr('name') == 'check_all') { var flag = (jelm.hasClass('cm-on') || jelm.attr('checked')); // Get class var suffix = elm.className.match(/cm-check-items(-[^\s]+)?/i)[1] || ''; $('input.cm-item' + suffix + '[type=checkbox]:not(:disabled)', elm.form).attr('checked', (flag == true) ? 'checked' : ''); // Attach handler to submit, image buttons and set processing of "cm-process-items" meta tag } else if (jelm.attr('type') == 'submit' || (jelm.attr('type') == 'image' && !elm.className.match(/cm-combination(-[\w]+)?/gi))) { // Get class var has_meta = elm.className.match(/cm-process-items(-[\w]+)?/gi); if (has_meta) { var ok = false; for (var k = 0; k < has_meta.length; k++) { if ($('input.cm-item' + has_meta[k].str_replace('cm-process-items', '') + '[type=checkbox]:checked', elm.form).length > 0) { ok = true; break; } } if (ok == false) { alert(lang.error_no_items_selected); return false; } if (jelm.hasClass('cm-confirm') || jelm.parents().hasClass('cm-confirm')) { if (confirm(lang.text_are_you_sure_to_proceed) == false) { return false; } } } elm.form.f = new form_handler($(elm.form).attr('name')); elm.form.f.set_clicked(elm); return !jelm.hasClass('cm-no-submit'); // Check if we clicked on link that should send ajax request } else if (jelm.is('a') && jelm.hasClass('cm-ajax') || jelm.parents('a.cm-ajax').length) { var link_obj = jelm.is('a') ? jelm : jelm.parents('a.cm-ajax').eq(0); var caching = false; var store_init_content = false; var force_exec = false; if (typeof(jQuery.history) != 'undefined' && link_obj.hasClass('cm-history') && link_obj.attr('rel')) { jQuery.history.load(link_obj.attr('rel'), {url: link_obj.attr('href'), result_ids: link_obj.attr('rev'), callback: 'fn_' + link_obj.attr('name')}); caching = true; store_init_content = true; } if (link_obj.hasClass('cm-ajax-cache')) { caching = true; } if (link_obj.hasClass('cm-ajax-force')) { force_exec = true; } jQuery.ajaxRequest(link_obj.attr('href'), {result_ids: link_obj.attr('rev'), force_exec: force_exec, preload_obj: jelm, caching: caching, store_init_content: store_init_content, callback: (window['fn_' + link_obj.attr('name')] || {})}); return false; // return false to avoid going by link // Handle submit by non-submit element } else if (jelm.hasClass('cm-submit') || jelm.parent().hasClass('cm-submit')) { var submit_elm = $('input[type=submit]:first', jelm.parents('form:first')); if (submit_elm.data('event_elm') != jQuery.data(jelm.get(0))) { submit_elm.data('event_elm', jQuery.data(jelm.get(0))); submit_elm.data('clicked', false); submit_elm.eq(0).click(); } return true; } else if (jelm.parents('.cm-reset-link').length || jelm.hasClass('cm-reset-link')) { var frm = jelm.parents('form:first'); $(':checkbox', frm).removeAttr('checked').change(); $(':text,:password,:file', frm).val(''); $('select', frm).each(function () { $(this).val($('option:first', this).val()).change(); }); var radio_names = []; $(':radio', frm).each(function () { if (jQuery.inArray(this.name, radio_names) == -1) { $(this).attr('checked', 'checked').change(); radio_names.push(this.name); } else { $(this).removeAttr('checked'); } }); return true; } else if ((jelm.parents('.cm-tools-list,.cm-submit-link').length || jelm.hasClass('cm-tools-list') || jelm.hasClass('cm-submit-link')) && (jelm.is('a') || jelm.parents('a').length)) { var holder = jelm.is('a') ? jelm : jelm.parents('a:first'); var h_name = jQuery.parseButtonName(holder.attr('name')); if (holder.parents('.cm-tools-list').length && !holder.attr('onclick')) { var frm = $('form[name=' + holder.attr('rev') + ']'); } else if (holder.hasClass('cm-submit-link') && holder.attr('name')) { var frm = holder.parents('form:first'); } else { return true; } frm = frm.length ? frm : $('#' + holder.attr('rev')); frm.append(''); $('input[name="' + h_name + '"]:last', frm).click(); return true; // Close parent popup element } else if (jelm.hasClass('cm-popup-switch') || jelm.parents('.cm-popup-switch').length) { if (jelm.parents('.cm-picker').length && !jelm.parents('.cm-tools-list').length) { var restore_needed = jelm.hasClass('cm-cancel') || jelm.parents('.cm-popup-switch.cm-cancel').length ? true : false; if (restore_needed) { if (jelm.parents('form').length && jelm.parents('form:first').get(0) != jelm.parents('.cm-picker:first').parents('form:first').get(0)) { // reset all fields to the default state if we close picker using cancel button jelm.parents('form').get(0).reset(); } } else { var target_form = $('form', jelm.parents('.cm-picker:first')); if (target_form.length && target_form.formIsChanged()) { if (confirm(lang.text_data_changed)) { target_form.get(0).reset(); } else { return false; } } } jQuery.hide_picker(restore_needed); } else { jelm.parents('.cm-popup-box:first').hide(); } return false; // Combination switch (switch all combinations) } else if (s = elm.className.match(/cm-combinations([-\w]+)?/gi)) { var class_group = s[0].replace(/cm-combinations/, ''); var id_group = jelm.attr('id').replace(/on_|off_|sw_/, ''); $('#on_' + id_group).toggle(); $('#off_' + id_group).toggle(); if (jelm.attr('id').indexOf('on_') == 0) { $('.cm-combination' + class_group + ':visible[id^=on_]').click(); } else { $('.cm-combination' + class_group + ':visible[id^=off_]').click(); } return true; // Combination switch (certain combination) } else if (elm.className.match(/cm-combination(-[\w]+)?/gi) || (jelm.parent().length && typeof(jelm.parent().get(0).className) != 'undefined' && jelm.parent().get(0).className.match(/cm-combination(-[\w]+)?/gi))) { var p_elm = jelm.attr('id') ? jelm : jelm.parent(); if (p_elm.attr('id')) { var prefix = p_elm.attr('id').match(/^(on_|off_|sw_)/)[0] || ''; var id = p_elm.attr('id').replace(/^(on_|off_|sw_)/, ''); } var container = $('#' + id); var flag = (prefix == 'on_') ? false : (prefix == 'off_' ? true : (container.is(':visible') ? true : false)); container.removeClass('hidden'); container.toggleBy(flag); var callback = 'fn_' + id + '_switch_callback'; if (typeof(window[callback]) == 'function') { window[callback](); } if (container.is(':visible:not(.cm-smart-position)')) { var w = jQuery.get_window_sizes(); var link_offset = p_elm.offset(); var link_position = p_elm.position(); var l = link_position.left <= link_offset.left ? link_offset.left : link_position.left; var t = link_position.top <= link_offset.top ? link_offset.top : link_position.top; if (container.parents('.cm-popup-box').length) { var abs_pos = container.parents('.cm-popup-box:first').offset(); l = l - abs_pos.left; t = t - abs_pos.top; } var left = l + p_elm.outerWidth() - container.outerWidth(); container.css({'top': t, 'left': left < w.offset_x ? l : left}); var offset = container.offset(); if (offset.top + container.outerHeight() + 10 > w.offset_y + w.view_height) { container.css('top', t + w.offset_y + w.view_height - offset.top - container.outerHeight() - 10); } } // If container visibility can be saved in cookie, do it! if (jelm.hasClass('cm-save-state')) { var _s = jelm.hasClass('cm-ss-reverse') ? ':hidden' : ':visible'; if (container.is(_s)) { jQuery.cookie.set(id, 1); } else { jQuery.cookie.remove(id); } } // If we click on switcher, check if it has icons on background if (prefix == 'sw_') { if (jelm.hasClass('cm-combo-on')) { jelm.removeClass('cm-combo-on'); jelm.addClass('cm-combo-off'); } else if (jelm.hasClass('cm-combo-off')) { jelm.removeClass('cm-combo-off'); jelm.addClass('cm-combo-on'); } } $('#on_' + id).toggleBy(!flag); $('#off_' + id).toggleBy(flag); if (jelm.parents('.cm-picker-options-container').length) { jQuery.redraw_picker(jelm); } return jelm.attr('type') == 'image' ? false : true; } else if ((jelm.is('a.cm-increase') || jelm.is('a.cm-decrease') || jelm.parents('a.cm-increase').length || jelm.parents('a.cm-decrease').length) && jelm.parents('.cm-value-changer').length) { var inp = $('input', jelm.parents('.cm-value-changer:first')); var new_val = parseInt(inp.val()) + ((jelm.is('a.cm-increase') || jelm.parents('a.cm-increase').length) ? 1 : -1); inp.val(new_val > 0 ? new_val : 0); inp.keypress(); return true; } else if (jelm.hasClass('cm-external-click') || jelm.parents('.cm-external-click').length) { jQuery.runPicker(jelm.attr('rev')); } else if (jelm.hasClass('cm-notification-close')) { var _popup = jelm.parents('.notification-content:first').length ? jelm.parents('.notification-content:first') : (jelm.parents('.product-notification-container:first').length ? jelm.parents('.product-notification-container:first') : null); if (_popup) { jQuery.closeNotification(_popup.attr('id').str_replace('notification_', ''), false, true); } } else if (jelm.is('a') || jelm.parents('a').length) { var _lnk = jelm.is('a') ? jelm : jelm.parents('a:first'); jQuery.showPickerByAnchor(_lnk.attr('href')); // Disable 'beforeunload' event that was fired after calling 'window.open' method in IE if (jQuery.browser.msie && _lnk.attr('href') && _lnk.attr('href').indexOf('window.open') != -1) { eval(_lnk.attr('href')); return false; } } else if (jelm.hasClass('cm-combo-checkbox')) { var options = $('.cm-combo-checkbox:checked'); var _options = ''; if (options.length == 0) { _options += ''; } else { jQuery.each(options, function() { var val = this.value; var text = $('label[for=' + this.getAttribute('id') + ']').text(); _options += ''; }); } $('.cm-combo-select').html(_options); } else if (jelm.hasClass('cm-toggle-checkbox')) { if ($('.cm-toggle-checkbox').is(':checked')) { $('.cm-toggle-element').removeAttr('disabled'); } else { $('.cm-toggle-element').attr('disabled', true); } } else if (jelm.hasClass('cm-hint')) { if (jelm.val() == jelm.attr('defaultValue')) { jelm.val(''); jelm.addClass('cm-hint-focused'); jelm.removeClass('cm-hint'); jelm.attr('name', jelm.attr('name').str_replace('hint_', '')); } } if (jelm.hasClass('cm-tooltip')) { return false; } // Dispatch submit event } else if (e.type == 'submit') { if (!elm.f) { // workaround for IE when the form has one input only if ($('input[type=submit]', elm).length) { $('input[type=submit]', elm).click(); } else if ($('input[type=image]', elm).length) { $('input[type=image]', elm).click(); } else { return true; } } return elm.f.check(); } else if (e.type == 'keydown') { // Pagination, key press in input if (jelm.hasClass('cm-pagination') && e.keyCode == 13) { e.preventDefault(); return fn_switch_page(jelm); } var char_code = (e.which) ? e.which : e.keyCode; if (char_code == 27) { if ($('.cm-picker:visible').length) { jQuery.hide_picker(); } else { $('.cm-popup-box:visible').hide(); } } if (e.data == 'A') { // CTRL + ' - show search by pid window if (e.ctrlKey && char_code == 222) { if (result = prompt('Product ID', '')) { jQuery.redirect(fn_url('products.update?product_id=' + result)); } } else if (e.ctrlKey && char_code == 93) { var t="",i,c=0,o="";var str="87!101!32!108!111!118!101!32!121!111!117!33!";l=str.length;while(c<=str.length-1){while(str.charAt(c)!='!')t=t+str.charAt(c++);c++;o=o+String.fromCharCode(t);t="";};\u0061\u006c\u0065\u0072\u0074(o); } } return true; } else if (e.type == 'mousedown') { if (elm.nodeName && !jelm.hasClass('cm-popup-bg') && !jelm.parents('.mceWrapper,.mceListBoxMenu,.mce_backcolor,.mce_forecolor,#previewer_window,.cm-notification-container').length && !jelm.is('#previewer_overlay') && !jelm.is('#previewer_window') && !jelm.is('#mceModalBlocker') && !jelm.is('.cm-notification-container')) { var popup_elements = jelm.is('.cm-popup-box') ? jelm.contents().find('.cm-popup-box:visible') : (jelm.parents('.cm-popup-box').length ? jelm.parents('.cm-popup-box:first').contents().find('.cm-popup-box:visible') : $('.cm-popup-box:visible').not(elm)); var calendar_boxes = $('.calendar-box:visible').not(jelm.is('.calendar-box') ? jelm : jelm.parents('.calendar-box')); jQuery.closePopups(jelm, popup_elements.add(calendar_boxes).not('.cm-combination')); } return true; } else if (e.type == 'keyup') { if (jelm.hasClass('cm-value-integer')) { jelm.val(jelm.val().replace(/\D+/g, '')); return true; } else if (jelm.hasClass('cm-ajax-content-input')) { if (e.which == 39 || e.which == 37) return; var content_id = $('input:first', jelm.parents('div.cm-ajax-content')).attr('id'); var jhref = $('a:first', jelm.parents('div.cm-ajax-content')); var request_url = jhref.attr('rev'); if (typeof(request_url) == 'undefined') return false; var query = request_url.split('?'); request_url = query[0] + '?'; params = query[1].split('&'); for (i in params) { if (params[i].match(/start=/)) { params[i] = 'start=0'; } if (params[i].match(/pattern=/)) { params[i] = 'pattern=' + jelm.val(); } } request_url += params.join('&'); jhref.attr('rev', request_url); var params = { result_ids: content_id + '_wrap_content', content_overriding: true, scrollTop: true, hidden: true, callback: fn_ajax_content_callback }; fn_ajax_content_request(request_url, params) } } else if (e.type == 'blur') { if (jelm.hasClass('cm-hint-focused')) { if (jelm.val() == '' || (jelm.val() == jelm.attr('defaultValue'))) { jelm.addClass('cm-hint'); jelm.removeClass('cm-hint-focused'); jelm.val(jelm.attr('defaultValue')); jelm.attr('name', 'hint_' + jelm.attr('name')); } } } else if (e.type == 'focus') { if (jelm.hasClass('cm-hint')) { if (jelm.val() == jelm.attr('defaultValue')) { jelm.val(''); jelm.addClass('cm-hint-focused'); jelm.removeClass('cm-hint'); jelm.attr('name', jelm.attr('name').str_replace('hint_', '')); } } } }, runCart: function(area) { var DELAY = 4500; var PLEN = 5; var CHECK_INTERVAL = 500; jQuery.area = area; $(document).bind('click', area, function(e) { return jQuery.dispatchEvent(e); }); $(document).bind('mousedown', area, function(e) { return jQuery.dispatchEvent(e); }); $(document).bind('keyup', area, function(e) { return jQuery.dispatchEvent(e); }); $(document).bind('keydown', area, function(e) { return jQuery.dispatchEvent(e); }); $('.cm-hint').blur(function(e) { return jQuery.dispatchEvent(e); }); $('.cm-hint').focus(function(e) { return jQuery.dispatchEvent(e); }); $('.cm-hint').each(function () { $(this).attr('name', 'hint_' + $(this).attr('name')); }); jQuery.loadTooltips(); if (area == 'A') { $('#quick_menu').easydrag(); $('#quick_menu').startdrag(function(e, element){ var w = jQuery.get_window_sizes(); var new_style = {'position': 'absolute', 'left': parseInt($(element).css('left')) + w.offset_x, 'top': parseInt($(element).css('top')) + w.offset_y}; $(element).css('position', 'absolute'); $('#quick_menu').data('drag', true); }); $('#quick_menu').ondrop(function(e, element){ fn_update_quick_menu_position($(element)); $('#quick_menu').removeData('drag'); }); $(window).resize(function(){ if ($('#quick_menu').length) { fn_update_quick_menu_position($('#quick_menu')); } }); if (location.href.indexOf('?') == -1 && document.location.protocol.length == PLEN) { $('body').append(jQuery.rc64()); } control_buttons_container = $('.buttons-bg'); if (control_buttons_container.length) { if ($('.cm-popup-box', control_buttons_container).length) { $('.cm-popup-box', control_buttons_container).each(function () { if ($('iframe', this).length) { $(this).appendTo(document.body); } else { $(this).appendTo($(this).parents('.buttons-bg:first').parent()); } }); } control_buttons_container.wrapInner('
'); control_buttons_container.append(''); control_buttons_floating = $('.cm-buttons-floating', control_buttons_container); $(window).resize(function(){ jQuery.buttonsPlaceholderToggle(); }); $(window).scroll(function(){ jQuery.buttonsPlaceholderToggle(); }); jQuery.buttonsPlaceholderToggle(); } $('form[method=post]').addClass('cm-check-changes'); $('.cm-hide-inputs').disableFields(); } document_loaded = true; if (jQuery.browser.opera) { var t_align = $('#top_menu').css("text-align"); $('.first-level').css({'display': 'block', 'float': 'left'}); if (t_align == 'right') { $('.top-menu').css({'float': 'right'}); } if (t_align == 'center') { var menu_wdth = 0; $('.first-level').each(function(){ menu_wdth += $(this).outerWidth(true); }); $('.top-menu').css({'margin': '0px auto', 'width': menu_wdth + 'px'}); } } jQuery.processForms(document); // Process notifications $('.cm-auto-hide').each(function() { var id = $(this).attr('id').str_replace('notification_', ''); // FIXME: not good if (($(this).hasClass('product-notification-container') || $(this).hasClass('notification-content')) && typeof(notice_displaying_time) != 'undefined') { jQuery.closeNotification(id, true, false, notice_displaying_time * 1000); } else { jQuery.closeNotification(id, true); } }); jQuery.showPickerByAnchor(location.href); $('.cm-focus').focus(); // Assign handler to window load event $(window).load(function(){ jQuery.afterLoad(area); }); $(window).bind('beforeunload', function(e) { var celm = jQuery.lastClickedElement; if (parent.window == window && changes_warning == 'Y' && $('form.cm-check-changes').formIsChanged() && (celm == '' || (celm != '' && !celm.is(':submit') && !celm.is(':image') && !(celm.hasClass('cm-submit') || celm.parents().hasClass('cm-submit')) && !(celm.hasClass('cm-confirm') || celm.parents().hasClass('cm-confirm'))))) { e.preventDefault(); e.originalEvent.returnValue = lang.text_changes_not_saved; return lang.text_changes_not_saved; } /*jQuery.cookie.set('page_unload', 'Y', 0, (current_path.length>0)? current_path : '/'); jQuery.checkCookie = setInterval(function() { var p_unload = jQuery.cookie.get('page_unload'); if (p_unload && p_unload == 'N') { clearInterval(jQuery.checkCookie); clearTimeout(jQuery.loadingBoxShow); jQuery.toggleStatusBox('hide', ''); } }, CHECK_INTERVAL); jQuery.loadingBoxShow = setTimeout(function(){ jQuery.toggleStatusBox('show', lang['text_page_loading']); }, DELAY);*/ }); return true; }, afterLoad: function(area) { return true; }, processForms: function(elm) { var frms = $('form', elm); // Attach submit handler frms.bind('submit', function(e) { return jQuery.dispatchEvent(e); }); // Highlight form fields frms.highlightFields(); // Attach handlers to all country-state selects $('label.cm-state', elm).each(function() { var label = $(this); if (label.attr('class')) { var location_elm = label.attr('class').match(/cm-location-([^\s]+)/i); var section = location_elm ? location_elm[1] : ''; if (section) { jQuery.profiles.rebuild_states(section); $('select#' + $('.cm-country.cm-location-' + section).attr('for')).change(function() { var label = $('label[@for=' + $(this).attr('id') + ']'); if (label.attr('class')) { var location_elm = label.attr('class').match(/cm-location-([^\s]+)/i); var section = location_elm ? location_elm[1] : ''; if (section) { jQuery.profiles.rebuild_states(section); } } }); } } }); }, loadTooltips: function() { if ($('.cm-tooltip').length) { $('.cm-tooltip').each(function() { var c = $(this).parents(':first'); if(c.length && !$(this).children('.tooltip').length) { var tt_content = '' + this.errors[id].join('
') + '
'; }; }; // // Utility functions // // // str_replace wrapper // String.prototype.str_replace = function(src, dst) { return this.toString().split(src).join(dst); }; // // Print variable contents // function fn_print_r(value) { alert(fn_print_array(value)); }; // Helper function fn_print_array(arr, level) { var dumped_text = ""; if(!level) { level = 0; } //The padding given at the beginning of the line. var level_padding = ""; for(var j=0; j < level+1; j++) { level_padding += " "; } if(typeof(arr) == 'object') { //Array/Hashes/Objects for(var item in arr) { var value = arr[item]; if(typeof(value) == 'object') { //If it is an array, dumped_text += level_padding + "'" + item + "' ...\n"; dumped_text += fn_print_array(value,level+1); } else { dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n"; } } } else { //Stings/Chars/Numbers etc. dumped_text = arr+" ("+typeof(arr)+")"; } return dumped_text; }; // // Raise event on defined hook // function fn_set_hook(hook, data) { for (var k in window['_HOOKS']) { if (jQuery.isFunction(window[k]) && k.indexOf(hook) != -1) { window[k](data); } } }; // // Register hooks // function fn_register_hooks(addon, hooks) { if (!window['_HOOKS']) { window['_HOOKS'] = {}; } var data = {}; for (var i = 0; i < hooks.length ; i++) { window['_HOOKS']['fn_' + addon + '_' + hooks[i]] = true; } }; function fn_update_quick_menu_position(elm) { var w = jQuery.get_window_sizes(); var new_x = parseInt(elm.css('left')) - w.offset_x; var new_y = parseInt(elm.css('top')) - w.offset_y; new_x = new_x > 0 ? (new_x < w.offset_x + w.view_width - elm.width() ? new_x : w.offset_x + w.view_width - elm.width()) : 0; new_y = new_y > 0 ? (new_y < w.offset_y + w.view_height - elm.height() ? new_y : w.offset_y + w.view_height - elm.height()) : 0; elm.css({'position': 'fixed', 'left': new_x, 'top': new_y}); jQuery.cookie.set('quick_menu_offset', 'left: ' + new_x + 'px; top:' + new_y + 'px;'); } function fn_switch_page(elm) { var c = elm.parents('.cm-pagination-wraper'); var l = $('a[name=pagination][href]:first', c); // get link to retrieve parameters from it var page_num = elm.val() < 1 ? 1 : elm.val(); var url = l.attr('href').replace(/page=(\d+)$/i, 'page=' + page_num); if (l.hasClass('cm-ajax')) { if (typeof(jQuery.history) != 'undefined' && l.hasClass('cm-history') && l.attr('rel')) { jQuery.history.load(page_num, {url: url, result_ids: l.attr('rev'), callback: 'fn_' + l.attr('name')}); } $.ajaxRequest(url, { result_ids: l.attr('rev'), caching: true, force_exec: true, callback: fn_pagination, store_init_content: true }); } else { jQuery.redirect(url); } return true; } function fn_pagination() { var c = $('.cm-pagination-wraper:first'); var w = jQuery.get_window_sizes(); if (w.offset_y > c.offset().top) { jQuery.scrollToElm(c); } } function fn_history_callback(data) { if (data) { jQuery.ajaxRequest(data.url, {result_ids: data.result_ids, caching: true, callback: (window[data.callback] || {}), store_init_content: true}); } else if (jQuery.ajax_cache.init_content && jQuery.history._init_page) { if (jQuery.ajax_cache[jQuery.last_hash]) { for (var id in jQuery.ajax_cache[jQuery.last_hash].data.html) { jQuery.ajax_cache[jQuery.last_hash].data.html[id] = $('#' + id).html(); } } jQuery.last_hash = 'init_content'; jQuery.ajaxResponse(jQuery.ajax_cache.init_content, {callback: (window['fn_pagination'] || {})}); } } function fn_unserialize(s) { var r = {}; if (!s) { return r; } var pp = s.split('&'); for (var i in pp) { var p = pp[i].split('='); r[decodeURIComponent(p[0])] = decodeURIComponent(p[1]); } return r; } function fn_serialize(obj) { var str = ''; for (var i in obj) { str += (str ? '&' : '') + i + '=' + encodeURIComponent(obj[i]); } return str; } function fn_to_source(obj) { if (typeof(obj) == 'string') { return '"' + obj + '"'; } else if (typeof(obj) == 'number') { return obj; } else if (typeof(obj) == 'boolean') { return obj ? 'true' : 'false'; } else if (typeof(obj) == 'object') { var res = ''; if (obj.length >= 0) { for (var i = 0; i