/* Check Form */
var send_file = 'inquiry-s.php';
var form_id = '#inquiry';
var action_word = '送信';
var color = '#F3D9D9';

function form_check() {
  count = 0;
	check_empty('#comment');
	check_mail('#mail');
	check_empty('#tel');
	check_empty('#full_name');
  if (count>0) {
    return false;
	} else {
		if ($(form_id).attr('action')!=send_file) {
			$('#submit').before('<em>この内容で' + action_word + 'します。</em> ');
			$('#submit').replaceWith('<input name="submit" type="submit" id="submit" tabindex="999" value="' + action_word + '" />');
			$(form_id).attr('action',send_file);
			return false;
		}
		else {
			return true;
		}
	}
}

function check_empty(selecter) {
	if ($(selecter).val()=='') {
		warning_view('cfw', selecter, '入力してください。');
		count++;
	}
}

function check_mail(selecter) {
  if ($(selecter).val()=='') {
		warning_view('cfw', selecter, '入力してください。');
		count++;
	} else if (!$(selecter).val().match(/^\w+[\w\.\-\_]*@[\w\.\\_-]+\.\w{2,}$/)) {
		warning_view('cfw', selecter, '半角英数字で正確に入力してください。');
		count++;
	}
}

function warning_view(type, selecter, warning) {
	if (type.match(/c/)) {
		$(selecter).css('background-color',color);
		$(selecter).attr('class','warning');
	}
	if (type.match(/f/)) {
		$(selecter).focus();
		window.scrollBy(0,-20);
	}
	if (type.match(/w/)) {
		$(selecter).closest('p').before('<ins class="warning"><em>★' + warning + '</em><br /></ins>');
	}
}

$(function(){
	$('#submit').click(function(){
		$('ins.warning').remove();
		$('.warning').css('background-color','#FFF');
	});
});


