// JavaScript Document


//返信フォーム表示
function Inquiry(){
	var inquiry_form = document.getElementById("InquiryForm");

	if(inquiry_form.style.display == "block"){
		inquiry_form.style.display = "none";
	}else{
		inquiry_form.style.display = "block";
		document.getElementById("name").focus();
	}

}

//返信フォーム閉じる
function InquiryClose(){
	document.getElementById("InquiryForm").style.display = "none";
}

//BBS返信内容を送信
function sendInquiry(){
	var name = document.getElementById("name");
	var mail = document.getElementById("mail");
	var adviser = document.getElementById("adviser");
	var title = document.getElementById("title");
	var inquiry_text = document.getElementById("inquiry_text");
	var return_flg = false;
	var alert_msg = "";

	if(name.value == ""){
		alert_msg = "名前を入力してください\n";
		return_flg = true;
	}
	if(mail.value == ""){
		alert_msg += "メールアドレスが未入力です\n";
		return_flg = true;
	}else if(!chkData(mail.value,MAIL_DATA)){
		alert_msg += "メールアドレスが正しく入力されていません\n";
		return_flg = true;
	}
	if(inquiry_text.value == ""){
		alert_msg += "本文が無記入です\n";
		return_flg = true;
	}
	
	if(return_flg){
		alert(alert_msg);
		return;
	}
	
	if(confirm("この内容で送信しますか？")){

		//POST送信
		var url = "inquiry.php";
		var XMLhttp = createXMLHttpRequest();
		var post_data;

		XMLhttp.open("POST", url, true);
		//inquiry.phpにPOSTでデータを送る
		post_data = name.name + "=" + name.value;
		post_data += "&" + mail.name + "=" + mail.value;
		post_data += "&" + adviser.name + "=" + adviser.value;
		post_data += "&" + title.name + "=" + title.value;
		post_data += "&" + inquiry_text.name + "=" + inquiry_text.value;
		post_data += "&submit=bbs&mode_flg=1";
		
//		post_data = encodeURI(post_data);		
		XMLhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		XMLhttp.send(post_data);

		XMLhttp.onreadystatechange = function() {
			if (XMLhttp.readyState == 4 && XMLhttp.status == 200) {
				//受信完了時の処理
				alert("送信が完了しました。\n\n返信ありがとうございました。");
			}
		}

		document.getElementById("InquiryForm").style.display = "none";

	}
	
	
}

//リクエストオブジェクト生成
function createXMLHttpRequest() {
  if (window.XMLHttpRequest) {
    return new XMLHttpRequest();
  }else if(window.ActiveXObject) {
    try {
      return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        return new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
        return null;
      }
    }
  } else {
    return null;
  }
}


