<!-- Paste this code into an external JavaScript file  -->

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Down Home Consulting :: http://downhomeconsulting.com */

/*
Country State Drop Downs v1.0.
(c) Copyright 2005 Down Home Consulting, Inc.
www.DownHomeConsulting.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, itness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

*/

// If you have PHP you can set the post values like this
//var postState = '<?= $_POST["state"] ?>';
//var postCountry = '<?= $_POST["country"] ?>';
var postState = '';
var postCountry = '';

// State table
//
// To edit the list, just delete a line or add a line. Order is important.
// The order displayed here is the order it appears on the drop down.
//
var state = '\
United States:Alaska:Alaska|\
United States:Alabama:Alabama|\
United States:Arkansas:Arkansas|\
United States:American Samoa:American Samoa|\
United States:Arizona:Arizona|\
United States:California:California|\
United States:Colorado:Colorado|\
United States:Connecticut:Connecticut|\
United States:D.C.:D.C.|\
United States:Delaware:Delaware|\
United States:Florida:Florida|\
United States:Micronesia:Micronesia|\
United States:Georgia:Georgia|\
United States:Guam:Guam|\
United States:Hawaii:Hawaii|\
United States:Iowa:Iowa|\
United States:Idaho:Idaho|\
United States:Illinois:Illinois|\
United States:Indiana:Indiana|\
United States:Kansas:Kansas|\
United States:Kentucky:Kentucky|\
United States:Louisiana:Louisiana|\
United States:Massachusetts:Massachusetts|\
United States:Maryland:Maryland|\
United States:Maine:Maine|\
United States:Marshall Islands:Marshall Islands|\
United States:Michigan:Michigan|\
United States:Minnesota:Minnesota|\
United States:Missouri:Missouri|\
United States:Marianas:Marianas|\
United States:Mississippi:Mississippi|\
United States:Montana:Montana|\
United States:North Carolina:North Carolina|\
United States:North Dakota:North Dakota|\
United States:Nebraska:Nebraska|\
United States:New Hampshire:New Hampshire|\
United States:New Jersey:New Jersey|\
United States:New Mexico:New Mexico|\
United States:Nevada:Nevada|\
United States:New York:New York|\
United States:Ohio:Ohio|\
United States:Oklahoma:Oklahoma|\
United States:Oregon:Oregon|\
United States:Pennsylvania:Pennsylvania|\
United States:Puerto Rico:Puerto Rico|\
United States:Palau:Palau|\
United States:Rhode Island:Rhode Island|\
United States:South Carolina:South Carolina|\
United States:South Dakota:South Dakota|\
United States:Tennessee:Tennessee|\
United States:Texas:Texas|\
United States:Utah:Utah|\
United States:Virginia:Virginia|\
United States:Virgin Islands:Virgin Islands|\
United States:Vermont:Vermont|\
United States:Washington:Washington|\
United States:Wisconsin:Wisconsin|\
United States:West Virginia:West Virginia|\
United States:Wyoming:Wyoming|\
United States:Military Americas:Military Americas|\
United States:Military Europe/ME/Canada:Military Europe/ME/Canada|\
United States:Military Pacific:Military Pacific|\
Canada:Alberta:Alberta|\
Canada:Manitoba:Manitoba|\
Canada:Alberta:Alberta|\
Canada:British Columbia:British Columbia|\
Canada:Manitoba:Manitoba|\
Canada:New Brunswick:New Brunswick|\
Canada:Newfoundland and Labrador:Newfoundland and Labrador|\
Canada:Nova Scotia:Nova Scotia|\
Canada:Northwest Territories:Northwest Territories|\
Canada:Nunavut:Nunavut|\
Canada:Ontario:Ontario|\
Canada:Prince Edward Island:Prince Edward Island|\
Canada:Quebec:Quebec|\
Canada:Saskatchewan:Saskatchewan|\
Canada:ukon Territory:Yukon Territory|\
Australia:Australian Antarctic Territory:Australian Antarctic Territory|\
Australia:Australian Capital Territory:Australian Capital Territory|\
Australia:Northern Territory:Northern Territory|\
Australia:New South Wales:New South Wales|\
Australia:Queensland:Queensland|\
Australia:South Australia:South Australia|\
Australia:Tasmania:Tasmania|\
Australia:Victoria:Victoria|\
Australia:Western Australia:Western Australia|\
Brazil:Acre:Acre|\
Brazil:Alagoas:Alagoas|\
Brazil:Amazonas:Amazonas|\
Brazil:Amapa:Amapa|\
Brazil:Baia:Baia|\
Brazil:Ceara:Ceara|\
Brazil:Distrito Federal:Distrito Federal|\
Brazil:Espirito Santo:Espirito Santo|\
Brazil:Fernando de Noronha:Fernando de Noronha|\
Brazil:Goias:Goias|\
Brazil:Maranhao:Maranhao|\
Brazil:Minas Gerais:Minas Gerais|\
Brazil:Mato Grosso do Sul:Mato Grosso do Sul|\
Brazil:Mato Grosso:Mato Grosso|\
Brazil:Para:Para|\
Brazil:Paraiba:Paraiba|\
Brazil:Pernambuco:Pernambuco|\
Brazil:Piaui:Piaui|\
Brazil:Parana:Parana|\
Brazil:Rio de Janeiro:Rio de Janeiro|\
Brazil:Rio Grande do Norte:Rio Grande do Norte|\
Brazil:Rondonia:Rondonia|\
Brazil:Roraima:Roraima|\
Brazil:Rio Grande do Sul:Rio Grande do Sul|\
Brazil:Santa Catarina:Santa Catarina|\
Brazil:Sergipe:Sergipe|\
Brazil:Sao Paulo:Sao Paulo|\
Brazil:Tocatins:Tocatins|\
Netherlands:Drente:Drente|\
Netherlands:Flevoland:Flevoland|\
Netherlands:Friesland:Friesland|\
Netherlands:Gelderland:Gelderland|\
Netherlands:Groningen:Groningen|\
Netherlands:Limburg:Limburg|\
Netherlands:Noord Brabant:Noord Brabant|\
Netherlands:Noord Holland:Noord Holland|\
Netherlands:Overijssel:Overijssel|\
Netherlands:Utrecht:Utrecht|\
Netherlands:Zuid Holland:Zuid Holland|\
Netherlands:Zeeland:Zeeland|\
EI:CO County Antrim:County Antrim|\
EI:CO ARMAGH:County Armagh|\
EI:CO DOWN:County Down|\
EI:CO FERMANAGH:County Fermanagh|\
EI:CO DERRY:County Londonderry|\
EI:CO TYRONE:County Tyrone|\
EI:CO CAVAN:County Cavan|\
EI:CO DONEGAL:County Donegal|\
EI:CO MONAGHAN:County Monaghan|\
EI:CO DUBLIN:County Dublin|\
EI:CO CARLOW:County Carlow|\
EI:CO KILDARE:County Kildare|\
EI:CO KILKENNY:County Kilkenny|\
EI:CO LAOIS:County Laois|\
EI:CO LONGFORD:County Longford|\
EI:CO LOUTH:County Louth|\
EI:CO MEATH:County Meath|\
EI:CO OFFALY:County Offaly|\
EI:CO WESTMEATH:County Westmeath|\
EI:CO WEXFORD:County Wexford|\
EI:CO WICKLOW:County Wicklow|\
EI:CO GALWAY:County Galway|\
EI:CO MAYO:County Mayo|\
EI:CO LEITRIM:County Leitrim|\
EI:CO ROSCOMMON:County Roscommon|\
EI:CO SLIGO:County Sligo|\
EI:CO CLARE:County Clare|\
EI:CO CORK:County Cork|\
EI:CO KERRY:County Kerry|\
EI:CO LIMERICK:County Limerick|\
EI:CO TIPPERARY:County Tipperary|\
EI:CO WATERFORD:County Waterford|\
';

