if(typeof(page_need_login) == 'undefined') var page_need_login=false;//如果没有定义是否需要登录才能浏览的标志page_need_login，则默认定义为不需要登录（false）

no_display_unlogind_info = true;//是否在退出登录后页面头部不显示登录窗口,true :是
var login_call_back_function = null;
function move_login_popup_dlg(forceMove) {
	var o_popup = $('popup');
	var popup_div_width  = parseInt(o_popup.style.width) || 342;
	var popup_div_height  = parseInt(o_popup.style.height) || 220;
	var window_width = window.innerWidth || document.documentElement.clientWidth;
	var window_height = window.innerHeight || document.documentElement.clientHeight;
	var window_x_offset = window.pageXOffset || document.documentElement.scrollLeft;
	var window_y_offset = window.pageYOffset || document.documentElement.scrollTop;
	o_popup.style.left = parseInt((window_width-popup_div_width)/2+window_x_offset)+'px';
	var top_position = parseInt((window_height-popup_div_height)/2+window_y_offset);
	top_position =  top_position < 100?top_position:top_position-100;
	o_popup.style.top = top_position+'px';
	var overlay_height = window_height>document.body.clientHeight?window_height:document.body.clientHeight;
	$('popup_login_overlay').style.height=overlay_height+'px';
}
function switch_login_popup_dlg_display(isdisplay,call_back_func) {
	try{
		if(page_need_login) {
			if(current_user.user_id == 0){
				if(isdisplay==false) { result = confirm("该页面需要登陆之后才能浏览，您确定要离开该页面吗？\r\n点击\"确定\"回到首页，点击\"取消\"登录！"); if(result) {window.location.href='http://www.meeli.cn'};}
			   move_login_popup_dlg();
				$('popup_login_overlay').style.display='';
				$('popup').style.display='block';
				$('popup_username').focus();
				return;
			}
		}
	}
	catch(e) {
		page_need_login = false;
		switch_login_popup_dlg_display(isdisplay);
		return;
	}
	if(isdisplay) {
		move_login_popup_dlg();
		$('popup_login_overlay').style.display='';
		$('popup').style.display='block';
		$('popup_username').focus()
		if(call_back_func) {
			login_call_back_function = call_back_func;
		}
	}
	else {
		$('popup').style.display='none';
		$('popup_login_overlay').style.display='none';
	}
}

function popup_user_login() {
	if($('popup_username').value=="") {alert('请输入用户名!');$('popup_username').focus();return;};
	if($('popup_password').value=="") {alert('请输入密码!');$('popup_password').focus();return};
	var is_auto_login=false;
	if($('autoLogin').checked) {
		is_auto_login = true;
	}
	
	AJAX_User.login($('popup_username').value,$('popup_password').value,is_auto_login);
	
	if(AJAX_User.login_callback) {
		AJAX_User.login_callback = function(resule){
			current_user = resule;
			
			if(current_user.user_id != 0){
				if(current_user.no_active == 0) {
					window.location.href="http://www.meeli.cn/Space_Blog_Active.php";
					return;
				}
				switch_login_popup_dlg_display(false);
				if(login_call_back_function != null) {
					login_call_back_function();
					login_call_back_function = null;
				}
				notify_login();
			}
			else {
				alert('用户名或密码错误！登录失败！');
    			$('popup_username').focus();
			}
		}
	}
}

function submitForm(evt) {
	if(evt.keyCode == 0x0D) {
		popup_user_login();
		Event.stop(evt);
	}
}

function popup_user_logout() {
	var log_out_Ajax = new Ajax.Request('/user_logout.php?obj',{method:'get',onComplete:popup_user_logout_callback});
}

function popup_user_logout_callback(response) 
{
	current_user = eval(response.responseText);
	reload_page();
	notify_login();
}
function reload_page() {
	/*
	if(window.location.pathname.toLowerCase()=='/show_suitupload.php') {
		location.reload(true);
	}
	if(window.location.pathname.toLowerCase()=='/show_clothupload.php') {
		location.reload(true);
	}
	if(window.location.pathname.toLowerCase()=='/show_suitedit.php') {
		location.reload(true);
	}
	if(window.location.pathname.toLowerCase()=='/show_clothedit.php') {
		location.reload(true);
	}
	*/
}
Event.observe(window, 'load', function() {try{if(page_need_login && current_user.user_id == 0) {switch_login_popup_dlg_display(true);}}catch(ee){}});
Event.observe( window, 'scroll', function(){if($('popup').style.display=='block') move_login_popup_dlg();});
login_register(switch_login_popup_dlg_display);