//「成果物の必要部数」項目の親ノードのID
g_parentId = 'doc_num_id';
//キー=会社設立コース
//値=表示する「成果物の必要部数」項目のID
g_docIdList = new Array();
g_docIdList['1'] = new Array('articles_association_num');
g_docIdList['2'] = new Array('registry_book_num', 'articles_association_num');
g_docIdList['3'] = new Array('registry_book_num', 'articles_association_num');
g_docIdList['4'] = new Array('registry_book_num', 'official_seal_num', 'articles_association_num');

function init4DocNumByCourse(formName, courseName) {
	//引数のチェックをする。
	if (typeof(document.forms[formName]) == 'undefined') {
		alert('フォーム名 = "'+formName+'"が不正です。');
		return false;
	}
	if (typeof(document.forms[formName].elements[courseName]) == 'undefined') {
		alert('会社設立コース = "'+courseName+'"が不正です。');
		return false;
	}
	
	var len = document.forms[formName].elements[courseName].length;
	var courseId = '';
	for (var i = 0; i < len; i++) {
		if (document.forms[formName].elements[courseName][i].checked == true) {
			courseId = document.forms[formName].elements[courseName][i].value;
		}
	}
	
	showDocNumByCourse(courseId);
}

/**
 * 選択された「会社設立コース」によって、「成果物の必要部数」項目の表示・非表示を切り替える。
 *
 * @param   string	会社設立コース
 * @param   string	親ノードのID
 * @param   array	表示する「成果物の必要部数」項目ノードのIDの配列
 *
 * @return  boolean
 */
/*function showDocNumByCourse(courseId, parentId, docIdList) {*/
function showDocNumByCourse(courseId) {

	if (courseId == '') return false;
	
	parentId = g_parentId;
	docIdList = g_docIdList[courseId];
	
	if (parentId == '') return false;
	if (document.getElementById(parentId) == null) return false;

	
	//親ノードのを取得する。
	var parent = document.getElementById(parentId);
	//Div子ノードのを取得する。
	var divChild = parent.getElementsByTagName('div');

	//一旦全て非表示にする。
	var divLen = divChild.length;
	for (var i = 0; i < divLen; i++) {
		divChild[i].style.display = 'none';

		//input子ノードのを取得する。
		var inputChild = divChild[i].getElementsByTagName('input');
		var inputLen = inputChild.length;
		for (var j = 0; j < inputLen; j++) {
			var inputName = inputChild[j].name;
			
			//inputのnameを変更する。変更されたnameは、POST後のサーバ処理で無視される。→入力チェック、確認画面、メールで表示されなくなる。
			if (inputName.search(/_del_$/) == -1) {
				var test = '';
				test += '変更前 '+inputName+'\n';
				
				inputName += '_del_';
				inputChild[j].name = inputName;
				
				test += '変更後 '+inputChild[j].name+'\n';
			
				//alert(test);
			}
		}
		
	}

	//対象の「成果物の必要部数」項目を表示する。
	var docLen = docIdList.length;
	for (var i = 0; i < docLen; i++) {
		var docId = docIdList[i];
		
		if (document.getElementById(docId) == null) continue;
		
		document.getElementById(docId).style.display = 'block';

		//input子ノードのを取得する。
		var inputChild = document.getElementById(docId).getElementsByTagName('input');
		var inputLen = inputChild.length;
		for (var j = 0; j < inputLen; j++) {
			var inputName = inputChild[j].name;
			
			//inputのnameを元に戻す。戻すと、POST後のサーバ処理が行われる。→入力チェック、確認画面、メールで表示される。
			if (inputName.search(/_del_$/) != -1) {
				var test = '';
				test += '戻し前 '+inputName+'\n';
				
				inputName = inputName.replace(/_del_$/, '');
				inputChild[j].name = inputName;
				
				test += '戻し後 '+inputChild[j].name+'\n';
				
				//alert(test);
			}
		}
		
		
	}

	return true;
}