// Country data table
//
// To edit the list, just delete a line or add a line. Order is important.
// The order displayed here is the order it appears on the drop down.
//
var country = '\
Afghanistan:Afghanistan|\
Albania:Albania|\
Algeria:Algeria|\
American Samoa:American Samoa|\
Andorra:Andorra|\
Angola:Angola|\
Anguilla:Anguilla|\
Antarctica:Antarctica|\
Antigua and Barbuda:Antigua and Barbuda|\
Argentina:Argentina|\
Armenia:Armenia|\
Aruba:Aruba|\
Australia:Australia|\
Austria:Austria|\
Azerbaijan:Azerbaijan|\
Azores:Azores|\
Bahamas:Bahamas|\
Bahrain:Bahrain|\
Bangladesh:Bangladesh|\
Barbados:Barbados|\
Belarus:Belarus|\
Belgium:Belgium|\
Belize:Belize|\
Benin:Benin|\
Bermuda:Bermuda|\
Bhutan:Bhutan|\
Bolivia:Bolivia|\
Bosnia And Herzegowina:Bosnia And Herzegowina|\
Bosnia-Herzegovina:Bosnia-Herzegovina|\
Botswana:Botswana|\
Bouvet Island:Bouvet Island|\
Brazil:Brazil|\
British Indian Ocean Territory:British Indian Ocean Territory|\
British Virgin Islands:British Virgin Islands|\
Brunei Darussalam:Brunei Darussalam|\
Bulgaria:Bulgaria|\
Burkina Faso:Burkina Faso|\
Burundi:Burundi|\
Cambodia:Cambodia|\
Cameroon:Cameroon|\
Canada:Canada|\
Cape Verde:Cape Verde|\
Cayman Islands:Cayman Islands|\
Central African Republic:Central African Republic|\
Chad:Chad|\
Chile:Chile|\
China:China|\
Christmas Island:Christmas Island|\
Cocos (Keeling) Islands:Cocos (Keeling) Islands|\
Colombia:Colombia|\
Comoros:Comoros|\
Congo:Congo|\
Congo, The Democratic Republic O:Congo, The Democratic Republic O|\
Cook Islands:Cook Islands|\
Corsica:Corsica|\
Costa Rica:Costa Rica|\
Cote d` Ivoire (Ivory Coast):Cote d` Ivoire (Ivory Coast)|\
Croatia:Croatia|\
Cuba:Cuba|\
Cyprus:Cyprus|\
Czech Republic:Czech Republic|\
Denmark:Denmark|\
Djibouti:Djibouti|\
Dominica:Dominica|\
Dominican Republic:Dominican Republic|\
East Timor:East Timor|\
Ecuador:Ecuador|\
Egypt:Egypt|\
El Salvador:El Salvador|\
Equatorial Guinea:Equatorial Guinea|\
Eritrea:Eritrea|\
Estonia:Estonia|\
Ethiopia:Ethiopia|\
Falkland Islands (Malvinas):Falkland Islands (Malvinas)|\
Faroe Islands:Faroe Islands|\
Fiji:Fiji|\
Finland:Finland|\
France (Includes Monaco):France (Includes Monaco)|\
France, Metropolitan:France, Metropolitan|\
French Guiana:French Guiana|\
French Polynesia:French Polynesia|\
French Polynesia (Tahiti):French Polynesia (Tahiti)|\
French Southern Territories:French Southern Territories|\
Gabon:Gabon|\
Gambia:Gambia|\
Georgia:Georgia|\
Germany:Germany|\
Ghana:Ghana|\
Gibraltar:Gibraltar|\
Greece:Greece|\
Greenland:Greenland|\
Grenada:Grenada|\
Guadeloupe:Guadeloupe|\
Guam:Guam|\
Guatemala:Guatemala|\
Guinea:Guinea|\
Guinea-Bissau:Guinea-Bissau|\
Guyana:Guyana|\
Haiti:Haiti|\
Heard And Mc Donald Islands:Heard And Mc Donald Islands|\
Holy See (Vatican City State):Holy See (Vatican City State)|\
Honduras:Honduras|\
Hong Kong:Hong Kong|\
Hungary:Hungary|\
Iceland:Iceland|\
India:India|\
Indonesia:Indonesia|\
Iran:Iran|\
Iraq:Iraq|\
Ireland:Ireland|\
Ireland (Eire):Ireland (Eire)|\
Israel:Israel|\
Italy:Italy|\
Jamaica:Jamaica|\
Japan:Japan|\
Jordan:Jordan|\
Kazakhstan:Kazakhstan|\
Kenya:Kenya|\
Kiribati:Kiribati|\
Korea, Democratic People\'S Repub:Korea, Democratic People\'S Repub|\
Kuwait:Kuwait|\
Kyrgyzstan:Kyrgyzstan|\
Laos:Laos|\
Latvia:Latvia|\
Lebanon:Lebanon|\
Lesotho:Lesotho|\
Liberia:Liberia|\
Libya:Libya|\
Liechtenstein:Liechtenstein|\
Lithuania:Lithuania|\
Luxembourg:Luxembourg|\
Macao:Macao|\
Macedonia:Macedonia|\
Madagascar:Madagascar|\
Madeira Islands:Madeira Islands|\
Malawi:Malawi|\
Malaysia:Malaysia|\
Maldives:Maldives|\
Mali:Mali|\
Malta:Malta|\
Marshall Islands:Marshall Islands|\
Martinique:Martinique|\
Mauritania:Mauritania|\
Mauritius:Mauritius|\
Mayotte:Mayotte|\
Mexico:Mexico|\
Micronesia, Federated States Of:Micronesia, Federated States Of|\
Moldova, Republic Of:Moldova, Republic Of|\
Monaco:Monaco|\
Mongolia:Mongolia|\
Montserrat:Montserrat|\
Morocco:Morocco|\
Mozambique:Mozambique|\
Myanmar (Burma):Myanmar (Burma)|\
Namibia:Namibia|\
Nauru:Nauru|\
Nepal:Nepal|\
Netherlands:Netherlands|\
Netherlands Antilles:Netherlands Antilles|\
New Caledonia:New Caledonia|\
New Zealand:New Zealand|\
Nicaragua:Nicaragua|\
Niger:Niger|\
Nigeria:Nigeria|\
Niue:Niue|\
Norfolk Island:Norfolk Island|\
Northern Mariana Islands:Northern Mariana Islands|\
Norway:Norway|\
Oman:Oman|\
Pakistan:Pakistan|\
Palau:Palau|\
Palestinian Territory, Occupied:Palestinian Territory, Occupied|\
Panama:Panama|\
Papua New Guinea:Papua New Guinea|\
Paraguay:Paraguay|\
Peru:Peru|\
Philippines:Philippines|\
Pitcairn:Pitcairn|\
Poland:Poland|\
Portugal:Portugal|\
Puerto Rico:Puerto Rico|\
Qatar:Qatar|\
Reunion:Reunion|\
Romania:Romania|\
Russian Federation:Russian Federation|\
Rwanda:Rwanda|\
Saint Kitts And Nevis:Saint Kitts And Nevis|\
San Marino:San Marino|\
Sao Tome and Principe:Sao Tome and Principe|\
Saudi Arabia:Saudi Arabia|\
Senegal:Senegal|\
Serbia-Montenegro:Serbia-Montenegro|\
Seychelles:Seychelles|\
Sierra Leone:Sierra Leone|\
Singapore:Singapore|\
Slovak Republic:Slovak Republic|\
Slovenia:Slovenia|\
Solomon Islands:Solomon Islands|\
Somalia:Somalia|\
South Africa:South Africa|\
South Georgia And The South Sand:South Georgia And The South Sand|\
South Korea:South Korea|\
Spain:Spain|\
Sri Lanka:Sri Lanka|\
St. Christopher and Nevis:St. Christopher and Nevis|\
St. Helena:St. Helena|\
St. Lucia:St. Lucia|\
St. Pierre and Miquelon:St. Pierre and Miquelon|\
St. Vincent and the Grenadines:St. Vincent and the Grenadines|\
Sudan:Sudan|\
Suriname:Suriname|\
Svalbard And Jan Mayen Islands:Svalbard And Jan Mayen Islands|\
Swaziland:Swaziland|\
Sweden:Sweden|\
Switzerland:Switzerland|\
Syrian Arab Republic:Syrian Arab Republic|\
Taiwan:Taiwan|\
Tajikistan:Tajikistan|\
Tanzania:Tanzania|\
Thailand:Thailand|\
Togo:Togo|\
Tokelau:Tokelau|\
Tonga:Tonga|\
Trinidad and Tobago:Trinidad and Tobago|\
Tristan da Cunha:Tristan da Cunha|\
Tunisia:Tunisia|\
Turkey:Turkey|\
Turkmenistan:Turkmenistan|\
Turks and Caicos Islands:Turks and Caicos Islands|\
Tuvalu:Tuvalu|\
Uganda:Uganda|\
Ukraine:Ukraine|\
United Arab Emirates:United Arab Emirates|\
United Kingdom:United Kingdom|\
United States:UnitedStates|\
United States Minor Outlying Isl:United States Minor Outlying Isl|\
Uruguay:Uruguay|\
Uzbekistan:Uzbekistan|\
Vanuatu:Vanuatu|\
Vatican City:Vatican City|\
Venezuela:Venezuela|\
Vietnam:Vietnam|\
Virgin Islands (U.S.):Virgin Islands (U.S.)|\
Wallis and Furuna Islands:Wallis and Furuna Islands|\
Western Sahara:Western Sahara|\
Western Samoa:Western Samoa|\
Yemen:Yemen|\
Yugoslavia:Yugoslavia|\
Zaire:Zaire|\
Zambia:Zambia|\
Zimbabwe:Zimbabwe|\
';

