function initLoginInfo(a)
{
	var user=getCookie("user");       
	var htmlStr="";
	if(user==null){	
		htmlStr+='<ul>';
		htmlStr+='<li><img src="/style/images/yh.jpg"></li>';
		htmlStr+='<li><input type="text" id="user" class="logint"></li>';
		htmlStr+='<li><img src="/style/images/mm.jpg"></li>';
		htmlStr+='<li><input type="password" id="pwd" class="logint"></li>';
		htmlStr+='<li><input type="submit" value="登录" id="loginButton"  onclick="login();" class="loginb"></li>';
		htmlStr+='<li><input type="button" value="注册"   onclick="reg();" class="loginb"></li>';
		htmlStr+='<li><div id="loginMsg"></div></li>';
	}
	else
	{
		getUserLoged(decodeURIComponent(user));
	}
	$(a).innerHTML=htmlStr;
}

function goSearchU()
{
	var keyword=$("userNameS").value;
	if($("userNameS").value==null||$("userNameS").value=="会员名称") {alert("请输入关键字！");$("userNameS").focus();return false;};
	var url="/user/operate.php?type=searchUser";
	if(keyword) url+="&userName="+keyword+"";
	  //开始拼凑XML文件
    Ajax("post",url,showMsg);
	function showMsg(xmlHttp)
	{
		if(xmlHttp.readyState==4)
		{	
		  var re=xmlHttp.responseText;
		  if(re==1){alert("查无此用户,请重新输入！");$("userNameS").focus();return false;}
		  else
		  {
		    //window.open("/"+re+".shtml");
			location.href="/"+re+".shtml";
			
		  }
		}
	}	
}


function login()
{
	var alertStr="";
	var user=$("user").value;
	var pwd=$("pwd").value;
	if(user=="") alertStr+="用户名不能为空!";
	if(pwd=="") alertStr+="密码不能为空!";
	if(alertStr!=""){
		$("loginMsg").className="loginErr";
		$("loginMsg").innerHTML=alertStr;
	}else{
		Ajax("post","/user/operate.php?type=login&user="+user+"&pwd="+pwd,showMsg);
	}
	function showMsg(xmlHttp)
	{
		$("loginMsg").className="loginMsg";
		$("loginMsg").innerHTML="<img src='/style/images/ico/loading.gif' align=absmiddle />登录中...";
		if(xmlHttp.readyState==4){
			$("loginMsg").innerHTML="";
			var re=xmlHttp.responseText;
			if(re=="1"){
				initLoginInfo("ll");
				Ext.example.msg('提示', '登录网站成功!');
			}
		    else if(re=="2")
			{
				alert("您的帐户未审核，或者被管理员锁定！");
				}
			else{
				$("loginMsg").className="loginErr";
				$("loginMsg").innerHTML="用户名或密码错误!";
			}
		}
	}
}

function reg()
{
	location.href="/reg.php";
}

function getUserLoged(user)
{
    Ajax("post","/data.php?type=getUserLoged&user="+user+"",showData);
	function showData(xmlHttp)
	{
		if(xmlHttp.readyState==4)
		{
		  var re=xmlHttp.responseText;
		  $('ll').innerHTML=re;
		}
	}	
}


function go(a)
{
	writeCookie("usertype",a);
	location.href="/user/";
}

function goPay()
{
	//location.href="/pay.html";
	window.open('/pay.html');
}

function loginOut()
{
	if(confirm("确定注销吗?"))
	{
		deleteCookie("user","/");
		Clearcookie();
		initLoginInfo("ll");
		Ext.example.msg("提示","成功退出系统！");
	}
}

function roundNum(number,X){
// rounds number to X decimal places,default 2   
	X=(!X?2:X);
	var num=(Math.round(number*Math.pow(10,X))/Math.pow(10,X))*100;
	num=(num.toString()).substring(0,4);
	return num;
} 

function userLoginOut()
{
	if(confirm("确定注销吗?"))
	{
		deleteCookie("user","/");
		Clearcookie();
		initLoginInfo("ll");
		Ext.example.msg("提示","成功退出系统！");
		location.href="/";
	}
}


function judgeUser()
{
	var user=getCookie("user");
	if(!user)
	{
		alert("您还没有登录,无权访问该页面...");
		self.location="/index.php";
	}
}

