/**
 *	js for TopPage
 */
if (document.all) {
	window.attachEvent("onload",init);
} else {
	window.addEventListener("load",init,false);
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, '');
}
function init() {
	document.form1.onsubmit = submitCheck;
	document.form1.hope[0].onclick = changeHopeDate;
	document.form1.hope[1].onclick = changeHopeDate;
	document.getElementById('radio_hope_1').style.display = '';
	document.getElementById('radio_hope_2').style.display = '';
	document.getElementById('zip1').focus();//郵便番号入力にフォーカス

	replace_company_number_major();
}
function submitCheck() {
	err = new Array();
	if ((document.form1.zip1.value.trim().length + document.form1.zip2.value.trim().length) < 7) {
		err.push('「現在のご住所の郵便番号」を入力してください。');
	}
	if ((document.form1.m_pref_number.selectedIndex < 1)
	 || (document.form1.m_pref_number.selectedIndex > 47)) {
		err.push('「引越し先のご住所の都道府県」を指定してください。');
	}
	//if ((document.form1.adult_number.selectedIndex + document.form1.child_number.selectedIndex) < 1) {
	//	err.push('「引越しされる人数」を指定してください。');
	//}
	tmp = new Array();
	if (document.form1.hope[0].checked) {
		if (document.form1.first_year.value == 0) {
			tmp.push('年');
		}
		if (document.form1.first_month.selectedIndex == 0) {
			tmp.push('月');
		}
		if (document.form1.first_day.selectedIndex == 0) {
			tmp.push('日');
		}
		if (document.form1.first_when.selectedIndex == 0) {
			tmp.push('時間帯');
		}
	} else if (document.form1.hope[1].checked) {
		if (document.form1.third_year.value == 0) {
			tmp.push('年');
		}
		if (document.form1.third_month.selectedIndex == 0) {
			tmp.push('月');
		}
		if (document.form1.bme_month.selectedIndex == 0) {
			tmp.push('旬');
		}
		if (document.form1.weekday_or_holiday.selectedIndex == 0) {
			tmp.push('曜日');
		}
		if (document.form1.third_when.selectedIndex == 0) {
			tmp.push('時間帯');
		}
	} else {
		err.push('「引越し予定日」を指定してください。');
	}
	if (tmp.length > 0) {
		err.push('「引越し予定日」(' + tmp.join('・') + ')を指定してください。');
	}
	
	if (err.length > 0) {
		alert(err.join("\n\n"));
		return false;
	}
	return true;
}
function changeHopeDate() {
	switch (parseInt(this.value)) {
		case 1:
			document.getElementById('hope_date_input').style.display = '';
			document.getElementById('hope_date_input2').style.display = 'none';
			break;
		case 2:
			document.getElementById('hope_date_input').style.display = 'none';
			document.getElementById('hope_date_input2').style.display = '';
			break;
	}
}

function replace_company_number_major() {
	var _num_obj = document.getElementById('company_number_major');
    if(!_num_obj){
        return;
    }
	var _num_str = (_num_obj.innerText) ? _num_obj.innerText : _num_obj.textContent;
	var _replace_str = '';
	for(var i=0;i<_num_str.length; i++) {
		_replace_str += '<img src="/images/top/'+ _num_str.charAt(i) +'.gif" alt="'+ _num_str.charAt(i) +'">';
	}
	_num_obj.innerHTML = _replace_str;
}
