var	ref	= null;
var	USER	= null;
var	PROFILE	= null;
var	BIND	= null;
function loadReference(){
	var	_ref= (new JSRequest(document.URL)).getParameter('ref');
	if(Require.test(_ref)){
		ref	= _ref;
	}
	return _ref;
}
function quit(){
	$.ajax({
		url: 'uc!logout.uc', type: 'POST', dataType:'json',
		success: function(res){
			if(res.success){
				top.location	= './login.html';
			}
		}
	});
}
function loadCurrentUser(){
	$.ajax({
		url: 'uc!current.uc', type: 'POST', dataType:'json',
		async: false, success: function(res){
			if(res.success){
				USER	= res.obj[0];
				PROFILE	= res.obj[1];
				BIND	= res.obj[2];
				if(PROFILE.idCard==undefined || PROFILE.idCard==null || PROFILE.idCard==''){
					if(document.URL.search('update_idcard.html') < 0){
						top.location	= './update_idcard.html';
					}
				}
			}else{
				alert(res.message);
				top.location	= './login.html';
			}
		}
	});
}

function loadHeader(){
	var	tpl_header	= load('./header.html');
	$('#header').html(rplc({hide_quit_btn: 'display: none;'}, tpl_header));	
}
function loadHeaderWithQuit(){
	var	tpl_header	= load('./header.html');
	$('#header').html(tpl_header);	
}
function loadHelper(){
	var	tpl_helper	= load('./helper.html');
	$('#helper').html(tpl_helper);
}
function loadFooter(){
	var	tpl_footer	= load('./footer.html');
	$('#footer').html(tpl_footer);
}

function uc_vfcode(){
	$('#img_vfcode').attr('src', 'uc!vfcode.uc?'+Math.random());
}

//加载登录用户信息
function loadUserInfo(){
	var	tpl	= load('./view_userinfo.html');
	tpl	= rplc(USER, tpl);
	tpl	= rplc(PROFILE, tpl);
	$('#userinfo').html(tpl);
	
	var	count	= 0;
	if(/.+/.test(PROFILE.lastName)){ count++; }
	if((USER.bindFlag&0x0001)==0x0001){ count++; }
	if((USER.bindFlag&0x0002)==0x0002){ count++; }
	if((USER.bindFlag&0x0004)==0x0004){ count++; }
	switch(count){
		case 0:
		case 1:
			$('#us_level').html('低');
			$('#us_level').attr('class', 'low');
			break;
		case 2:
			$('#us_level').html('中');
			$('#us_level').attr('class', 'normal');
			break;
		case 3:
		case 4:
			$('#us_level').html('高');
			$('#us_level').attr('class', 'high');
			break;
	}
}
//加载Title图片
function loadMainTitle(mt){
	var	tpl	= load('./view_main_title.html');
	$('#main_title').html(rplc(mt, tpl));
}

//处理ie与firefox兼容问题
function addEventListener(evth){
	var	_document	= document;
	if(_document.addEventListener){
		_document.addEventListener("keypress",evth, true);
	}else{
		_document.attachEvent("onkeypress",evth);
	}
}
