function login() {
	$.blockUI({
    	message: '<iframe src="/user/login.php" width="430px" height="330px" scrolling="no" frameborder="0"></iframe>', 
        fadeIn: 300, 
        fadeOut: 300,
        showOverlay: true, 
        overlayCSS: {opacity: .8},
        css: { 
        	top:  ($(window).height() - 330) /2 + 'px', 
            left: ($(window).width() - 430) /2 + 'px',
        	width: '430px',
        	height: '330px',
        	border: 0
        }
    });
}

function register() {
	$.blockUI({
    	message: '<iframe src="/user/register.php" width="520px" height="480px" scrolling="no" frameborder="0"></iframe>', 
        fadeIn: 300, 
        fadeOut: 300,
        showOverlay: true, 
        overlayCSS: {opacity: .8},
        css: { 
        	top:  ($(window).height() - 480) /2 + 'px', 
            left: ($(window).width() - 520) /2 + 'px',
        	width: '520px',
        	height: '480px',
        	border: 0
        }
    });
}

function forgetPasswd() {
	$.blockUI({
    	message: '<iframe src="/user/forget_passwd.php" width="405px" height="225px" scrolling="no" frameborder="0"></iframe>', 
        fadeIn: 300, 
        fadeOut: 300,
        showOverlay: true, 
        overlayCSS: {opacity: .8},
        css: { 
        	top:  ($(window).height() - 225) /2 + 'px', 
            left: ($(window).width() - 405) /2 + 'px',
        	width: '405px',
        	height: '225px',
        	border: 0
        }
    });
}

function setPassword(uid, checksum) {
	$.blockUI({
    	message: '<iframe src="/user/set_passwd.php?uid='+uid+'&checksum='+checksum+'" width="405px" height="225px" scrolling="no" frameborder="0"></iframe>', 
        fadeIn: 300, 
        fadeOut: 300,
        showOverlay: true, 
        overlayCSS: {opacity: .8},
        css: { 
        	top:  ($(window).height() - 225) /2 + 'px', 
            left: ($(window).width() - 405) /2 + 'px',
        	width: '405px',
        	height: '225px',
        	border: 0
        }
    });
}

function regMail() {
	$.blockUI({
    	message: '<iframe src="/user/register_mail.php" width="405px" height="275px" scrolling="no" frameborder="0"></iframe>', 
        fadeIn: 300, 
        fadeOut: 300,
        showOverlay: true, 
        overlayCSS: {opacity: .8},
        css: { 
        	top:  ($(window).height() - 275) /2 + 'px', 
            left: ($(window).width() - 405) /2 + 'px',
        	width: '405px',
        	height: '275px',
        	border: 0
        }
    });
}

function logout() {
	$.ajax({
		url : "/user/logout.php",
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			alert("获取失败");
			},
		success : function(json, textStatus, XMLHttpRequest) {
				ret = json.split("|||");
				$.cookie("uId", "");
				$.cookie("uName", "");
				$.cookie("isLogin", "");
				$.cookie("rName", "");
				$.cookie("fCar", "");
				if(ret[1] == '登出成功') {
				window.location.reload();
				}
			}
	});
}

function doLogin() {
	if(jQuery("#loginName").val() == "" ||  jQuery("#password").val() =="") {
		alert("请填写登录帐号和密码");
		return;
	}
	jQuery.ajax({
		url : "/user/loginSubmit.php",
		type : "POST",
		data : {loginName:jQuery("#loginName").val(),password: jQuery("#password").val(),rememberLogin:jQuery("#rememberLogin").attr("checked")},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			alert("获取失败");
			},
		success : function(json, textStatus, XMLHttpRequest) {
				ret = json.split("|||");
				if(ret[1] == '登录成功') {
					synlogin(ret[2]);
					if(ret.length>3) {
						$.cookie("uId", ret[2], {expires:30,path:"/"});
						$.cookie("uName", ret[3], {expires:30,path:"/"});
						$.cookie("isLogin", 1, {expires:30,path:"/"});
						$.cookie("rName", ret[4], {expires:30,path:"/"});
						$.cookie("fCar", ret[5], {expires:30,path:"/"});
					}
				}
				else
				{
					alert(ret[1]);
				}
			}
	});
}

function synlogin(uId) {
	jQuery.blockUI({
    	message: '<iframe src="/user/synlogin.php?uId='+uId+'" width="1px" height="1px" scrolling="no" frameborder="0"></iframe>', 
        fadeIn: 300, 
        fadeOut: 300,
        showOverlay: true, 
        overlayCSS: {opacity: 0},
        css: { 
        	width: '1px',
        	height: '1px',
        	border: 0
        },
        onBlock: function() {
			parent.jQuery.unblockUI();
			if(parent.window.location == "http://www.ouraudi.com/?act=login") {
				parent.window.location = "http://www.ouraudi.com/";
			} else if(parent.window.location == "http://www.ouraudi.com/?act=login&ref=user_profile.php") {
				parent.window.location = "http://www.ouraudi.com/user/user_profile.php";
			} else {
				parent.window.location.reload();
			}
			
        }
    });
}

$("document").ready(function() {
	$("#password").keydown(function(e) {
		var isie = (document.all) ? true : false; 
		if(isie) {
			key = event.keyCode; 
		} else {
			key = e.which;
		}
		if(key == 13) {
			doLogin();
		}
	});
});

