var uniqid = (new Date()).getTime();

$(document).ready(function() {
	$("#send_btn").hide();
	$("#contact_back_btn").hide();
	$("#message").html("下記フォームに必要事項をご記入の上、送信してください。（<strong class='txt_or'>※</strong>印は入力必須項目です。）");
});

function _confirm(){
	var er = false;
	$("#send_form td.hissu div.input :input").each(function (){
		//必須データのチェック(text)
		if($(this).val() == ''){
			$(this).css("backgroundColor","#ff8888");
			er = true;
		} else {
			$(this).css("backgroundColor","white");
		}
	});

	if($("input[name=about]").is(":checked") == false){
		$('input[name=about]').css("backgroundColor","#ff8888");
	} else {
		$('input[name=about]').css("backgroundColor","white");
	}

	if($('input[name=about]:checked').val() == "その他" &&
			$('input[name=about_text]').val() == ""){
			$('input[name=about_text]').css("backgroundColor","#ff8888");
		er = true;
	} else {
			$('input[name=about_text]').css("backgroundColor","white");
	}

	if(er){
		alert("必須項目は全て入力してください。");
		return;
	}

	$("div.input").hide();
	$("div.input :input").each(function (){
		$(this).parents('div.input').next('div.confirm').text($(this).val());
	});

	$("input[name=about]:checked").parents('div.input').next('div.confirm').text($("input[name=about]:checked").val());
	if($('input[name=about]:checked').val() == "その他" &&
			$('input[name=about_text]').val() != ""){
	$("input[name=about_text]").parents('div.input').next('div.confirm').text($('input[name=about]:checked').val() + " ・" + $("input[name=about_text]").val());
	}

	$("input[name=know]:checked").parents('div.input').next('div.confirm').text($("input[name=know]:checked").val());
	if($('input[name=know]:checked').val() == "その他" &&
			$('input[name=know_text]').val() != ""){
	$("input[name=know_text]").parents('div.input').next('div.confirm').text($('input[name=know]:checked').val() + " ・" + $("input[name=know_text]").val());
	}

	$("input[name=tel1]").parents('div.input').next('div.confirm').text($("input[name=tel1]").val() + "-" + $("input[name=tel2]").val() + "-" + $("input[name=tel3]").val());
	$("input[name=zip1]").parents('div.input').next('div.confirm').text($("input[name=zip1]").val() + "-" + $("input[name=zip2]").val());

	$("#check_btn").hide();
	$("#reset_btn").hide();
	$("#send_btn").show();
	$("#contact_back_btn").show();
}

function _back(){
	$("div.input").show();
	$("div.confirm").text("");
	$("#check_btn").show();
	$("#reset_btn").show();
	$("#send_btn").hide();
	$("#contact_back_btn").hide();
}

function _send(){
	if(confirm('送信します。よろしいですか？')){
		if($('#send_form').is(':has(#entry_id)')){
			$('#entry_id').remove();
		}

		$('#send_form').append($('<input name="entry_id" id="entry_id" type="hidden" value="' + uniqid +'">'));

		$('#send_form').ajaxSubmit({
			url: 'sendmail.php',
			dataType: 'json',
			success: function(json){
				alert(json.message);
				if(json.error == false){
					document.send_form.reset();
				} else {
				}
				_back();
			}
		});
		$("#send_form :input").val('');
	}
	return false;
}
