/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Michael J. Damato | http://developing.damato.net/ */
// State lists
var states = new Array();

states['China'] = new Array('Segway Beijing','Segway Tianjin','Segway Qingdao','Segway Guangzhou');
states['HongKong'] = new Array('Segway SAR');
states['Macau'] = new Array('Segway SAR');
states['Indonesia'] = new Array('Segway SAR');
states['Malaysia'] = new Array('Segway Malaysia');
states['Philippines'] = new Array('Segway SAR');
states['Singapore'] = new Array('Segway Singapore');
states['SouthKorea'] = new Array('Segway South Korea');
states['Vietnam'] = new Array('Segway Vietnam');

function setStates() {
  cntrySel = document.getElementById('PurchaseCountry');
  stateList = states[cntrySel.value];
  changeSelect('PurchaseCity', stateList, stateList);
  setCities();
}

function setCities() {
  cntrySel = document.getElementById('PurchaseCountry');
  stateSel = document.getElementById('PurchaseCity');
  cityList = cities[cntrySel.value][stateSel.value];
  changeSelect('city', cityList, cityList);
}

function changeSelect(fieldID, newOptions, newValues) {
  selectField = document.getElementById(fieldID);
  selectField.options.length = 0;
  for (i=0; i<newOptions.length; i++) {
    selectField.options[selectField.length] = new Option(newOptions[i], newValues[i]);
  }
}

// Multiple onload function created by: Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  setStates();
});

