EmailAFriend = Class.create( {
initialize: function( data ) {
this.event_id = data.event_id || "";
this.auction_id = data.auction_id || "";
var form_submit_function = this.submit_form.bind( this );
var thisobj = this;
EmailAFriend.popup.addLinks( [ {
link_id: data.share_link.id('share_link'),
popup_align: {
x: 'center',
y: 'center'
},
onShow: function() {
thisobj.on_link_click( this );
$('eaf_submit').observe( 'click', form_submit_function );
},
onHide: function() {
$('eaf_submit').stopObserving( 'click', form_submit_function );
}
} ] );
},
on_link_click: function() {
$('eaf_form').style.display = "";
$('eaf_confirm').style.display = "none";
this.clear_form();
},
clear_form: function() {
$('eaf_correct_msg').style.display = "none";
[
"your_name",
"your_email",
"recip_email1"
].each( function ( name ) {
var id = 'eaf_' + name + '_label';
$(id).className = "";
} );
[
'your_name',
'your_email',
'recip_email1',
'recip_email2',
'recip_email3',
'recip_email4'
].each( function( id ) {
$('eaf_' + id).value = "";
} );
$('eaf_copy_me').checked = "";
},
submit_form: function() {
var parameters = {};
parameters.v = EmailAFriend.v;
parameters.page_type = EmailAFriend.page_type;
parameters.event_id = this.event_id;
parameters.auction_id = this.auction_id;
$('eaf_cancel').disabled = "disabled";
$('eaf_submit').disabled = "disabled";
[
'your_name',
'your_email',
'recip_email1',
'recip_email2',
'recip_email3',
'recip_email4'
].each( function( id ) {
parameters[id] = $('eaf_' + id).value;
} );
if ( $('eaf_copy_me').checked )
parameters.copy_me = 1;
var eafobj = this;
new Ajax.Request( "/email_friend", {
method: 'post',
parameters: parameters,
onSuccess: function( transport ) {
$('eaf_cancel').disabled = "";
$('eaf_submit').disabled = "";
var data = transport.responseText.evalJSON();
if ( data.errors ) {
$('eaf_correct_msg').style.display = "";
[
"your_name",
"your_email",
"recip_email1",
"recip_email2",
"recip_email3",
"recip_email4"
].each( function ( name ) {
var id = 'eaf_' + name + '_label';
if ( typeof(data.errors[name]) == 'object' )
$(id).className = "errorMessage";
else
$(id).className = "";
} );
}
else if ( data.emails ) {
while ( $('eaf_recip_email_list').hasChildNodes() )
$('eaf_recip_email_list').removeChild( $('eaf_recip_email_list').firstChild );
for ( var i = 0 ; i < data.emails.length ; i ++ ) {
var email = new Element ( 'li' );
email.innerHTML = data.emails[i];
$('eaf_recip_email_list').appendChild( email );
}
$('eaf_confirm').style.display = "";
$('eaf_form').style.display = "none";
EmailAFriend.popup.show( {
anchor_id: document.body,
popup_align: {
x: 'center',
y: 'center'
}
} );
}
else {
eafobj.on_server_error();
}
},
onFailure: function( transport ) {
$('eaf_cancel').disabled = "";
$('eaf_submit').disabled = "";
eafobj.on_server_error();
}
});
},
on_server_error: function() {
alert ( "Something went wrong.  Please try again later." );
}
});
EmailAFriend.popup = new Popup( 'eaf_display', {
zIndex: 110,
lightbox: { opacity: 0.6 },
close_id: [ "eaf_form_close", "eaf_cancel", "eaf_conf_close", "eaf_conf_close_box" ]
} );

