
// ------------------------------
// Billing Address Functions
// ------------------------------

function changeCountry(c) {
  canada = document.getElementById('provCanada');
  usa = document.getElementById('stateUSA');
  other = document.getElementById('stateOther');
  useOther = 1;
  if (c == 'CA') {
    useOther = 0;
    canada.disabled = false;
    canada.style.visibility = 'visible';
  } else {
    canada.value = '';
    canada.disabled = true;
    canada.style.visibility = 'hidden';
  }
  if (c == 'US') {
    useOther = 0;
    usa.disabled = false;
    usa.style.visibility = 'visible';
  } else {
    usa.value = '';
    usa.disabled = true;
    usa.style.visibility = 'hidden';
  }
  if (useOther) {
    other.disabled = false;
    other.style.visibility = 'visible';
  } else {
    other.value = '';
    other.disabled = true;
    other.style.visibility = 'hidden';
  }
  /*
  numAvail = 0;
  for (i=0; i<numShipping; i++) {
    if (countryShipping[c]['s'+i] == i) {
      document.getElementById('shipping'+i).style.display = 'block';
      if (numAvail == 0)
        document.getElementById('shipradio'+i).checked = true;
      numAvail++;
    } else {
      document.getElementById('shipping'+i).style.display = 'none';
    }
  }
  if (numAvail > 0) {
    document.getElementById('noshipping').style.display = 'none';
  } else {
    document.getElementById('noshipping').style.display = 'block';
  }
  */
}

function changeProvince(currState) {
  if (currState.length == 3) {
    country = document.getElementById('country');
    country.value = 'US';
    changeCountry('US');
    state = document.getElementById('stateUSA');
    state.value = trim(currState);
  }
}

function changeState(currState) {
  if (currState.length == 3) {
    country = document.getElementById('country');
    country.value = 'CA';
    changeCountry('CA');
    state = document.getElementById('provCanada');
    state.value = trim(currState);
  }
}

// ------------------------------
// Shipping Address Functions
// ------------------------------

function changeCountryShipping(c) {
  canada = document.getElementById('provCanadaShipping');
  usa = document.getElementById('stateUSAShipping');
  other = document.getElementById('stateOtherShipping');
  useOther = 1;
  if (c == 'CA') {
    useOther = 0;
    canada.disabled = false;
    canada.style.visibility = 'visible';
  } else {
    canada.value = '';
    canada.disabled = true;
    canada.style.visibility = 'hidden';
  }
  if (c == 'US') {
    useOther = 0;
    usa.disabled = false;
    usa.style.visibility = 'visible';
  } else {
    usa.value = '';
    usa.disabled = true;
    usa.style.visibility = 'hidden';
  }
  if (useOther) {
    other.disabled = false;
    other.style.visibility = 'visible';
  } else {
    other.value = '';
    other.disabled = true;
    other.style.visibility = 'hidden';
  }
}

function changeProvinceShipping(currState) {
  if (currState.length == 3) {
    country = document.getElementById('countryShipping');
    country.value = 'US';
    changeCountry('US');
    state = document.getElementById('stateUSAShipping');
    state.value = trim(currState);
  }
}

function changeStateShipping(currState) {
  if (currState.length == 3) {
    country = document.getElementById('countryShipping');
    country.value = 'CA';
    changeCountry('CA');
    state = document.getElementById('provCanadaShipping');
    state.value = trim(currState);
  }
}





function trim(s) {
  return s.replace(/^\s*|\s*$/g,"");
}


