﻿var http;

function loadXMLDoc(url, functionCall) {
  http = getHTTPObject();

  if (http) {
    http.onreadystatechange = functionCall;
    http.open("GET", url, true);
    http.send("");
  }
}

function getHTTPObject() {
  var xmlhttp;

/*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
    xmlhttp = false;
@end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }

  return xmlhttp;
}

function fillStates_Response()
{
	if (http.readyState == 4) {
		if (http.status == 200) {
			var stateChoice = document.getElementsByName('state')[0];
			while (stateChoice.length > 0) {
				stateChoice.remove(0);
			}

			var states = http.responseText.split(",");
			for (i = 0; i < states.length; i += 2) {
				opt = document.createElement('option');
				opt.value = states[i];
				opt.text = states[i + 1];
				stateChoice.add(opt, null);
			}
		}
	}
}

function fillStates(country_id)
{
	loadXMLDoc("rpc.php?country=" + country_id, fillStates_Response);
}

