
//头部菜单hover样式
$(".headMenuLeft li:not(.now)").hover(
	function(){
		$(this).addClass("now");
	},
	function(){
		$(this).removeClass("now");
	}
);

//搜索
$(".searchTxt").val($(".searchTxt").attr("tell"));
$(".searchTxt").focus(function(){
	if ($(this).val() == $(this).attr("tell")){
		$(this).val("");
	}
}).blur(function(){
	if ($(this).val() == ""){
		$(this).val($(this).attr("tell"));
	}
});

//头部浮动列表
var headfloatflag1 = false;
var headfloatflag2 = false;
//家具类
$("#jajuMenu").mouseover(function(){
	if ($("#jajuMenu1").css("display") == "none"){
		showHeadFloat($("#jajuMenu1"), $("#jajuMenu2"));
	} else {
		headfloatflag1 = true;
	}
}).mouseout(function(){
	headfloatflag1 = false;
	setTimeout(function(){
		if (!headfloatflag1){
			hideHeadFloat($("#jajuMenu1"), $("#jajuMenu2"));
		}
	}, 20);
});
$("#jajuMenu1").mouseover(function(){
	headfloatflag1 = true;
}).mouseout(function(){
	headfloatflag1 = false;
	setTimeout(function(){
		if (!headfloatflag1){
			hideHeadFloat($("#jajuMenu1"), $("#jajuMenu2"));
		}
	}, 20);
});

//建材类
$("#jiancaiMenu").mouseover(function(){
	if ($("#jiancaiMenu1").css("display") == "none"){
		showHeadFloat($("#jiancaiMenu1"), $("#jiancaiMenu2"));
	} else {
		headfloatflag2 = true;
	}
}).mouseout(function(){
	headfloatflag2 = false;
	setTimeout(function(){
		if (!headfloatflag2){
			hideHeadFloat($("#jiancaiMenu1"), $("#jiancaiMenu2"));
		}
	}, 20);
});
$("#jiancaiMenu1").mouseover(function(){
	headfloatflag2 = true;
}).mouseout(function(){
	headfloatflag2 = false;
	setTimeout(function(){
		if (!headfloatflag2){
			hideHeadFloat($("#jiancaiMenu1"), $("#jiancaiMenu2"));
		}
	}, 20);
});

//展开浮动列表
function showHeadFloat(obj1, obj2){
	obj1.next(".headMenuIframe").css("display", "block");
	obj1.css("display", "block");
	obj2.stop();
	obj2.animate({marginTop:"0px"}, 300);
}
//收起浮动列表
function hideHeadFloat(obj1, obj2){
	obj2.stop();
	obj2.animate({marginTop:"-242px"}, 200, function(){
			obj1.css("display", "none");
			obj1.next(".headMenuIframe").css("display", "none");
		});
}

$(function(){
	//打开登陆层
	$(".openLoginDialog").click(function(){
		$("#userLoginType").val("");
		openFloatBg();
		$("#loginDialog").css({width:window.screen.width, display:"block"});
	});
	//关闭登陆层
	$(".closeLoginDialog").click(function(){
		closeFloatBg();
		$("#loginDialog").css("display", "none");
	});
	
	//打开注册层
	$(".openRegDialog").click(function(){
		openFloatBg();
		$("#regDialog").css({width:window.screen.width, display:"block"});
	});
	//关闭注册层
	$(".closeRegDialog").click(function(){
		closeFloatBg();
		$("#regDialog").css("display", "none");
	});

	//还没注册
	$("#gotoReg").click(function(){
		$("#loginDialog").css("display", "none");
		$("#regDialog").css({width:window.screen.width, display:"block"});
	});
	//注册过了
	$("#gotoLogin").click(function(){
		$("#regDialog").css("display", "none");
		$("#loginDialog").css({width:window.screen.width, display:"block"});
	});
});

//用户登录回车事件
$("#u_password").keypress(function(e){
	var code = window.event ? e.keyCode : e.which;
	if (code == 13){
		checkLogin2();
	}
});

//商家登陆信息验证
function checkLogin(){
	if (!myck.cknull($("#username"), "请输入正确的用户名。")) return false;
	if (!myck.cknull($("#password"), "请输入密码。")) return false;
	var login_username = $('#username').val();
	$('#username').val(login_username.toLowerCase());
	return true;
}
//用户登陆信息验证
function checkLogin2(){
	if (!myck.cknull($("#u_username"), "请输入正确的用户名。")) return false;
	if (!myck.cknull($("#u_password"), "请输入密码。")) return false;
	var login_username = $('#u_username').val();
	$('#u_username').val(login_username.toLowerCase());

	jQuery.getJSON("/membersLogin.do?ts="+(new Date().getTime()),{username : $("#u_username").val(),password :$("#u_password").val(),userLoginType:$("#userLoginType").val()},function(data){
			if(data.msg == 1){
				alert("用户名或密码错误!");
				$("#u_password").focus();
			}else{
				document.location.reload();
			}	
	});
}


