

if(!postState)
	var postState = '';
var postCountry = 'ANY';

var state = '\
ANY:Any state:Any state|\
US:Alaska:Alaska|\
US:Alabama:Alabama|\
US:Arkansas:Arkansas|\
US:American Samoa:American Samoa|\
US:Arizona:Arizona|\
US:California:California|\
US:Colorado:Colorado|\
US:Connecticut:Connecticut|\
US:D.C.:D.C.|\
US:Delaware:Delaware|\
US:Florida:Florida|\
US:Micronesia:Micronesia|\
US:Georgia:Georgia|\
US:Guam:Guam|\
US:Hawaii:Hawaii|\
US:Iowa:Iowa|\
US:Idaho:Idaho|\
US:Illinois:Illinois|\
US:Indiana:Indiana|\
US:Kansas:Kansas|\
US:Kentucky:Kentucky|\
US:Louisiana:Louisiana|\
US:Massachusetts:Massachusetts|\
US:Maryland:Maryland|\
US:Maine:Maine|\
US:Marshall Islands:Marshall Islands|\
US:Michigan:Michigan|\
US:Minnesota:Minnesota|\
US:Missouri:Missouri|\
US:Marianas:Marianas|\
US:Mississippi:Mississippi|\
US:Montana:Montana|\
US:North Carolina:North Carolina|\
US:North Dakota:North Dakota|\
US:Nebraska:Nebraska|\
US:New Hampshire:New Hampshire|\
US:New Jersey:New Jersey|\
US:New Mexico:New Mexico|\
US:Nevada:Nevada|\
US:New York:New York|\
US:Ohio:Ohio|\
US:Oklahoma:Oklahoma|\
US:Oregon:Oregon|\
US:Pennsylvania:Pennsylvania|\
US:Puerto Rico:Puerto Rico|\
US:Palau:Palau|\
US:Rhode Island:Rhode Island|\
US:South Carolina:South Carolina|\
US:South Dakota:South Dakota|\
US:Tennessee:Tennessee|\
US:Texas:Texas|\
US:Utah:Utah|\
US:Virginia:Virginia|\
US:Virgin Islands:Virgin Islands|\
US:Vermont:Vermont|\
US:Washington:Washington|\
US:Wisconsin:Wisconsin|\
US:West Virginia:West Virginia|\
US:Wyoming:Wyoming|\
US:Military Americas:Military Americas|\
US:Military Europe/ME/Canada:Military Europe/ME/Canada|\
US:Military Pacific:Military Pacific|\
CA:Alberta:Alberta|\
CA:Manitoba:Manitoba|\
CA:Alberta:Alberta|\
CA:British Columbia:British Columbia|\
CA:Manitoba:Manitoba|\
CA:New Brunswick:New Brunswick|\
CA:Newfoundland and Labrador:Newfoundland and Labrador|\
CA:Nova Scotia:Nova Scotia|\
CA:Northwest Territories:Northwest Territories|\
CA:Nunavut:Nunavut|\
CA:Ontario:Ontario|\
CA:Prince Edward Island:Prince Edward Island|\
CA:Quebec:Quebec|\
CA:Saskatchewan:Saskatchewan|\
CA:Yukon Territory:Yukon Territory|\
AU:Australian Antarctic Territory:Australian Antarctic Territory|\
AU:Australian Capital Territory:Australian Capital Territory|\
AU:Northern Territory:Northern Territory|\
AU:New South Wales:New South Wales|\
AU:Queensland:Queensland|\
AU:South Australia:South Australia|\
AU:Tasmania:Tasmania|\
AU:Victoria:Victoria|\
AU:Western Australia:Western Australia|\
BR:Acre:Acre|\
BR:Alagoas:Alagoas|\
BR:Amazonas:Amazonas|\
BR:Amapa:Amapa|\
BR:Baia:Baia|\
BR:Ceara:Ceara|\
BR:Distrito Federal:Distrito Federal|\
BR:Espirito Santo:Espirito Santo|\
BR:Fernando de Noronha:Fernando de Noronha|\
BR:Goias:Goias|\
BR:Maranhao:Maranhao|\
BR:Minas Gerais:Minas Gerais|\
BR:Mato Grosso do Sul:Mato Grosso do Sul|\
BR:Mato Grosso:Mato Grosso|\
BR:Para:Para|\
BR:Paraiba:Paraiba|\
BR:Pernambuco:Pernambuco|\
BR:Piaui:Piaui|\
BR:Parana:Parana|\
BR:Rio de Janeiro:Rio de Janeiro|\
BR:Rio Grande do Norte:Rio Grande do Norte|\
BR:Rondonia:Rondonia|\
BR:Roraima:Roraima|\
BR:Rio Grande do Sul:Rio Grande do Sul|\
BR:Santa Catarina:Santa Catarina|\
BR:Sergipe:Sergipe|\
BR:Sao Paulo:Sao Paulo|\
BR:Tocatins:Tocatins|\
NL:Drente:Drente|\
NL:Flevoland:Flevoland|\
NL:Friesland:Friesland|\
NL:Gelderland:Gelderland|\
NL:Groningen:Groningen|\
NL:Limburg:Limburg|\
NL:Noord Brabant:Noord Brabant|\
NL:Noord Holland:Noord Holland|\
NL:Overijssel:Overijssel|\
NL:Utrecht:Utrecht|\
NL:Zuid Holland:Zuid Holland|\
NL:Zeeland:Zeeland|\
UK:Avon:Avon|\
UK:Bedfordshire:Bedfordshire|\
UK:Berkshire:Berkshire|\
UK:Buckinghamshire:Buckinghamshire|\
UK:Cambridgeshire:Cambridgeshire|\
UK:Cheshire:Cheshire|\
UK:Cleveland:Cleveland|\
UK:Cornwall:Cornwall|\
UK:Cumbria:Cumbria|\
UK:Derbyshire:Derbyshire|\
UK:Devon:Devon|\
UK:Dorset:Dorset|\
UK:Durham:Durham|\
UK:Essex:Essex|\
UK:Gloucestershire:Gloucestershire|\
UK:Greater London:Greater London|\
UK:Greater Manchester:Greater Manchester|\
UK:Hampshire:Hampshire|\
UK:Hereford :HERWOR: Worcestershire:Hereford & Worcestershire|\
UK:Hertfordshire:Hertfordshire|\
UK:Humberside:Humberside|\
UK:Isle of Man:Isle of Man|\
UK:Isle of Wight:Isle of Wight|\
UK:Kent:Kent|\
UK:Lancashire:Lancashire|\
UK:Leicestershire:Leicestershire|\
UK:Lincolnshire:Lincolnshire|\
UK:Merseyside:Merseyside|\
UK:Norfolk:Norfolk|\
UK:Northamptonshire:Northamptonshire|\
UK:Northumberland:Northumberland|\
UK:Nottinghamshire:Nottinghamshire|\
UK:Oxfordshire:Oxfordshire|\
UK:Shropshire:Shropshire|\
UK:Somerset:Somerset|\
UK:Staffordshire:Staffordshire|\
UK:Suffolk:Suffolk|\
UK:Surrey:Surrey|\
UK:Sussex:Sussex|\
UK:Warwickshire:Warwickshire|\
UK:West Midlands:West Midlands|\
UK:Wiltshire:Wiltshire|\
UK:Yorkshire:Yorkshire|\
BE:Antwerpen:Antwerpen|\
BE:Limburg:Limburg|\
BE:Oost-Vlaanderen:Oost-Vlaanderen|\
BE:Vlaams-Brabant:Vlaams-Brabant|\
BE:West-Vlaanderen:West-Vlaanderen|\
BE:Brussel:Brussel|\
BE:Brabant wallon:Brabant wallon|\
BE:Henegouwen:Henegouwen|\
BE:Liege:Liege|\
BE:Luxemburg:Luxemburg|\
BE:Namur:Namur|\
EI:County Antrim:County Antrim|\
EI:County Armagh:County Armagh|\
EI:County Down:County Down|\
EI:County Fermanagh:County Fermanagh|\
EI:County Londonderry:County Londonderry|\
EI:County Tyrone:County Tyrone|\
EI:County Cavan:County Cavan|\
EI:County Donegal:County Donegal|\
EI:County Monaghan:County Monaghan|\
EI:County Dublin:County Dublin|\
EI:County Carlow:County Carlow|\
EI:County Kildare:County Kildare|\
EI:County Kilkenny:County Kilkenny|\
EI:County Laois:County Laois|\
EI:County Longford:County Longford|\
EI:County Louth:County Louth|\
EI:County Meath:County Meath|\
EI:County Offaly:County Offaly|\
EI:County Westmeath:County Westmeath|\
EI:County Wexford:County Wexford|\
EI:County Wicklow:County Wicklow|\
EI:County Galway:County Galway|\
EI:County Mayo:County Mayo|\
EI:County Leitrim:County Leitrim|\
EI:County Roscommon:County Roscommon|\
EI:County Sligo:County Sligo|\
EI:County Clare:County Clare|\
EI:County Cork:County Cork|\
EI:County Kerry:County Kerry|\
EI:County Limerick:County Limerick|\
EI:County Tipperary:County Tipperary|\
EI: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 here is the order it appears on the drop down.
//
var country = '\
AF:Afghanistan|\
AL:Albania|\
DZ:Algeria|\
AS:American Samoa|\
AD:Andorra|\
AO:Angola|\
AI:Anguilla|\
AQ:Antarctica|\
AG:Antigua and Barbuda|\
AR:Argentina|\
AM:Armenia|\
AW:Aruba|\
AU:Australia|\
AT:Austria|\
AZ:Azerbaijan|\
AP:Azores|\
BS:Bahamas|\
BH:Bahrain|\
BD:Bangladesh|\
BB:Barbados|\
BY:Belarus|\
BE:Belgium|\
BZ:Belize|\
BJ:Benin|\
BM:Bermuda|\
BT:Bhutan|\
BO:Bolivia|\
BA:Bosnia And Herzegowina|\
XB:Bosnia-Herzegovina|\
BW:Botswana|\
BV:Bouvet Island|\
BR:Brazil|\
IO:British Indian Ocean Territory|\
VG:British Virgin Islands|\
BN:Brunei Darussalam|\
BG:Bulgaria|\
BF:Burkina Faso|\
BI:Burundi|\
KH:Cambodia|\
CM:Cameroon|\
CA:Canada|\
CV:Cape Verde|\
KY:Cayman Islands|\
CF:Central African Republic|\
TD:Chad|\
CL:Chile|\
CN:China|\
CX:Christmas Island|\
CC:Cocos (Keeling) Islands|\
CO:Colombia|\
KM:Comoros|\
CG:Congo|\
CD:Congo, The Democratic Republic O|\
CK:Cook Islands|\
XE:Corsica|\
CR:Costa Rica|\
CI:Cote d` Ivoire (Ivory Coast)|\
HR:Croatia|\
CU:Cuba|\
CY:Cyprus|\
CZ:Czech Republic|\
DK:Denmark|\
DJ:Djibouti|\
DM:Dominica|\
DO:Dominican Republic|\
TP:East Timor|\
EC:Ecuador|\
EG:Egypt|\
SV:El Salvador|\
GQ:Equatorial Guinea|\
ER:Eritrea|\
EE:Estonia|\
ET:Ethiopia|\
FK:Falkland Islands (Malvinas)|\
FO:Faroe Islands|\
FJ:Fiji|\
FI:Finland|\
FR:France (Includes Monaco)|\
FX:France, Metropolitan|\
GF:French Guiana|\
PF:French Polynesia|\
TA:French Polynesia (Tahiti)|\
TF:French Southern Territories|\
GA:Gabon|\
GM:Gambia|\
GE:Georgia|\
DE:Germany|\
GH:Ghana|\
GI:Gibraltar|\
GR:Greece|\
GL:Greenland|\
GD:Grenada|\
GP:Guadeloupe|\
GU:Guam|\
GT:Guatemala|\
GN:Guinea|\
GW:Guinea-Bissau|\
GY:Guyana|\
HT:Haiti|\
HM:Heard And Mc Donald Islands|\
VA:Holy See (Vatican City State)|\
HN:Honduras|\
HK:Hong Kong|\
HU:Hungary|\
IS:Iceland|\
IN:India|\
ID:Indonesia|\
IR:Iran|\
IQ:Iraq|\
IE:Ireland|\
EI:Ireland (Eire)|\
IL:Israel|\
IT:Italy|\
JM:Jamaica|\
JP:Japan|\
JO:Jordan|\
KZ:Kazakhstan|\
KE:Kenya|\
KI:Kiribati|\
KP:Korea, Democratic People\'S Repub|\
KW:Kuwait|\
KG:Kyrgyzstan|\
LA:Laos|\
LV:Latvia|\
LB:Lebanon|\
LS:Lesotho|\
LR:Liberia|\
LY:Libya|\
LI:Liechtenstein|\
LT:Lithuania|\
LU:Luxembourg|\
MO:Macao|\
MK:Macedonia|\
MG:Madagascar|\
ME:Madeira Islands|\
MW:Malawi|\
MY:Malaysia|\
MV:Maldives|\
ML:Mali|\
MT:Malta|\
MH:Marshall Islands|\
MQ:Martinique|\
MR:Mauritania|\
MU:Mauritius|\
YT:Mayotte|\
MX:Mexico|\
FM:Micronesia, Federated States Of|\
MD:Moldova, Republic Of|\
MC:Monaco|\
MN:Mongolia|\
MS:Montserrat|\
MA:Morocco|\
MZ:Mozambique|\
MM:Myanmar (Burma)|\
NA:Namibia|\
NR:Nauru|\
NP:Nepal|\
NL:Netherlands|\
AN:Netherlands Antilles|\
NC:New Caledonia|\
NZ:New Zealand|\
NI:Nicaragua|\
NE:Niger|\
NG:Nigeria|\
NU:Niue|\
NF:Norfolk Island|\
MP:Northern Mariana Islands|\
NO:Norway|\
OM:Oman|\
PK:Pakistan|\
PW:Palau|\
PS:Palestinian Territory, Occupied|\
PA:Panama|\
PG:Papua New Guinea|\
PY:Paraguay|\
PE:Peru|\
PH:Philippines|\
PN:Pitcairn|\
PL:Poland|\
PT:Portugal|\
PR:Puerto Rico|\
QA:Qatar|\
RE:Reunion|\
RO:Romania|\
RU:Russian Federation|\
RW:Rwanda|\
KN:Saint Kitts And Nevis|\
SM:San Marino|\
ST:Sao Tome and Principe|\
SA:Saudi Arabia|\
SN:Senegal|\
XS:Serbia-Montenegro|\
SC:Seychelles|\
SL:Sierra Leone|\
SG:Singapore|\
SK:Slovak Republic|\
SI:Slovenia|\
SB:Solomon Islands|\
SO:Somalia|\
ZA:South Africa|\
GS:South Georgia And The South Sand|\
KR:South Korea|\
ES:Spain|\
LK:Sri Lanka|\
NV:St. Christopher and Nevis|\
SH:St. Helena|\
LC:St. Lucia|\
PM:St. Pierre and Miquelon|\
VC:St. Vincent and the Grenadines|\
SD:Sudan|\
SR:Suriname|\
SJ:Svalbard And Jan Mayen Islands|\
SZ:Swaziland|\
SE:Sweden|\
CH:Switzerland|\
SY:Syrian Arab Republic|\
TW:Taiwan|\
TJ:Tajikistan|\
TZ:Tanzania|\
TH:Thailand|\
TG:Togo|\
TK:Tokelau|\
TO:Tonga|\
TT:Trinidad and Tobago|\
XU:Tristan da Cunha|\
TN:Tunisia|\
TR:Turkey|\
TM:Turkmenistan|\
TC:Turks and Caicos Islands|\
TV:Tuvalu|\
UG:Uganda|\
UA:Ukraine|\
AE:United Arab Emirates|\
UK:United Kingdom|\
US:United States|\
UM:United States Minor Outlying Isl|\
UY:Uruguay|\
UZ:Uzbekistan|\
VU:Vanuatu|\
XV:Vatican City|\
VE:Venezuela|\
VN:Vietnam|\
VI:Virgin Islands (U.S.)|\
WF:Wallis and Furuna Islands|\
EH:Western Sahara|\
WS:Western Samoa|\
YE:Yemen|\
YU:Yugoslavia|\
ZR:Zaire|\
ZM:Zambia|\
ZW:Zimbabwe\
';

