

/**
*
* Retreive all the state according to the addressType.
*
**/
function getState(type){
	var caText = new Array();
	var caValue = new Array();
	var miText = new Array();
	var miValue	= new Array();
	var usText = new Array();
	var usValue = new Array();
	var mexText = new Array();
	var mexValue = new Array();							

usText[0]='Alabama';usValue[0]='AL';
usText[1]='Alaska';usValue[1]='AK';
usText[2]='American Samoa';usValue[2]='AS';
usText[3]='Arizona';usValue[3]='AZ';
usText[4]='Arkansas';usValue[4]='AR';
usText[5]='California';usValue[5]='CA';
usText[6]='Colorado';usValue[6]='CO';
usText[7]='Connecticut';usValue[7]='CT';
usText[8]='Delaware';usValue[8]='DE';
usText[9]='District of Columbia';usValue[9]='DC';
usText[10]='Florida';usValue[10]='FL';
usText[11]='Georgia';usValue[11]='GA';
usText[12]='Hawaii';usValue[12]='HI';
usText[13]='Idaho';usValue[13]='ID';
usText[14]='Illinois';usValue[14]='IL';
usText[15]='Indiana';usValue[15]='IN';
usText[16]='Iowa';usValue[16]='IA';
usText[17]='Kansas';usValue[17]='KS';
usText[18]='Kentucky';usValue[18]='KY';
usText[19]='Louisiana';usValue[19]='LA';
usText[20]='Maine';usValue[20]='ME';
usText[21]='Maryland';usValue[21]='MD';
usText[22]='Massachusetts';usValue[22]='MA';
usText[23]='Michigan';usValue[23]='MI';
usText[24]='Minnesota';usValue[24]='MN';
usText[25]='Mississippi';usValue[25]='MS';
usText[26]='Missouri';usValue[26]='MO';
usText[27]='Montana';usValue[27]='MT';
usText[28]='Nebraska';usValue[28]='NE';
usText[29]='Nevada';usValue[29]='NV';
usText[30]='New Hampshire';usValue[30]='NH';
usText[31]='New Jersey';usValue[31]='NJ';
usText[32]='New Mexico';usValue[32]='NM';
usText[33]='New York';usValue[33]='NY';
usText[34]='North Carolina';usValue[34]='NC';
usText[35]='North Dakota';usValue[35]='ND';
usText[36]='Ohio';usValue[36]='OH';
usText[37]='Oklahoma';usValue[37]='OK';
usText[38]='Oregon';usValue[38]='OR';
usText[39]='Pennsylvania';usValue[39]='PA';
usText[40]='Rhode Island';usValue[40]='RI';
usText[41]='South Carolina';usValue[41]='SC';
usText[42]='South Dakota';usValue[42]='SD';
usText[43]='Tennessee';usValue[43]='TN';
usText[44]='Texas';usValue[44]='TX';
usText[45]='Utah';usValue[45]='UT';
usText[46]='Vermont';usValue[46]='VT';
usText[47]='Virgin Islands';usValue[47]='VI';
usText[48]='Virginia';usValue[48]='VA';
usText[49]='Washington';usValue[49]='WA';
usText[50]='West Virginia';usValue[50]='WV';
usText[51]='Wisconsin';usValue[51]='WI';
usText[52]='Wyoming';usValue[52]='WY';



	
	miText[0]="AA";
	miValue[0]="AA";
	miText[1]="AE";
	miValue[1]="AE";
	miText[2]="AP";
	miValue[2]="AP";
	
caText[0]='Alberta';caValue[0]='AB';
caText[1]='British Columbia';caValue[1]='BC';
caText[2]='Manitoba';caValue[2]='MB';
caText[3]='New Brunswick';caValue[3]='NB';
caText[4]='Newfoundland/Labrador';caValue[4]='NL';
caText[5]='Northwest Territories';caValue[5]='NT';
caText[6]='Nova Scotia';caValue[6]='NS';
caText[7]='Nunavut';caValue[7]='NU';
caText[8]='Ontario';caValue[8]='ON';
caText[9]='Prince Edward Island';caValue[9]='PE';
caText[10]='Quebec';caValue[10]='QC';
caText[11]='Saskatchewan';caValue[11]='SK';
caText[12]='Yukon';caValue[12]='YT';



mexText[0]='Aguascalientes';mexValue[0]='Aguascalientes';
mexText[1]='Durango';mexValue[1]='Durango';
mexText[2]='Guanajuato';mexValue[2]='Guanajuato';
mexText[3]='Guerrero';mexValue[3]='Guerrero';  
mexText[4]='Hidalgo';mexValue[4]='Hidalgo';
mexText[5]='Jalisco';mexValue[5]='Jalisco';
mexText[6]='Mexico';mexValue[6]='Mexico';
mexText[7]='Michoacan De Ocampo';mexValue[7]='Michoacan De Ocampo';
mexText[8]='Morelos';mexValue[8]='Morelos';
mexText[9]='Nayarit';mexValue[9]='Nayarit';
mexText[10]='Nuevo Leon';mexValue[10]='Nuevo Leon';
mexText[11]='Baja California';mexValue[11]='Baja California';
mexText[12]='Oaxaca';mexValue[12]='Oaxaca';
mexText[13]='Puebla';mexValue[13]='Puebla';
mexText[14]='Queretaro De Arteaga';mexValue[14]='Queretaro De Arteaga';
mexText[15]='Quintana Roo';mexValue[15]='Quintana Roo';
mexText[16]='San Luis Potosi';mexValue[16]='San Luis Potosi';
mexText[17]='Sinaloa';mexValue[17]='Sinaloa';
mexText[18]='Sonora';mexValue[18]='Sonora';
mexText[19]='Tabasco';mexValue[19]='Tabasco';
mexText[20]='Tamaulipas';mexValue[20]='Tamaulipas';
mexText[21]='Tlaxcala';mexValue[21]='Tlaxcala';
mexText[22]='Baja California Sur';mexValue[22]='Baja California Sur';
mexText[23]='Veracruz Llave';mexValue[23]='Veracruz Llave';
mexText[24]='Yucatan';mexValue[24]='Yucatan';
mexText[25]='Zacatecas';mexValue[25]='Zacatecas';
mexText[26]='Campeche';mexValue[26]='Campeche';
mexText[27]='Coahuila De Zaragoza';mexValue[27]='Coahuila De Zaragoza';
mexText[28]='Colima';mexValue[28]='Colima';
mexText[29]='Chiapas';mexValue[29]='Chiapas';
mexText[30]='Chihuahua';mexValue[30]='Chihuahua';
mexText[31]='Distrito Federal';mexValue[31]='Distrito Federal';

		
	switch(type){
		case "ca":		
			return {text:caText,value:caValue};
			break;
		case "military":
			return {text:miText,value:miValue};
			break;
		default:
			return {text:usText,value:usValue};	
	}
}


