/*******************************/
/***** エリアリストの設定  *****/
/*******************************/
function listArea(){
	var i=0;
	this[i++] = new opt('地域を選択してください','');
	this[i++] = new opt('アジア、太平洋地域','1');
	this[i++] = new opt('ラテンアメリカ・カリブ地域','2');
	this[i++] = new opt('ヨーロッパ、地中海、近東・中央アジア地域','3');
	this[i++] = new opt('東アフリカ、中央アフリカ地域','4');
	this[i++] = new opt('南部アフリカ地域','5');
	this[i++] = new opt('西アフリカ地域','6');
	this.length = i;
	return this;
}

/**************************/
/***** 国リストの設定 *****/
/**************************/
function listCountry()
{
	var i=0;
	this[i++] = new listCountry0();
	this[i++] = new listCountry1();
	this[i++] = new listCountry2();
	this[i++] = new listCountry3();
	this[i++] = new listCountry4();
	this[i++] = new listCountry5();
	this[i++] = new listCountry6();
	this.length = i;
	return this;
}

/***********************************/
/***** 国リスト0 エリア未選択  *****/
/***********************************/
function listCountry0(){
	var i=0;
	this[i++] = new noCountry();
	this.length = i;
	return this;
}

/*********************/
/***** 国リスト1 *****/
/*********************/
function listCountry1(){
	var i=0;
	this[i++] = new noCountry();
	this[i++] = new opt('バングラデシュ','050');
	this[i++] = new opt('ブータン','064');
	this[i++] = new opt('カンボジア','116');
	this[i++] = new opt('中華人民共和国','156');
	this[i++] = new opt('東ティモール','626');
	this[i++] = new opt('インド','356');
	this[i++] = new opt('インドネシア','360');
	this[i++] = new opt('朝鮮民主主義人民共和国','408');
	this[i++] = new opt('ラオス','418');
	this[i++] = new opt('ミャンマー','104');
	this[i++] = new opt('ネパール','524');
	this[i++] = new opt('スリランカ','144');
	this.length = i;
	return this;
}

/*********************/
/***** 国リスト2 *****/
/*********************/
function listCountry2(){ 
	var i=0;
	this[i++] = new noCountry();
	this[i++] = new opt('ボリビア','068');
	this[i++] = new opt('コロンビア','170');
	this[i++] = new opt('キューバ','192');
	this[i++] = new opt('ドミニカ共和国','214');
	this[i++] = new opt('エクアドル','218');
	this[i++] = new opt('エルサルバドル','222');
	this[i++] = new opt('グアテマラ','320');
	this[i++] = new opt('ハイチ','332');
	this[i++] = new opt('ホンジュラス','340');
	this[i++] = new opt('ニカラグア','558');
	this[i++] = new opt('ペルー','604');
	this.length = i;
	return this;
}

/*********************/
/***** 国リスト3 *****/
/*********************/
function listCountry3(){ 
	var i=0;
	this[i++] = new noCountry();
	this[i++] = new opt('アフガニスタン','004');
	this[i++] = new opt('アルバニア','008');
	this[i++] = new opt('アルジェリア','012');
	this[i++] = new opt('アルメニア','051');
	this[i++] = new opt('アゼルバイジャン','031');
	this[i++] = new opt('エジプト','818');
	this[i++] = new opt('グルジア','268');
	this[i++] = new opt('イラン','364');
	this[i++] = new opt('イラク','368');
	this[i++] = new opt('ヨルダン','400');
	this[i++] = new opt('モロッコ','504');
	this[i++] = new opt('パキスタン','586');
	this[i++] = new opt('パレスチナ自治区','275');
	this[i++] = new opt('ロシア連邦','643');
	this[i++] = new opt('シリア','760');
	this[i++] = new opt('タジキスタン','762');
	this[i++] = new opt('イエメン','887');
	this.length = i;
	return this;
}

/*********************/
/***** 国リスト4 *****/
/*********************/
function listCountry4(){ 
	var i=0;
	this[i++] = new noCountry();
	this[i++] = new opt('ブルンジ','108');
	this[i++] = new opt('コンゴ共和国','178');
	this[i++] = new opt('コンゴ民主共和国','180');
	this[i++] = new opt('ジプチ','262');
	this[i++] = new opt('エリトリア','232');
	this[i++] = new opt('エチオピア','231');
	this[i++] = new opt('ケニア','404');
	this[i++] = new opt('ルワンダ','646');
	this[i++] = new opt('ソマリア','706');
	this[i++] = new opt('スーダン','736');
	this[i++] = new opt('ウガンダ','800');
	this.length = i;
	return this;
}