function TrimString(sInString) {
  if ( sInString ) {
    sInString = sInString.replace( /^\s+/g, "" );// strip leading
    return sInString.replace( /\s+$/g, "" );// strip trailing
  }
}

// Populates the country selected with the counties from the country list
function populateCountry(defaultCountry) {
  if ( postCountry != '' ) {
    defaultCountry = postCountry;
  }
  var countryLineArray = country.split('|');  // Split into lines
  var selObj = document.getElementById('countrySelect');
  selObj.options[0] = new Option('Select Country','');
  selObj.selectedIndex = 0;
  for (var loop = 0; loop < countryLineArray.length; loop++) {
    lineArray = countryLineArray[loop].split(':');
    countryCode  = TrimString(lineArray[0]);
    countryName  = TrimString(lineArray[1]);
    if ( countryCode != '' ) {
      selObj.options[loop + 1] = new Option(countryName, countryCode);
    }
    if ( defaultCountry == countryCode ) {
      selObj.selectedIndex = loop + 1;
    }
  }
}


function populateCountry1(defaultCountry) {
	defaultCountry=TrimString(defaultCountry); 
  if ( postCountry != '' ) {
    defaultCountry = postCountry;
  }
  var countryLineArray = country.split('|');  // Split into lines
  var selObj = document.getElementById('countrySelect1');
  selObj.options[0] = new Option('Select Country','');
  selObj.selectedIndex = 0;
  for (var loop = 0; loop < countryLineArray.length; loop++) {
    lineArray = countryLineArray[loop].split(':');
    countryCode  = TrimString(lineArray[0]);
    countryName  = TrimString(lineArray[1]);
    if ( countryCode != '' ) {
      selObj.options[loop + 1] = new Option(countryName, countryCode);
    }
    if ( defaultCountry == countryCode ) {
      selObj.selectedIndex = loop + 1;
    }
  }
}



