$(document).ready(function() {
	
	// image align
	if($.browser.msie && $.browser.version<8) {
		$("img").each(function(i,img) {
			if($(img).attr("align")=="right") {
				$(img).css("float","right");
			}
		});
	}
	
	// contact
	$("#btn_contact_confirm").click(function() {
		try {
			$("#errormsg").empty().hide();
			if($("#name_last").val()=='')
				throw "お名前（姓）が入力されていません";
			if($("#name_first").val()=='')
				throw "お名前（名）が入力されていません";
			if($("#email").val()=='')
				throw "メールアドレスが入力されていません";
			if($("#emailc").val()=='')
				throw "メールアドレス（確認用）が入力されていません";
			if($("#email").val()!=$("#emailc").val())
				throw "メールアドレスが一致しません";
			if($("#message").val()=='')
				throw "お問い合わせ内容が入力されていません";
			// copy input
			$("#name_last_c").empty().append(htmlspecialchars($("#name_last").val()));
			$("#name_first_c").empty().append(htmlspecialchars($("#name_first").val()));
			$("#email_c").empty().append(htmlspecialchars($("#email").val()));
			$("#message_c").empty().append(nl2br(htmlspecialchars($("#message").val())));
			$("#contact_input").hide();
			$("#contact_confirm").show();
		} catch(e) {
			alert(e);
			$("#errormsg").empty().append(e).show();
		}
		return false;
	});
	$("#btn_contact_back").click(function() {
		$("#contact_confirm").hide();
		$("#contact_input").show();
		return false;
	});
	$("#btn_contact_submit").click(function() {
		$("<input/>")
			.attr("type","hidden")
			.attr("name","contact_submit")
			.attr("value","contact_submit")
			.appendTo("#contact_input");
		$("#contact_input").submit();
		return false;
	});
	
});

function htmlspecialchars(ch) { 
	ch = ch.replace(/&/g,"&amp;") ;
	ch = ch.replace(/"/g,"&quot;") ;
	ch = ch.replace(/'/g,"&#039;") ;
	ch = ch.replace(/</g,"&lt;") ;
	ch = ch.replace(/>/g,"&gt;") ;
	return ch ;
}

function nl2br(ch) {
	return ch.replace(/\n/g,'<br />');
}

