﻿// This method is called from getStates.js 
function generateStateOptions(stateResponse, stateListBox)
{
	var stateArray = stateResponse.split(",");
	
	if (stateListBox.length > 0)
	{
		clearStateListBox(stateListBox, stateListBox.length);
	}
	
	for (var i = 0; i < stateArray.length; i++)
	{
		var stateItemArray = stateArray[i].split("|");
		var stateOption = new Option(stateItemArray[1], stateItemArray[0]);
		
		try
		{
			stateListBox.add(stateOption, null)
		}
		catch(e)
		{
			stateListBox.add(stateOption);
		}
	}
	return true;
}


function clearStateListBox(stateSelectControl, count)
{
	for (var i = count; i > -1; i--)
	{
		stateSelectControl.options[i] = null;
	}	
}


function addNotListedItem(stateSelectControl, text, value)
{
	var notListedOption = new Option(text, value);
	
	try
	{
		stateSelectControl.add(notListedOption, null);
	}
	catch(e)
	{
		stateSelectControl.add(notListedOption);
	}
}


function hideStateSelectControl()
{
	clearStateListBox(document.getElementById(controlName), document.getElementById(controlName).length);
	handleStateCallback(controlName);
	return true;
}


function getCountry(controlName)
{
	var countryListBox = document.getElementById(controlName);
	var selectedIndex = countryListBox.selectedIndex;
	var country = countryListBox.options[selectedIndex].value;
	return country;
}


function getState(controlName)
{
	var stateListBox = document.getElementById(controlName);
	var selectedIndex = stateListBox.selectedIndex;
	var state = stateListBox.options[selectedIndex].value;
	return state;
}



