[%# This Source Code Form is subject to the terms of the Mozilla Public
  # License, v. 2.0. If a copy of the MPL was not distributed with this
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  #
  # This Source Code Form is "Incompatible With Secondary Licenses", as
  # defined by the Mozilla Public License, v. 2.0.
  #%]

[% PROCESS global/variables.none.tmpl %]

[%

items = [
  { id => '',          name => 'Splendidest Gear' },
  { id => '#185687',   name => 'Moleskine Notebook (Firefox)' },
# { id => '#155749',   name => 'Rickshaw Messenger Bag ' },
# { id => '#155415S',  name => 'Champion Hooded Sweatshirt S' },
# { id => '#155415M',  name => 'Champion Hooded Sweatshirt M' },
# { id => '#155415L',  name => 'Champion Hooded Sweatshirt L' },
# { id => '#155415X',  name => 'Champion Hooded Sweatshirt XL' },
# { id => '#1554152',  name => 'Champion Hooded Sweatshirt 2XL' },
# { id => '#157452S',  name => 'Very Splendid Package Ladies S' },
# { id => '#157452M',  name => 'Very Splendid Package Ladies M' },
# { id => '#157452L',  name => 'Very Splendid Package Ladies L' },
# { id => '#157452X',  name => 'Very Splendid Package Ladies XL' },
# { id => '#1574522',  name => 'Very Splendid Package Ladies 2XL' },
# { id => '#157454S',  name => 'Very Splendid Package Men\'s S' },
# { id => '#157454M',  name => 'Very Splendid Package Men\'s M' },
# { id => '#157454L',  name => 'Very Splendid Package Men\'s L' },
# { id => '#157454X',  name => 'Very Splendid Package Men\'s XL' },
# { id => '#1574542',  name => 'Very Splendid Package Men\'s 2XL' },
# { id => '#1574543',  name => 'Very Splendid Package Men\'s 3XL' },
# { id => '#157451S',  name => 'Most Splendid Package, S' },
# { id => '#157451M',  name => 'Most Splendid Package, M' },
# { id => '#157451L',  name => 'Most Splendid Package, L' },
# { id => '#157451X',  name => 'Most Splendid Package, XL' },
# { id => '',          name => 'Splendider Gear' },
# { id => '#155751',   name => 'Drawstring Tote ' },
# { id => '#155340',   name => 'Beanie' },
# { id => '#155339',   name => 'Black Cap with Tote ' },
# { id => '#212669',   name => 'Stoneware Ceramic Mug' },
# { id => '#190928S',  name => 'Firefox Tee w/Woven Tag Navy S' },
# { id => '#190928M',  name => 'Firefox Tee w/Woven Tag Navy M' },
# { id => '#190928L',  name => 'Firefox Tee w/Woven Tag Navy L' },
# { id => '#190928X',  name => 'Firefox Tee w/Woven Tag Navy XL' },
# { id => '#1909282',  name => 'Firefox Tee w/Woven Tag Navy 2XL' },
# { id => '#1909283',  name => 'Firefox Tee w/Woven Tag Navy 3XL' },
# { id => '#190929S',  name => 'Firefox SS Lapis Tee Lapis S' },
# { id => '#190929M',  name => 'Firefox SS Lapis Tee Lapis M' },
# { id => '#190929L',  name => 'Firefox SS Lapis Tee Lapis L' },
# { id => '#190929X',  name => 'Firefox SS Lapis Tee Lapis XL' },
# { id => '#155413S',  name => 'Ladies\' T-shirt Navy S' },
# { id => '#155413M',  name => 'Ladies\' T-shirt Navy M' },
# { id => '#155413L',  name => 'Ladies\' T-shirt Navy L' },
# { id => '#155413X',  name => 'Ladies\' T-shirt Navy XL' },
# { id => '#1554132',  name => 'Ladies\' T-shirt Navy 2XL' },
  { id => '',          name => 'Splendid Gear' },
# { id => '#192150',   name => '1.25" Firefox Button-PKG25 ' },
  { id => '#197156',   name => 'Firefox Tattoos- Pkg50' },
# { id => '#197158',   name => 'Firefox Sticker' },
# { id => '#197159',   name => 'Firefox Laminated Badge' },
# { id => '#155754',   name => 'Lanyard with Bulldog Clip (Mozilla)' },
  { id => '#155756',   name => 'Silicone Wristband ' },
# { id => '',          name => 'Limited Availability Gear' },
# { id => '#265073',   name => 'Mozilla Cap' },
  { id => '#265080',   name => 'Fox Plush' },
# { id => '#265072S',  name => 'Mozilla Custom Hoodie' },
# { id => '#265072M',  name => 'Mozilla Custom Hoodie' },
# { id => '#265072L',  name => 'Mozilla Custom Hoodie' },
# { id => '#265072X',  name => 'Mozilla Custom Hoodie' },
# { id => '#2650722',  name => 'Mozilla Custom Hoodie' },
# { id => '#265074S',  name => 'Ladies\' Firefox Logo T-Shirt' },
# { id => '#265074M',  name => 'Ladies\' Firefox Logo T-Shirt' },
# { id => '#265074L',  name => 'Ladies\' Firefox Logo T-Shirt' },
# { id => '#265074X',  name => 'Ladies\' Firefox Logo T-Shirt' },
# { id => '#2650742',  name => 'Ladies\' Firefox Logo T-Shirt' },
# { id => '#265075S',  name => 'Women\'s Vertical T-Shirt' },
# { id => '#265075M',  name => 'Women\'s Vertical T-Shirt' },
# { id => '#265075L',  name => 'Women\'s Vertical T-Shirt' },
# { id => '#265075X',  name => 'Women\'s Vertical T-Shirt' },
# { id => '#2650752',  name => 'Women\'s Vertical T-Shirt' },
# { id => '#265078S',  name => 'Mozilla Horizontal T-Shirt' },
# { id => '#265078M',  name => 'Mozilla Horizontal T-Shirt' },
# { id => '#265078L',  name => 'Mozilla Horizontal T-Shirt' },
# { id => '#265078X',  name => 'Mozilla Horizontal T-Shirt' },
# { id => '#2650782',  name => 'Mozilla Horizontal T-Shirt' },
];

mozspaces = [
  {
    name     => 'Beijing',
    address1 => 'Mozilla Online Ltd.',
    address2 => 'China Resources Building, Suite 1708, 8 Jianguomenbei Avenue',
    city     => 'Beijing',
    state    => 'Dongcheng District',
    country  => 'China',
    postcode => '100005',
  },
  {
    name     => 'Berlin',
    address1 => 'MZ Denmark ApS - Germany',
    address2 => 'GSG-Hof Schlesische Straße, Gebäude 3, 4. Obergeschoss, Schlesische Straße 27',
    city     => 'Berlin',
    state    => 'Germany',
    country  => 'Germany',
    postcode => '10997',
  },
  {
    name     => 'London',
    address1 => 'Mozilla London',
    address2 => 'Metal Box Factory, Suite 441, 4th floor, 30 Great Guildford Street',
    city     => 'London',
    state    => 'Greater London',
    country  => 'UK',
    postcode => 'SE1 0HS',
  },
  {
    name     => 'Mountain View',
    address1 => 'Mozilla',
    address2 => '331 E. Evelyn Ave.',
    city     => 'Mountain View',
    state    => 'CA',
    country  => 'USA',
    postcode => '94041',
  },
  {
    name     => 'Paris',
    address1 => 'Mozilla',
    address2 => '16 bis Boulevard Montmartre',
    city     => 'Paris',
    state    => 'Paris',
    country  => 'France',
    postcode => '75009',
  },
  {
    name     => 'Portland',
    address1 => 'Mozilla Portland',
    address2 => 'Brewery Block 2, 1120 NW Couch St. Suite 320',
    city     => 'Portland',
    state    => 'OR',
    country  => 'USA',
    postcode => '97209',
  },
  {
    name     => 'San Francisco',
    address1 => 'Mozilla',
    address2 => '2 Harrison Street, Suite 175',
    city     => 'San Francisco',
    state    => 'CA',
    country  => 'USA',
    postcode => '94105',
  },
  {
    name     => 'Taipei',
    address1 => '4F-A1, No. 106, Sec.5, Xinyi Rd',
    address2 => '',
    city     => 'Taipei City',
    state    => 'Xinyi District',
    country  => 'Taiwan',
    postcode => '11047',
  },
  {
    name     => 'Toronto',
    address1 => 'Mozilla Canada',
    address2 => '366 Adelaide Street W, Suite 500',
    city     => 'Toronto',
    state    => 'Ontario',
    country  => 'Canada',
    postcode => 'M5V 1R9',
  },
  {
    name     => 'Vancouver',
    address1 => 'Mozilla Canada',
    address2 => '163 West Hastings Street, Suite 209',
    city     => 'Vancouver',
    state    => 'BC',
    country  => 'Canada',
    postcode => 'V6B 1H5',
  },
];

PROCESS "bug/create/cost-centers.none.tmpl";

%]

[% inline_style = BLOCK %]
#gear_form th {
  text-align: right;
  font-weight: normal;
}

