// JavaScript Document
$(function(){
	var emailReg = /^[-_A-Za-z0-9]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/;
	var data;
	var e_btn = $('#e_btn');
	/* search表单 和 email表单 的点击默认 */
	$(".email_input,.search_input").focus(function(){
		if ($(this).val() == this.defaultValue){
				$(this).val(""); 
			}
		}).blur(function(){
		if ($(this).val() == ''){
				$(this).val(this.defaultValue);
			}
	});
	/* email表单提交状态动作 */
	function popup(_id){
		$(_id).animate({
			height: 102 },800,function(){
				}).delay(2000).animate({
					height:0},800,function(){
						//调用重新初始化文本内容的方法
						$("#email").val('Your email here');
						});
	};
	//按enter提交表單
	$("#email").keypress(function (e) {
		if (e.keyCode == 13) {
			e_btn.trigger("click");
			return false;
		}
	});
	/* email表单的点击 */
	e_btn.click(function(){
		if( ($('#email').val() == " ") || (!emailReg.test($('#email').val())) )
			{
				popup("#msg_subscribe_wrong");
				return false;
			}
		else{
		};
		data = $('#form').serialize();
		//表单提交动作
		$.ajax({
			type: "POST",
			url: "enewsletter.php",
			data: data,
			success: function(){
				popup("#msg_subscribe_ok");
				//(result=="OK") ? alert ("Submit Successfully!") : '';
				//(result=="Been") ? alert ("We already have this email in our list.") : '';
				//(result=="Wrong") ? alert ("Please enter a valid email address!") : '';
			}
		});
	});
});

