var CityBoxController = function() {};

CityBoxController.selected_city = new Array(48);
CityBoxController.selected_city_id = new Array(48);

//指定された都道府県に該当する市区町村のチェックを変更する
//同時に設定条件の【希望エリア】の欄の表示を変更する
CityBoxController.checkAllCityOfPref = function(box,pref,check) {
	var _box = $(box);
	var _pref = $(pref).value;
	var _checked = $(check).checked;
	var area_all = "city_id_"+_pref+"_all";

	CityBoxController._overwriteSelectedCity(_box,_pref,check);
	CityBoxController._setCheckBox(_pref,check);
	CityBoxController._displayWishAreaAll(pref);
}

//１番目に行うこと
//選択された市区町村を都道府県別に記録（上書き）する
//checked=trueで動作するとき
//全域がchecked=trueの場合は全域のみ記録し、市区町村は記録しない
//全域がchecked=falseの場合は、市区町村すべてのcheckedを調べてtrueの市区町村のみ記録する
//checked=falseで動作するとき
//全域がchecked=falseの場合は、すべて消去する
//全域がchecked=trueの場合は、市区町村すべてのcheckedを調べてtrueの市区町村のみ記録する
CityBoxController._overwriteSelectedCity = function(box,pref,check){
	var checked = $(check).checked;
	var area_all = "box_city_id_"+pref+"_all";
	CityBoxController.selected_city[pref] = new Array();
	CityBoxController.selected_city_id[pref] = new Array();
	
	if(checked){
		if(check==area_all){
			//全域がチェックされた場合、全域表示のみを記憶する
			CityBoxController.selected_city[pref][0] = $("label_"+area_all).innerHTML;
			CityBoxController.selected_city_id[pref][0] = $(area_all).value;
		} else {
			//市区町村がチェックされた場合、チェックされている市区町村すべてを
			//記憶する。ただし市区町村全てがチェックされている場合には
			//全域のみを記録する。
			var all_checked = true;
			for(i=1;;i++){
				var _id = "box_city_id_"+pref+"_"+i;
				if($(_id)==null){
					break;
				}
				if($(_id).checked){
					var box = "box_city_id_"+pref+"_"+i;
					var label = "label_"+box;
					CityBoxController.selected_city[pref][i] = $(label).innerHTML;
					CityBoxController.selected_city_id[pref][i] = $(box).value;
				} else {
					all_checked = false;
				}
			}
			if(all_checked){
				CityBoxController.selected_city[pref] = new Array();
				CityBoxController.selected_city_id[pref] = new Array();
				CityBoxController.selected_city[pref][0] = $("label_"+area_all).innerHTML;
				CityBoxController.selected_city_id[pref][0] = $(area_all).value;
			}
		}
	} else {
		if(check==area_all){
			//全域がチェック消去された場合、記録をすべて消去する
			CityBoxController.selected_city[pref] = new Array();
			CityBoxController.selected_city_id[pref] = new Array();
		} else {
			//市区町村がチェック消去された場合、チェックされている市区町村記録をすべて記録する
			for(i=1;;i++){
				var _id = "box_city_id_"+pref+"_"+i;
				if($(_id)==null){
					break;
				}
				if($(_id).checked){
					var box = "box_city_id_"+pref+"_"+i;
					var label = "label_"+box;
					CityBoxController.selected_city[pref][i] = $(label).innerHTML;
					CityBoxController.selected_city_id[pref][i] = $(box).value;
				}
			}
		}
	}
	

}