function pay()
{
  window.open("/pay.html", "win"); 	
}

////////////////以下为定义用户弹出窗口
var HiddenTimer;//广告窗口关闭的定时器
function getMousePos(ev)//获取鼠标的位置
{
 if(ev.pageX || ev.pageY)//firefox中的位置
 {
  return {x:ev.pageX, y:ev.pageY};
 }
 return {//ie中的位置
  x:ev.clientX + document.documentElement.scrollLeft - document.documentElement.clientLeft,
  y:ev.clientY + document.documentElement.scrollTop  - document.documentElement.clientTop
 };
}

function matchAds(e)
{
  var UserBox=document.createElement("div");//广告显示窗体 
  var str="";
  UserBox.id="ShowBox";
  UserBox.setAttribute("id","UserBox");
  UserBox.setAttribute("name","BoxName");
  UserBox.style.position="absolute";
  str+='<div id="UserBox" name="BoxName">';
  str+='<div id="UserBoxC" name="UserBoxC" >loading...</div>';
  str+='</div>';
  UserBox.innerHTML=str;
  document.body.insertBefore(UserBox); 
  $('UserBox').style.display="none";
}

function showAdsearch(userName,userId,e)
{
	try{clearTimeout(HiddenTimer);}//关闭定时消失事件
    catch(e){}
	moveBox(e);//移动广告窗体
	var str="";
	str+='<div class="userbox"><ul><li onclick="boxfav(\''+userName+'\');">添加关注</li><li  onclick=usergo('+userId+');>历史战绩</li><li onclick="hiddenUserBox();"><img src="/style/images/delete.gif"></li></ul></div>';
	$('UserBox').innerHTML=str;
	$('UserBox').style.display="block";
}

function boxfav(fuser)
{
	if(getCookie("user")==null){alert("对不起，只有登录后才可以享用权限！");return false;};
	if(fuser==""){alert("请填入用户ID");return false;}
	if(fuser==getCookie("user")){alert("自己不用添加自己");return false;}
	url="/user/operate.php?type=adduser&fuser="+encodeURIComponent(fuser)+"";
	Ajax("post",url,showData);
	function showData(xmlHttp)
	{
		if(xmlHttp.readyState==4)
		{
			var re=xmlHttp.responseText;
		    alert(re);
		}
	}
}

//移动广告窗体
function moveBox(e)
{
	var BoxLeft=getMousePos(e).x;//当前鼠标的横坐标
	//如果广告窗体超出显示区域
	if(parseInt(document.documentElement.clientWidth)-BoxLeft<parseInt($('UserBox').style.width))
		{
		BoxLeft=(BoxLeft-parseInt($('UserBox').style.width))+"px";
		}
	else
		{
		BoxLeft=BoxLeft+"px";
		}
	$('UserBox').style.left=BoxLeft;//设置横坐标
	var BoxTop=getMousePos(e).y//当前鼠标的纵坐标
	if(parseInt(document.documentElement.clientHeight)-BoxTop<parseInt($('UserBox').style.height))
		{
		BoxTop=(BoxTop-parseInt($('UserBox').style.height)-55)+"px";
		}
	else
		{
		BoxTop=(BoxTop+5)+"px";
		}
	 $('UserBox').style.top=BoxTop;//设置纵坐标
}
//鼠标移动事件
document.onmouseover=function(e)
{
  e = e || window.event;   
  var eSrc=e.target||e.srcElement;
  if(eSrc.name!="BoxName")
  {
     try{clearTimeout(HiddenTimer);} catch(e){}
     HiddenTimer=setTimeout("hiddenUserBox()",2000);
  }
  else
  {
     try{clearTimeout(HiddenTimer);} catch(e){}
  }
}
//隐藏广告窗体
function hiddenUserBox()
{
 try{clearTimeout(HiddenTimer);} 
 catch(e){}
 $('UserBox').style.display="none";
}
//定义用户弹出窗口结束

function clickgo(url){ 
   window.top.location.href=url;
} 
function clickgo_blank(url){ 
   window.open(url);
} 


function showResult(btn){
 Ext.example.msg('事件提示', 'You clicked the {0} button', btn);
};
	
function showResultText(btn, text){
  Ext.example.msg('事件提示', 'You clicked the {0} button and entered the text "{1}".', btn, text);
};
