// 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").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('Receive our E-newsletter');
						});
	};
	//按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!") : '';
			}
		});
	});
	/* 性别下拉列表 */
	var btn = $(".btn_list")
	btn.toggle(
		function () {
			$(".fre_list").show();
		  },
		  function () {
			$(".fre_list").hide();
		  }
	);
	$(".fre_list li").click(function(){
		var $this = $(this);
		$("#prefix").val($this[0].getAttribute('value'));
		//alert($this.find('a').text());
		$(".fre_nor")[0].innerHTML= $this.find('a').text();
		$(".fre_list").hide();
	});	
});