function populateState() {
  var selObj = document.getElementById('stateSelect');
  var foundState = false;
  // Empty options just in case new drop down is shorter
  if ( selObj.type == 'select-one' ) {
    for (var i = 0; i < selObj.options.length; i++) {
      selObj.options[i] = null;
    }
    selObj.options.length=null;
    selObj.options[0] = new Option('Select State','');
    selObj.selectedIndex = 0;
  }
  // Populate the drop down with states from the selected country
  var stateLineArray = state.split("|");  // Split into lines
  var optionCntr = 1;
  for (var loop = 0; loop < stateLineArray.length; loop++) {
    lineArray = stateLineArray[loop].split(":");
    countryCode  = TrimString(lineArray[0]);
    stateCode    = TrimString(lineArray[1]);
    stateName    = TrimString(lineArray[2]);
  if (document.getElementById('countrySelect').value == countryCode && countryCode != '' ) {
    // If it's a input element, change it to a select
      if ( selObj.type == 'text' ) {
        parentObj = document.getElementById('stateSelect').parentNode;
        parentObj.removeChild(selObj);
        var inputSel = document.createElement("SELECT");
        inputSel.setAttribute("name","state");
        inputSel.setAttribute("id","stateSelect");
		inputSel.setAttribute("className","popup-textBox");
        parentObj.appendChild(inputSel) ;
        selObj = document.getElementById('stateSelect');
        selObj.options[0] = new Option('Select State','');
        selObj.selectedIndex = 0;
      }
      if ( stateCode != '' ) {
        selObj.options[optionCntr] = new Option(stateName, stateCode);
      }
      // See if it's selected from a previous post
      if ( stateCode == postState && countryCode == postCountry ) {
        selObj.selectedIndex = optionCntr;
      }
      foundState = true;
      optionCntr++
    }
  }
  // If the country has no states, change the select to a text box
  if ( ! foundState ) {
    parentObj = document.getElementById('stateSelect').parentNode;
    parentObj.removeChild(selObj);
  // Create the Input Field
    var inputEl = document.createElement("INPUT");
    inputEl.setAttribute("id", "stateSelect");
    inputEl.setAttribute("type", "text");
    inputEl.setAttribute("name", "state");
    inputEl.setAttribute("size", 26);
    inputEl.setAttribute("value", postState);
	inputEl.setAttribute("className","popup-textBox");
	
    parentObj.appendChild(inputEl) ;
  }
}