/*********************/
/***** 国リスト5 *****/
/*********************/
function listCountry5(){ 
	var i=0;
	this[i++] = new noCountry();
	this[i++] = new opt('アンゴラ','024');
	this[i++] = new opt('レソト','426');
	this[i++] = new opt('マダガスカル','450');
	this[i++] = new opt('マラウイ','454');
	this[i++] = new opt('モザンビーク','508');
	this[i++] = new opt('ナミビア','516');
	this[i++] = new opt('スワジランド','748');
	this[i++] = new opt('タンザニア','834');
	this[i++] = new opt('ザンビア','894');
	this[i++] = new opt('ジンバブエ','716');
	this.length = i;
	return this;
}

/*********************/
/***** 国リスト6 *****/
/*********************/
function listCountry6(){ 
	var i=0;
	this[i++] = new noCountry();
	this[i++] = new opt('ベナン','204');
	this[i++] = new opt('ブルキナファソ','854');
	this[i++] = new opt('カメルーン','120');
	this[i++] = new opt('カーボヴェルデ','132');
	this[i++] = new opt('中央アフリカ','140');
	this[i++] = new opt('チャド','148');
	this[i++] = new opt('コートジボワール','384');
	this[i++] = new opt('ガボン','266');
	this[i++] = new opt('ガンビア','270');
	this[i++] = new opt('ガーナ','288');
	this[i++] = new opt('ギニア','324');
	this[i++] = new opt('ギニアビサウ','624');
	this[i++] = new opt('リベリア','430');
	this[i++] = new opt('マリ','466');
	this[i++] = new opt('モーリタニア','478');
	this[i++] = new opt('ニジェール','562');
	this[i++] = new opt('サントメ・ブリンシペ','678');
	this[i++] = new opt('セネガル','686');
	this[i++] = new opt('シエラレオネ','694');
	this.length = i;
	return this;
}

/****************************/
/***** オプションを設定 *****/
/****************************/
function opt(text,value){
	this.text = text;
	this.value = value;
}

/*********************************/
/***** 国未選択のオプション  *****/
/*********************************/
function noCountry(){
	this.text = '国を選択してください';
	this.value = '';
}

/**********************************/
/***** オプションをロードする *****/
/**********************************/
function loadOption(list,selection){
	var gOptions = new listCountry();
	var resultOptions = list.options;
	var dbOptions = gOptions[selection];
	resultOptions.length = dbOptions.length;
	for (var i=0;i<dbOptions.length;i++) resultOptions[i] = new Option(dbOptions[i].text,dbOptions[i].value,false,false)
	document.unit.country.options[0].selected = true;
}

/********************************/
/***** エリア変更 国書き換え*****/
/********************************/
function changeArea(){
	var selection = document.unit.area.selectedIndex;
	document.unit.country.options[0].selected = true;
	loadOption(document.unit.country,selection);
}

/***********************/
/***** 国変更 移動 *****/
/***********************/
function changeCountry(){
	var selection = document.unit.country.selectedIndex;
	var code = document.unit.country.options[selection].value;
	if(code==''){
		alert('国を選択してください');
		return;
	}else{
		location.href = '../country/' + code + '.html';
	}
}

/********************/
/***** 書き出し *****/
/********************/
function SelectCountry(){
	document.writeln('<form name="unit" onSubmit="changeCountry()">');
	document.writeln('<table id="areaform_table" border="0" cellspacing="0" cellpadding="0"><tr>');
	document.writeln('<td class="fr1"><select name="area" size="7" onChange="changeArea()" class="text1"></select></td>');
	document.writeln('<td class="im" align="center" valign="middle"><img id="areaform_arrow" src="./img/area_arrow.gif" border="0" width="16" height="15" alt=""></td>');
	document.writeln('<td class="fr2"><select name="country" size="7" onChange="changeCountry()" class="text1"></select></td>');
	document.writeln('</tr></table>');
	document.writeln('<form>');
	var gOptions = new listArea();
	var resultOptions = document.unit.area.options;
	resultOptions.length = gOptions.length;
	for (var i=0;i<gOptions.length;i++) resultOptions[i] = new Option(gOptions[i].text,gOptions[i].value,false,false)
	loadOption(document.unit.country,0);
	document.unit.area.options[0].selected = true;
}
