CONFMAN.abstract_submit_wizard_upload = function() {
  var form = $('abstract_submit_wizard_upload_form');
  
  var clean_abstract_text = function() {
    var field = $('abstract_text');
    
    field.value = CONFMAN.demoronize(field.value);
    return this;
  }
  
  form.observe('submit', function() {
      clean_abstract_text();
  });
};

CONFMAN.abstract_download = function(options) {
  var options = options || {};
  var cid = options.cid || '';
  var datasource = options.datasource || '';
  var user_id = options.user_id || '';
  var args = options.args || {};
  var file_manager = options.file_manager || {};
  var zip_all = options.zip_all || false;

  if ($$('a.download_link').size() > 0) {
    $$('a.download_link').invoke('observe', 'click', function(e) {
      var link = Event.findElement(e, 'a');
      var frame, timestamp, query_str;
      if (link !== null) {
        timestamp = new Date().getTime();
        if (!zip_all) {
          options.path = link.getAttribute('data-path');
          options.file = link.getAttribute('data-file');
        }
        query_str = Object.toQueryString(options);
        frame = new Element('iframe', {'name': 'downloader'+timestamp, 'src': '/ajax/download_abstract_file.cfm?'+query_str});
        frame.setStyle({'display': 'none'});
        link.insert({after: frame});
        frame.observe('load', function() {
          setTimeout(function() { frame.remove(); }, 100);
        });
      }
    });
  }
}

CONFMAN.toggle_abstract_summary = function() {
	new Effect.toggle($('abstract_summary_html'),'Appear');	
};

CONFMAN.author_address = function() {

  var address = "";
  var city = "";
  var province = "";
  var postalcode = "";
  var country = "";

  var get_primary_address = function() {
    address = $$('input[name=primary_address]').first().value;  
    city = $$('input[name=primary_city]').first().value;  
    province = $$('input[name=primary_prov]').first().value;  
    postalcode = $$('input[name=primary_postalcode]').first().value;  
    country = $$('select[name=primary_country]').first().value;  
    return this;
  };

  var set_additional_author_address = function(author) {
    $$('input[name='+author+'_address]').first().setValue(address);
    $$('input[name='+author+'_city]').first().setValue(city);
    $$('input[name='+author+'_prov]').first().setValue(province);
    $$('input[name='+author+'_postalcode]').first().setValue(postalcode);
    $$('select[name='+author+'_country]').first().setValue(country);
    return this;
  };

  $$('.js_copy_address').invoke('observe', 'click', function(e) {
    var checkbox = Event.findElement(e, 'input[type=checkbox]');
    var author = "";
    if (checkbox !== null) {
      author = checkbox.getAttribute('data-author');
      if (checkbox.checked === true) {
        get_primary_address();
        set_additional_author_address(author);
      }
    }
  });

};

