/*
	Country State Drop Downs v1.1.  

	(c) Copyright 2006 by 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.


	To install, add the following to the top of your page paste the html between the 
   form tags from demo2.html or demo.html into your page.

*/


// State table
// 
// To edit the list, just delete a line or add a line.  Order is important.  The order 
// displayed 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:Yukon 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|\
United Kingdom:Avon:Avon|\
United Kingdom:Bedfordshire:Bedfordshire|\
United Kingdom:Berkshire:Berkshire|\
United Kingdom:Buckinghamshire:Buckinghamshire|\
United Kingdom:Cambridgeshire:Cambridgeshire|\
United Kingdom:Cheshire:Cheshire|\
United Kingdom:Cleveland:Cleveland|\
United Kingdom:Cornwall:Cornwall|\
United Kingdom:Cumbria:Cumbria|\
United Kingdom:Derbyshire:Derbyshire|\
United Kingdom:Devon:Devon|\
United Kingdom:Dorset:Dorset|\
United Kingdom:Durham:Durham|\
United Kingdom:Essex:Essex|\
United Kingdom:Gloucestershire:Gloucestershire|\
United Kingdom:Greater London:Greater London|\
United Kingdom:Greater Manchester:Greater Manchester|\
United Kingdom:Hampshire:Hampshire|\
United Kingdom:Hereford & Worcestershire:Hereford & Worcestershire|\
United Kingdom:Hertfordshire:Hertfordshire|\
United Kingdom:Humberside:Humberside|\
United Kingdom:Isle of Man:Isle of Man|\
United Kingdom:Isle of Wight:Isle of Wight|\
United Kingdom:Kent:Kent|\
United Kingdom:Lancashire:Lancashire|\
United Kingdom:Leicestershire:Leicestershire|\
United Kingdom:Lincolnshire:Lincolnshire|\
United Kingdom:Merseyside:Merseyside|\
United Kingdom:Norfolk:Norfolk|\
United Kingdom:Northamptonshire:Northamptonshire|\
United Kingdom:Northumberland:Northumberland|\
United Kingdom:Nottinghamshire:Nottinghamshire|\
United Kingdom:Oxfordshire:Oxfordshire|\
United Kingdom:Shropshire:Shropshire|\
United Kingdom:Somerset:Somerset|\
United Kingdom:Staffordshire:Staffordshire|\
United Kingdom:Suffolk:Suffolk|\
United Kingdom:Surrey:Surrey|\
United Kingdom:Sussex:Sussex|\
United Kingdom:Warwickshire:Warwickshire|\
United Kingdom:West Midlands:West Midlands|\
United Kingdom:Wiltshire:Wiltshire|\
United Kingdom:Yorkshire:Yorkshire|\
Ireland:County Antrim:County Antrim|\
Ireland:County Armagh:County Armagh|\
Ireland:County Down:County Down|\
Ireland:County Fermanagh:County Fermanagh|\
Ireland:County Londonderry:County Londonderry|\
Ireland:County Tyrone:County Tyrone|\
Ireland:County Cavan:County Cavan|\
Ireland:County Donegal:County Donegal|\
Ireland:County Monaghan:County Monaghan|\
Ireland:County Dublin:County Dublin|\
Ireland:County Carlow:County Carlow|\
Ireland:County Kildare:County Kildare|\
Ireland:County Kilkenny:County Kilkenny|\
Ireland:County Laois:County Laois|\
Ireland:County Longford:County Longford|\
Ireland:County Louth:County Louth|\
Ireland:County Meath:County Meath|\
Ireland:County Offaly:County Offaly|\
Ireland:County Westmeath:County Westmeath|\
Ireland:County Wexford:County Wexford|\
Ireland:County Wicklow:County Wicklow|\
Ireland:County Galway:County Galway|\
Ireland:County Mayo:County Mayo|\
Ireland:County Leitrim:County Leitrim|\
Ireland:County Roscommon:County Roscommon|\
Ireland:County Sligo:County Sligo|\
Ireland:County Clare:County Clare|\
Ireland:County Cork:County Cork|\
Ireland:County Kerry:County Kerry|\
Ireland:County Limerick:County Limerick|\
Ireland:County Tipperary:County Tipperary|\
Ireland:County Waterford:County Waterford|\
';