#gear_form .heading {
  text-align: left;
  font-size: var(--font-size-h3);
  font-weight: bold;
}

.mandatory {
  color: var(--required-label-color);
}
[% END %]

[% inline_javascript = BLOCK %]
var Dom = YAHOO.util.Dom;
var needed = {
[% FOREACH item = items %]
  [% NEXT UNLESS item.id %]
  '[% item.id FILTER js %]': 0[% ',' UNLESS loop.last %]
[% END %]
};
var needed_freeform = [];

var gear = [
[% FOREACH item = items %]
  { id: '[% item.id FILTER js %]', name: '[% item.name FILTER js %]' }
  [% ',' UNLESS loop.last %]
[% END %]
];

var mozspaces = {
[% FOREACH space = mozspaces %]
  '[% space.name FILTER js %]': {
    [% FOREACH key = space.keys.sort %]
      '[% key FILTER js %]': '[% space.$key FILTER js %]'[% ',' UNLESS loop.last %]
    [% END %]
  }[% ',' UNLESS loop.last %]
[% END %]
};

[%# implemented this way to allow for dynamic updating of mandatory fields #%]
var fields = [
  { id: 'firstname',       mandatory: true  },
  { id: 'lastname',        mandatory: true  },
  { id: 'email',           mandatory: true  },
  { id: 'mozspace',        mandatory: false },
  { id: 'teamcode',        mandatory: true  },
  { id: 'purpose',         mandatory: true  },
  { id: 'purpose_other',   mandatory: false },
  { id: 'date_required',   mandatory: false },
  { id: 'items',           mandatory: true  },
  { id: 'shiptofirstname', mandatory: true  },
  { id: 'shiptolastname',  mandatory: true  },
  { id: 'shiptoemail',     mandatory: true  },
  { id: 'shiptoaddress1',  mandatory: true  },
  { id: 'shiptoaddress2',  mandatory: false },
  { id: 'shiptocity',      mandatory: true  },
  { id: 'shiptostate',     mandatory: true  },
  { id: 'shiptocountry',   mandatory: true  },
  { id: 'shiptopostcode',  mandatory: true  },
  { id: 'shiptophone',     mandatory: true  },
  { id: 'shiptoidrut',     mandatory: false },
  { id: 'comment',         mandatory: false }
];

function initFields() {
  [%# find fields in the form, and update the fields array #%]
  var rows = Dom.get('gear_form').getElementsByTagName('TR');
  for (var i = 0, l = rows.length; i < l; i++) {
    var row = rows[i];
    var field = firstChild(row, 'INPUT') || firstChild(row, 'SELECT') || firstChild(row, 'TEXTAREA');
    if (!field || field.type == 'submit') continue;
    var id = field.id;
    var label = firstChild(row, 'TH');
    for (var j = 0, m = fields.length; j < m; j++) {
      if (fields[j].id == id) {
        fields[j].field = field;
        fields[j].label = label;
        fields[j].caption = label.textContent;
        break;
      }
    }
  }
  createCalendar('date_required');
}

function tagMandatoryFields() {
  [%# add or remove the "* mandatory" marker from fields #%]
  for (var i = 0, l = fields.length; i < l; i++) {
    var f = fields[i];
    if (!f.label) continue;
    var caption = f.caption;
    if (f.mandatory)
      caption = caption + '&nbsp;<span class="mandatory">*</span>';
    f.label.innerHTML = caption;
  }
}

function validateAndSubmit() {
  var alert_text = '';
  for(var i = 0, l = fields.length; i < l; i++) {
    var f = fields[i];
    if (f.mandatory && !isFilledOut(f.id))
      if (f.field.nodeName == 'SELECT') {
        alert_text += 'Please select the ' + f.caption + ".\n";
      } else {
        alert_text += 'Please enter the ' + f.caption + ".\n";
      }
  }
  if (isFilledOut('email') && !isValidEmail(Dom.get('email').value))
    alert_text += "Please enter a valid Email Address.\n";
  if (isFilledOut('shiptoemail') && !isValidEmail(Dom.get('shiptoemail').value))
    alert_text += "Please enter a valid Shipping Email Address.\n";

  if (alert_text != '') {
    alert(alert_text);
    return false;
  }

  Dom.get('short_desc').value = 'Mozilla Gear - ' + Dom.get('firstname').value + ' ' + Dom.get('lastname').value;
  return true;
}

function onPurposeChange() {
  var value = Dom.get('purpose').value;
  var other = Dom.get('purpose_other');

  if (value == 'Event') {
    getField('purpose_other').mandatory = true;
    other.placeholder = 'link to wiki'
    Dom.removeClass('purpose_other_row', 'bz_default_hidden');
    Dom.addClass('recognition_row', 'bz_default_hidden');

  } else if (value == 'Gear Space Stock') {
    getField('purpose_other').mandatory = true;
    other.placeholder = 'indicate space'
    Dom.removeClass('purpose_other_row', 'bz_default_hidden');
    Dom.addClass('recognition_row', 'bz_default_hidden');

  } else if (value == 'Other') {
    getField('purpose_other').mandatory = true;
    other.placeholder = 'more information';
    Dom.removeClass('purpose_other_row', 'bz_default_hidden');
    Dom.addClass('recognition_row', 'bz_default_hidden');

  } else if (value == 'Mozillian Recognition') {
    getField('purpose_other').mandatory = false;
    Dom.addClass('purpose_other_row', 'bz_default_hidden');
    Dom.removeClass('recognition_row', 'bz_default_hidden');
    onRecognitionChange();

  } else {
    getField('purpose_other').mandatory = false;
    Dom.addClass('purpose_other_row', 'bz_default_hidden');
    Dom.addClass('recognition_row', 'bz_default_hidden');
  }

  onRecognitionChange();
}

function onRecognitionChange() {
  var mandatory = Dom.get('purpose').value != 'Mozillian Recognition'
                  || !Dom.get('recognition_shipping').checked;
  getField('shiptoaddress1').mandatory = mandatory;
  getField('shiptocity').mandatory = mandatory;
  getField('shiptostate').mandatory = mandatory;
  getField('shiptocountry').mandatory = mandatory;
  getField('shiptopostcode').mandatory = mandatory;
  getField('shiptophone').mandatory = mandatory;
  tagMandatoryFields();
}

function onMozSpaceChange() {
  if (Dom.get('mozspace').value) {
    Dom.removeClass('shipto_mozspace_container', 'bz_default_hidden');
  } else {
    Dom.addClass('shipto_mozspace_container', 'bz_default_hidden');
  }
  onShipToMozSpaceClick();
}

function onShipToMozSpaceClick() {
  var address1 = address2 = city = state = country = postcode = '';
  if (Dom.get('shipto_mozspace').checked) {
    var space = Dom.get('mozspace').value;
    address1 = mozspaces[space].address1;
    address2 = mozspaces[space].address2;
    city = mozspaces[space].city;
    state = mozspaces[space].state;
    country = mozspaces[space].country;
    postcode = mozspaces[space].postcode;
  }
  Dom.get('shiptoaddress1').value = address1;
  Dom.get('shiptoaddress2').value = address2;
  Dom.get('shiptocity').value = city;
  Dom.get('shiptostate').value = state;
  Dom.get('shiptocountry').value = country;
  Dom.get('shiptopostcode').value = postcode;
  Dom.get('shiptophone').value = '';
  Dom.get('shiptoidrut').value = '';
  onRecognitionChange();
}

function onAddGearChange(focusInput) {
  var add_gear = Dom.get('add_gear').value;
  var isFreeform = add_gear == 'custom' || add_gear == 'other';
  if (isFreeform) {
    Dom.addClass('quantity', 'bz_default_hidden');
    resetFreeform();
    Dom.get('freeform_quantity').value = Dom.get('quantity').value;
    Dom.removeClass('freeform_quantity', 'bz_default_hidden');
    Dom.removeClass('add_freeform', 'bz_default_hidden');
    if (focusInput)
      Dom.get('freeform_add').focus();
  } else {
    Dom.get('quantity').value = Dom.get('freeform_quantity').value;
    Dom.removeClass('quantity', 'bz_default_hidden');
    Dom.addClass('freeform_quantity', 'bz_default_hidden');
    Dom.addClass('add_freeform', 'bz_default_hidden');
  }
}

function firstChild(parent, name) {
  var a = parent.getElementsByTagName(name);
  return a.length == 0 ? false : a[0];
}

function getField(id) {
  for(var i = 0, l = fields.length; i < l; i++) {
    if (fields[i].id == id)
      return fields[i];
  }
  return false;
}

function addGear() {
  var id = Dom.get('add_gear').value;
  if (id == 'custom' || id == 'other') {
    var quantity = parseInt(Dom.get('freeform_quantity').value, 10);
    var name = Dom.get('freeform_add').value;
    if (!quantity || !name) return;
    needed_freeform.push({ 'type': id, 'quantity': quantity, 'name': name });
    Dom.get('add_gear').value = '';
    resetFreeform();
    onAddGearChange();
  } else {
    var quantity = parseInt(Dom.get('quantity').value, 10);
    if (!quantity || !id) return;
    needed[id] += quantity;
  }
  showGear();
}

function resetFreeform() {
  Dom.get('freeform_quantity').value = '1';
  Dom.get('freeform_add').value = '';
}

function removeGear(id) {
  if (!id) return;
  needed[id] = 0;
  showGear();
}

function removeFreeform(index) {
  needed_freeform.splice(index, 1);
  showGear();
}

function showGear() {
  var html = '<table border="0" cellpadding="2" cellspacing="0">';
  var text = '';
  var count = 0;
  for (var i = 0, l = gear.length; i < l; i++) {
    var item = gear[i];
    var id = item.id;
    if (!id) continue;
    if (!needed[id]) continue;
    count += needed[id];
    html += '<tr>' +
            '<td>' + needed[id] + ' x&nbsp;</td>' +
            '<td>' + item.name.htmlEncode() + '</td>' +
            '<td><button onclick="removeGear(\'' + id + '\');return false">Remove</button></td>' +
            '</tr>';
    text += needed[id] + ' x ' + id + ' ' + item.name + "\n";
  }
  for (var i = 0, l = needed_freeform.length; i < l; i++) {
    var item = needed_freeform[i];
    count += item.quantity;
    html += '<tr>' +
            '<td>' + item.quantity + ' x&nbsp;</td>' +
            '<td>(' + item.type + ') ' + item.name.htmlEncode() + '</td>' +
            '<td><button onclick="removeFreeform(\'' + i + '\');return false">Remove</button></td>' +
            '</tr>';
    text += item.quantity + ' x (' + item.type + ') ' + item.name + "\n";
  }
  if (!count)
    html += '<tr><td><i>No gear selected.</i></td></tr>';
  html += '</table>';
  Dom.get('gear_container').innerHTML = html;
  Dom.get('items').value = text;
}

[% END %]

[% PROCESS global/header.html.tmpl
   title = "Mozilla Gear"
   generate_api_token = 1
   style = inline_style
   javascript = inline_javascript
   javascript_urls = [ 'extensions/BMO/web/js/form_validate.js',
                       'js/field.js' ]
%]

<h1>Mozilla Gear</h1>

<p>
  Want gear? Follow the steps below and click Submit Request.
</p>
<p>
  Requests are reviewed and processed on Monday morning (US/Pacific). Any
  requests received after 9am Monday will be processed the following week.
</p>
<ul>
  <li>
    If approved, your request will either be sent to our gear partner, Staples,
    for shipment or it will be available for pick-up from your Mozilla space.
  </li>
  <li>
    If your request is not approved, we will let you know why or possibly ask
    for more information.
  </li>
</ul>

<p>
  Check <a href="https://wiki.mozilla.org/GearStore" target="_blank" rel="noopener noreferrer">the gear
  wiki</a> for more information about gear, including approved uses and the
  list of available gear.
</p>

<p>
  Gear requests for Rep-driven events and campaigns should continue to be
  submitted through <a href="https://wiki.mozilla.org/ReMo/Tools_and_Resources"
  target="_blank" rel="noopener noreferrer">their existing process</a>.
</p>

<form method="post" action="[% basepath FILTER none %]post_bug.cgi" id="swagRequestForm" enctype="multipart/form-data"
      onSubmit="return validateAndSubmit();">
  <input type="hidden" name="filed_via" value="custom_form">
  <input type="hidden" name="format" value="swag">
  <input type="hidden" name="product" value="Marketing">
  <input type="hidden" name="component" value="Swag Requests">
  <input type="hidden" name="rep_platform" value="All">
  <input type="hidden" name="op_sys" value="Other">
  <input type="hidden" name="bug_type" value="task">
  <input type="hidden" name="version" value="unspecified">
  <input type="hidden" name="short_desc" id="short_desc" value="">
  <input type="hidden" name="groups" value="mozilla-engagement">
  <input type="hidden" name="token" value="[% token FILTER html %]">

<table id="gear_form">

<tr>
  <td>&nbsp;</td>
</tr>
<tr>
  <th class="heading" colspan="2">Tell Us What You Want</th>
</tr>

<tr>
  <th>Purpose of Gear</th>
  <td>
    <select name="purpose" id="purpose" onchange="onPurposeChange()">
      <option value="">Please select..</option>
      <option value="Campaign">Campaign</option>
      <option value="Event">Event</option>
      <option value="Gear Space Stock">Gear Space Stock</option>
      <option value="Mozillian Recognition">Mozillian Recognition</option>
      <option value="Onboarding">Onboarding</option>
      <option value="Press">Press</option>
      <option value="Recruiting">Recruiting</option>
      <option value="VIP">VIP</option>
      <option value="Other">Other</option>
    </select>
  </td>
</tr>

<tr id="purpose_other_row" class="bz_default_hidden">
  <th>Purpose Text</th>
  <td>
    <input name="purpose_other" id="purpose_other" size="50">
  </td>
</tr>

<tr id="recognition_row" class="bz_default_hidden">
  <th>&nbsp;</th>
  <td>
    <input type="checkbox" name="recognition_shipping" id="recognition_shipping" value="Yes"
            onclick="onRecognitionChange()">
    <label for="recognition_shipping">
      This [% terms.bug %] needs recipient shipping information
    </label><br>
    <input type="checkbox" name="recognition_sizing" id="recognition_sizing" value="Yes">
    <label for="recognition_sizing">
      This [% terms.bug %] needs recipient size information
    </label><br>
  </td>
</tr>

<tr>
  <th>Date Required</th>
  <td>
    <input name="date_required" id="date_required" size="25"
           onchange="updateCalendarFromField(this)">
    <button type="button" class="calendar_button" id="button_calendar_date_required"
            onclick="showCalendar('date_required')"><span>cal</span></button>
    <div id="con_calendar_date_required"></div>
  </td>
</tr>

<tr>
  <th>Gear Needed</th>
  <td>
    <input type="hidden" name="items" id="items" value="">
    <a href="https://wiki.mozilla.org/GearStore/Gearavailable" target="_blank" rel="noopener noreferrer">
    View the current inventory</a>, then add your selection(s):<br>

    <input type="text" size="2" id="quantity" value="1"
           onblur="this.value = parseInt(this.value, 10) ? Math.floor(parseInt(this.value, 10)) : 1">
    <select id="add_gear" onChange="onAddGearChange(true)">
      <option value="">Please select..</option>
      [% first_group = 1 %]
      [% FOREACH item = items %]
        [% IF item.id == "" %]
          [% "</optgroup>" UNLESS first_group %]
          [% first_group = 0 %]
          <optgroup label="[% item.name FILTER html %]">
        [% ELSE %]
          <option value="[% item.id FILTER html %]">[% item.name FILTER html %]</option>
        [% END %]
      [% END %]
      [% "</optgroup>" UNLESS first_group %]
      <optgroup label="otherwise">
        <option value="custom">custom</option>
        <option value="other">other</option>
      </optgroup>
    </select>
    <span id="add_freeform" class="bz_default_hidden">
      <br>
      Tell us how many and what you are looking for here. Add details in the
      comments field below.
      <br>
      <input type="text" size="2" id="freeform_quantity" value="1"
            onblur="this.value = parseInt(this.value, 10) ? Math.floor(parseInt(this.value, 10)) : 1">
      <input type="text" id="freeform_add" size="40">
    </span>
    <button onclick="addGear();return false">Add</button>
    <br>

    <div id="gear_container"></div>
  </td>
</tr>

<tr>
  <td>&nbsp;</td>
</tr>
<tr>
  <th class="heading" colspan="2">Tell Us About You</th>
</tr>

<tr>
  <th>First Name</th>
  <td><input name="firstname" id="firstname" size="50" maxlength="30"></td>
</tr>

<tr>
  <th>Last Name</th>
  <td><input name="lastname" id="lastname" size="50" maxlength="30"></td>
</tr>

<tr>
  <th>Email Address</th>
  <td><input name="email" id="email" size="50" maxlength="50"></td>
</tr>

<tr>
  <th>My Mozilla Space</th>
  <td>
    <select name="mozspace" id="mozspace" onchange="onMozSpaceChange()">
      <option value="">Please select..</option>
      [% FOREACH space = mozspaces %]
        <option value="[% space.name FILTER html %]">[% space.name FILTER html %]</option>
      [% END %]
    </select>
    <i>(if applicable)</i>
    <div id="shipto_mozspace_container" class="bz_default_hidden">
      <input type="checkbox" id="shipto_mozspace" onclick="onShipToMozSpaceClick()">
      <label for="shipto_mozspace">Ship to this address</label>
    </div>
</tr>

<tr>
  <th>Team + Department Code</th>
  <td>
    <select name="teamcode" id="teamcode">
      <option value="">Please select..</option>
      [% FOREACH cost IN cost_centers_by_name %]
        <option value="[% cost FILTER html %]">[% cost FILTER html %]</option>
      [% END %]
    </select>
  </td>
</tr>

<tr>
  <td>&nbsp;</td>
</tr>
<tr>
  <th class="heading" colspan="2">Tell Us Where To Send It</th>
</tr>

<tr>
  <td colspan="2">
    Please be aware that shipping can cost as much as, if not more than, your
    item. And, items shipped internationally incur customs fees that can be
    100%+ the cost of the package. When possible, requests will be filled from
    gear at your Mozilla space.
  </td>
</tr>

<tr>
  <th>First Name</th>
  <td><input name="shiptofirstname" id="shiptofirstname" size="50" maxlength="50"></td>
</tr>
<tr>
  <th>Last Name</th>
  <td><input name="shiptolastname" id="shiptolastname" size="50" maxlength="50"></td>
</tr>
<tr>
  <th>Email Address</th>
  <td><input name="shiptoemail" id="shiptoemail" size="50" maxlength="50"></td>
</tr>
<tr>
  <th>Address</th>
  <td><input name="shiptoaddress1" id="shiptoaddress1" size="50" maxlength="50"></td>
</tr>
<tr>
  <th>Address 2</th>
  <td><input name="shiptoaddress2" id="shiptoaddress2" size="50" maxlength="50"></td>
</tr>
<tr>
  <th>City</th>
  <td><input name="shiptocity" id="shiptocity" size="50" maxlength="50"></td>
</tr>
<tr>
  <th>State</th>
  <td><input name="shiptostate" id="shiptostate" size="50" maxlength="50"></td>
</tr>
<tr>
  <th>Country</th>
  <td><input name="shiptocountry" id="shiptocountry" size="50" maxlength="50"></td>
</tr>
<tr>
  <th>Postal Code</th>
  <td><input name="shiptopostcode" id="shiptopostcode" size="50" maxlength="50"></td>
</tr>
<tr>
  <th>Recipient Telephone</th>
  <td>
    <input name="shiptophone" id="shiptophone" size="50" maxlength="50">
    <i>(include country code if outside of the US)</i>
  </td>
</tr>
<tr>
  <th>Personal ID/RUT</th>
  <td>
    <input name="shiptoidrut" id="shiptoidrut" size="50" maxlength="50">
    <i>(if your country requires this)</i>
  </td>
</tr>

<tr>
  <td>&nbsp;</td>
</tr>
<tr>
  <th class="heading" colspan="2">Tell Us Anything Else</th>
</tr>

<tr>
  <th>Additional Comments</th>
  <td><textarea id="comment" name="comment" rows="5" cols="50"></textarea></td>
</tr>

<tr>
  <td>&nbsp;</td>
</tr>

<tr>
  <td>&nbsp;</td>
  <td><input type="submit" id="commit" value="Submit Request"></td>
</tr>

</table>
</form>

<p>
  <span class="mandatory">*</span> Required Field
</p>

<p>
  Requests will only be visible to the person who submitted it, authorized
  members of the Mozilla Engagement team, and our Staples Customer Service rep.
  We do this to help protect the personal identifying information in this [% terms.bugs %].
</p>

<script [% script_nonce FILTER none %]>
  initFields();
  onPurposeChange();
  onAddGearChange();
  tagMandatoryFields();
  showGear();
</script>

[% PROCESS global/footer.html.tmpl %]
