/******************************************************************************************
*	IAS countries and states
*
*		Populate dropdown lists with IAS supported countries and states required by Blackwell Pub.
*
*		Countrylist based on:
*		http://en.wikipedia.org/wiki/List_of_countries (ISO 3166 country code list (2006) ISO 3166-1)
*
*		Portions taken from:
*		Country State Drop Downs v1.0. by Down Home Consulting, Inc. (www.DownHomeConsulting.com)
*		(See also: http://javascript.internet.com/forms/country-state-drop-down.html)
*
*	(c)2007, IAS.
*
*******************************************************************************************/


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.
// States to support: United States (US), Canada (CA) & Australia (AU)
var state = '\
US:AL:Alabama|\
US:AK:Alaska|\
US:AZ:Arizona|\
US:AR:Arkansas|\
US:CA:California|\
US:CO:Colorado|\
US:CT:Connecticut|\
US:DE:Delaware|\
US:FL:Florida|\
US:GA:Georgia|\
US:HI:Hawaii|\
US:ID:Idaho|\
US:IL:Illinois|\
US:IN:Indiana|\
US:IA:Iowa|\
US:KS:Kansas|\
US:KY:Kentucky|\
US:LA:Louisiana|\
US:ME:Maine|\
US:MD:Maryland|\
US:MA:Massachusetts|\
US:MI:Michigan|\
US:MN:Minnesota|\
US:MS:Mississippi|\
US:MO:Missouri|\
US:MT:Montana|\
US:NE:Nebraska|\
US:NV:Nevada|\
US:NH:New Hampshire|\
US:NJ:New Jersey|\
US:NM:New Mexico|\
US:NY:New York|\
US:NC:North Carolina|\
US:ND:North Dakota|\
US:OH:Ohio|\
US:OK:Oklahoma|\
US:OR:Oregon|\
US:PA:Pennsylvania|\
US:RI:Rhode Island|\
US:SC:South Carolina|\
US:SD:South Dakota|\
US:TN:Tennessee|\
US:TX:Texas|\
US:UT:Utah|\
US:VT:Vermont|\
US:VA:Virginia|\
US:WA:Washington|\
US:WV:West Virginia|\
US:WI:Wisconsin|\
US:WY:Wyoming|\
CA:AB:Alberta|\
CA:BC:British Columbia|\
CA:MB:Manitoba|\
CA:NB:New Brunswick|\
CA:NL:Newfoundland and Labrador|\
CA:NT:Northwest Territories|\
CA:NS:Nova Scotia|\
CA:NU:Nunavut|\
CA:ON:Ontario|\
CA:PE:Prince Edward Island|\
CA:QC:Quebec|\
CA:SK:Saskatchewan|\
CA:YT:Yukon Territory|\
AU:ACT:Australian Capital Territory|\
AU:NSW:New South Wales|\
AU:NT:Northern Territory|\
AU:QLD:Queensland|\
AU:SA:South Australia|\
AU:TAS:Tasmania|\
AU:VIC:Victoria|\
AU:WA:Western Australia|\
';



