// JavaScript Document
// Define a list of Microsoft XML HTTP ProgIDs.
var XMLHTTPREQUEST_MS_PROGIDS = new Array(
	"Msxml2.XMLHTTP.7.0",
	"Msxml2.XMLHTTP.6.0",
	"Msxml2.XMLHTTP.5.0",
	"Msxml2.XMLHTTP.4.0",
	"MSXML2.XMLHTTP.3.0",
	"MSXML2.XMLHTTP",
	"Microsoft.XMLHTTP"
);

// Define ready state constants.
var XMLHTTPREQUEST_READY_STATE_UNINITIALIZED = 0;
var XMLHTTPREQUEST_READY_STATE_LOADING       = 1;
var XMLHTTPREQUEST_READY_STATE_LOADED        = 2;
var XMLHTTPREQUEST_READY_STATE_INTERACTIVE   = 3;
var XMLHTTPREQUEST_READY_STATE_COMPLETED     = 4;

//-----------------------------------------------------------------------------
// Returns an XMLHttpRequest object.
//-----------------------------------------------------------------------------
function getXMLHttpRequest()
{
	var httpRequest = null;

	// Create the appropriate HttpRequest object for the browser.
	if (window.XMLHttpRequest != null)
		httpRequest = new window.XMLHttpRequest();
	else if (window.ActiveXObject != null)
	{
		// Must be IE, find the right ActiveXObject.
		var success = false;
		for (var i = 0; i < XMLHTTPREQUEST_MS_PROGIDS.length && !success; i++)
		{
			try
			{
				httpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
				success = true;
			}
			catch (ex)
			{}
		}
	}

	// Display an error if we couldn't create one.
	if (httpRequest == null)
		alert("Error in HttpRequest():\n\nCannot create an XMLHttpRequest object.");

	// Return it.
	return httpRequest;
}

<!------------------------------ zip to state auto fill  ----------------------------->

function cleanFields() {
	var option;
	
	for (i=0; document.forms[0].elements["state"].options.length = i ; i++)
    	document.forms[0].elements["state"].remove(0);

	option = document.createElement("OPTION");
	option.text = "Select state...";
	option.value = "";

	try
	{
		document.forms[0].elements["state"].add(option, null);
	}
	catch(ex)
	{
		// For IE.
		document.forms[0].elements["state"].add(option);
	}
	
	for (i=0; document.forms[0].elements["city"].options.length = i ; i++)
    	document.forms[0].elements["city"].remove(0);

	option = document.createElement("OPTION");
	option.text = "Select city...";
	option.value = "";

	try
	{
		document.forms[0].elements["city"].add(option, null);
	}
	catch(ex)
	{
		// For IE.
		document.forms[0].elements["city"].add(option);
	}
	
	for (i=0; document.forms[0].elements["county"].options.length = i ; i++)
    	document.forms[0].elements["county"].remove(0);

	option = document.createElement("OPTION");
	option.text = "Select county...";
	option.value = "";

	try
	{
		document.forms[0].elements["county"].add(option, null);
	}
	catch(ex)
	{
		// For IE.
		document.forms[0].elements["county"].add(option);
	}
	
	if (document.forms[0].elements["affiliate"]){
		for (i=0; document.forms[0].elements["affiliate"].options.length = i ; i++)
			document.forms[0].elements["affiliate"].remove(0);
	
		option = document.createElement("OPTION");
		option.text = "Select affiliate...";
		option.value = "";
		try{
			document.forms[0].elements["affiliate"].add(option, null);
		}catch(ex){
			// For IE.
			document.forms[0].elements["affiliate"].add(option);
		}
	}
}


var stateLookup = getXMLHttpRequest();

function initiatestateLookup(event)
{

  // Clear the zip code drop-down list.
  while (document.forms[0].elements["state"].options.length > 1)
    document.forms[0].elements["state"].remove(1);

  // Abort any currently active request.
  stateLookup.abort();
 
 var stateVal = document.forms[0].elements["zip"].value;
  // Perform an asynchronous request to get a list of zip codes for
  // that state and state.
  if(stateVal!=""){
  	var url = "admin/DB_TO_XML.php?state=" + encodeURI(stateVal); 
  	stateLookup.onreadystatechange = stateCodeReadyStateChange;
  	stateLookup.open("GET", url, true);
  	stateLookup.send(null);
  }
}

