function userLogin()
{
	showStatusDiv();
	var frm = document.getElementById("frmLogin");
	var check = inputCheck(frm);
	if(!check) return check;

	var ajaxObj      = new AjaxFrame;
	ajaxObj.url      = "index.php?mod=Login&action=userLogin";
	ajaxObj.method   = "POST";
	ajaxObj.content  = "username=" + frm.username.value + "&password=" + frm.password.value + "&authNum=" + frm.authNum.value;
	ajaxObj.callback = loginResult;
	ajaxObj.sendReq();
}

function inputCheck(frm)
{
	var username = frm.username.value;
	var password = frm.password.value;
	var authNum  = frm.authNum.value;
	result = true;

	if(username == "")
	{
		alert("帐号不能为空!");
		frm.username.focus();
		result = false;
	}

	else if(password == "")
	{
		alert("密码不能为空!");
		frm.password.focus();
		result = false;
	}
	
	else if(authNum == "")
	{
		alert("验证码不能为空!");
		frm.authNum.focus();
		result = false;
	}
	if (false == result) hideStatusDiv();
	return result;
}

function loginResult(httpReq,objId)
{
	if(httpReq.responseText == 1)
	{
		location.href = "index.php?mod=Main&action=idxAdmin";
	}
	else
	{
		if(httpReq.responseText == -999)
		{
			alert("您是特殊的合同推广员，请登录迅游合作推广查询系统");
			location.href = "http://tg.xunyou.com/partnerIndex.php";
		}
		else
		{
			alert(httpReq.responseText);
			getAuthCode();
		}
	}
	hideStatusDiv();
}

function getAuthCode()
{
	document.getElementById("authCode").src = "authlogin.php?r="+Math.random();
}

//====同意协议并注册成为推广员===========================================================
function userAgree()
{
//	showStatusDiv();
	var ajaxObj      = new AjaxFrame;
	ajaxObj.url      = "index.php?mod=Login&action=displayAgreement";
	ajaxObj.method   = "POST";
	ajaxObj.content  = "agree=1";
	ajaxObj.callback = agreeResult;
	ajaxObj.sendReq();
}

function agreeResult(httpReq,objId)
{
	if(httpReq.responseText == 1)
	{
		top.location.href = "index.php?mod=Main&action=idxAdmin";
	}
	else
	{
		alert(httpReq.responseText);
	}
//	hideStatusDiv();
}

function retLogin(evt)
{
	if(evt == null) evt = window.event;
	var frmCode = evt.keyCode ? evt.keyCode : evt.which; // IE使用keyCode, 而Firefox使用which
	if(frmCode == 13)
	{
		var frm = document.getElementById("frmLogin");
		// 检查表单是否都填写了
		if (frm.username.value != '' && frm.password.value != '' && frm.authNum.value != '') userLogin();
	}
}