// 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 = '\
AB:Abkhazia|\
AF:Afghanistan|\
AL:Albania|\
DZ:Algeria|\
AD:Andorra|\
AO:Angola|\
AG:Antigua and Barbuda|\
AR:Argentina|\
AM:Armenia|\
AU:Australia|\
AT:Austria|\
AZ:Azerbaijan|\
BS:Bahamas|\
BH:Bahrain|\
BD:Bangladesh|\
BB:Barbados|\
BY:Belarus|\
BE:Belgium|\
BZ:Belize|\
BJ:Benin|\
BT:Bhutan|\
BO:Bolivia|\
BA:Bosnia And Herzegowina|\
BW:Botswana|\
BR:Brazil|\
BN:Brunei|\
BG:Bulgaria|\
BF:Burkina Faso|\
BI:Burundi|\
KH:Cambodia|\
CM:Cameroon|\
CA:Canada|\
CV:Cape Verde|\
CF:Central African Republic|\
TD:Chad|\
CL:Chile|\
CN:China, Peoples` Republic of|\
TW:China, Republic of (Taiwan)|\
CO:Colombia|\
KM:Comoros|\
CD:Congo|\
CR:Costa Rica|\
CI:Cote d` Ivoire|\
HR:Croatia|\
CU:Cuba|\
CY:Cyprus|\
TRNC:Cyprus, Turkish Republic of Northern|\
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|\
FO:Faroe Islands|\
FJ:Fiji|\
FI:Finland|\
FR:France|\
GA:Gabon|\
GM:Gambia|\
GE:Georgia|\
DE:Germany|\
GH:Ghana|\
GR:Greece|\
GD:Grenada|\
GT:Guatemala|\
GN:Guinea|\
GW:Guinea-Bissau|\
GY:Guyana|\
HT:Haiti|\
HN:Honduras|\
HU:Hungary|\
IS:Iceland|\
IN:India|\
ID:Indonesia|\
IR:Iran|\
IQ:Iraq|\
EI:Ireland|\
IL:Israel|\
IT:Italy|\
JM:Jamaica|\
JP:Japan|\
JO:Jordan|\
KZ:Kazakhstan|\
KE:Kenya|\
KI:Kiribati|\
KP:Korea, North|\
KR:Korea, South|\
KW:Kuwait|\
KG:Kyrgyzstan|\
LA:Laos|\
LV:Latvia|\
LB:Lebanon|\
LS:Lesotho|\
LR:Liberia|\
LY:Libya|\
LI:Liechtenstein|\
LT:Lithuania|\
LU:Luxembourg|\
MK:Macedonia|\
MG:Madagascar|\
MW:Malawi|\
MY:Malaysia|\
MV:Maldives|\
ML:Mali|\
MT:Malta|\
MH:Marshall Islands|\
MR:Mauritania|\
MU:Mauritius|\
MX:Mexico|\
FM:Micronesia|\
MD:Moldova|\
MC:Monaco|\
MN:Mongolia|\
MS:Montenegro|\
MA:Morocco|\
MZ:Mozambique|\
MM:Myanmar|\
NK:Nagorno Karabakh|\
NA:Namibia|\
NR:Nauru|\
NP:Nepal|\
NL:Netherlands|\
NZ:New Zealand|\
NI:Nicaragua|\
NE:Niger|\
NG:Nigeria|\
NO:Norway|\
OM:Oman|\
OS:Ossetia, South|\
PK:Pakistan|\
PW:Palau|\
PA:Panama|\
PG:Papua New Guinea|\
PY:Paraguay|\
PE:Peru|\
PH:Philippines|\
PL:Poland|\
PT:Portugal|\
QA:Qatar|\
RO:Romania|\
RU:Russia|\
RW:Rwanda|\
EH:Sahara, Western|\
KN:Saint Kitts And Nevis|\
LC:Saint Lucia|\
VC:Saint Vincent and the Grenadines|\
WS:Samoa|\
SM:San Marino|\
ST:Sao Tome and Principe|\
SA:Saudi Arabia|\
SN:Senegal|\
XS:Serbia|\
SC:Seychelles|\
SL:Sierra Leone|\
SG:Singapore|\
SVK:Slovakia|\
SI:Slovenia|\
SB:Solomon Islands|\
SO:Somalia|\
SS:Somaliland|\
ZA:South Africa|\
ES:Spain|\
LK:Sri Lanka|\
SD:Sudan|\
SR:Suriname|\
SZ:Swaziland|\
SE:Sweden|\
CH:Switzerland|\
SY:Syria|\
TJ:Tajikistan|\
TZ:Tanzania|\
TH:Thailand|\
TG:Togo|\
TO:Tonga|\
MD:Transnistria|\
TT:Trinidad and Tobago|\
TN:Tunisia|\
TR:Turkey|\
TM:Turkmenistan|\
TV:Tuvalu|\
UG:Uganda|\
UA:Ukraine|\
AE:United Arab Emirates|\
UK:United Kingdom|\
US:United States|\
UY:Uruguay|\
UZ:Uzbekistan|\
VU:Vanuatu|\
XV:Vatican City|\
VE:Venezuela|\
VN:Vietnam|\
YE:Yemen|\
ZM:Zambia|\
ZW:Zimbabwe|\
';

function TrimString(sInString) {

	if (sInString) {
		
    	sInString = sInString.replace( /^\s+/g, "" );
		
    	return sInString.replace( /\s+$/g, "" );
		
  	}
	
}

function populateCountry(defaultCountry) {

	if (postCountry != "") {
		
    	defaultCountry = postCountry;
		
  	}
	
	var countryLineArray = country.split("|");
	
	var selObj = document.getElementById("countrySelect");
	
	selObj.options[0] = new Option("...","");
	
	selObj.selectedIndex = 0;
	
	for (var loop = 0; loop < countryLineArray.length-1; 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(selectedstate,prevselcountry) {
	
	var selObj = document.getElementById("stateSelect");
	
	var foundState = false;
		
	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("...","");
		
		selObj.selectedIndex = 0;
		
  	}

	var stateLineArray = state.split("|");
	
	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 != "" ) {

			document.getElementById("stateSelect").disabled = false;	
			
			document.getElementById("statetitle").style.fontWeight = "bold";	
			
			document.getElementById("statetitle").style.color = "#EBEBEB";    
			
			parentObj = document.getElementById("stateSelect").parentNode;
			
			selObj = document.getElementById("stateSelect");
			
			selObj.options[0] = new Option("...","");
			
			if (selectedstate.length == 0 || prevselcountry != countryCode) {
				
				selObj.selectedIndex = 0;
				
			}

			if ( stateCode != "" ) {
				
        		selObj.options[optionCntr] = new Option(stateName, stateCode);
				
      		}

			if ( stateCode == selectedstate ) {
				
        		selObj.selectedIndex = optionCntr;
				
      		}						
			
			foundState = true;
			
			optionCntr++
			
    	}
		
	}
  
	if ( !foundState ) {
	  
		document.getElementById("stateSelect").disabled = true;
			
		document.getElementById("statetitle").style.fontWeight = "normal";
			
		document.getElementById("statetitle").style.color = "#CCCCCC";    
	
	}
	

}

function initCountry(country,state) {
	
	populateCountry(country);
	
	populateState(state,country);
	
}