//注册层提示信息
var regTell = [ "中、英文均可(3-15个字符)。",
				"请输入有效的邮件地址。",
				"请输入您的中文名。",
				"例(0510-8825131)或(01398678832)" ];
$(".regTell").focus(function(){
	var tempStr = regTell[0];
	if ($(this).hasClass("regEmail")) {tempStr = regTell[1];}
	if ($(this).hasClass("regTrueName")) {tempStr = regTell[2];}
	if ($(this).hasClass("regPhone")) {tempStr = regTell[3];}
	if ($(this).val() == tempStr){
		$(this).val("");
		$(this).removeClass("col999").removeClass("font12");
	}
}).blur(function(){
	var tempStr = regTell[0];
	if ($(this).hasClass("regEmail")) {tempStr = regTell[1];}
	if ($(this).hasClass("regTrueName")) {tempStr = regTell[2];}
	if ($(this).hasClass("regPhone")) {tempStr = regTell[3];}
	if ($(this).val() == ""){
		$(this).addClass("col999").addClass("font12");
		$(this).val(tempStr);
	}
});

//注册表单验证
function checkReg(){
	if (!myck.cknull($(".regName"), "请输入用户名。", regTell[0])) return false;
	if (!myck.cknull($(".regPass"), "请输入您的个人密码。", "")) return false;
	if (!myck.cknull($(".regRePass"), "请再输入一次您的个人密码。", "")) return false;
	if (!myck.cknull($(".regEmail"), "请输入您的邮箱地址。", regTell[1])) return false;
	if (!myck.cklenl($(".regName"), 3, "对不起，您的用户名小于3个字符, 请输入一个较长的用户名。")) return false;
	if (!myck.cklenr($(".regName"), 15, "对不起，您的用户名超过了 15 个字符，请输入一个较短的用户名。")) return false;
	if (!myck.cklenl($(".regPass"), 4, "您的密码长度小于四位，请输入一个较长的密码。")) return false;
	if (!myck.ckpwd($(".regPass"), $(".regRePass"), "两次输入的密码不一致，请检查后重试。")) return false;
	if (!myck.ckemail($(".regEmail"), "Email 地址无效，请重新填写。")) return false;
	
	$(".regTrueName").val($(".regTrueName").val() == regTell[2] ? "" : $(".regTrueName").val());
	$(".regPhone").val($(".regPhone").val() == regTell[3] ? "" : $(".regPhone").val());
	
	return true;
}

//会员升级层控制
function openUpLogin(){
	openFloatBg();
	$(".upLogin").css({width:window.screen.width, display:"block"});
}
function closeUpLogin(){
	closeFloatBg();
	$(".upLogin").css("display", "none");
}

//会员升级表单验证
function upLoginCheck(){
	if (!myck.cknull($("#up_name"), "请输入您的真实姓名。", "")) return false;
	if (!myck.cknull($("#up_phone"), "请输入您的联系电话。", "")) return false;
	if (!myck.cknull($("#up_address"), "请输入您的详细地址。", "")) return false;
	
	jQuery.post("upgradMember.do",{username : $("#up_userName").val(),truename :$("#up_name").val(),tel :$("#up_phone").val(),address :$("#up_address").val()},function(data){
		     if(data != ""){
			     alert(data);
			 }
	});
	return true;
}

//会员参加拼购
function attendPg(pgId){
	jQuery.post("pgActivityMemberAttend.do",{pgid : pgId},function(data){
		     if(data != ""){
			     alert(data);
			 }
			location.href = window.location.href;
	});
	
}

//打开浮动层背景
function openFloatBg(){
	var width = window.screen.width;
	var height = window.screen.height >= $("body").height() ? window.screen.height : $("body").height();
	document.documentElement.scrollTop = 0;
	$(".bigIframe").css({width:width, height:height, display:"block"});
	$(".bigFloatBg").css({width:width, height:height, display:"block"});
	$("html").css("overflow-x", "hidden");
	$("body").css({"overflow-x":"hidden", width:width});
}
//关闭浮动等背景
function closeFloatBg(){
	$("html").css("overflow-x", "auto");
	$("body").css({"overflow-x":"auto", width:"auto"});
	$(".bigIframe").css("display", "none");
	$(".bigFloatBg").css("display", "none");
}

//主搜索功能
$(".searchBtn").click(function(){
	indexAllSearch();
	return false;
});
$(".headSearchTxt").keypress(function(e){
	var code = window.event ? e.keyCode : e.which;
	if (code == 13){
		$("#searchBtn").trigger("click");
	}
});

function indexAllSearch(){
	var s = "/productSearch.do";
	var txt = $(".searchTxt").val();
	if(jQuery.trim(txt) == "" || txt == $(".searchTxt").attr("tell")){
		$(".searchTxt").focus();
		return;
	}
	s += "?keyword="+encodeURI(txt);
	location.href=s;
}

function keyWordSearch(keyword){
	var s = "/productSearch.do";
	s += "?keyword="+encodeURI(keyword);
	location.href=s;
}

function logOutSys(){
	jQuery.getJSON("/membersLogin.do?ts="+(new Date().getTime()),{logOut:"1"},function(data){
		document.location.reload();
	})
}

