$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(
  function f_checkForm() {
	var title = $("input#formtext_1").val();
	if (document.getElementById('formtext_1').value=='') {	
		window.alert('件名を記入してください。');
		return false;
	}

	var contents = $("textarea#formtextarea_1").val();
	if (document.getElementById('formtextarea_1').value=='') {	
		window.alert('内容を記入してください。');
		return false;
	}

    var company = $("input#formtext_4").val();	
	if (document.getElementById('formtext_4').value=='') {	
		window.alert('会社名を記入してください。');
		return false;
	}

    var name = $("input#formtext_2").val();	
	if (document.getElementById('formtext_2').value=='') {	
		window.alert('お名前を記入してください。');
		return false;
	}

    var email = $("input#formtext_3").val();
	if (document.getElementById('formtext_3').value=='') {	
		window.alert('Ｅメールアドレスを記入してください。');
		return false;
	}

    var email = $("input#formtext_3").val();	
	if (!document.getElementById('formtext_3').value.match(/[!#-9A-~]+@+[a-z0-9]+.+[^.]$/)) {
		window.alert('Ｅメールアドレスを正しく記述してください。');
		return false;
	}


    var phone = $("input#formtext_7").val();	
	if (document.getElementById('formtext_7').value=='') {	
		window.alert('電話番号を記入してください。');
		return false;
	}
	

/*process.phpに渡してやるために、変数dataStringにまとめる*/		
		var dataString = 'title='+ title + '&contents='+ contents + '&company='+ company + '&name='+ name + '&email='+ email + '&phone='+ phone;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      
/*送信が完了した際に出力されるメッセージ*/
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h4>お問い合わせいただき、ありがとうございました。</h4>")	//１．タグを変更。<h2>より　/２．文末に「。」を追加
        .append("<p>折り返し連絡いたしますので、今しばらくお待ちください。</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='image/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