/**
*
* Prefilled All the Intl Countries into the country select box and set the selectValue to value.
*
**/

function fillIntlCountries(id, value){
	var countryOpts = document.getElementById(id);
	
countryOpts.options[0]=new Option('Select Country','',false,false);
countryOpts.options[1]=new Option('Afghanistan','AF',false,false);

countryOpts.options[2]=new Option('Albania','AL',false,false);
countryOpts.options[3]=new Option('Algeria','DZ',false,false);
countryOpts.options[4]=new Option('American Samoa','AS',false,false);
countryOpts.options[5]=new Option('Andorra','AD',false,false);
countryOpts.options[6]=new Option('Angola','AO',false,false);
countryOpts.options[7]=new Option('Anguilla','AI',false,false);
countryOpts.options[8]=new Option('Antigua and Barbuda','AG',false,false);
countryOpts.options[9]=new Option('Argentina','AR',false,false);
countryOpts.options[10]=new Option('Armenia','AM',false,false);
countryOpts.options[11]=new Option('Aruba','AW',false,false);
countryOpts.options[12]=new Option('Australia','AU',false,false);
countryOpts.options[13]=new Option('Austria','AT',false,false);
countryOpts.options[14]=new Option('Azerbaijan','AZ',false,false);
countryOpts.options[15]=new Option('Bahamas','BS',false,false);
countryOpts.options[16]=new Option('Bahrain','BH',false,false);
countryOpts.options[17]=new Option('Bangladesh','BD',false,false);
countryOpts.options[18]=new Option('Barbados','BB',false,false);
countryOpts.options[19]=new Option('Belarus','BY',false,false);
countryOpts.options[20]=new Option('Belgium','BE',false,false);
countryOpts.options[21]=new Option('Belize','BZ',false,false);
countryOpts.options[22]=new Option('Benin','BJ',false,false);
countryOpts.options[23]=new Option('Bermuda','BM',false,false);
countryOpts.options[24]=new Option('Bhutan','BT',false,false);
countryOpts.options[25]=new Option('Bolivia','BO',false,false);
countryOpts.options[26]=new Option('Bosnia and Herzegovina','BA',false,false);
countryOpts.options[27]=new Option('Botswana','BW',false,false);
countryOpts.options[28]=new Option('Brazil','BR',false,false);
countryOpts.options[29]=new Option('British Virgin Islands','VG',false,false);
countryOpts.options[30]=new Option('Brunei Darussalam','BN',false,false);
countryOpts.options[31]=new Option('Bulgaria','BG',false,false);
countryOpts.options[32]=new Option('Burkina Faso','BF',false,false);
countryOpts.options[33]=new Option('Burundi','BI',false,false);
countryOpts.options[34]=new Option('Cambodia','KH',false,false);
countryOpts.options[35]=new Option('Cameroon','CM',false,false);
countryOpts.options[36]=new Option('Cape Verde','CV',false,false);
countryOpts.options[37]=new Option('Cayman Islands','KY',false,false);
countryOpts.options[38]=new Option('Central African Republic','CF',false,false);
countryOpts.options[39]=new Option('Chad','TD',false,false);

countryOpts.options[40]=new Option('Chile','CL',false,false);
countryOpts.options[41]=new Option('China','CN',false,false);
countryOpts.options[42]=new Option('Colombia','CO',false,false);
countryOpts.options[43]=new Option('Comoros','KM',false,false);
countryOpts.options[44]=new Option('Congo','CG',false,false);
countryOpts.options[45]=new Option('Cook Islands','CK',false,false);
countryOpts.options[46]=new Option('Costa Rica','CR',false,false);
countryOpts.options[47]=new Option('Côte d\'Ivoire','CI',false,false);
countryOpts.options[48]=new Option('Croatia','HR',false,false);
countryOpts.options[49]=new Option('Cuba','CU',false,false);
countryOpts.options[50]=new Option('Cyprus','CY',false,false);
countryOpts.options[51]=new Option('Czech Republic','CZ',false,false);
countryOpts.options[52]=new Option('Democratic Republic of the Congo','CD',false,false);
countryOpts.options[53]=new Option('Denmark','DK',false,false);
countryOpts.options[54]=new Option('Djibouti','DJ',false,false);
countryOpts.options[55]=new Option('Dominica','DM',false,false);
countryOpts.options[56]=new Option('Dominican Republic','DO',false,false);
countryOpts.options[57]=new Option('Ecuador','EC',false,false);
countryOpts.options[58]=new Option('Egypt','EG',false,false);
countryOpts.options[59]=new Option('El Salvador','SV',false,false);
countryOpts.options[60]=new Option('Equatorial Guinea','GQ',false,false);
countryOpts.options[61]=new Option('Eritrea','ER',false,false);
countryOpts.options[62]=new Option('Estonia','EE',false,false);
countryOpts.options[63]=new Option('Ethiopia','ET',false,false);
countryOpts.options[64]=new Option('Faeroe Islands','FO',false,false);
countryOpts.options[65]=new Option('Falkland Islands (Malvinas)','FK',false,false);
countryOpts.options[66]=new Option('Fiji','FJ',false,false);
countryOpts.options[67]=new Option('Finland','FI',false,false);
countryOpts.options[68]=new Option('France','FR',false,false);
countryOpts.options[69]=new Option('French Guiana','GF',false,false);
countryOpts.options[70]=new Option('French Polynesia','PF',false,false);
countryOpts.options[71]=new Option('Gabon','GA',false,false);
countryOpts.options[72]=new Option('Gambia','GM',false,false);
countryOpts.options[73]=new Option('Georgia','GE',false,false);
countryOpts.options[74]=new Option('Germany','DE',false,false);
countryOpts.options[75]=new Option('Ghana','GH',false,false);
countryOpts.options[76]=new Option('Gibraltar','GI',false,false);
countryOpts.options[77]=new Option('Greece','GR',false,false);
countryOpts.options[78]=new Option('Greenland','GL',false,false);
countryOpts.options[79]=new Option('Grenada','GD',false,false);
countryOpts.options[80]=new Option('Guadeloupe','GP',false,false);
countryOpts.options[81]=new Option('Guam','GU',false,false);
countryOpts.options[82]=new Option('Guatemala','GT',false,false);

countryOpts.options[83]=new Option('Guinea','GN',false,false);
countryOpts.options[84]=new Option('Guinea-Bissau','GW',false,false);
countryOpts.options[85]=new Option('Guyana','GY',false,false);
countryOpts.options[86]=new Option('Haiti','HT',false,false);
countryOpts.options[87]=new Option('Holy See','VA',false,false);
countryOpts.options[88]=new Option('Honduras','HN',false,false);
countryOpts.options[89]=new Option('Hong Kong','HK',false,false);
countryOpts.options[90]=new Option('Hungary','HU',false,false);
countryOpts.options[91]=new Option('Iceland','IS',false,false);
countryOpts.options[92]=new Option('India','IN',false,false);
countryOpts.options[93]=new Option('Indonesia','ID',false,false);
countryOpts.options[94]=new Option('Iran, Islamic Republic of','IR',false,false);
countryOpts.options[95]=new Option('Iraq','IQ',false,false);
countryOpts.options[96]=new Option('Ireland','IE',false,false);

countryOpts.options[97]=new Option('Israel','IL',false,false);
countryOpts.options[98]=new Option('Italy','IT',false,false);
countryOpts.options[99]=new Option('Jamaica','JM',false,false);
countryOpts.options[100]=new Option('Japan','JP',false,false);

countryOpts.options[101]=new Option('Jordan','JO',false,false);
countryOpts.options[102]=new Option('Kazakhstan','KZ',false,false);
countryOpts.options[103]=new Option('Kenya','KE',false,false);
countryOpts.options[104]=new Option('Kiribati','KI',false,false);
countryOpts.options[105]=new Option('Kuwait','KW',false,false);
countryOpts.options[106]=new Option('Kyrgyzstan','KG',false,false);
countryOpts.options[107]=new Option('Lao People\'s Democratic Republic','LA',false,false);
countryOpts.options[108]=new Option('Latvia','LV',false,false);
countryOpts.options[109]=new Option('Lebanon','LB',false,false);
countryOpts.options[110]=new Option('Lesotho','LS',false,false);
countryOpts.options[111]=new Option('Liberia','LR',false,false);
countryOpts.options[112]=new Option('Libyan Arab Jamahiriya','LY',false,false);
countryOpts.options[113]=new Option('Liechtenstein','LI',false,false);
countryOpts.options[114]=new Option('Lithuania','LT',false,false);
countryOpts.options[115]=new Option('Luxembourg','LU',false,false);
countryOpts.options[116]=new Option('Macao','MO',false,false);
countryOpts.options[117]=new Option('Madagascar','MG',false,false);
countryOpts.options[118]=new Option('Malawi','MW',false,false);
countryOpts.options[119]=new Option('Malaysia','MY',false,false);
countryOpts.options[120]=new Option('Maldives','MV',false,false);
countryOpts.options[121]=new Option('Mali','ML',false,false);
countryOpts.options[122]=new Option('Malta','MT',false,false);
countryOpts.options[123]=new Option('Marshall Islands','MH',false,false);
countryOpts.options[124]=new Option('Martinique','MQ',false,false);
countryOpts.options[125]=new Option('Mauritania','MR',false,false);
countryOpts.options[126]=new Option('Mauritius','MU',false,false);
countryOpts.options[127]=new Option('Mayotte','YT',false,false);
countryOpts.options[128]=new Option('Mexico','MX',false,false);
countryOpts.options[129]=new Option('Micronesia, Federated States of','FM',false,false);
countryOpts.options[130]=new Option('Monaco','MC',false,false);
countryOpts.options[131]=new Option('Mongolia','MN',false,false);
countryOpts.options[132]=new Option('Montenegro','ME',false,false);
countryOpts.options[133]=new Option('Montserrat','MS',false,false);
countryOpts.options[134]=new Option('Morocco','MA',false,false);
countryOpts.options[135]=new Option('Mozambique','MZ',false,false);
countryOpts.options[136]=new Option('Myanmar','MM',false,false);
countryOpts.options[137]=new Option('Namibia','NA',false,false);
countryOpts.options[138]=new Option('Nauru','NR',false,false);
countryOpts.options[139]=new Option('Nepal','NP',false,false);
countryOpts.options[140]=new Option('Netherlands','NL',false,false);
countryOpts.options[141]=new Option('Netherlands Antilles','AN',false,false);
countryOpts.options[142]=new Option('New Caledonia','NC',false,false);
countryOpts.options[143]=new Option('New Zealand','NZ',false,false);
countryOpts.options[144]=new Option('Nicaragua','NI',false,false);
countryOpts.options[145]=new Option('Niger','NE',false,false);
countryOpts.options[146]=new Option('Nigeria','NG',false,false);
countryOpts.options[147]=new Option('Niue','NU',false,false);
countryOpts.options[148]=new Option('Norfolk Island','NF',false,false);
countryOpts.options[149]=new Option('North Korea','KP',false,false);
countryOpts.options[150]=new Option('Northern Mariana Islands','MP',false,false);
countryOpts.options[151]=new Option('Norway','NO',false,false);

countryOpts.options[152]=new Option('Oman','OM',false,false);
countryOpts.options[153]=new Option('Pakistan','PK',false,false);
countryOpts.options[154]=new Option('Palau','PW',false,false);
countryOpts.options[155]=new Option('Panama','PA',false,false);
countryOpts.options[156]=new Option('Papua New Guinea','PG',false,false);
countryOpts.options[157]=new Option('Paraguay','PY',false,false);
countryOpts.options[158]=new Option('Peru','PE',false,false);
countryOpts.options[159]=new Option('Philippines','PH',false,false);
countryOpts.options[160]=new Option('Pitcairn','PN',false,false);
countryOpts.options[161]=new Option('Poland','PL',false,false);
countryOpts.options[162]=new Option('Portugal','PT',false,false);
countryOpts.options[163]=new Option('Puerto Rico','PR',false,false);
countryOpts.options[164]=new Option('Qatar','QA',false,false);
countryOpts.options[165]=new Option('Republic of Moldova','MD',false,false);
countryOpts.options[166]=new Option('Réunion','RE',false,false);
countryOpts.options[167]=new Option('Romania','RO',false,false);
countryOpts.options[168]=new Option('Russian Federation','RU',false,false);
countryOpts.options[169]=new Option('Rwanda','RW',false,false);
countryOpts.options[170]=new Option('Saint Helena','SH',false,false);
countryOpts.options[171]=new Option('Saint Kitts and Nevis','KN',false,false);
countryOpts.options[172]=new Option('Saint Lucia','LC',false,false);
countryOpts.options[173]=new Option('Saint Pierre and Miquelon','PM',false,false);
countryOpts.options[174]=new Option('Saint Vincent and the Grenadines','VC',false,false);


countryOpts.options[175]=new Option('Samoa','WS',false,false);
countryOpts.options[176]=new Option('San Marino','SM',false,false);
countryOpts.options[177]=new Option('Sao Tome and Principe','ST',false,false);
countryOpts.options[178]=new Option('Saudi Arabia','SA',false,false);
countryOpts.options[179]=new Option('Senegal','SN',false,false);
countryOpts.options[180]=new Option('Serbia','RS',false,false);
countryOpts.options[181]=new Option('Seychelles','SC',false,false);
countryOpts.options[182]=new Option('Sierra Leone','SL',false,false);
countryOpts.options[183]=new Option('Singapore','SG',false,false);
countryOpts.options[184]=new Option('Slovakia','SK',false,false);
countryOpts.options[185]=new Option('Slovenia','SI',false,false);
countryOpts.options[186]=new Option('Solomon Islands','SB',false,false);
countryOpts.options[187]=new Option('Somalia','SO',false,false);
countryOpts.options[188]=new Option('South Africa','ZA',false,false);
countryOpts.options[189]=new Option('South Korea','KR',false,false);
countryOpts.options[190]=new Option('Spain','ES',false,false);
countryOpts.options[191]=new Option('Sri Lanka','LK',false,false);
countryOpts.options[192]=new Option('Sudan','SD',false,false);
countryOpts.options[193]=new Option('Suriname','SR',false,false);

countryOpts.options[194]=new Option('Swaziland','SZ',false,false);
countryOpts.options[195]=new Option('Sweden','SE',false,false);
countryOpts.options[196]=new Option('Switzerland','CH',false,false);
countryOpts.options[197]=new Option('Syrian Arab Republic','SY',false,false);
countryOpts.options[198]=new Option('Tajikistan','TJ',false,false);
countryOpts.options[199]=new Option('Thailand','TH',false,false);
countryOpts.options[200]=new Option('The former Yugoslav Republic of Macedonia','MK',false,false);
countryOpts.options[201]=new Option('Timor-Leste','TL',false,false);
countryOpts.options[202]=new Option('Togo','TG',false,false);
countryOpts.options[203]=new Option('Tokelau','TK',false,false);
countryOpts.options[204]=new Option('Tonga','TO',false,false);
countryOpts.options[205]=new Option('Trinidad and Tobago','TT',false,false);
countryOpts.options[206]=new Option('Tunisia','TN',false,false);
countryOpts.options[207]=new Option('Turkey','TR',false,false);
countryOpts.options[208]=new Option('Turkmenistan','TM',false,false);
countryOpts.options[209]=new Option('Turks and Caicos Islands','TC',false,false);
countryOpts.options[210]=new Option('Tuvalu','TV',false,false);
countryOpts.options[211]=new Option('Uganda','UG',false,false);
countryOpts.options[212]=new Option('Ukraine','UA',false,false);
countryOpts.options[213]=new Option('United Arab Emirates','AE',false,false);
countryOpts.options[214]=new Option('United Kingdom and Northern Ireland','GB',false,false);
countryOpts.options[215]=new Option('United Republic of Tanzania','TZ',false,false);
countryOpts.options[216]=new Option('Uruguay','UY',false,false);
countryOpts.options[217]=new Option('Uzbekistan','UZ',false,false);
countryOpts.options[218]=new Option('Vanuatu','VU',false,false);
countryOpts.options[219]=new Option('Venezuela','VE',false,false);
countryOpts.options[220]=new Option('Viet Nam','VN',false,false);
countryOpts.options[221]=new Option('Wallis and Futuna Islands','WF',false,false);
countryOpts.options[222]=new Option('Western Sahara','EH',false,false);
countryOpts.options[223]=new Option('Yemen','YE',false,false);
countryOpts.options[224]=new Option('Zambia','ZM',false,false);
countryOpts.options[225]=new Option('Zimbabwe','ZW',false,false);









	if(value != null) {
	  countryOpts.value = value;
	 }	 
	 
}

