 var provinces = [];
 provinces['Canada'] = ['AB','MB','BC','NB','NL','NS','NT','NU','ON','PE','QC','SK','YT'];
 provinces['USA'] = ['AK','AL','AR','AZ','CA','CO','CT','DC','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MP','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','PR','PW','RI','SC','SD','TN','TX','UT','VA','VI','VT','WA','WI','WV','WY','AS','FM','GU','MH','AA','AE','AP'];
   
 function setProvinces() {
  
  // Load country drop down and check to see if a country has been selected
  var countryContainer = document.getElementById('country_field');
  var countryFields = countryContainer.getElementsByTagName('select');
  var countryField = countryFields[0];
  var country = countryField.options[countryField.selectedIndex].value;
  
  // Set country on change
  if (!countryField.onchange) {
    countryField.onchange = new Function('setProvinces()');
  }
  
  // Load province drop down or textfield
  var container = document.getElementById('province_field');
  var elements = container.getElementsByTagName('select');
  if (!elements || elements.length == 0) {
    elements = container.getElementsByTagName('input');
  }
  var select = elements[0];
  
  // Alter province field options to match country selection
  var html = '';
  if (country) {  	  	
    var options = provinces[country];
    if (options) {
      // If there are options for this country, reset field as select box with province options
      html += '<select class="' + select.className + '" name="' + select.name + '" id="' + select.id + '"><option value="">Please select</option>';
      for (var a = 0; a < options.length; a++) {
        html += '<option value="' + options[a] + '">' + options[a] + '</option>';
      }
      html += '</select>';
    } else {
      // If no options are found reset field as textfield
      if (select.type != 'text') {
        html = '<input  class="' + select.className + '"  name="' + select.name + '" id="' + select.id + '" />';
      }
    }
  } else {
    // If no country is selected, set province field as empty disabled dropdown
    html = '<select class="form_disabled" disabled name="' + select.name + '" id="' + select.id + '"><option value="">Please select country</option></select>';
  }
  
  if (html) {
    // Replace existing province field with our new field
    container.innerHTML = html;
  }
 }
