var OPEN_POPUP_SPEED = 400;
var MailingPopup = new Class({
Implements: [Events],
Binds: ['close', 'submitClicked', 'onScroll'],
initialize: function(__emailId, __name) {
this.emailId = __emailId;
this.name = __name;
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.addClass('mailing-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() {
var html = '
' +
'Thank you
Please Check your email and confirm your subscription
' +
'Submit failed
There was a problem submitting
';
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();
$('ErrorMsgMailing').innerHTML=iFrameErrorMsg;
$('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.getElementById('formMailing'),{
requiredFieldIds: ['name', 'surname', 'company', 'email', 'country', 'jobtitle'],
onFailure: function(){
log('iframe onFailure()');
t.showFailedMsg();
return false;
},
onComplete: function(response){
log('iframe onComplete()');
t.showThankyouMsg();
return false;
}
});
}, 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');
}
}
});