function TrimString(sInString) {
  if ( sInString ) {
    sInString = sInString.replace( /^\s+/g, "" );// strip leading
    return sInString.replace( /\s+$/g, "" );// strip trailing
  }
}

function populateCountry(defaultCountry) {
  var countryLineArray = country.split('|');  // Split into lines
  var selObj = document.getElementById('country');
  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;
    }
  }
  jQuery("#country").uniform();
}

function populateState() {
  var selObj = document.getElementById('state');
  var foundState = false;
  if ( selObj.type == 'select-one' ) {
    for (var i = 0; i < selObj.options.length; i++) {
      selObj.remove(i);
    }
    selObj.options.length=null;	
  }
  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('country').value == countryCode && countryCode != '' ) {
      if ( optionCntr == 1 ) {
		  if(selObj.type == 'text')
		  {
	    parentObj = document.getElementById('state').parentNode;
		topparent = parentObj.parentNode;
		parentObj.removeChild(selObj);
        var inputSel = document.createElement("SELECT");
        inputSel.setAttribute("name","state");
        inputSel.setAttribute("id","state");
        parentObj.appendChild(inputSel) ;
		  } else {
			    parentObj = document.getElementById('state').parentNode;
		topparent = parentObj.parentNode;
		parentObj.removeChild(selObj);
		topparent.removeChild(parentObj	);
        var inputSel = document.createElement("SELECT");
        inputSel.setAttribute("name","state");
        inputSel.setAttribute("id","state");
        topparent.appendChild(inputSel) ;
		  }
        selObj = document.getElementById('state');	
		if(document.getElementById('country').value != 'ANY')
		  {
		if (! location.href.match('join'))
			selObj.options[0] = new Option('Any state','Any state');
		else
			selObj.options[0] = new Option('Select State','Select State');
			selObj.options[0].disabled=true;
		  } else {
			  foundState = true;
			  selObj.options[0] = new Option('Any state','Any state');
			  break;
		  }
      }	
      if ( stateCode != '' ) {
        selObj.options[optionCntr] = new Option(stateName, stateCode);
      }
	  if(stateCode != '' && stateCode == postState)
		  selObj.selectedIndex = optionCntr;
      foundState = true;
      optionCntr++
    } 
  }
  	var selLen = selObj.length;
	for (i=0;i<selLen ;i++ )  
	{  
		if (selObj.options[i].value == '')  
			selObj.remove(i);
	} 

  if ( ! foundState ) {
	  if ( selObj.type == 'text' ) {		
		parentObj = document.getElementById('state').parentNode;
		parentObj.removeChild(selObj);
		var inputEl = document.createElement("INPUT");
		inputEl.setAttribute("id", "state");
	    inputEl.setAttribute("type", "text");
		inputEl.setAttribute("name", "state");
		inputEl.setAttribute("style", "padding-left:6px");
		if (! location.href.match('join'))
			inputEl.setAttribute("value", "Any state");
		else
			inputEl.setAttribute("value", "Enter state");
		//inputEl.setAttribute("value", postState);
		inputEl.setAttribute("onclick","this.value='';");
		parentObj.appendChild(inputEl) ;
		jQuery("#state").uniform();
	  } else {
		parentObj = document.getElementById('state').parentNode;
		topparent = parentObj.parentNode;
		parentObj.removeChild(selObj);
		topparent.removeChild(parentObj	);
	    var inputEl = document.createElement("INPUT");
		inputEl.setAttribute("id", "state");
	    inputEl.setAttribute("type", "text");
		inputEl.setAttribute("name", "state");
		inputEl.setAttribute("style", "padding-left:6px");
		if (! location.href.match('join'))
			inputEl.setAttribute("value", "Any state");
		else
			inputEl.setAttribute("value", "Enter state");
		inputEl.setAttribute("onclick","this.value='';");
	    //inputEl.setAttribute("value", postState);
		topparent.appendChild(inputEl) ;
	  }
  }
  jQuery("#state").uniform();
}

function initCountry(country) {
  populateCountry(country);
  populateState();
}