function stateCodeReadyStateChange()
{
	var statusText;

	// Check the ready state.
	switch (stateLookup.readyState)
	{

		case XMLHTTPREQUEST_READY_STATE_COMPLETED:


			// Get the XML document returned from the request and fill in the
			// form fields.
			try {
				var xmlDoc = stateLookup.responseXML;
		// Copy the state and state attributes from the root XML node to the appropriate form fields.
		// Get all the zip code tags returned from the request.
				var  statenamelist = xmlDoc.getElementsByTagName("state_name");
				var stateidlist = xmlDoc.getElementsByTagName("state_prefix");
				var citynamelist = xmlDoc.getElementsByTagName("city");
				var cityidlist = xmlDoc.getElementsByTagName("city");
				var  countynamelist = xmlDoc.getElementsByTagName("county");
				var countyidlist = xmlDoc.getElementsByTagName("county");
		// Add an option to to the drop-down list for each zip code returned from the request.
				for (var i = 0; i < statenamelist.length; i++){
					option = document.createElement("OPTION");
					option.text = statenamelist[i].firstChild.nodeValue;
					option.value = stateidlist[i].firstChild.nodeValue;
					if (statenamelist.length == 1){
						option.selected = true;	
					}
					try{
						document.forms[0].elements["state"].add(option, null);
					} catch(ex) {
						// For IE.
						document.forms[0].elements["state"].add(option);
					}
				}
				if (citynamelist.length == 1) {
					// Clear the zip code drop-down list.
					for (var i = 0; i < citynamelist.length; i++){
						option = document.createElement("OPTION");
						option.text = citynamelist[i].firstChild.nodeValue;
						option.value = cityidlist[i].firstChild.nodeValue;
						option.selected = true;
							try{
								document.forms[0].elements["city"].add(option, null);
							} catch(ex) {
								// For IE.
								document.forms[0].elements["city"].add(option);
							}
						}
					for (var i = 0; i < countynamelist.length; i++){
						option = document.createElement("OPTION");
						option.text = countynamelist[i].firstChild.nodeValue;
						option.value = countyidlist[i].firstChild.nodeValue;
						option.selected = true;
						try{
							document.forms[0].elements["county"].add(option, null);
						} catch(ex) {
							// For IE.
							document.forms[0].elements["county"].add(option);
						}
					}
				} //del if
				  

			}
			catch (ex)
			{}
			break;

		default:
			statusText = "Unknown error.";
			break;
	}
<!------------------------------------------------------------------------------------------------->
var cityLookup = getXMLHttpRequest();

function initiateCityLookup(event)
{

  // Clear the zip code drop-down list.
  while (document.forms[0].elements["city"].options.length > 1)
    document.forms[0].elements["city"].remove(1);

  // Abort any currently active request.
  cityLookup.abort();
 
 var cityVal = document.forms[0].elements["state"].options[document.forms[0].elements["state"].selectedIndex].value;
  // Perform an asynchronous request to get a list of zip codes for
  // that state and state.
  if(cityVal!=""){
  	var url = "admin/CI_TO_XML.php?city=" + encodeURI(cityVal); 
	cityLookup.onreadystatechange = cityCodeReadyStateChange;
  	cityLookup.open("GET", url, true);
  	cityLookup.send(null);
  }
}

function cityCodeReadyStateChange()
{
	var statusText;

	// Check the ready state.
	switch (cityLookup.readyState)
	{

		case XMLHTTPREQUEST_READY_STATE_COMPLETED:


			// Get the XML document returned from the request and fill in the
			// form fields.
			try
			{
				var xmlDoc = cityLookup.responseXML;

				// Copy the state and state attributes from the root XML node to the appropriate form fields.

				// Get all the zip code tags returned from the request.
				var  citynamelist = xmlDoc.getElementsByTagName("city");
				var cityidlist = xmlDoc.getElementsByTagName("city");

				// Add an option to to the drop-down list for each zip code returned from the request.
				for (var i = 0; i < citynamelist.length; i++)
				{

					option = document.createElement("OPTION");

					option.text = citynamelist[i].firstChild.nodeValue;
					option.value = cityidlist[i].firstChild.nodeValue;
					
					try
					{
						document.forms[0].elements["city"].add(option, null);
					}
					catch(ex)
					{
						// For IE.
						document.forms[0].elements["city"].add(option);
					}
				}

			}
			catch (ex)
			{}
			break;

		default:
			statusText = "Unknown error.";
			break;
	}

}

<!------------------------------------------------------------------------------------------------->
var countyLookup = getXMLHttpRequest();

function initiateCountyLookup(event)
{

  // Clear the zip code drop-down list.
  while (document.forms[0].elements["county"].options.length > 1)
    document.forms[0].elements["county"].remove(1);

  // Abort any currently active request.
  countyLookup.abort();
 
 var countyVal = document.forms[0].elements["city"].options[document.forms[0].elements["city"].selectedIndex].value;
  // Perform an asynchronous request to get a list of zip codes for
  // that state and state.
  if(countyVal!=""){
  	var url = "admin/CO_TO_XML.php?county=" + encodeURI(countyVal); 
	countyLookup.onreadystatechange = countyCodeReadyStateChange;
  	countyLookup.open("GET", url, true);
  	countyLookup.send(null);
  }
}

function countyCodeReadyStateChange()
{
	var statusText;

	// Check the ready state.
	switch (countyLookup.readyState)
	{

		case XMLHTTPREQUEST_READY_STATE_COMPLETED:


			// Get the XML document returned from the request and fill in the
			// form fields.
			try
			{
				var xmlDoc = countyLookup.responseXML;

				// Copy the state and state attributes from the root XML node to the appropriate form fields.

				// Get all the zip code tags returned from the request.
				var  countynamelist = xmlDoc.getElementsByTagName("county");
				var countyidlist = xmlDoc.getElementsByTagName("county");

				// Add an option to to the drop-down list for each zip code returned from the request.
				for (var i = 0; i < countynamelist.length; i++)
				{

					option = document.createElement("OPTION");

					option.text = countynamelist[i].firstChild.nodeValue;
					option.value = countyidlist[i].firstChild.nodeValue;
					
					try
					{
						document.forms[0].elements["county"].add(option, null);
					}
					catch(ex)
					{
						// For IE.
						document.forms[0].elements["county"].add(option);
					}
				}

			}
			catch (ex)
			{}
			break;

		default:
			statusText = "Unknown error.";
			break;
	}

}

<!------------------------------------------------------------------------------------------------->
var affLookup = getXMLHttpRequest();

function fillAffiliates(event)
{
  // Clear the zip code drop-down list.
  while (document.forms[0].elements["affiliate"].options.length > 1)
    document.forms[0].elements["affiliate"].remove(1);

  // Abort any currently active request.
  affLookup.abort();
 

  // Perform an asynchronous request to get a list of zip codes for
  // that state and state.

  var url = "admin/AFF_TO_XML.php"; 
  affLookup.onreadystatechange = affiliateCodeReadyStateChange; 
  affLookup.open("GET", url, true);
  affLookup.send(null);

}

function affiliateCodeReadyStateChange()
{
	var statusText;

	// Check the ready state.
	switch (affLookup.readyState)
	{

		case XMLHTTPREQUEST_READY_STATE_COMPLETED:


			// Get the XML document returned from the request and fill in the
			// form fields.
			try
			{
				var xmlDoc = affLookup.responseXML;

				// Copy the state and state attributes from the root XML node to the appropriate form fields.

				// Get all the zip code tags returned from the request.
				var  affiliatenamelist = xmlDoc.getElementsByTagName("aff_MneumonicKey");
				var affiliateidlist = xmlDoc.getElementsByTagName("aff_Id");
								
				// Add an option to to the drop-down list for each zip code returned from the request.
				for (var i = 0; i < affiliatenamelist.length; i++)
				{

					option = document.createElement("OPTION");

					option.text = affiliatenamelist[i].firstChild.nodeValue;
					option.value = affiliateidlist[i].firstChild.nodeValue;
					
					try
					{
						document.forms[0].elements["affiliate"].add(option, null);
					}
					catch(ex)
					{
						// For IE.
						document.forms[0].elements["affiliate"].add(option);
					}
				}

			}
			catch (ex)
			{}
			break;

		default:
			statusText = "Unknown error.";
			break;
	}

}

<!--------------------------------------------------------------------------------------------------->
<!------------------------------    other address section ------------------------------------------->
<!--------------------------------------------------------------------------------------------------->

function cleanFields2() {
	var option;
	
	for (i=0; document.forms[0].elements["secState"].options.length = i ; i++)
    	document.forms[0].elements["secState"].remove(0);

	option = document.createElement("OPTION");
	option.text = "Select state...";
	option.value = "";

	try
	{
		document.forms[0].elements["secState"].add(option, null);
	}
	catch(ex)
	{
		// For IE.
		document.forms[0].elements["secState"].add(option);
	}
	
	for (i=0; document.forms[0].elements["secCity"].options.length = i ; i++)
    	document.forms[0].elements["secCity"].remove(0);

	option = document.createElement("OPTION");
	option.text = "Select city...";
	option.value = "";

	try
	{
		document.forms[0].elements["secCity"].add(option, null);
	}
	catch(ex)
	{
		// For IE.
		document.forms[0].elements["secCity"].add(option);
	}
	
	for (i=0; document.forms[0].elements["secCounty"].options.length = i ; i++)
    	document.forms[0].elements["secCounty"].remove(0);

	option = document.createElement("OPTION");
	option.text = "Select county...";
	option.value = "";

	try
	{
		document.forms[0].elements["secCounty"].add(option, null);
	}
	catch(ex)
	{
		// For IE.
		document.forms[0].elements["secCounty"].add(option);
	}
	
	if (document.forms[0].elements["secAffiliate"]){
		for (i=0; document.forms[0].elements["secAffiliate"].options.length = i ; i++)
			document.forms[0].elements["secAffiliate"].remove(0);
	
		option = document.createElement("OPTION");
		option.text = "Select affiliate...";
		option.value = "";
		try{
			document.forms[0].elements["secAffiliate"].add(option, null);
		}catch(ex){
			// For IE.
			document.forms[0].elements["secAffiliate"].add(option);
		}
	}
}


var stateLookup = getXMLHttpRequest();

function initiatestateLookup2(event){

  // Clear the zip code drop-down list.
  while (document.forms[0].elements["secState"].options.length > 1)
    document.forms[0].elements["secState"].remove(1);

  // Abort any currently active request.
  stateLookup.abort();
 
 var stateVal = document.forms[0].elements["secZip"].value;
  // Perform an asynchronous request to get a list of zip codes for
  // that state and state.
  if(stateVal!=""){
  	var url = "admin/DB_TO_XML.php?state=" + encodeURI(stateVal); 
  	stateLookup.onreadystatechange = stateCodeReadyStateChange2;
  	stateLookup.open("GET", url, true);
  	stateLookup.send(null);
  }
}

function stateCodeReadyStateChange2()
{
	var statusText;

	// Check the ready state.
	switch (stateLookup.readyState)
	{

		case XMLHTTPREQUEST_READY_STATE_COMPLETED:


			// Get the XML document returned from the request and fill in the
			// form fields.
			try
			{
				var xmlDoc = stateLookup.responseXML;

				// Copy the state and state attributes from the root XML node to the appropriate form fields.

				// Get all the zip code tags returned from the request.
				var  statenamelist = xmlDoc.getElementsByTagName("state_name");
				var stateidlist = xmlDoc.getElementsByTagName("state_prefix");
				var  citynamelist = xmlDoc.getElementsByTagName("city");
				var cityidlist = xmlDoc.getElementsByTagName("city");
				var  countynamelist = xmlDoc.getElementsByTagName("county");
				var countyidlist = xmlDoc.getElementsByTagName("county");
				

				// Add an option to to the drop-down list for each zip code returned from the request.
				for (var i = 0; i < statenamelist.length; i++){
					option = document.createElement("OPTION");
					option.text = statenamelist[i].firstChild.nodeValue;
					option.value = stateidlist[i].firstChild.nodeValue;
					if (statenamelist.length == 1){
						option.selected = true;	
					}
					try {
						document.forms[0].elements["secState"].add(option, null);
					} catch(ex) {
						// For IE.
						document.forms[0].elements["secState"].add(option);
					}
				}
				if (citynamelist.length == 1) {
					for (var i = 0; i < citynamelist.length; i++){
						option = document.createElement("OPTION");
						option.text = citynamelist[i].firstChild.nodeValue;
						option.value = cityidlist[i].firstChild.nodeValue;
						option.selected = true;
						try	{
							document.forms[0].elements["secCity"].add(option, null);
						} catch(ex) {
							// For IE.
							document.forms[0].elements["secCity"].add(option);
						}
					}
					for (var i = 0; i < countynamelist.length; i++){
						option = document.createElement("OPTION");
						option.text = countynamelist[i].firstChild.nodeValue;
						option.value = countyidlist[i].firstChild.nodeValue;
						option.selected = true;
						try	{
							document.forms[0].elements["secCounty"].add(option, null);
						} catch(ex) {
							// For IE.
							document.forms[0].elements["secCounty"].add(option);
						}
					}
				} //del if

			}
			catch (ex)
			{}
			break;

		default:
			statusText = "Unknown error.";
			break;
	}

}
<!------------------------------------------------------------------------------------------------->
var cityLookup = getXMLHttpRequest();

function initiateCityLookup2(event)
{

  // Clear the zip code drop-down list.
  while (document.forms[0].elements["secCity"].options.length > 1)
    document.forms[0].elements["secCity"].remove(1);

  // Abort any currently active request.
  cityLookup.abort();
 
 var cityVal = document.forms[0].elements["secState"].options[document.forms[0].elements["secState"].selectedIndex].value;
  // Perform an asynchronous request to get a list of zip codes for
  // that state and state.
  if(cityVal!=""){
  	var url = "admin/CI_TO_XML.php?city=" + encodeURI(cityVal); 
	cityLookup.onreadystatechange = cityCodeReadyStateChange2;
  	cityLookup.open("GET", url, true);
  	cityLookup.send(null);
  }
}

function cityCodeReadyStateChange2()
{
	var statusText;

	// Check the ready state.
	switch (cityLookup.readyState)
	{

		case XMLHTTPREQUEST_READY_STATE_COMPLETED:


			// Get the XML document returned from the request and fill in the
			// form fields.
			try
			{
				var xmlDoc = cityLookup.responseXML;

				// Copy the state and state attributes from the root XML node to the appropriate form fields.

				// Get all the zip code tags returned from the request.
				var  citynamelist = xmlDoc.getElementsByTagName("city");
				var cityidlist = xmlDoc.getElementsByTagName("city");

				// Add an option to to the drop-down list for each zip code returned from the request.
				for (var i = 0; i < citynamelist.length; i++)
				{

					option = document.createElement("OPTION");

					option.text = citynamelist[i].firstChild.nodeValue;
					option.value = cityidlist[i].firstChild.nodeValue;
					
					try
					{
						document.forms[0].elements["secCity"].add(option, null);
					}
					catch(ex)
					{
						// For IE.
						document.forms[0].elements["secCity"].add(option);
					}
				}

			}
			catch (ex)
			{}
			break;

		default:
			statusText = "Unknown error.";
			break;
	}

}

<!------------------------------------------------------------------------------------------------->
var countyLookup = getXMLHttpRequest();

function initiateCountyLookup2(event)
{

  // Clear the zip code drop-down list.
  while (document.forms[0].elements["secCounty"].options.length > 1)
    document.forms[0].elements["secCounty"].remove(1);

  // Abort any currently active request.
  countyLookup.abort();
 
 var countyVal = document.forms[0].elements["secCity"].options[document.forms[0].elements["secCity"].selectedIndex].value;
  // Perform an asynchronous request to get a list of zip codes for
  // that state and state.
  if(countyVal!=""){
  	var url = "admin/CO_TO_XML.php?county=" + encodeURI(countyVal); 
	countyLookup.onreadystatechange = countyCodeReadyStateChange2;
  	countyLookup.open("GET", url, true);
  	countyLookup.send(null);
  }
}

function countyCodeReadyStateChange2()
{
	var statusText;

	// Check the ready state.
	switch (countyLookup.readyState)
	{

		case XMLHTTPREQUEST_READY_STATE_COMPLETED:


			// Get the XML document returned from the request and fill in the
			// form fields.
			try
			{
				var xmlDoc = countyLookup.responseXML;

				// Copy the state and state attributes from the root XML node to the appropriate form fields.

				// Get all the zip code tags returned from the request.
				var  countynamelist = xmlDoc.getElementsByTagName("county");
				var countyidlist = xmlDoc.getElementsByTagName("county");

				// Add an option to to the drop-down list for each zip code returned from the request.
				for (var i = 0; i < countynamelist.length; i++)
				{

					option = document.createElement("OPTION");

					option.text = countynamelist[i].firstChild.nodeValue;
					option.value = countyidlist[i].firstChild.nodeValue;
					
					try
					{
						document.forms[0].elements["secCounty"].add(option, null);
					}
					catch(ex)
					{
						// For IE.
						document.forms[0].elements["secCounty"].add(option);
					}
				}

			}
			catch (ex)
			{}
			break;

		default:
			statusText = "Unknown error.";
			break;
	}

}

<!------------------------------------------------------------------------------------------------->
var affLookup = getXMLHttpRequest();

function fillAffiliates(event)
{
  // Clear the zip code drop-down list.
  while (document.forms[0].elements["secAffiliate"].options.length > 1)
    document.forms[0].elements["secAffiliate"].remove(1);

  // Abort any currently active request.
  affLookup.abort();
 

  // Perform an asynchronous request to get a list of zip codes for
  // that state and state.

  var url = "admin/AFF_TO_XML.php"; 
  affLookup.onreadystatechange = affiliateCodeReadyStateChange2; 
  affLookup.open("GET", url, true);
  affLookup.send(null);

}

function affiliateCodeReadyStateChange2()
{
	var statusText;

	// Check the ready state.
	switch (affLookup.readyState)
	{

		case XMLHTTPREQUEST_READY_STATE_COMPLETED:


			// Get the XML document returned from the request and fill in the
			// form fields.
			try
			{
				var xmlDoc = affLookup.responseXML;

				// Copy the state and state attributes from the root XML node to the appropriate form fields.

				// Get all the zip code tags returned from the request.
				var  affiliatenamelist = xmlDoc.getElementsByTagName("aff_MneumonicKey");
				var affiliateidlist = xmlDoc.getElementsByTagName("aff_Id");
								
				// Add an option to to the drop-down list for each zip code returned from the request.
				for (var i = 0; i < affiliatenamelist.length; i++)
				{

					option = document.createElement("OPTION");

					option.text = affiliatenamelist[i].firstChild.nodeValue;
					option.value = affiliateidlist[i].firstChild.nodeValue;
					
					try
					{
						document.forms[0].elements["secAffiliate"].add(option, null);
					}
					catch(ex)
					{
						// For IE.
						document.forms[0].elements["secAffiliate"].add(option);
					}
				}

			}
			catch (ex)
			{}
			break;

		default:
			statusText = "Unknown error.";
			break;
	}

}
<!------------------------------------------------------------------------------------------------->
var messageShow = getXMLHttpRequest();

function showMessage(event){

  messageShow.abort();
 
 var zip = document.forms[0].elements["zip"].value;
 var state = document.forms[0].elements["state"].options[document.forms[0].elements["state"].selectedIndex].value;
 var city = document.forms[0].elements["city"].options[document.forms[0].elements["city"].selectedIndex].value;
 var county = document.forms[0].elements["county"].options[document.forms[0].elements["county"].selectedIndex].value;
  // Perform an asynchronous request to get a list of zip codes for
  // that state and state.
  if(city!="" && state!="" && zip!="" && county!=""){
  	var url = "admin/SHOWMESSAGE.php?city=" + encodeURI(city) + "&state="+encodeURI(state)+"&county="+encodeURI(county)+"&zip="+encodeURI(zip) ; 
	messageShow.onreadystatechange = showMessageCodeReadyStateChange;
  	messageShow.open("GET", url, true);
  	messageShow.send(null);
  }
}

function showMessageCodeReadyStateChange()
{
	var statusText;
	switch (messageShow.readyState)
	{

		case XMLHTTPREQUEST_READY_STATE_COMPLETED:


			// Get the XML document returned from the request and fill in the
			// form fields.
			try
			{
				document.getElementById('message').innerHTML = messageShow.responseText;
			}
			catch (ex)
			{}
			break;

		default:
			statusText = "Unknown error.";
			break;
	}
}

}

<!-------------------------------------------------------------------------------------------------><!-- 

 -->