/*
 *
 * JavaScript for the Multiple Row Carrier Lookup Form
 *
 * IMPORTANT: Do not use this JavaScript on any other pages besides the
 * multiple-row carrier lookup form!
 *
 */

whitepages.page = function() {};

whitepages.page.add_carrier_lookup_row = function(row_to_duplicate, insert_before) {
  var cloned = $(row_to_duplicate).clone();
  $(row_to_duplicate).removeClass();
  
  var row_html = cloned.html();
  
  // Get existing row number
  var matches = row_html.match(/name_(\d+)/);
  var row_num = matches[1];
  
  // Replace existing row number with (row number + 1)
  var search_for = new RegExp('_' + row_num, 'g');
  row_html = row_html.replace(search_for, '_' + (parseInt(row_num) + 1));
  cloned.html(row_html);
  
  cloned.insertBefore(insert_before);
};