/**
*
* Fill the country input field according to the addressType.
*
**/	 
function fillBillingCountry(type){
	var countryOpts = document.getElementById("billingCountry");
	countryOpts.length = 0;
	switch(type){
		case "int":		
			fillIntlCountries("billingCountry");
			break;		
		case "ca":	
			countryOpts.options[0] = new Option("Canada","CA",true,false);
			//countryOpts.options[1] = new Option("Mexico","Mexico",false,false);
			break;
		default:
			countryOpts.options[0] = new Option("USA","US",true,false);
	}
}

function fillShippingCountry(type){
	var countryOpts = document.getElementById("shippingCountry");
	countryOpts.length = 0;
	switch(type){
		case "int":		
			fillIntlCountries("shippingCountry");
			break;		
		case "ca":	
			countryOpts.options[0] = new Option("Canada","CA",true,false);
			//countryOpts.options[1] = new Option("Mexico","Mexico",false,false);
			break;
		default:
			countryOpts.options[0] = new Option("USA","US",true,false);
	}
}

function fillShippingState(type){
	var stateOpts = document.getElementById("shippingState");
	if(type=="int"){
			var parent = stateOpts.parentNode;			
			var stateField = document.createElement("input");
			stateField.type = stateOpts.type;
			stateField.className = stateOpts.className;
			stateField.name = stateOpts.name; 
			stateField.id = stateOpts.id;
			
			parent.replaceChild(stateField,stateOpts);
	}else{		
			if(stateOpts.nodeName!="select"){
				var parent = stateOpts.parentNode;				
				n_stateOpts = document.createElement("select");
				n_stateOpts.className = stateOpts.className;
				n_stateOpts.name = stateOpts.name;
				n_stateOpts.id = stateOpts.id;
				parent.replaceChild(n_stateOpts,stateOpts);	
				stateOpts = n_stateOpts;						
			}
			fillAllState("shippingState",type);
	}
}