function populateState1() {

  var postState=document.getElementById('txtstate').value; 
  var selObj = document.getElementById('stateSelect1');
  var foundState = false;
  // Empty options just in case new drop down is shorter
  if ( selObj.type == 'select-one' ) {
    for (var i = 0; i < selObj.options.length; i++) {
      selObj.options[i] = null;
    }
    selObj.options.length=null;
    selObj.options[0] = new Option('Select State','');
    selObj.selectedIndex = 0;
  }
  // Populate the drop down with states from the selected country
  var stateLineArray = state.split("|");  // Split into lines
  var optionCntr = 1;
  for (var loop = 0; loop < stateLineArray.length; loop++) {
    lineArray = stateLineArray[loop].split(":");
    countryCode  = TrimString(lineArray[0]);
    stateCode    = TrimString(lineArray[1]);
    stateName    = TrimString(lineArray[2]);
  if (document.getElementById('countrySelect1').value == countryCode && countryCode != '' ) {

    // If it's a input element, change it to a select
      if ( selObj.type == 'text' ) {
        parentObj = document.getElementById('stateSelect1').parentNode;
        parentObj.removeChild(selObj);
        var inputSel = document.createElement("SELECT");
        inputSel.setAttribute("name","state1");
        inputSel.setAttribute("id","stateSelect1");
		inputSel.setAttribute("className","popup-textBox");
        parentObj.appendChild(inputSel) ;
        selObj = document.getElementById('stateSelect1');
        selObj.options[0] = new Option('Select State','');
        selObj.selectedIndex = 0;
      }
      if ( stateCode != '' ) {
        selObj.options[optionCntr] = new Option(stateName, stateCode);
      }
      // See if it's selected from a previous post
      if ( stateCode == postState ) {
        selObj.selectedIndex = optionCntr;
      }
      foundState = true;
      optionCntr++
    }
  }
  // If the country has no states, change the select to a text box
  if ( ! foundState ) {
    parentObj = document.getElementById('stateSelect1').parentNode;
    parentObj.removeChild(selObj);
  // Create the Input Field
    var inputEl = document.createElement("INPUT");
    inputEl.setAttribute("id", "stateSelect1");
    inputEl.setAttribute("type", "text");
    inputEl.setAttribute("name", "state1");
    inputEl.setAttribute("size", 26);
    inputEl.setAttribute("value", postState);
	inputEl.setAttribute("className","popup-textBox");
    parentObj.appendChild(inputEl) ;
  }
}

function initCountry1(country,state1)
{
	populateCountry1(country);
	populateState1(); 
}

function initCountry(country) {
  populateCountry(country);
  populateState();
}



