/**
 * 住所をコピーする。
 *
 * @param   string	フォーム名
 * @param   string	コピーー元の郵便番号1のテキスト名
 * @param   string	コピーー元の郵便番号2のテキスト名
 * @param   string	コピーー元の住所(都道府県)のプルダウンメニュー名
 * @param   string	コピーー元の住所(市町村番地)のテキスト名
 * @param   string	コピーー元の住所(以降)のテキスト名
 * @param   string	コピーー先の郵便番号1のテキスト名
 * @param   string	コピーー先の郵便番号2のテキスト名
 * @param   string	コピーー先の住所(都道府県)のプルダウンメニュー名
 * @param   string	コピーー先の住所(市町村番地)のテキスト名
 * @param   string	コピーー先の住所(以降)のテキスト名
 *
 * @return  boolean
 */
function copyAddress(form, fromZip1, fromZip2, fromPref, fromAddress1, fromAddress2, toZip1, toZip2, toPref, toAddress1, toAddress2) {

	//引数のチェックをする。
	if (typeof(document.forms[form]) == 'undefined') {
		alert('フォーム名 = "form"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[fromZip1]) == 'undefined') {
		alert('郵便番号1From = "'+fromZip1+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[fromZip2]) == 'undefined') {
		alert('郵便番号2From = "'+fromZip2+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[fromPref]) == 'undefined') {
		alert('住所(都道府県)From = "'+fromPref+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[fromAddress1]) == 'undefined') {
		alert('住所(市町村番地)From = "'+fromAddress1+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[fromAddress2]) == 'undefined') {
		alert('住所(以降)From = "'+fromAddress2+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[form]) == 'undefined') {
		alert('フォーム名 = "form"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[toZip1]) == 'undefined') {
		alert('郵便番号1To = "'+toZip1+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[toZip2]) == 'undefined') {
		alert('郵便番号2To = "'+toZip2+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[toPref]) == 'undefined') {
		alert('住所(都道府県)To = "'+toPref+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[toAddress1]) == 'undefined') {
		alert('住所(市町村番地)To = "'+toAddress1+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[toAddress2]) == 'undefined') {
		alert('住所(以降)To = "'+toAddress2+'"が不正です。');
		return false;
	}

	//住所をコピーする。
	document.forms[form].elements[toZip1].value = document.forms[form].elements[fromZip1].value;
	document.forms[form].elements[toZip2].value = document.forms[form].elements[fromZip2].value;
	document.forms[form].elements[toPref].selectedIndex = document.forms[form].elements[fromPref].selectedIndex;
	document.forms[form].elements[toAddress1].value = document.forms[form].elements[fromAddress1].value;
	document.forms[form].elements[toAddress2].value = document.forms[form].elements[fromAddress2].value;

	return true;
}


/**
 * 郵便番号から住所を検索する。
 *
 * @param   string	フォーム名
 * @param   string	検索条件の郵便番号1のテキスト名
 * @param   string	検索条件の郵便番号2のテキスト名
 * @param   string	設定先の住所(都道府県)のプルダウンメニュー名
 * @param   string	設定先の住所(市町村番地)のテキスト名
 * @param   string	設定先の住所(以降)のテキスト名
 *
 * @return  boolean
 */
function searchAddress(form, zip1, zip2, pref, address1, address2) {

	//引数のチェックをする。
	if (typeof(document.forms[form]) == 'undefined') {
		alert('フォーム名 = "form"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[zip1]) == 'undefined') {
		alert('郵便番号1 = "'+zip1+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[zip2]) == 'undefined') {
		alert('郵便番号2 = "'+zip2+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[pref]) == 'undefined') {
		alert('住所(都道府県) = "'+pref+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[address1]) == 'undefined') {
		alert('住所(市町村番地) = "'+address1+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[form].elements[address2]) == 'undefined') {
		alert('住所(以降) = "'+address2+'"が不正です。');
		return false;
	}


	
	var target = 'http://www.sin-kaisha.jp/search_comp/postal_common.php';
	target += '?postalcode=' + document.forms[form].elements[zip1].value + document.forms[form].elements[zip2].value;
	target += '&form=' + form;
	target += '&pref=' + pref;
	target += '&address1=' + address1;
	target += '&address2=' + address2;
	
	var SWA;
	SWA = window.open(target,"zipresult","WIDTH=500,HEIGHT=300,toolbar=no,location=no,status=no,menubar=no,directories=no,scrollbars=yes");
	SWA.focus();	
	
	return true;
}


/**
 * 選択された希望プランによって、項目を表示・非表示する。
 *
 * @param   string	希望プランID
 *
 * @return  boolean
 */
function showGoodCompItem(planId) {

	//以下は、希望プランで選択された場合、表示する項目のID
	//「会社売却」を選んだ時に表示する項目ID。
	var sellList = new Array(
	'director'								//取締役は何人
	,'employee'								//従業員は何人
	,'joint_surety'							//連帯保証人を用意
	,'joint_surety_relation'				//連帯保証人との関係
	,'corporation_bank_account'				//法人口座
	,'social_insurance_insured'				//社会保険に加入
	,'labor_insurance_insured'				//労働保険に加入
	,'latest_settling_doc'					//最新の決算書
	,'settling_doc_period'					//決算書は何期分
	,'current_sales'						//今期の売上高
	,'latest_settling'						//最新の決算
	,'blue_form'							//青色申告事業主
	,'balance_carried_deficit'				//繰越欠損金(過去7年間)
	,'active'								//会社は現在活動
	,'dormant'								//休眠届(異動届)
	,'corporation_debt'						//法人の債務
	,'corporation_borrowing'				//法人名義での借り入れ
	,'corporation_borrowing_details'		//法人名義での借り入れ詳細
	,'current_account'						//当座
	,'bill'									//手形
	,'cheque'								//小切手
	,'charter'								//許認可免許(登録)
	,'charter_type'							//免許の種類
	,'nonpayment'							//滞納
	,'corporation_car'						//法人名義の車
	,'settling_month'						//決算月(事業年度)
	);
	
	//「会社購入」を選んだ時に表示する項目ID。
	var buyList = new Array(
	'buy_hope'								//購入希望詳細
//	,'purpose'								//事業の目的
	,'option_service'						//オプションサービス
	,'care_service'							//介護事業サービス
	,'kyoninka'								//許認可選択
	,'kyoninka_details'						//許認可詳細
	,'syugyo'								//就業規則
	,'logo_plan'							//ロゴ制作 申込プラン
	,'logo_plan_option'						//ロゴ制作 オプションプラン
	,'goodcomp_inkan'						//印鑑全部
	,'goodcomp_uranai'						//占い全部
	);
	
	//全ての項目を非表示する。
	var l = sellList.length;
	for (var i = 0; i < l; i++) {
		showNode4GoodComp(false, sellList[i]);
	}
	var l = buyList.length;
	for (var i = 0; i < l; i++) {
		showNode4GoodComp(false, buyList[i]);
	}

	var showList = new Array();
	switch (planId) {
		case '1'://会社売却
			showList = sellList;
			break;
		case '2'://会社購入
			showList = buyList;
			break;
		default:
			return false;
			break;
	}

	var l = showList.length;
	for (var i = 0; i < l; i++) {
		showNode4GoodComp(true, showList[i]);
	}
	
	return true;
}


/**
 * 指定したIDのノードを表示・非表示する。
 *
 * @param   boolean	ON/OFF
 * @param   string	親ノードのID
 *
 * @return  boolean
 */
function showNode4GoodComp(flag, id) {

//	alert('falg='+flag+'/id='+id);

	if (id == '') return;
	if (document.getElementById(id) == null) return;

//alert('flag='+flag+'/id='+id+'/tag='+document.getElementById(id).tagName+'/display='+document.getElementById(id).style.display);

	if (flag == true) {
		var nextDisplay = null;
		switch (document.getElementById(id).tagName) {
			case 'TR':
				if (is_pc_ie) {
					//IEの場合
					nextDisplay = 'block';
				} else {
					//IE以外の場合
					nextDisplay = 'table-row';
				}
				break;
			default:
				nextDisplay = 'block';
				break;
		}
		document.getElementById(id).style.display = nextDisplay;
	} else {
		document.getElementById(id).style.display = 'none';
	}
}


/**
 * 入力欄を追加する。
 *
 * @param   string	親ノードのID
 *
 * @return  boolean
 */
function addInputArea4GoodComp(id) {

	//親ノードを取得する。
	var parent = document.getElementById(id);
//	//最初の子ノードを取得する。
//	var firstChild = parent.firstChild;	//これだと最初に改行がある場合、改行が取得されてしまう…

	//Div子ノードのを取得する。
	var divChild = parent.getElementsByTagName('div');
	//最初の子ノードを取得する。
	var firstChild = divChild[0];

	//子ノードをコピーする。
	var cloneChild = firstChild.cloneNode(true);//true:子ノードの子ノードもコピーする。/false:コピーしない。

//	//select要素をクリアする。
//	var select = cloneChild.getElementsByTagName('select');
//	for (var i = 0; i < select.length; i++) {
//		select[i].value = null;
//	}
	//input要素をクリアする。
	var input = cloneChild.getElementsByTagName('input');
	for (var i = 0; i < input.length; i++) {
		input[i].value = '';
	}

	//親ノードにコピーノードを追加する。
	parent.appendChild(cloneChild);

}


var ua = navigator.userAgent.toLowerCase();
var is_pc_ie = ((ua.indexOf('msie') != -1) && (ua.indexOf('win') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1));



