//SMTPの有り・無しによる変化
function smtp_status() {
	if(document.getElementById("ConfigrationSMTPSTATUS1").checked){
		radio_disabled(Array("SMTP_SECURITY", "SMTP_PROTOCOL"), false);
		document.getElementById("ConfigrationFROMNAME").disabled = false;
		document.getElementById("ConfigrationFROMMAIL").disabled = false;
		document.getElementById("ConfigrationSMTPHOST").disabled = false;
		document.getElementById("ConfigrationSMTPPORT").disabled = false;
		add_i_must(Array("i_must_from_name", "i_must_from_mail", "i_must_smtp_host", "i_must_smtp_port"));

		if(document.getElementById("ConfigrationSMTPPROTOCOL1").checked) {
			document.getElementById("ConfigrationSMTPUSER").disabled = false;
			document.getElementById("ConfigrationSMTPPASS").disabled = false;
			add_i_must(Array("i_must_smtp_user", "i_must_smtp_pass"));
		}else{
			document.getElementById("ConfigrationSMTPUSER").disabled = true;
			document.getElementById("ConfigrationSMTPPASS").disabled = true;
			remove_i_must(Array("i_must_smtp_user", "i_must_smtp_pass"));
			}
	}else{
		radio_disabled(Array("SMTP_SECURITY", "SMTP_PROTOCOL"), true);
		document.getElementById("ConfigrationFROMNAME").disabled = true;
		document.getElementById("ConfigrationFROMMAIL").disabled = true;
		document.getElementById("ConfigrationSMTPHOST").disabled = true;
		document.getElementById("ConfigrationSMTPPORT").disabled = true;
		document.getElementById("ConfigrationSMTPUSER").disabled = true;
		document.getElementById("ConfigrationSMTPPASS").disabled = true;
		remove_i_must(Array("i_must_from_name", "i_must_from_mail", "i_must_smtp_host", "i_must_smtp_port", "i_must_smtp_user", "i_must_smtp_pass"));
	}
}

//ラジオボタンの入力可・不可設定
function radio_disabled(r_name, torf) {
	for(var i = 0; i < r_name.length; i++) {
		var smtp_status = document.getElementsByName("data\[Configration\]\[" + r_name[i]  + "\]");
		for(j = 0; j < smtp_status.length; j++) {
			smtp_status[j].disabled = torf;
		}
	}
}

//必須マークを表示する
function add_i_must(id_name) {
//	for(var i = 0; i < id_name.length; i++) {
//		var picture = document.createElement("img");
//		picture.setAttribute("src", "/dev-invoice/wakabayashi-r/public_html/sns/img/common/i_must.jpg");
//		if(!document.getElementById(id_name[i] + "_p")) {
//			picture.setAttribute("id", id_name[i] + "_p");
//			document.getElementById(id_name[i]).appendChild(picture);
//		}
//	}
	for(var i = 0; i < id_name.length; i++) {
		document.getElementById(id_name[i]).style.display = 'block';
	}
}

//必須マークを非表示にする
function remove_i_must(id_name) {
//	for(var i = 0; i<id_name.length; i++) {
//		var dpicture = document.getElementById(id_name[i] + "_p");
//		document.getElementById(id_name[i]).removeChild(dpicture);
//	}
	for(var i = 0; i < id_name.length; i++) {
		document.getElementById(id_name[i]).style.display = 'none';
	}
}

//サブミットボタンを無効にして送信
function stop_button(button) {
	button.disabled = true;
	button.form.submit();
}

window.onload = function() {
	smtp_status();
}