//２番目に行うこと
//checkedの操作
//checked=trueで動作するとき
//全域がchecked=trueの場合は、市区町村すべてのcheckedをtrueにする
//全域がchecked=falseの場合は、市区町村すべてのcheckedを調べて全部trueなら全域をchecked=trueにする
//checked=falseで動作するとき
//全域がchecked=falseの場合は、市区町村すべてのcheckedをfalseにする
//全域がchecked=trueの場合は、市区町村すべてのcheckedを調べて全部falseなら全域のchecked=falseにする
CityBoxController._setCheckBox = function(pref,check){
	var checked = $(check).checked;
	var area_all = "box_city_id_"+pref+"_all";

	
	if(checked){
		if($(area_all).checked) {
			for(i=1;;i++){
				var _id = "box_city_id_"+pref+"_"+i;
				if($(_id)==null){
					break;
				}
				$(_id).checked = true;
			}
		} else {
			var checked_all = true;
			for(i=1;;i++){
				var _id = "box_city_id_"+pref+"_"+i;
				if($(_id)==null){
					break;
				}
				if(!$(_id).checked) {
					checked_all = false;
					break;
				}
			}
			if(checked_all) {
				$(area_all).checked = true;
			}
		}
	}else if($(area_all)==null){
	} else {
		if($(area_all).checked){
			$(area_all).checked = false;
		} else {
			if(check==area_all){
				for(i=1;;i++){
					var _id = "box_city_id_"+pref+"_"+i;
					if($(_id)==null){
						break;
					}
					$(_id).checked = false;
				}
			}
		}
	}
}

//３番目に行うこと
//希望エリア表示部分の上書き更新
//CityBoxController.selected_city[1]から[47]まで確認して、あれば表示する
CityBoxController._displayWishAreaAll = function(pref){
	for(i=1;i<=47;i++){
		CityBoxController._displayWishArea(pref,i);
	}
}