function fillAllState(stateId,type){
	var stateOpts = document.getElementById(stateId);
	stateOpts.length = 0;
	var states = getState(type);
	
	for(i=0;i<states.text.length;i++)
    	stateOpts.options[stateOpts.length] = new Option(states.text[i],states.value[i],false,false);	
}


function updateShippingAddressType(type){
	//alert(type);
	document.getElementById('shippingAddressType').value=type;
	fillShippingCountry(type);
	fillShippingState(type);
	document.getElementById("shippingAddress1").value = "";
	document.getElementById("shippingAddress2").value = "";
	document.getElementById("shippingPostalCode").value = "";	
	if(type=="military"){
		var city = document.getElementById("shippingCity");
		var parent = city.parentNode;			
		var cityOpts = document.createElement("select");
		cityOpts.name = city.name;
		cityOpts.id = city.id;
		cityOpts.className = city.className;
		cityOpts.disabled = cityOpts.readonly;
		cityOpts.options[cityOpts.length] = new Option("APO","APO",true,false);
		cityOpts.options[cityOpts.length] = new Option("FPO","FPO",false,false);
		parent.replaceChild(cityOpts,city);
	}else{
		var city = document.getElementById("shippingCity");
		if(city.nodeName!="input"){
			var parent = city.parentNode;
			var n_city = document.createElement("input");
			n_city.type = city.type;
			n_city.name = city.name;
			n_city.className = city.className;
			n_city.id = city.id;
			n_city.readonly = city.disabled;			
			parent.replaceChild(n_city, city);
		}
	}
}

