var TP = { Element: { clearPopUps: function () { var popups = $$('div.popup'); if (popups.length == 0) return; var popup_contents = $$('.popup_content'); popup_contents.each(function (popup_content) { popup_content.addClass('hide'); popup_content.inject(document.body); }); popups.each(function (popup) { popup.destroy(); }); }, collide: function (ev, el) { var ev = new Event(ev); var el = new Element(el); return ( (ev.page.x > el.getCoordinates().left) && (ev.page.x < el.getCoordinates().right) && (ev.page.y > el.getCoordinates().top) && (ev.page.y < el.getCoordinates().bottom) ); }, Data: {}, hideShow: function (elh, els) { if (typeof(elh) == 'string') elh = [elh]; if (typeof(els) == 'string') els = [els]; if (elh && (elh.length>0)) { var el_id = elh.pop(); var el = $(el_id); if (!el) throw('cannot find id:'+el_id); var hasMore = (elh.length > 0); var fx = new Fx.Morph(el); fx.start({'opacity':0}).chain(function() { el.addClass('hide'); if (els && (!hasMore)) TP.Element.hideShow(null, els); }); if (hasMore) TP.Element.hideShow(elh, els); } else if (els && (els.length>0)) { for (var i = 0; i < els.length; i++) { var el = $(els[i]); if (!el) throw('cannot find id:'+els[i]); el.removeClass('hide'); var fx = new Fx.Morph(el); fx.start({'opacity':1}); } } }, popUp: function (ev, el, title, width, height, offset_x, offset_y) { if (!ev || !el || el.nodeType != 1) return; width = (width) ? width : 300; offset_x = (offset_x) ? offset_x : 10; offset_y = (offset_y) ? offset_y : 15; TP.Element.clearPopUps(); var ev = new Event(ev); var el = new Element(el); var popup = document.createElement('div'); popup = new Element(popup); popup.addClass('popup'); popup.style.width = width + 'px'; var popup_header = document.createElement('div'); popup_header = new Element(popup_header); popup_header.addClass('popup_header'); popup_header.addClass('clfx'); var popup_title = document.createElement('h4'); popup_title = new Element(popup_title); popup_title.addClass('popup_title'); popup_title.set('text', (title) ? title : ''); var popup_close = document.createElement('a'); popup_close = new Element(popup_close); popup_close.addClass('popup_close'); popup_close.set('text', 'Close'); popup_close.setAttribute('href', '#'); popup_close.onclick = function () { popup.addClass('hide'); return false; }; el.addClass('popup_content'); el.removeClass('hide'); if (height) el.style.height = height + 'px'; if (title) popup_header.appendChild(popup_title); popup_header.appendChild(popup_close); popup.appendChild(popup_header); popup.appendChild(el); var popup_x = ev.page.x + offset_x; var popup_y = ev.page.y + offset_y; popup.style.left = popup_x + 'px'; popup.style.top = popup_y + 'px'; document.body.appendChild(popup); if (popup.getCoordinates().right > (window.getScrollLeft() + window.getWidth())) { popup.style.left = popup_x - (popup.getCoordinates().right - (window.getScrollLeft() + window.getWidth())) + 'px'; } if (popup.getCoordinates().bottom > (window.getScrollTop() + window.getHeight())) { var adjusted_y = popup_y - (popup.getCoordinates().bottom - (window.getScrollTop() + window.getHeight())); popup.style.top = ((adjusted_y < 0) ? 0 : adjusted_y) + 'px'; } ev.stop(); document.addEvent('click', function (ev) { if (!TP.Element.collide(ev, popup)) { TP.Element.clearPopUps(); } }); }, setButtonText: function (el, txt) { el = new Element(el); el.getElement('td.label a.content').set('text', txt); } }, f: function (key, func) { if (!func) { func = key; key = false; } return function() { try { return func.apply(this, arguments); } catch (e) { TP.f._last_exception = e; if (TP.f._last_key) { if (key) TP.f._last_key += ":" + key; } else { TP.f._last_key = key; } if (navigator.userAgent.toLowerCase().indexOf('msie') > 0) throw e; var mess = e.message; if (e.name) mess = e.name+":"+mess; var line = $pick(e.lineNumber /*firefox*/, e.line /*safari*/); var src = $pick(e.fileName /*firefox*/, e.sourceURL /*safari*/); window.onerror(mess, src, line); } }; }, Form: { clear: function (el) { this.clearInputs(el); this.clearErrors(el); }, clearErrors: function (el) { el.getElements('label.field_error').each(function (error) { error.destroy(); }); }, clearInputs: function (el) { el.getElements('input, textarea').each(function (input) { if (input.getAttribute('type') != 'hidden' && input.getAttribute('type') != 'submit') input.value = ''; }); }, disable: function (el) { el.getElements('button, input, select, textarea').each(function (input) { input.setAttribute('disabled', 'disabled'); input.addClass('disabled'); }); }, displayErrors: function (el, errors) { for (var input_id in errors) { var input = $(input_id); if (input) { var error_label = new Element('label', { 'class': 'field_error', 'for': input_id }); var error_text = new Element('span', { 'class': 'error_text' }); error_text.set('text', errors[input_id]); error_text.injectInside(error_label); error_label.injectAfter(input); } } }, enable: function (el) { el.getElements('button, input, select, textarea').each(function (input) { input.removeAttribute('disabled'); input.removeClass('disabled'); }); }, lock: function (el) { el.getElements('button, input, select, textarea').each(function (input) { input.setAttribute('readonly', 'readonly'); input.addClass('disabled'); }); }, submit: function (el, params) { if (typeof(el) == "string") el = $(el); while(el && (el.nodeName != "FORM")) el=el.parentNode; if ((!el) && (1 == document.forms.length)) { el = document.forms[0]; } if (!el) { throw('Error: Could not find form'); return; } var form = el; for(var key in params) { var value = params[key]; if (form.elements[key]) { form.elements[key].value = value; } else { var div = document.createElement('div'); div.innerHTML = ""; form.appendChild(div); } } form.submit(); return false; } }, Format: { currency: function (amt) { amt -= 0; amt = (Math.round(amt.toFloat()*100))/100; return (amt == Math.floor(amt)) ? amt + '.00' : ( (amt*10 == Math.floor(amt*10)) ? amt + '0' : amt); } }, Request: { post: function (url, params) { var form = new Element('form', { 'action': url, 'method': 'post', 'styles': { 'display': 'none' } }).inject(document.body); TP.Form.submit(form, params); } }, Table: { zebraStripe: function (el) { if (!el || (el.tagName != 'TABLE' && el.tagName != 'TBODY')) return; var row_length = el.rows.length; var count = 0; for (var i = 0; i < row_length; i++) { var row = new Element(el.rows[i]); if (!row.hasClass('hide')) count++; if ((count % 2) == 0) { row.removeClass('alt'); } else { row.addClass('alt'); } } } }, logError: function (err_code, err_msg) { var image = new Image(); image.src = 'http://static.trialpay.com/error/?ec=' + err_code + ((err_msg && encodeURIComponent) ? '&d=' + encodeURIComponent(err_msg) : ''); } } window.onerror = function (msg, url, ln) { var code = 300; if (TP.f._last_exception) { code = 400; msg = ":"+msg; if (TP.f._last_key) { msg = TP.f._last_key+msg; } delete TP.f._last_exception; delete TP.f._last_key; } TP.logError(code, msg + ":" + url + ":" + ln); return true; }