// Country data table
//
// 
// To edit the list, just delete a line or add a line.  Order is important.  The order 
// displayed is the order it appears on the drop down.
//
var country = '\
Afghanistan:Afghanistan|\
Åland Islands:Åland Islands|\
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|\
Bahamas:Bahamas|\
Bahrain:Bahrain|\
Bangladesh:Bangladesh|\
Barbados:Barbados|\
Belarus:Belarus|\
Belgium:Belgium|\
Belize:Belize|\
Benin:Benin|\
Bermuda:Bermuda|\
Bhutan:Bhutan|\
Bolivia:Bolivia|\
Bosnia and Herzegovina:Bosnia and Herzegovina|\
Botswana:Botswana|\
Bouvet Island:Bouvet Island|\
Brazil:Brazil|\
British Indian Ocean Territory:British Indian Ocean Territory|\
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 of the:Congo, The Democratic Republic of the|\
Cook Islands:Cook Islands|\
Costa Rica:Costa Rica|\
Côte d\'Ivoire:Côte d\'Ivoire|\
Croatia:Croatia|\
Cuba:Cuba|\
Cyprus:Cyprus|\
Czech Republic:Czech Republic|\
Denmark:Denmark|\
Djibouti:Djibouti|\
Dominica:Dominica|\
Dominican Republic:Dominican Republic|\
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:France|\
French Guiana:French Guiana|\
French Polynesia:French Polynesia|\
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|\
Guernsey:Guernsey|\
Guinea:Guinea|\
Guinea-Bissau:Guinea-Bissau|\
Guyana:Guyana|\
Haiti:Haiti|\
Heard Island and Mcdonald Islands:Heard Island and Mcdonald 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, Islamic Republic of:Iran, Islamic Republic of|\
Iraq:Iraq|\
Ireland:Ireland|\
Isle of Man:Isle of Man|\
Israel:Israel|\
Italy:Italy|\
Jamaica:Jamaica|\
Japan:Japan|\
Jersey:Jersey|\
Jordan:Jordan|\
Kazakhstan:Kazakhstan|\
Kenya:Kenya|\
Kiribati:Kiribati|\
Korea, Democratic People\'s Republic of:Korea, Democratic People\'s Republic of|\
Korea, Republic of:Korea, Republic of|\
Kuwait:Kuwait|\
Kyrgyzstan:Kyrgyzstan|\
Lao People\'s Democratic Republic:Lao People\'s Democratic Republic|\
Latvia:Latvia|\
Lebanon:Lebanon|\
Lesotho:Lesotho|\
Liberia:Liberia|\
Libyan Arab Jamahiriya:Libyan Arab Jamahiriya|\
Liechtenstein:Liechtenstein|\
Lithuania:Lithuania|\
Luxembourg:Luxembourg|\
Macao:Macao|\
Macedonia, The Former Yugoslav Republic of:Macedonia, The Former Yugoslav Republic of|\
Madagascar:Madagascar|\
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|\
Montenegro:Montenegro|\
Montserrat:Montserrat|\
Morocco:Morocco|\
Mozambique:Mozambique|\
Myanmar:Myanmar|\
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|\
Réunion:Réunion|\
Romania:Romania|\
Russian Federation:Russian Federation|\
Rwanda:Rwanda|\
Saint Helena:Saint Helena|\
Saint Kitts and Nevis:Saint Kitts and Nevis|\
Saint Lucia:Saint Lucia|\
Saint Pierre and Miquelon:Saint Pierre and Miquelon|\
Saint Vincent and the Grenadines:Saint Vincent and the Grenadines|\
Samoa:Samoa|\
San Marino:San Marino|\
Sao Tome and Principe:Sao Tome and Principe|\
Saudi Arabia:Saudi Arabia|\
Senegal:Senegal|\
Serbia:Serbia|\
Seychelles:Seychelles|\
Sierra Leone:Sierra Leone|\
Singapore:Singapore|\
Slovakia:Slovakia|\
Slovenia:Slovenia|\
Solomon Islands:Solomon Islands|\
Somalia:Somalia|\
South Africa:South Africa|\
South Georgia and the South Sandwich Islands:South Georgia and the South Sandwich Islands|\
Spain:Spain|\
Sri Lanka:Sri Lanka|\
Sudan:Sudan|\
Suriname:Suriname|\
Svalbard and Jan Mayen:Svalbard and Jan Mayen|\
Swaziland:Swaziland|\
Sweden:Sweden|\
Switzerland:Switzerland|\
Syrian Arab Republic:Syrian Arab Republic|\
Taiwan, Province of China:Taiwan, Province of China|\
Tajikistan:Tajikistan|\
Tanzania, United Republic of:Tanzania, United Republic of|\
Thailand:Thailand|\
Timor-Leste:Timor-Leste|\
Togo:Togo|\
Tokelau:Tokelau|\
Tonga:Tonga|\
Trinidad and Tobago:Trinidad and Tobago|\
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:United States|\
United States Minor Outlying Islands:United States Minor Outlying Islands|\
Uruguay:Uruguay|\
Uzbekistan:Uzbekistan|\
Vanuatu:Vanuatu|\
Venezuela:Venezuela|\
Viet Nam:Viet Nam|\
Virgin Islands (British):Virgin Islands (British)|\
Virgin Islands (U.S.):Virgin Islands (U.S.)|\
Wallis and Futuna:Wallis and Futuna|\
Western Sahara:Western Sahara|\
Yemen:Yemen|\
Zambia:Zambia|\
Zimbabwe:Zimbabwe|\
';

