$(function() {
	var basePath = $($("body")[0]).attr("base");
	//关闭窗口
	$("#closeLogin").click(function() { closeWinLogin(); });
	$("#closeLogin2").click(function() { closeWinLogin(); });
	var divLogin = $("#divLogin");
	var divLoginF = $("#divLoginF");
	var windowObj = $(window);//获取window对象
	var browserWidth = windowObj.width();//获取当前浏览器长度
	var browserHeight = windowObj.height();//获取当前浏览器宽度
	var scrollLeft = windowObj.scrollLeft();
	var scrollTop = windowObj.scrollTop();
	var cwinWidth = divLogin.width();
	var cwinHeight = divLogin.height();
	var left = scrollLeft + (browserWidth - cwinWidth) / 2;
	var top = scrollTop + (browserHeight - cwinHeight) / 2;
	divLogin.css("top", top).css("left", left);
	divLoginF.css("top", top).css("left", left);
	$(window).scroll(function(){
		var windowObj = $(window);//获取window对象
		var browserWidth = windowObj.width();//获取当前浏览器长度
		var browserHeight = windowObj.height();//获取当前浏览器宽度
		var scrollLeft = windowObj.scrollLeft();
		var scrollTop = windowObj.scrollTop();
		var cwinWidth = divLogin.width();
		var cwinHeight = divLogin.height();
		var left = scrollLeft + (browserWidth - cwinWidth) / 2;
		var top = scrollTop + (browserHeight - cwinHeight) / 2;
		divLogin.css("top", top).css("left", left);
		divLoginF.css("top", top).css("left", left);
	});
	//注册跳转
	$("#O_RegGo").click(function() {
		$("#divLogin").hide();
		$("#divReg").show();
		$("#divRegF").show();
	});
	//登录
	var O_WinLoginUsername = $("#O_WinLoginUsername");//获取用户帐号控件
    var O_WinLoginPassword = $("#O_WinLoginPassword");//获取密码控件
	$("#O_WinLoginSubmit").click(function() {
		var v_account = $.trim(O_WinLoginUsername.val());
		var v_psd = $.trim(O_WinLoginPassword.val());
		if(v_account == "") {
			alert("帐号不能为空！");
			O_WinLoginUsername.val("");
			O_WinLoginUsername.focus();
		} else if(v_psd == "") {
			alert("密码不能为空！");
			O_WinLoginPassword.val("");
			O_WinLoginPassword.focus();
		} else {
			$.post(basePath + "?m=login.check", { account:v_account, password:v_psd }, function(data) {//alert(data);
				if(data[0] == "success") {
					closeWinLogin();
					var O_LoginSuccessUrl = $("#O_LoginSuccessUrl");
					if(O_LoginSuccessUrl != null) {
						window.location = O_LoginSuccessUrl.val();
					} else {
						window.reload();
					}
				} else {
					alert(data[1]);
					if(data[2] == "account is null") {
						O_WinLoginUsername.val("");
						O_WinLoginUsername.focus();
					} else if(data[2] == "password is null") {
						O_WinLoginPassword.val("");
						O_WinLoginPassword.focus();
					} else if(data[2] == "member is not exists") {
						O_WinLoginUsername.focus();
					} else if(data[2] == "member is stopped") {
						O_WinLoginUsername.focus();
					} else if(data[2] == "password error") {
						O_WinLoginPassword.val("");
						O_WinLoginPassword.focus();
					}
				}
			}, "json");
		}
	});
}); 
//清空所有内容
function clearText($thisNode){
	var $parent = $thisNode.parent();
	if($thisNode.is("#O_Account")) {
		$thisNode.val("");
		$parent.find("span.formtips").removeClass("Normal").removeClass("onSuccess").removeClass("onError").addClass("Normal").html("用户ID不能为空！");
	} else if($thisNode.is("#O_Psd")) {
		$thisNode.val("");
		$parent.find("span.formtips").removeClass("Normal").removeClass("onSuccess").removeClass("onError").addClass("Normal").html("设置登录密码");
	} else if($thisNode.is("#O_RePsd")) {
		$thisNode.val("");
		$parent.find("span.formtips").removeClass("Normal").removeClass("onSuccess").removeClass("onError").addClass("Normal").html("确认登录密码");
	} else if($thisNode.is("#O_Phone")) {
		$thisNode.val("");
		$parent.find("span.formtips").removeClass("Normal").removeClass("onSuccess").removeClass("onError").addClass("Normal").html("输入常用手机号码");
	} else if($thisNode.is("#O_Email")) {
		$thisNode.val("");
		$parent.find("span.formtips").removeClass("Normal").removeClass("onSuccess").removeClass("onError").addClass("Normal").html("输入常用Email");
	}
}
//关闭窗口
function closeWinLogin(){
	//清空所有内容
	$("#doing").hide();
	$("#divLogin").hide();
	$("#divLoginF").hide();
}