function updateBillingAddressType(type){//alert(type);
	//document.getElementById('billAddressType').value=type;
	document.getElementById('billingAddressType').value=type;
	fillBillingCountry(type);
	fillBillingState(type);

	document.getElementById("billingAddress1").value = "";
	document.getElementById("billingAddress2").value = "";
	document.getElementById("billingPostalCode").value = "";	
	
	if(type=="military"){
		var city = document.getElementById("billingCity");
		var parent = city.parentNode;			
		var cityOpts = document.createElement("select");
		cityOpts.name = city.name;
		cityOpts.id = city.id;
		cityOpts.className = city.className;
		cityOpts.options[cityOpts.length] = new Option("APO","APO",true,false);
		cityOpts.options[cityOpts.length] = new Option("FPO","FPO",false,false);
		cityOpts.onchange = city.onchange;
		cityOpts.onkeyup = city.onkeyup;
		parent.replaceChild(cityOpts,city);
	}else{
		var city = document.getElementById("billingCity");
		if(city.nodeName!="input"){
			var parent = city.parentNode;
			var n_city = document.createElement("input");
			n_city.type = city.type;
			n_city.name = city.name;
			n_city.className = city.className;  
			n_city.id = city.id;
			n_city.onkeyup = city.onkeyup;
			n_city.onchange = city.onchange;
			parent.replaceChild(n_city, city);
		}
	}
}

