/*
 * 任意数値の指定桁数でのゼロ埋め
 */
function my_uZeroPadding(num,max){
	var tmp=''+num;
	while(tmp.length<max){
		tmp='0'+tmp;
	}
	return new String(tmp);
}

function postFormShowMessage(action_uri,fm) {
	var options = {
		method : 'post',
		postBody : Form.serialize(fm),
		onFailure: function() { alert("通信エラー"); },
		onComplete: function(res) {
			var obj = eval('(' + res.responseText + ')');
			var hash = $H(obj);
			for(i=0;i<obj.length;i++){
				$(obj[i]).style.display='inline';
			}
		}.bind(this)
	};
	new Ajax.Request(action_uri, options);

}

function getDataValue(action_uri) {
	var options = {
		method : 'get',
		onFailure: function() { alert("通信エラー"); },
		onComplete: function(res) {
			var obj = eval('(' + res.responseText + ')');
			var hash = $H(obj);
			hash.each( function(pair) {
				$(pair.key).value=pair.value;
			} );
		}.bind(this)
	};
	new Ajax.Request(action_uri , options);
}

function getDataInner(action_uri) {
	var options = {
		method : 'get',
		onFailure: function() { alert("通信エラー"); },
		onComplete: function(res) {
			var obj = eval('(' + res.responseText + ')');
			var hash = $H(obj);
			hash.each( function(pair) {
				$(pair.key).innerHTML=pair.value;
			} );
		}.bind(this)
	};
	new Ajax.Request(action_uri , options);
}

function myplUtilExpander(expand_id,img_id) {
	if($(expand_id).style.display=='none'){
		$(expand_id).show();
		$(img_id + '_open').hide();
		$(img_id + '_close').show();
	}else{
		$(expand_id).hide();
		$(img_id + '_open').show();
		$(img_id + '_close').hide();
	}
}

function getCityList(pref_list_object, city_list_object){
	if( !$(pref_list_object) || !$(city_list_object) ){
		return false;
	}
	var pref_select = $(pref_list_object);

	var pref_cd = pref_select.options[pref_select.selectedIndex].value;
	if( pref_cd < 0 ){
		$(city_list_object).options.length = 0;
		return false;
	}

	var options = {
		method : 'get',
		onFailure: function() { alert("通信エラー"); },
		onComplete: function(res) {
			var obj = eval('(' + res.responseText + ')');
			var city_html = '';
			if( obj.status < 0 ){
				//このエリアは現在準備中です
			}else{
				$(city_list_object).options.length = 0;
				for(i=0;i<obj.result.length;i++){
					div_id = obj.result[i].div_id;
					city_name = obj.result[i].city_name;
					city_kana = obj.result[i].city_kana;
					var option_obj = document.createElement("option");
					var option_text = document.createTextNode(city_name + ' ( ' + city_kana + ' ) ');
					option_obj.value = div_id;
					option_obj.appendChild(option_text);
					$(city_list_object).appendChild(option_obj);
				}
			}
		}.bind(this)
	};
	new Ajax.Request('/com/get_div.js?c=mcl&mpcd=' + pref_cd, options);

}

function initDoc() {
	cancelEvent_objs = document.getElementsByClassName("cancelEvent");
	cancelEvent_objs.each(function(obj){
		if (obj.addEventListener) {
			obj.addEventListener("click", cancelEvent, false);
		} else if (obj.attachEvent) {
			/* IE */
			obj.attachEvent("onclick", cancelEvent);
		} else {
			obj.onclick = cancelEvent;
		}
	});
}

function cancelEvent(evt) {
	if (evt.target) {
		evt.stopPropagation();
	} else if (window.event.srcElement) {
		/* IE */
		window.event.cancelBubble = true;
	}
}

function listChange(on_obj,list_url) {
	var obj_id_01 = on_obj + '_01';
	var obj_id_02 = on_obj + '_02';
	var obj_id_03 = on_obj + '_03';
	var obj_id_04 = on_obj + '_04';
	var obj_id_05 = on_obj + '_05';
	var area_name = $('fw_division_jp').value;
	var area_cd = $('division_mypl_cd').value;

	if($(obj_id_01).style.display=="none"){
		$(obj_id_01).style.display="block";
		$(obj_id_02).style.display="none";
		$(obj_id_03).innerHTML = '全国';
		$(obj_id_04).innerHTML = area_name + 'を見る';
		$(obj_id_05).href = list_url + '0';
	}else{
		$(obj_id_01).style.display="none";
		$(obj_id_02).style.display="block";
		$(obj_id_03).innerHTML = area_name;
		$(obj_id_04).innerHTML = '全国を見る';
		$(obj_id_05).href = list_url + area_cd;
	}
}

function listChange2(on_obj,firstname,changename) {
	if(firstname == undefined)firstname = '開く';
	if(changename == undefined)changename = '閉じる';
	var obj_id_01 = on_obj + '_01';
	var obj_id_02 = on_obj + '_02';
	var obj_id_03 = on_obj + '_03';

	if($(obj_id_01).style.display=="none"){
		$(obj_id_01).style.display="block";
		$(obj_id_02).style.display="none";
		$(obj_id_03).innerHTML = changename;
	}else{
		$(obj_id_01).style.display="none";
		$(obj_id_02).style.display="block";
		$(obj_id_03).innerHTML = firstname;
	}
}

function threadChange(element,element1,element2,element3){
	$(element).show();
	$('a_' + element).className = 'active';
	if($(element1)){
		$(element1).hide();
		$('a_' + element1).className = '';
	}
	if($(element2)){
		$(element2).hide();
		$('a_' + element2).className = '';
	}
	if($(element3)){
		$(element3).hide();
		$('a_' + element3).className = '';
	}
}


function listtabChange(element,count,on_no){
	$(element + on_no).show();
	$('a_' + element + on_no).className = 'active';
	for(i=0;i<count;i++){
		var tab_no = i + 1;
		if(tab_no != on_no){
			if($(element + tab_no)){
				$(element + tab_no).hide();
				$('a_' + element + tab_no).className = '';
			}
		}
	}
}