// Save the country & state field names
var countryFieldCfgArray = document.getElementById('cs_config_country_field').value.split(' ');
var stateFieldCfgArray   = document.getElementById('cs_config_state_field').value.split(' ');

// Save the names of the fields that hold the country & state default values
var countryDefaultCfgArray = document.getElementById('cs_config_country_default').value.split(' ');
var stateDefaultCfgArray   = document.getElementById('cs_config_state_default').value.split(' ');

var defaultState = false;
var defaultCountry = false;

function TrimString(sInString) {
   
   if ( sInString ) {

      sInString = sInString.replace( /^\s+/g, "" );// strip leading
      return sInString.replace( /\s+$/g, "" );// strip trailing
   }
}
// Populates the country select with the counties from the country list
//
function populateCountry(idName) {

   var countryLineArray = country.split('|');      // Split into lines

   var selObj = document.getElementById( idName );

   selObj.options[0] = new Option('---Choose One---','');
   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 != '' && countryCode != null ) {

         selObj.options[loop + 1] = new Option(countryName, countryCode);
      }

      if ( defaultCountry == countryCode ) {

         selObj.selectedIndex = loop + 1;
      }
   }
}
function populateState( stateIdName, countryIdName ) {

   var selObj = document.getElementById( stateIdName );
	 var stateFieldName = selObj.getAttribute("name");
   var foundState = false;

   // Empty options just in case new drop down is shorter
   //
   if ( selObj.type == 'select-one' ) {

      selObj.options.length = 0;

      selObj.options[0] = new Option('---Choose One---','');
      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( countryIdName ).value == countryCode && countryCode != '' ) {

         // If it's a input element, change it to a select
         //
         if ( selObj.type == 'text' ) {

            parentObj = document.getElementById( stateIdName ).parentNode;
            parentObj.removeChild(selObj);

            var inputSel = document.createElement("SELECT");
            inputSel.setAttribute("name", stateFieldName); 
            inputSel.setAttribute("id", stateIdName ); 

            parentObj.appendChild(inputSel) ;

            selObj = document.getElementById( stateIdName );
            selObj.options[0] = new Option('---Choose One---','');
            selObj.selectedIndex = 0;
         }
   
         if ( stateCode != '' ) {

            selObj.options[optionCntr] = new Option(stateName, stateCode);
         }
         // See if it's selected from a previous post
         //
         if ( stateCode == defaultState && countryCode == defaultCountry ) {

            selObj.selectedIndex = optionCntr;
         }
         foundState = true;
         optionCntr++
      }
   }
   // If the country has no states, change the select to a text box
   //
   if ( ! foundState ) {

      parentObj = document.getElementById( stateIdName ).parentNode;
      parentObj.removeChild(selObj);
 
      // Create the Input Field
      var inputEl = document.createElement("INPUT");

      inputEl.setAttribute("id",  stateIdName ); 
      inputEl.setAttribute("type", "text"); 
      inputEl.setAttribute("name", stateFieldName); 
      inputEl.setAttribute("size", 20); 
      inputEl.setAttribute("value", defaultState); 
      parentObj.appendChild(inputEl) ;
   }
   
}
// Called when state drop down is changed
// 
function updateState( countryIdNameIn ) {

   for (var loop = 0; loop < countryFieldCfgArray.length; loop++) {
   
      countryIdName  = countryFieldCfgArray[loop];
      stateIdName    = stateFieldCfgArray[loop];

      // Read the default value hidden fields
      defaultCountry = document.getElementById( countryDefaultCfgArray[loop] ).value;
      defaultState   = document.getElementById( stateDefaultCfgArray[loop] ).value;

      if ( countryIdNameIn == countryIdName ) {

         populateState( stateIdName, countryIdName );
      }
   }
}
// Initialize the drop downs
// 
function initCountry() {

   for (var loop = 0; loop < countryFieldCfgArray.length; loop++) {
   
      countryIdName  = countryFieldCfgArray[loop];
      stateIdName    = stateFieldCfgArray[loop];

      // Read the default value hidden fields
      defaultCountry = document.getElementById( countryDefaultCfgArray[loop] ).value;
      defaultState   = document.getElementById( stateDefaultCfgArray[loop] ).value;

      populateCountry( countryIdName);
      populateState( stateIdName, countryIdName );
   }
}