CityBoxController._displayWishArea = function(pref,pref_id){
	var _pref = $(pref).options[pref_id].text;
	var dd_id = "wish_area_list_"+pref_id;
	
	//都道府県のselectのoptionの背景色をクリアする
	$(pref).options[pref_id].style.background = "";
	
	//対象のDDとinputタグを削除する
	if($(dd_id)!=null){
		$(dd_id).parentNode.removeChild($(dd_id));
	}
	if($("mem_wish_area_"+pref_id)!=null){
		$("mem_wish_area_"+pref_id).parentNode.removeChild($("mem_wish_area_"+pref_id));
	}
	if($("mem_wish_area_"+pref_id+"_city")!=null){
		$("mem_wish_area_"+pref_id+"_city").parentNode.removeChild($("mem_wish_area_"+pref_id+"_city"));
	}
	if($("mem_wish_area_"+pref_id+"_city_text")!=null){
		$("mem_wish_area_"+pref_id+"_city_text").parentNode.removeChild($("mem_wish_area_"+pref_id+"_city_text"));
	}
	if($("mem_wish_pref_"+pref_id+"_text")!=null){
		$("mem_wish_pref_"+pref_id+"_text").parentNode.removeChild($("mem_wish_pref_"+pref_id+"_text"));
	}
	if($("mem_wish_pref_"+pref_id+"_city_text")!=null){
		$("mem_wish_pref_"+pref_id+"_city_text").parentNode.removeChild($("mem_wish_pref_"+pref_id+"_city_text"));
	}

	//チェックされている都道府県だったらDDとinputタグを挿入する
	if( CityBoxController.selected_city[pref_id] != null ){
		if(CityBoxController.selected_city[pref_id].length>0){
			
			//都道府県のselectのoptionの背景色をセットする
			$(pref).options[pref_id].style.background = "yellow";
			
			
			//<dd>作成（都道府県ごとの希望エリア表示
			var dd = document.createElement('dd');
			dd.setAttribute('class','clear');
			dd.setAttribute('id',dd_id);
			//都道府県表示部分作成
			var span_pref = document.createElement('span');
			span_pref.setAttribute('class','pref');
			var span_pref_id = "wish_area_list_pref"+pref_id;
			span_pref.setAttribute('id',span_pref_id);
			var span_pref_txt = document.createTextNode(_pref+" ： ");
			span_pref.appendChild(span_pref_txt);
			//市区町村表示部分作成
			var span_area = document.createElement('span');
			span_area.setAttribute('class','town');
			var span_area_id = "wish_area_list_city_"+pref_id;
			span_area.setAttribute('id',span_area_id);
			var cnt = 0;
			var input_txt = "";
			CityBoxController.selected_city[pref_id].each( function(val,idx){
				if(val!=null && val != undefined && val.length>0){
					if(cnt > 0) input_txt += "、";
					input_txt += val;
					cnt++;
				}
			});
			if(cnt==0) return;
			var span_area_txt = document.createTextNode(input_txt);
			span_area.appendChild(span_area_txt);

			//DDに突っ込む
			dd.appendChild(span_pref);
			dd.appendChild(span_area);
			
			//表示する場所に突っ込む
			$('wish_display').insertBefore(dd,$('wish_display').lastChild);
			
			//ページ遷移時の記憶用inputタグ作成
			//都道府県
			var pref_input = document.createElement('input');
			pref_input.setAttribute('id',"mem_wish_area_"+pref_id.toString());
			pref_input.setAttribute('type','hidden');
			pref_input.setAttribute('name','mem_wish_area[]');
			pref_input.setAttribute('value',pref_id);
			//<DD>の後ろに突っ込む
			var insert_point = $("mem_wish_area_"+pref_id);
			if( insert_point != null) {
				insert_point.parentNode.removeChild(insert_point);
			}
			$('wish_display').insertBefore(pref_input,$('wish_display').lastChild);
			//市区町村
			var city_input = document.createElement('input');
			city_input.setAttribute('id',"mem_wish_area_"+pref_id.toString()+"_city");
			city_input.setAttribute('type','hidden');
			city_input.setAttribute('name','mem_wish_area_city[]');
			var input_value = "";
			//一番最初には都道府県の番号をいれておく
			input_value += pref_id ;
			CityBoxController.selected_city_id[pref_id].each( function(val,idx){
				if(val!=null && val.length>0){
					input_value += ",";
					input_value += val ;
				}
			});
			city_input.setAttribute('value',input_value);
			//<DD>の後ろに突っ込む
			insert_point = $("mem_wish_area_"+pref_id+"_city");
			if(insert_point != null) {
				insert_point.parentNode.removeChild(insert_point);
			}
			$('wish_display').insertBefore(city_input,$('wish_display').lastChild);
			
			//市区町村文字列
			var city_text_input = document.createElement('input');
			city_text_input.setAttribute('id',"mem_wish_area_"+pref_id.toString()+"_city_text");
			city_text_input.setAttribute('type','hidden');
			city_text_input.setAttribute('name','mem_wish_area_city_text[]');
			input_value = _pref+" ： ";
			cnt = 0;
			CityBoxController.selected_city[i].each( function(val,idx){
				if(val!=null && val.length>0){
					if(cnt>0){
						input_value += "、";
					}
					input_value += val ;
					cnt++;
				}
			});
			city_text_input.setAttribute('value',input_value);
			//<DD>の後ろに突っ込む
			insert_point = $("mem_wish_area_"+pref_id+"_city_text");
			if(insert_point != null) {
				insert_point.parentNode.removeChild(insert_point);
			}
			$('wish_display').insertBefore(city_text_input,$('wish_display').lastChild);
			
			//都道府県文字列と市区町村文字列が別々の方が都合のよい部分があったので
			//それ用に出力する。後々、上記の市区町村文字列の処理はこちらに統合すること。
			//都道府県
			city_text_input = document.createElement('input');
			city_text_input.setAttribute('id',"mem_wish_pref_"+pref_id+"_text");
			city_text_input.setAttribute('type','hidden');
			city_text_input.setAttribute('name','mem_wish_pref_text[]');
			city_text_input.setAttribute('value',_pref);
			//<DD>の後ろに突っ込む
			insert_point = $("mem_wish_pref_"+pref_id+"_text");
			if(insert_point != null) {
				insert_point.parentNode.removeChild(insert_point);
			}
			$('wish_display').insertBefore(city_text_input,$('wish_display').lastChild);
			//市区町村
			city_text_input = document.createElement('input');
			city_text_input.setAttribute('id',"mem_wish_pref_"+pref_id+"_city_text");
			city_text_input.setAttribute('type','hidden');
			city_text_input.setAttribute('name','mem_wish_pref_city_text[]');
			cnt = 0;
			input_value = "";
			CityBoxController.selected_city[i].each( function(val,idx){
				if(val!=null && val.length>0){
					if(cnt>0){
						input_value += "、";
					}
					input_value += val ;
					cnt++;
				}
			});
			city_text_input.setAttribute('value',input_value);
			//<DD>の後ろに突っ込む
			insert_point = $("mem_wish_pref_"+pref_id+"_city_text");
			if(insert_point != null) {
				insert_point.parentNode.removeChild(insert_point);
			}
			$('wish_display').insertBefore(city_text_input,$('wish_display').lastChild);
			
		}
	}
}