function updateAddressType(type){
	fillCountry(type);
	fillState(type);
	if(type=="military"){
		var city = document.getElementById("city");
		var parent = city.parentNode;			
		var cityOpts = document.createElement("select");
		cityOpts.name = city.name; 
		cityOpts.className = city.className;
		cityOpts.id = city.id;
		cityOpts.options[cityOpts.length] = new Option("APO","APO",true,false);
		cityOpts.options[cityOpts.length] = new Option("FPO","FPO",false,false);
		parent.replaceChild(cityOpts,city);
	}else{
		var city = document.getElementById("city");
		if(city.nodeName!="INPUT"){
			var parent = city.parentNode;
			var n_city = document.createElement("input");
			n_city.type = city.type;
			n_city.name = city.name;  
			n_city.id = city.id;
			n_city.className = city.className;
			n_city.value = "";
			parent.replaceChild(n_city, city);
		}
	}
	document.getElementById("addressType").value = type;   // used in register.jsp
}

function fillState(type){
	var stateOpts = document.getElementById("state");
	
	if(type=="int"){		
			var parent = stateOpts.parentNode;			
			var stateField = document.createElement("input");
			stateField.type = stateOpts.type;
			stateField.className = stateOpts.className;
			stateField.name = stateOpts.name; 
			stateField.id = stateOpts.id;
			stateField.value="";
			parent.replaceChild(stateField,stateOpts);
	}else{					
		if(stateOpts.nodeName!="SELECT"){
			var parent = stateOpts.parentNode;				
			n_stateOpts = document.createElement("select");
			n_stateOpts.className = stateOpts.className;
			n_stateOpts.name = stateOpts.name; 
			n_stateOpts.id = stateOpts.id;
			
			parent.replaceChild(n_stateOpts,stateOpts);	
			stateOpts = n_stateOpts;						
		}
		fillAllState('state',type);
	}
}

