AdaAddressForm = Class.create( Module, {
initialize: function( $super, data ) {
$super( 'ada_address_form', { removeParent: true } );
if ( data.states ) {
var select = $('ada_state');
for ( var i = 0 ; i < data.states.length ; i ++ )
select.options[select.options.length] = new Option( data.states[i], data.states[i] );
this.require_state = true;
}
else
$('ada_state_display').style.display = "none";
if (data.webtrend) {
Event.observe('purchase_ada_link', 'click', function() {
dcsMultiTrack ('DCS.dcsuri', data.webtrend,'WT.ti', data.webtrend);
});
}
}
} );
AdaMSAttribute = Class.create( Module, {
initialize: function( $super, data ) {
$super( { parent: 'ada_conf_mastersearch_attribute', removeParent: true } );
}
} );
Ada = Class.create( Module, {
initialize: function( $super, data ) {
$super( { dom: 'ada_form' } );
this.ticket_limit = 50;
this.event_id = data.event_id;
this.opt_in = data.opt_in;
this.is_shoppinglist = data.shoppinglist;
if ( data.shoppinglist ) {
while ( this.$('ada_feature_submit_box').hasChildNodes() )
this.$('ada_feature_submit_box').removeChild( this.$('ada_feature_submit_box').firstChild );
}
else {
this.$('ada_address_box').style.display = "";
this.address_form = new AdaAddressForm( data );
$('purchase_ada_link').style.display = "";
$('purchase_ada_link').observe( 'click', this.show.bind( this ) );
this.address_form.attach( this.$('ada_address_box') );
this.show_function = data.show_function;
this.cancel_function = data.cancel_function;
new Module( 'ada_submit_buttons' ).attach( this.$('ada_feature_submit_box') );
$('ada_cancel_button').observe( 'click', this.hide.bind( this ) );
$('ada_submit_button').observe( 'click', this.submit.bind( this ) );
$('ada_event_name').innerHTML = data.event_name;
if ( data.venue )
$('ada_venue').innerHTML = data.venue;
else
$('ada_venue_display').style.display ="none";
if ( data.venue_location )
$('ada_venue_location').innerHTML = data.venue_location;
else
$('ada_venue_location_display').style.display ="none";
if ( data.event_date )
$('ada_event_date').innerHTML = data.event_date;
else
$('ada_event_date').style.display ="none";
}
this.set_quantity_limits();
if ( this.opt_in ) {
new Module( 'ada_opt_in_frag' ).attach( this.$('ada_opt_in_display') );
$('ada_vv_opt_in_item_label').innerHTML = this.opt_in.label;
$('ada_opt_in_text').innerHTML = this.opt_in.text;
}
this.$('ada_venue_phone').update( data.venue_phone );
var ada_info = this.$('ada_info');
var info_text = ada_info.innerHTML;
var i = 220;
while ( info_text.charAt(i) != ' ' )
i ++;
var info_parts = [ info_text.slice(0,i), info_text.slice(i) ];
while ( ada_info.hasChildNodes() )
ada_info.removeChild( ada_info.firstChild );
ada_info.appendChild( new Element( 'span', {} ).update( info_parts[0] ) );
this.extra_info = new Element( 'span', {} ).update( info_parts[1] );
ada_info.appendChild( this.extra_info );
this.toggle_ada_info();
this.$('ada_info_toggle').observe( 'click', this.toggle_ada_info.bind( this ) );
},
attach: function( $super, element ) {
$super( element );
new Module( 'ada_confirmation' ).attach( element );
},
toggle_ada_info: function() {
if( !this.extra_info.style.display ) {
this.$('ada_info_toggle').update( Ada.see_more );
this.$('ada_info_toggle').className = "highlight moreLink";
this.extra_info.style.display = "none";
}
else {
this.$('ada_info_toggle').update( Ada.see_less );
this.$('ada_info_toggle').className = "highlight moreLink-open";
this.extra_info.style.display = "";
}
},
_add_parameter: function ( obj, id ) {
obj[id+'_'+this.event_id] = this.$('ada_' + id).value;
},
_add_form_parameter: function ( form, id ) {
form.appendChild( new Element( 'input', { type: 'hidden', name: id+'_'+this.event_id, value: this.$('ada_' + id).value } ) );
},
_add_address_parameter: function ( obj, id ) {
obj[id] = $('ada_' + id).value;
},
get_total_selected: function () {
var q = parseInt(this.$('ada_quantity').value) || 0;
var cq = parseInt(this.$('ada_companion_quantity').value) || 0;
return q + cq;
},
get_selected_type: function () {
return this.$('ada_type').options[this.$('ada_type').selectedIndex].value;
},
add_form_values: function( form ) {
this._add_form_parameter( form, 'quantity' );
this._add_form_parameter( form, 'type' );
this._add_form_parameter( form, 'companion_quantity' );
if ( this.$('ada_canine_companion').checked )
this._add_form_parameter( form, 'canine_companion' );
this._add_form_parameter( form, 'price_section' );
this._add_form_parameter( form, 'notes' );
this._add_form_parameter( form, 'presale_pass' );
this._add_form_parameter( form, 'discount_code' );
},
validate: function() {
var errors = [];
if ( ( parseInt( this.$('ada_quantity').value ) || 0 ) == 0 )
errors.push( Ada.error.select_quantity );
if ( !this.get_selected_type() )
errors.push( Ada.error.select_type );
if ( errors.length ) {
window.alert( Ada.error.please_fix + "\n\n" + errors.join( "\n" ) );
return false;
}
return true;
},
submit: function() {
var parameters = {};
$('ada_cancel_button').disabled = "disabled";
$('ada_submit_button').disabled = "disabled";
this._add_parameter( parameters, 'quantity' );
this._add_parameter( parameters, 'type' );
this._add_parameter( parameters, 'companion_quantity' );
if ( this.$('ada_canine_companion').checked )
this._add_parameter( parameters, 'canine_companion' );
this._add_parameter( parameters, 'price_section' );
this._add_parameter( parameters, 'notes' );
this._add_parameter( parameters, 'presale_pass' );
this._add_parameter( parameters, 'discount_code' );
if ( this.opt_in && $('ada_vv_opt_in_item').checked )
parameters.vv_opt_in_item = this.opt_in.value;
this._add_address_parameter( parameters, 'fname' );
this._add_address_parameter( parameters, 'mname' );
this._add_address_parameter( parameters, 'lname' );
this._add_address_parameter( parameters, 'addr1' );
this._add_address_parameter( parameters, 'care_of' );
this._add_address_parameter( parameters, 'unit' );
this._add_address_parameter( parameters, 'city' );
var state = "";
if ( $('ada_state').selectedIndex >=0 )
state = $('ada_state').options[$('ada_state').selectedIndex].value;
parameters.state = state;
this._add_address_parameter( parameters, 'zip' );
this._add_address_parameter( parameters, 'phone' );
this._add_address_parameter( parameters, 'evephone' );
this._add_address_parameter( parameters, 'email' );
this._add_address_parameter( parameters, 'verify_email' );
if ( this.mastersearch )
this.mastersearch.add_ajax_parameters( parameters, this.event_id );
var adaobj = this;
new Ajax.Request( "/ada/" + this.event_id, {
method: 'post',
parameters: parameters,
onSuccess: function( transport ) {
var data = transport.responseText.evalJSON();
$('ada_cancel_button').disabled = "";
$('ada_submit_button').disabled = "";
if ( data.errors ) {
adaobj.$('ada_correct_msg').style.display = "";
[
"vv_opt_in_item",
"evephone",
"fname",
"phone",
"state",
"email",
"city",
"zip",
"lname",
"addr1",
"verify_email"
].each( function ( name ) {
var id = 'ada_' + name + '_label';
if ( typeof(data.errors[name]) == 'object' )
$(id).className = "labal errorMessage";
else
$(id).className = "labal";
} );
[
"quantity",
"type"
].each( function ( name ) {
var id = 'ada_' + name + '_label';
if ( typeof(data.errors[name]) == 'object' )
adaobj.$(id).className = "labal errorMessage";
else
adaobj.$(id).className = "labal";
} );
Effect.ScrollTo( adaobj.$('ada_correct_msg') );
}
else if ( data.selections ) {
[
"evephone",
"phone",
"state",
"email",
"city",
"zip",
"addr1",
"care_of",
"unit"
].each( function ( name ) {
var id = 'ada_conf_' + name;
if ( data.contact[name] )
$(id).innerHTML = data.contact[name];
else
$(id + '_display').style.display = "none";
} );
$('ada_conf_full_name').innerHTML = [data.contact.fname, data.contact.mname, data.contact.lname].join(' ');
var selections = data.selections[0];
[
"price_section",
"canine_companion",
"discount_code",
"presale_pass",
"notes",
"type"
].each( function ( name ) {
if ( selections[name] )
$('ada_conf_' + name).innerHTML = selections[name];
else
$('ada_conf_' + name + '_display').style.display = "none";;
} );
var quantity = selections.quantity;
if ( selections.companion_quantity && !isNaN(selections.companion_quantity) )
quantity += selections.companion_quantity;
$('ada_conf_quantity').innerHTML = quantity.toString() + " ";
$('ada_confirmation').style.display = "";
adaobj.$('ada_form').style.display = "none";
if ( adaobj.mastersearch && ( selections.ms_month || selections.ms_day || selections.ms_time || selections.ms_other ) )  {
var table = $('ada_conf_mastersearch_results');
while ( table.hasChildNodes() )
table.removeChild( table.firstChild );
[
"month",
"day",
"time",
"other"
].each( function ( type ) {
var id = "ms_" + type;
if ( selections[id] ) {
var attr = new AdaMSAttribute();
attr.$('ada_conf_ms_attribute_title').innerHTML = Ada.mastersearch[type];
attr.$('ada_conf_ms_attribute_choices').innerHTML = typeof(selections[id]) == 'string' ? selections[id] : selections[id].join( ', ' );
attr.attach( table );
}
} );
$('ada_conf_mastersearch_display').style.display = "";
}
else
$('ada_conf_mastersearch_display').style.display = "none";
}
else {
adaobj.on_server_error();
}
},
onFailure: function( transport ) {
$('ada_cancel_button').disabled = "";
$('ada_submit_button').disabled = "";
adaobj.on_server_error();
}
});
},
on_server_error: function() {
alert ( "Something went wrong.  Please try again later." );
},
show: function( $super ) {
this.original_scroll = document.viewport.getScrollOffsets();
if ( !this.is_shoppinglist )
$('purchase_ada_link').hide();
$super();
this.$('ada_form').style.display = "";
$('ada_confirmation').style.display = "none";
this.$('ada_correct_msg').style.display = "none";
var thisobj = this;
[
"price_section",
"canine_companion",
"companion_quantity",
"discount_code",
"presale_pass",
"notes",
"type",
"vv_opt_in_item",
"evephone",
"fname",
"quantity",
"phone",
"state",
"email",
"city",
"zip",
"lname",
"mname",
"care_of",
"unit",
"addr1",
"type",
"verify_email"
].each( function ( name ) {
var id = 'ada_' + name;
var label_id = id + '_label';
if ( $(label_id) )
$(label_id).className = "labal";
switch ( name ) {
case 'quantity':
case 'companion_quantity':
case 'type':
thisobj.$(id).selectedIndex = 0;
break;
case "price_section":
case "discount_code":
case "presale_pass":
case "notes":
thisobj.$(id).value = "";
break;
case 'canine_companion':
thisobj.$(id).checked = "";
break;
case 'state':
$(id).selectedIndex = 0;
break;
case 'vv_opt_in_item':
$(id).checked = "";
break;
default:
$(id).value = "";
break;
}
} );
if ( this.mastersearch ) {
this.$('ada_mastersearch_box').style.display = "";
this.mastersearch.attach( this.$( 'ada_mastersearch_box' ) );
this.mastersearch.reset();
}
if ( this.show_function )
this.show_function();
this.is_visible = true;
},
hide: function( $super ) {
if ( !this.is_shoppinglist )
$('purchase_ada_link').show();
$super();
if ( this.cancel_function )
this.cancel_function();
this.is_visible = false;
},
get_selected_quantity: function ( select ) {
if ( select.selectedIndex >= 0 )
return parseInt( select.options[select.selectedIndex].value );
else
return 0;
},
set_quantity: function( select, max ) {
var selectedIndex = select.selectedIndex < 0 ? 0 : select.selectedIndex;
select.options.length = 0;
select.options[select.options.length] = new Option( Ada.select_quantity, 0 );
for ( var i = 1 ; i <= max + selectedIndex ; i ++ )
select.options[select.options.length] = new Option( i, i );
select.selectedIndex = selectedIndex;
},
set_quantity_limits: function() {
var selected_quantity = this.get_selected_quantity(this.$('ada_quantity')) + this.get_selected_quantity(this.$('ada_companion_quantity'));
var max = this.ticket_limit - selected_quantity;
this.set_quantity(this.$('ada_quantity'), max);
this.set_quantity(this.$('ada_companion_quantity'), max);
},
add_mastersearch: function ( mastersearch ) {
this.mastersearch = mastersearch;
}
});