//作成時にチェックずみにする？
CityBoxController._checkedNumbers = new Array();
CityBoxController._doChecked = function(boxNumber){
	if(CityBoxController._checkedNumbers.length < 2) return false;
	
	//０番目は都道府県番号なので１から始める
	for(i=1; i<CityBoxController._checkedNumbers.length; i++){
		if(CityBoxController._checkedNumbers[i] == boxNumber.toString()) return true;
	}
	return false;
}

CityBoxController._column_size = 3;

//テーブル＆チェックボックス軍作成
CityBoxController._createCityBox = function(src_pref,dst_city,eval_obj,default_checked_list,column_size){
	CityBoxController._checkedNumbers = default_checked_list || new Array();
	CityBoxController._column_size = column_size || 3;
	//テーブルのインスタンス取得
	var table = document.getElementById(dst_city);
	//テーブルの行をすべて削除
	for(i=table.rows.length;i>1;i--){
		table.deleteRow(i-1);
	}

	//取得したテーブルへ行を追加する。  
	//全部選択ボタンを追加する。
	var tr = table.insertRow(-1);
	var td = tr.insertCell(-1);

	//都道府県セレクトで選択されたのが「選択してください」だった場合は、
	//テーブルの項目はチェックボックスなしで「選択してください」のみにする。
	if($(src_pref).value==0){
		td.innerHTML = "市区町村を選択してください";
		return;
	}

	//チェックボックス生成
	var chk = document.createElement('input');
	chk.type   = "checkbox";
	chk.id     = "box_city_id_"+$(src_pref).value+"_all";
	chk.value  = "0";
	chk.name   = "box_city_all";
	chk.checked = CityBoxController._doChecked(chk.value);
//	var param1 = "CityBoxController.checkAllCityOfPref('"+SearchCity.dst_city+"','"+SearchCity.src_pref+"','"+chk.id+"')";
//	chk.setAttribute("onclick", param1 );
	var prefId = $(src_pref).value;
	var checkBoxId = "box_city_id_"+$(src_pref).value+"_all";

	td.appendChild(chk);
	Event.observe(document.getElementById("box_city_id_"+prefId+"_all"),'click',function(){
		CityBoxController.checkAllCityOfPref(dst_city,src_pref,checkBoxId);
		},false);
	var label = document.createElement('label');
	label.id = "label_"+chk.id;
	label.htmlFor = "box_city_id_"+$(src_pref).value+"_all";
	var txt = document.createTextNode($(src_pref).options[$(src_pref).value].text+"全域");
	label.appendChild(txt);
	label.setAttribute('value',$(src_pref).options[$(src_pref).value].text+"全域");
	//<td>に挿入
	td.appendChild(label);
	eval_obj.each(
		function(val,idx) {
			//valに(sys_are_)city_idと(sys_are_)city_nameが入っている
			//１行あたりに３つのチェックボックスを生成する為の処理
			if((idx%CityBoxController._column_size)==0){
				//引数は、行を挿入したい位置。1行目として作成したいなら0。  
				//-1を指定すると末尾になる。  
				//戻り値は作成された行(tr)への参照。  
				tr = table.insertRow(-1);
			}
			//<TD>作成
			td = tr.insertCell(-1);
			//チェックボックス生成
			chk = document.createElement('input');
			chk.type   = "checkbox";
			chk.id     = "box_city_id_"+$(src_pref).value+"_"+(idx+1);
//			chk.value  = (idx+1).toString();
			chk.value  = val.city_id;
			chk.name   = "box_city[]";
			chk.checked = CityBoxController._doChecked(chk.value);
//			var param1 = "CityBoxController.checkAllCityOfPref('"+SearchCity.dst_city+"','"+SearchCity.src_pref+"','"+chk.id+"')";
//			chk.setAttribute("onclick", param1 );
			var _prefId = $(src_pref).value;
			var _checkBoxId = "box_city_id_"+$(src_pref).value+"_"+(idx+1).toString();
			//<td>に挿入
			td.appendChild(chk);
			Event.observe(document.getElementById("box_city_id_"+_prefId+"_"+(idx+1).toString()),'click',function(){
				CityBoxController.checkAllCityOfPref(dst_city,src_pref,_checkBoxId);
				},false);
			//市区町村ラベル生成
			label = document.createElement('label');
			label.id = "label_"+chk.id;
			label.htmlFor = chk.id;
			label.setAttribute('value',val.city_name);
			txt = document.createTextNode(val.city_name);
			label.appendChild(txt);
			//<td>に挿入
			td.appendChild(label);				
		}
	);
	//希望エリアに表示され、チェックボックステーブルに表示されている市区町村にはチェックをつける処理
	CityBoxController._checkedCityBox($(src_pref).value);
/**/	
}