function fillBillingState(type){
	var stateOpts = document.getElementById("billingState");
	
	if(type=="int"){		
			var parent = stateOpts.parentNode;			
			var stateField = document.createElement("input");
			stateField.type = stateOpts.type;
			stateField.className = stateOpts.className;
			stateField.name = stateOpts.name; 
			stateField.id = stateOpts.id;
			stateField.value = "";
			stateField.onkeyup = stateOpts.onchange;
			parent.replaceChild(stateField,stateOpts);
	}else{					
		if(stateOpts.nodeName!="SELECT"){
			var parent = stateOpts.parentNode;				
			n_stateOpts = document.createElement("select");
			n_stateOpts.className = stateOpts.className;
			n_stateOpts.name = stateOpts.name; 
			n_stateOpts.id = stateOpts.id;
			n_stateOpts.onchange = stateOpts.onkeyup;			
			parent.replaceChild(n_stateOpts,stateOpts);	
			stateOpts = n_stateOpts;						
		}
		fillAllState("billingState",type);
	}
}

function fillCountry(type){
	var countryOpts = document.getElementById("country");
	countryOpts.length = 0;
	switch(type){
		case "int":		
			fillIntlCountries("country");
			break;		
		case "ca":	
			countryOpts.options[0] = new Option("Canada","CA",true,false);
			//countryOpts.options[1] = new Option("Mexico","Mexico",false,false);
			break;
		default:
			countryOpts.options[0] = new Option("USA","US",true,false);
	}
}

function setCountry(id,type,value){
	var countryOpts = document.getElementById(id);
	countryOpts.length = 0;
	switch(type){
		case "int":
			
			fillIntlCountries(id, value);
			break;		
		case "ca":	
			countryOpts.options[0] = new Option("Canada","CA",true,false);
			//countryOpts.options[1] = new Option("Mexico","Mexico",false,false);
			break;
		default:
			countryOpts.options[0] = new Option("USA","US",true,false);
	}
}

function setBillingAddress(addType,cityVal,stateVal,countryVal){
	//alert(addType+","+cityVal+","+stateVal+","+countryVal);
	setCity("billingCity",addType,cityVal);
	setState("billingState",addType,stateVal);
	setCountry("billingCountry",addType,countryVal);
}

function setShippingAddress(addType,cityVal,stateVal,countryVal){
	//alert(addType+","+cityVal+","+stateVal+","+countryVal);
	setCity("shippingCity",addType,cityVal);
	setState("shippingState",addType,stateVal);
	setCountry("shippingCountry",addType,countryVal);
}

function setCity(id,addType,value){
	if(addType=="military"){
		var city = document.getElementById(id);
		var parent = city.parentNode;
		var cityOpts = document.createElement("select");
		cityOpts.name = city.name; 
		cityOpts.className = city.className;
		cityOpts.id = city.id;
		cityOpts.onchange = city.onchange;
		cityOpts.onkeyup = city.onkeyup;
		if(id=="shippingCity"){
			var shipTo = document.getElementById("shipTo");
			if(shipTo!=null && shipTo.value=="Billing"){
				cityOpts.disabled = true;
			}
		}
		cityOpts.options[cityOpts.length] = new Option(value,value,true,false);
		if(value=="APO"){
			cityOpts.options[cityOpts.length] = new Option("FPO","FPO",false,false);
		}else{
			cityOpts.options[cityOpts.length] = new Option("APO","APO",false,false);
		}
		parent.replaceChild(cityOpts,city);
	}else{
		var city = document.getElementById(id);
		city.value = value;
	}	
}

