	gCurrCountryID = 1;	// Default Country on start-up is countrycode 1

	function PopulateStateList()
	{
		var FormRef = document.ContactForm;
		var StateNameListLen = gStateName.length;

		// Add an empty row to the State drop-down list
		FormRef.State.options[0] = new Option("Please Select...");

		// Add elements of array to State drop-down lists
    	for (var i = 0; i < StateNameListLen; i++)
		{
    		var ListBoxLen = FormRef.State.length;
			if (gStateCID[i] == gCurrCountryID)	// Only add the State if the country ID matches
			{
				FormRef.State.options[ListBoxLen] = new Option(gStateName[i]);
				FormRef.State.options[ListBoxLen].value = gStateAbbrev[i];
			}
		}
	}
	
	// Set items in the form to initial values
	function InitForm()
	{
		var FormRef = document.ContactForm;
		var CountryNameListLen = gCountryName.length;

		// Add elements of array to Country drop-down lists
    	for (var i = 0; i < CountryNameListLen; i++)
		{
    		var ListBoxLen = FormRef.Country.length;
			FormRef.Country.options[ListBoxLen] = new Option(gCountryName[i]);
			FormRef.Country.options[ListBoxLen].value = gCountryID[i];
		}

		PopulateStateList();
		FormRef.FirstName.focus();
	}
	
	function SetSelectedState(StateAbbrev)
	{
		var FormRef = document.ContactForm;
		var StateNameListLen = FormRef.State.length;

    	for (var i = 0; i < StateNameListLen; i++)
		{
    		if (FormRef.State.options[i].value == StateAbbrev)
			{
				FormRef.State.selectedIndex = i;
				break;
			}
		}
	}
	
	function ChangeCountry()
	{
		var FormRef = document.ContactForm;
		var StateNameListLen = FormRef.State.length;
		var CountryListLen = FormRef.Country.length;
		var i;


		// Remove existing state names
		for ( i = (StateNameListLen - 1); i >= 0; i--) FormRef.State.options[i] = null;

		// Find out which country is selected and populate States based on this
		for (i = 0; i < CountryListLen; i++)
		{
			if (FormRef.Country.options[i].selected == true)
			{
				gCurrCountryID = gCountryID[i];
				PopulateStateList();
				break;
			}
		}
	}
	
	function SetSelectedCountry(lCountryID)
	{
		var FormRef = document.ContactForm;
		var CountryNameListLen = gCountryName.length;

		gCurrCountryID = lCountryID;
    	for (var i = 0; i < CountryNameListLen; i++)
		{
    		if (FormRef.Country.options[i].value == lCountryID)
			{
				FormRef.Country.selectedIndex = i;
				break;
			}
		}
		PopulateStateList();
	}
	
	function isEmail()
	{
		var FormRef = document.ContactForm;
		var x = FormRef.Email.value;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

		return (filter.test(x));
	}
	
	function Validate()
	{
		var FormRef = document.ContactForm;

		if (FormRef.FirstName.value == '')
		{
			alert('First Name needs to be entered');
			FormRef.FirstName.focus();
			return false;
		}

		if (FormRef.LastName.value == '')
		{
			alert('Last Name needs to be entered');
			FormRef.LastName.focus();
			return false;
		}

		if (FormRef.Email.value == '' || !isEmail())
		{
			alert('Email address needs to be valid');
			FormRef.Email.focus();
			return false;
		}

		if (FormRef.State.value == '')
		{
			alert('State needs to be selected');
			FormRef.State.focus();
			return false;
		}
		
//		event.returnValue=true;
		return true;
	}

	InitForm();
	