//希望エリアに表示され、チェックボックステーブルに表示されている市区町村にはチェックをつける処理
CityBoxController._checkedCityBox = function(pref) {
	if($("mem_wish_area_"+pref+"_city")!=null){
		var checked_flags = $("mem_wish_area_"+pref+"_city").value.split(",");
		checked_flags.each( function(val,idx){
			//０番目は都道府県番号だから飛ばす
			if(idx>0) {
				if(val==0){
					if($("box_city_id_"+pref+"_all")!=null)
					$("box_city_id_"+pref+"_all").checked = true;
					//全域の場合には市区町村すべてにチェックする
					var elms = $('city_table').getElementsByTagName("input");
					if(elms!=null){
						for(box_idx=0;box_idx<elms.length;box_idx++){
							elms[box_idx].checked = true;
						}
					}
				} else {
					elms = $('city_table').getElementsByTagName("input");
					for(box_idx=0;box_idx<elms.length;box_idx++){
						if(elms[box_idx].value==val){
							elms[box_idx].checked = true;
							break;
						}
					}
				}
			}
		});
	}
}

//登録確認画面から戻ってきた時にチェックボックステーブルを再現するための処理
CityBoxController._cities = new Array();
CityBoxController.setCityBoxConfEnt = function(wish_area_list,pref_elm) {
	var pref_elm = pref_elm || "mem_mgz_pref_id" ;
	//wish_area_listの内容を保存する
	for(i=0;i<wish_area_list.length;i++){
		var cities = wish_area_list[i].split(",");
		//都道府県番号と市区町村番号が絶対あるはずなので２未満は処理しない
		if(cities.length<2) return;
		var pref = cities[0];
		CityBoxController._cities[pref] = cities;

		//都道府県に対応する市区町村のリストを取ってくる
		CityBoxController._getCityNameList(pref,pref_elm);
	}
	
	//画面の【希望エリア】部分にwish_area_listの市区町村を表示する
	CityBoxController._displayWishAreaAll(pref_elm);
/**/
}


