var OPEN_POPUP_SPEED = 400; var ContactPopup = new Class({ Implements: [Events], Binds: ['close', 'submitClicked', 'onScroll'], initialize: function(__emailId, __name, __modc, __enq) { this.emailId = __emailId; this.name = __name; this.modc = __modc; this.enq = __enq; this.setup(); }, containerDiv : 0, formDiv : 0, isOpen : false, setup: function() { this.containerDiv = new Element('div'); this.containerDiv.addClass('lightbox'); this.createHtml(); if (!SUPPORT_OPACITY) { this.containerDiv.setStyle('opacity', 0); this.formDiv.setStyle('opacity', 0); this.formDiv.setAnimationProperties(['opacity'], [OPEN_POPUP_SPEED], [''], [0]); } this.containerDiv.setAnimationProperties(['opacity'], [OPEN_POPUP_SPEED], [''], [0]); if (!SUPPORT_POSITION_FIXED) { window.addEvent('scroll', this.onScroll); } this.open(); this.resize(window.getSize().x, window.getSize().y); //$('submitContactForm').addEvent('click', this.submitClicked); }, onScroll: function(e) { var scrolled = window.getScroll().y, windowHeight = window.getSize().y, formHeight = this.formDiv.getSize().y, diff = windowHeight - formHeight, toTop = Math.round( scrolled + +(diff * .5) ); this.formDiv.setStyle('margin-top', toTop + 'px'); }, createHtml: function() { var bgDiv = new Element('div'); bgDiv.addClass('bg'); bgDiv.inject(this.containerDiv); bgDiv.addEvent('click', this.close); this.formDiv = new Element('div'); this.formDiv.addClass('contact-form-holder'); this.formDiv.inject(this.containerDiv); this.formDiv.set('html', this.getFormHtml()); this.formDiv.getElements('.close-popup-btn').addEvent('click', this.close); }, getFormHtml: function() { //in the office pages we can have multiple. So let's get the right modc // alert(eval('typeOf(modc_'+this.emailId+')')); var html = '

Your message for ' + this.name + '

' + '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '' + '
Cancel
' + '' + ''; return html; }, submitClicked: function() { //this.close(); //return true; //if (this.validateForm()) return true; //else return false; }, showThankyouMsg: function() { this.open(); $('lb-form-holder').setStyle('display', 'none'); $('lb-fail-holder').setStyle('display', 'none'); $('lb-thanks-holder').setStyle('display', 'block'); }, showFailedMsg: function() { this.open(); $('lb-form-holder').setStyle('display', 'none'); $('lb-thanks-holder').setStyle('display', 'none'); $('lb-fail-holder').setStyle('display', 'block'); }, open: function() { if (!this.isOpen) { this.isOpen = true; this.containerDiv.inject($$('body')[0]); var t = this; setTimeout(function() { //if (!SUPPORT_POSITION_FIXED) t.onScroll(); //will be called in resize() instead t.containerDiv.animateStyle('opacity', 1); if (!SUPPORT_OPACITY) t.formDiv.animateStyle('opacity', 1); var iFrame = new iFrameFormRequest(document.getElement('form'),{ requiredFieldIds: ['name', 'surname', 'company', 'email', 'jobtitle', 'msg'], onFailure: function(){ log('iframe onFailure()'); t.showFailedMsg(); }, onComplete: function(response){ log('iframe onComplete()'); t.showThankyouMsg(); } }); }, 5); } }, close: function() { if (this.isOpen) { this.isOpen = false; this.containerDiv.animateStyle('opacity', 0); if (!SUPPORT_OPACITY) this.formDiv.animateStyle('opacity', 0); var t = this; setTimeout(function() { t.containerDiv.dispose(); t.fireEvent('popupClosed'); }, OPEN_POPUP_SPEED); } }, resize: function(w, h) { if (!SUPPORT_POSITION_FIXED) { var fullPageHeight = $$('.main')[0].getSize().y + $$('.main')[0].getPosition().y; this.containerDiv.setStyle('height', fullPageHeight + 'px'); this.onScroll(); } else { var toTop = Math.round( (h * .5) - (this.formDiv.getSize().y * .5) ); this.formDiv.setStyle('margin-top', toTop + 'px'); var el = document.getElementById('navburger'); var styleObj; if (typeof window.getComputedStyle != "undefined") { styleObj = window.getComputedStyle(el, null); } else if (el.currentStyle != "undefined") { styleObj = el.currentStyle; } var isMobile = false; //initiate as false if (styleObj) { if(styleObj.display=='block'){ isMobile = true; } } if (isMobile == true) { var fullPageHeight = $$('.main')[0].getSize().y + $$('.main')[0].getPosition().y; this.containerDiv.setStyle('height', fullPageHeight + 'px'); this.onScroll(); } } } });