// JavaScript Document

function resetReservation(){
	$('#reservation_form input').val('');
	clearErrorText()
	
}
function clearErrorText(){
	
	$('#reservation_form input').removeClass('error');
	$('.error_txt').html('');
	$('.error_txt').hide('');
}

function submitReservation(){
	
	clearErrorText()
	var error = false;
	
	//Checking no empty
	$('.must_fill').each(function(){
		var this_name = $(this).attr('name');
		var this_val = $.trim($(this).val());
		if (!this_val){
			error = true;
			$(this).addClass('error');
			$('#er_'+this_name).show();
			$('#er_'+this_name).html(' 此項必填');
		}
	})
	
	$('.txt_only').each(function(){
		var this_name = $(this).attr('name');
		var this_val = $.trim($(this).val());
		
		if(!textOnly(this_val)){
			$(this).addClass("error");
			$('#er_'+this_name).show();
			$('#er_'+this_name).html(' 只接受文字');
			error = true;
		}
	})
	
	$('.is_email').each(function(){
		var this_name = $(this).attr('name');
		var this_val = $.trim($(this).val());
		
		if(!checkEmail(this_val)){
			error = true;
			$(this).addClass('error');
			$('#er_'+this_name).show();
			$('#er_'+this_name).html(' 電郵不正確');
		}
	})
	

	if (error == true){
		return
	} else {
		var dataString = $('#reservation_form').serialize();
		$.ajax({
				url: 'mail_contact.php', 
				type: 'POST',
				data: dataString,
				cache: false,
				success: function(html){
					var done_html = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="300" align="center" valign="middle"><p class="title_text" style="text-align:center">你已成功登記，將有專人與您聯絡。</p><p style="text-align:center">於 10 秒後自動返回或<a href="?section=Home">按此</a>返回。</p></td></tr></table>';
					
					$('#form_checkout').html(done_html);
					
					setTimeout(function(){window.location = "?section=Home"}, 10000);
				}
			})
	}
}