CityBoxController._pref = 0;
CityBoxController._getCityNameList = function(pref,pref_elm) {
	CityBoxController._pref = pref;
//	var myAjax = new Ajax.Request( "?act=public_getareacity",
//			{method: "post",asynchronous:true, parameters: "pref[]="+pref,onComplete: CityBoxController._callback_getCityNameList});
	var myAjax = new Ajax.Request( "/?act=public_getareacity",
			{method: "post",asynchronous:false, parameters: "pref[]="+pref});
	
	CityBoxController._callback_getCityNameList(myAjax.transport,pref_elm);
}

CityBoxController._getCityOrderByCityId = function(_city_ids,_city_id) {
	var _city_order = 0;
	for(_city_order=0;_city_order<_city_ids.length;_city_order++){
		if(_city_ids[_city_order]==_city_id)
			return _city_order+1;
	}
	return 0;
}

CityBoxController._callback_getCityNameList = function(request,pref_elm){
	var eval_obj = eval(request.responseText);
	var list = Array();
	var ids = Array();
	eval_obj.each(
	function(val,idx){
			//valに(sys_are_)city_idと(sys_are_)city_nameが入っている
			list[idx] = val.city_name;
			ids[idx] = val.city_id;
	});
	
	CityBoxController.selected_city[CityBoxController._pref] = new Array();
	CityBoxController.selected_city_id[CityBoxController._pref] = new Array();
	var _cities = CityBoxController._cities[CityBoxController._pref];
	for(j=1;j<_cities.length;j++){
		var city_id = _cities[j];
		//リストから名前をとってきて記憶する
		if(city_id==0){
			CityBoxController.selected_city[CityBoxController._pref][0] = 
				$(pref_elm).options[CityBoxController._pref].text+"全域";
			CityBoxController.selected_city_id[CityBoxController._pref][0] = "0";
		}else{
			//city_idをキーにしてorder番号を取得する。
			var order = CityBoxController._getCityOrderByCityId(ids,city_id);
			CityBoxController.selected_city[CityBoxController._pref][order] = list[order-1];
			CityBoxController.selected_city_id[CityBoxController._pref][order] = city_id;
		}
	}
//	console.log("CityBoxController._pref = " + CityBoxController._pref);
//	console.log("CityBoxController._cities[CityBoxController._pref] = " +CityBoxController._cities[CityBoxController._pref]);
//	console.log("CityBoxController.selected_city_id[CityBoxController._pref] = "+CityBoxController.selected_city_id[CityBoxController._pref]);
}

//検索条件の保持
CityBoxController._rewite_search_list = function(pref,pref_id,city,city_id){

	//変数に選択した市区町村をセットする
    CityBoxController.selected_city[pref_id] = new Array();
    CityBoxController.selected_city_id[pref_id] = new Array();
    CityBoxController.selected_city[pref_id] = city; 
    CityBoxController.selected_city_id[pref_id] = city_id;
        
    //都道府県のselectのoptionの背景色をセットする
	$(pref).options[pref_id].style.background = "yellow";
	//チェックボックスをチェックする
//    CityBoxController._setCheckBox(pref,pref_id);
//    CityBoxController._checkedCityBox(pref_id);

}

//CityBoxのサイズ設定
CityBoxController._setHeight = function( src_pref, dst_city, height ){
	var _city = dst_city || 'city_selector';
	var _height = height || '143px';

	if( $(src_pref).value == '' || $(src_pref).value == '0' ){
		$(_city).style.height = 'auto';		
	} else {
		$(_city).style.height = _height;		
	}
}
/* #113 begin */
CityBoxController.closePopup = function() {	
	 $('TB_overlay').style.display = 'none';
      $('TB_window').style.display = 'none';
      Conditionpopup.closePopup();
}