function setState(id,addType,value){
	var state = document.getElementById(id);
	if(state.nodeName=="SELECT"){
		if(addType=="int"){
			var parent = state.parentNode;			
			var stateField = document.createElement("input");
			stateField.type = state.type;
			stateField.className = state.className;
			stateField.name = state.name; 
			stateField.id = state.id;
			stateField.disabled = state.disabled;
			stateField.value = value;
			stateField.onkeyup = state.onchange;
			parent.replaceChild(stateField,state);
		}else{
			fillAllState(id,addType);
			for (var x = 0; x < state.length; x++) { 
  				if (state.options[x].value == value) { 
    				state.options[x].selected = true; 
  				}
  			} 
		}
	} 
}

function copyFlds(id){
		var shipTo = document.getElementById("shipTo");
		if(shipTo!=null && shipTo.value=="Billing"){	
			document.getElementById("shipping"+id).value = document.getElementById("billing"+id).value;
		}
		// alert(document.getElementByID("shipping"+id).value);		
	}	
	
	function copyAddressType(){
		var shipTo = document.getElementById("shipTo");
		if(shipTo.value=="Billing"){		
			document.getElementById("shippingAddressType").value = document.getElementById("billingAddressType").value;
			
			var radioObj = document.getElementsByName("RadioGroup1");
			var ind;
			for(var i = 0; i < radioObj.length; i++) {
				if(radioObj[i].checked) {					
					 ind = i;
				}
			}
			document.getElementsByName("RadioGroup2")[ind].checked = true;
			updateShippingAddressType(document.getElementById("shippingAddressType").value);
			document.getElementById("shippingCity").disabled = true;
			document.getElementById("shippingState").disabled = true;
			document.getElementById("shippingCountry").disabled = true;
			document.getElementById("shippingCity").value = document.getElementById("billingCity").value;
			document.getElementById("shippingState").value = document.getElementById("billingState").value;
			document.getElementById("shippingCountry").value = document.getElementById("billingCountry").value;
			
		}
	}
	
	function submitAddresses(){
		document.getElementById("shippingfirstName").disabled = false;
		document.getElementById("shippinglastName").disabled = false;
		
		document.getElementById("shippingAddressType").disabled = false;

		document.getElementById("shippingAddress1").disabled = false;
		document.getElementById("shippingAddress2").disabled = false;
		document.getElementById("shippingPostalCode").disabled = false;
		document.getElementById('shipping_City').value = document.getElementById('shippingCity').value;
		document.getElementById('shipping_State').value = document.getElementById('shippingState').value;
		document.getElementById('shipping_Country').value = document.getElementById('shippingCountry').value;
	}	

function reselectShipping(){
	var selectShipTo = document.getElementById("shipTo");
	var selectNickname = selectShipTo[selectShipTo.selectedIndex].value;
	if (selectNickname.indexOf("New") >=0) {
		document.getElementById("shippingfirstName").disabled = false;
		document.getElementById("shippinglastName").disabled = false;
		
		document.getElementById("shippingAddressType").disabled = false;

		document.getElementById("shippingAddress1").disabled = false;
		document.getElementById("shippingAddress2").disabled = false;
		
		document.getElementById("shippingCity").disabled = false;
		document.getElementById("shippingState").disabled = false;
		document.getElementById("shippingCountry").disabled = false;
		
		document.getElementById("shippingPostalCode").disabled = false;
		
			
		
		document.getElementById("shippingfirstName").value = "";
		document.getElementById("shippinglastName").value = "";
		
		document.getElementById("shippingAddressType").value = "us";
		
		document.getElementById("shippingAddress1").value = "";
		document.getElementById("shippingAddress2").value = "";
		
		document.getElementById("shippingCity").value = "";
		document.getElementById("shipping_City").value = "";
		document.getElementById("shipping_State").value = "";
		document.getElementById("shippingState").value = "";
		document.getElementById("shipping_Country").value = "";
		document.getElementById("shippingCountry").value = "";
		
		document.getElementById("shippingPostalCode").value = "";
	}
	
	document.getElementById("withoutValidate").value=true;
	document.addressForm.submit();
}

function changeCountry(id){
	selectCountry = document.getElementById(id).value;
	if(selectCountry=="Mexico"){
		var state = document.getElementById("state");
		var parent = state.parentNode;
		var n_state = document.createElement("input");
		n_state.type = state.type;
		n_state.name = state.name;  
		n_state.id = state.id;
		n_state.className = "input";
		n_state.value = "";
		parent.replaceChild(n_state, state);		
	}else if(selectCountry=="CA"){
		fillState("ca");
	}
	document.getElementById("city").value = "";
}	