CityBoxController.checkAll = function() {
    //var PrefName = CityBoxController.getPrefName();    
    if($('check_all_city').checked) {
       $$('.city').each(function(ele) {
            $(ele).checked = "checked";
       });
       $('lable_check_all_city').innerHTML = prefSortName[$("pref").value]+'の選択を全て外す';
    } else {
         $$('.city').each(function(ele) {
            $(ele).checked = "";
       });
       $('lable_check_all_city').innerHTML = prefSortName[$("pref").value]+'を全て選択';
    }
    $('all_city').value = ($('check_all_city').checked) ? 1 : 0;
}

CityBoxController.getPrefName = function() {
    var prefName = '';
    prefName = $('pref_name_popup').value;
    return prefName;
}


CityBoxController.setCheckBox = function(id) {    
	if($(id).checked) {	    
       CityBoxController.resetCheckBox();        
    } else {
        $('check_all_city').checked = "";
        //var PrefName = CityBoxController.getPrefName();
        $('lable_check_all_city').innerHTML = prefSortName[$("pref").value]+'を全て選択';
        $('all_city').value = 0;
    }
}


CityBoxController.resetCheckBox = function() {
	 var flag = 0;
       $$('.city').each(function(ele){
           if(!$(ele).checked ) {               
            flag = 1;
           }
       });
       
       if(flag==0) {
           $('check_all_city').checked = 'checked';
           var prefName = CityBoxController.getPrefName();
           $('lable_check_all_city').innerHTML = prefSortName[$("pref").value] + 'の選択を全て外す';
       }
       $('all_city').value = (flag == 0) ? 1 : 0;
}

CityBoxController.choice = function() {
	var flagCity = 0;
     $$('.city').each(function(ele) {
       if( $(ele).checked ) {
            flagCity = 1;   
       }
     });
    
    if(flagCity == 0) {
        $('messageErrCity').innerHTML = '市区町村を選択してください';
        //document.location="#err";
        return;
    }
    
    $('messageErrCity').innerHTML = "";
    var prefId = $('prefId').value;    
    var prefName = CityBoxController.getPrefName();
    var strCityName = '';
    var strCityNameId = '';
    var cnt = 0;
    $('areaCity').innerHTML = "";    
    $$('.city').each(function(ele){
       if( $(ele).checked ) {
           strCityNameId += '<input type="hidden" class="form_city" name="city[]" value="'+$(ele).value+'"/>';
           strCityName += $(ele).title+'、';
           cnt++;
       }
    });
    
    $("city_selected").value = cnt;
    
     strCityName = strCityName.substring( 0, strCityName.length-1);
     
	if($('check_all_city').checked) {
		strCityNameId += '<input type="hidden" id="check_all_acc" value="1"/>';
		var strCityName = "  全て";
	}
	
    CityBoxController.closePopup();
    CityBoxController.displayCitySelected();
    $('messageErrCity').innerHTML = '';
    $('areaCity').innerHTML = strCityNameId;
    $('pref_name_selected').innerHTML = prefName;    
    //$('id_area_city_name').innerHTML = "【現在選択されている地域】";
    $('common_label').style.display = '';
    $('id_area_city_name').innerHTML = strCityName;
}

CityBoxController.displayCitySelected = function() {
	$('id_area_city_name').style.display = 'inline';
	$('pref_name_selected').style.display = 'inline';
     $('image_more_choice').style.display = 'inline';
     $('resetCitySelected').style.display = 'inline';
     $('pref').style.display = 'none';
}

CityBoxController.resetAll = function() {
     $('id_area_city_name').style.display = 'none';
     $('image_more_choice').style.display = 'none';     
     $('resetCitySelected').style.display = 'none';
     $('pref_name_selected').style.display = 'none';
     $('common_label').style.display = 'none';
     $('pref').style.display = '';
     $('pref_name_selected').innerHTML = '';
     $('id_area_city_name').innerHTML = '';   
     $('areaCity').innerHTML = '';
     $("city_selected").value = 0;
}

/* #113 end */


