// 用户登录

var xmlHttp;
function createXMLHttpRequest(){
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
}

function startRequest(){
	createXMLHttpRequest();	
	var queryString="/sessionServlet";
	xmlHttp.onreadystatechange=handleStateChange;
	xmlHttp.open("post",queryString,false);
	xmlHttp.send(null);
}

function handleStateChange(){
	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
			parseResults();
		}
	}
}

function parseResults(){
//	alert(xmlHttp.responseText);
//	document.write(xmlHttp.responseText);
	var char1 = xmlHttp.responseText;//char1的格式是user_id,user_name,score,login_name
	//alert(char1);
	if(char1 != "false"){   
      var   strarray = new   Array();   
      strarray[0]=char1.split(",")[0];
      strarray[1]=char1.split(",")[1];
      strarray[2]=char1.split(",")[2];
      strarray[3]=char1.split(",")[3];
		//另入html代码
document.write('<table width="205" border="0" cellspacing="0" cellpadding="0"><tr>');
document.write('    <td height="34"><img src="/images/userLoginTop.jpg" width="205" height="34" /></td></tr>');
document.write('  <tr><td width="205" height="220" align="center" valign="top" bgcolor="ff0000">');
document.write('<table width="205" height="228" border="0" cellpadding="0" cellspacing="0" bgcolor="ffffff" style="border:1px solid #cccccc;">');
document.write('                              <tr>');
document.write('                                <td width="61" height="70" align="left" valign="middle">');
document.write('			   <img src="/images/zixun_26.gif" width="40" height="34"></td>');
document.write('                                <td width="132" rowspan="3" align="left" valign="bottom">');
document.write('                                <table width="100%" border="0" cellspacing="0" cellpadding="0">');
document.write('                                   <tr>');
document.write('                                      <td width="40%" height="20">您好！</td>');
document.write('                                      <td width="60%"><span style="color:#ff0000;">'+strarray[1]+'</span></td>');
document.write('                                    </tr>');
document.write('                                    <tr>');
document.write('                                      <td height="20"><span class="yasfRed">积分：</span></td>');
document.write('                                      <td><span style="color:#ff0000;">'+strarray[2]+'分</span></td>');
document.write('                                   </tr>');
document.write('                                    <tr>');
document.write('                                      <td height="20"><span class="yasfRed">用户名：</span></td>');
document.write('                                      <td><span style="color:#ff0000;">'+strarray[3]+'</span></td>');
document.write('                                    </tr>');
document.write('                                    <tr>');
document.write('                                <td height="20" colspan="2"><span style="color:#ff0000;">问题（精品）数：*</span></td>');
document.write('                                    </tr>');
document.write('                                </table></td>');
document.write('                              </tr>');
document.write('							  <tr>');
document.write('                                <td width="61" height="18" valign="top">');
document.write('<img src="/images/zixun_39.gif" width="51" height="15" border="0"></td> ');
document.write('                              </tr> ');
document.write('                              <tr> ');
document.write('                                <td height="15"> ');
document.write('<a href="/columns/009add.jsp"><img src="/images/zixun_50.gif" width="51" height="15" border="0"></a></td> ');
document.write('                              </tr> ');
document.write('                              <tr> ');
document.write('                                <td height="17" colspan="2"> ');
document.write('<table width="193" height="17" border="0" cellpadding="0" cellspacing="0"> ');
document.write('                                    <tr> ');
document.write('                                      <td height="17">&nbsp;</td> ');
document.write('                                    </tr> ');
document.write('                                </table></td> ');
document.write('                              </tr> ');
document.write('                              <tr align="center" valign="middle"> ');
document.write('                                <td height="30" colspan="2"> ');
document.write('<span class="STYLE1"><a href="/regiest/userinfo.jsp">个人管理中心</a></span>&nbsp;&nbsp; ');
document.write('<a href="/loginout.jsp">退出</a></td> ');
document.write('                              </tr> ');
document.write('                              <tr> ');
document.write('                               <td height="80" colspan="2"> ');
document.write('<table width="100%" height="80" border="0" cellpadding="0" cellspacing="0"> ');
document.write('                                    <tr> ');
document.write('                                      <td> ');
document.write('<table width="100%" height="70" border="0" cellpadding="0" cellspacing="0"> ');
document.write('                                          <tr> ');
document.write('                                            <td width="50%" align="center" valign="top"> ');
document.write('<img src="/images/zixun_61.gif" width="46" height="45"></td> ');
document.write('                                            <td width="50%" align="center" valign="top"> ');
document.write('<img src="/images/zixun_63.gif" width="46" height="45"></td> ');
document.write('                                          </tr> ');
document.write('                                         <tr> ');
document.write('                                   <td align="center"><a href="/columns/myQuestion.jsp">我的问题</a></td> ');
document.write('                                    <td align="center"><a href="/columns/myAnswer.jsp">我的回答</a></td> ');
document.write('                                          </tr> ');
document.write('                                      </table></td> ');
document.write('                                    </tr> ');
document.write('                                </table> ');
document.write('   </td></tr></table>');
document.write('   </td></tr></table>');
//document.write(char1);
	}else{
document.write('<table width="205" border="0" cellspacing="0" cellpadding="0"><tr>');
document.write('    <td height="34"><img src="/images/userLoginTop.jpg" width="205" height="34" /></td></tr>');
document.write('  <tr><td height="220" align="center" valign="bottom" style="background:url(/images/userLoginCon.jpg) no-repeat;">');
document.write('    <form method="post" action="/login.jsp" name="formlogin">');
document.write('      <table width="170" height="185" border="0" cellspacing="0" cellpadding="0">');
document.write('        <tr><td colspan="3"  height="20" align="left"><label class="colorWhite">用户名：</label>');
document.write('                <input type="text" name="login_name" style="width:110px; height:18px; border:1px solid #B4B4B4;"/></td></tr>');
document.write('<tr><td height="10"></td></tr>');
document.write('        <tr><td colspan="3" height="20" align="left"><label class="colorWhite">密&nbsp;&nbsp;码：</label>');
document.write('                <input type="password" name="password" style="width:110px; height:18px; border:1px solid #B4B4B4;"/></td></tr>');
document.write('        <tr><td height="10"></td></tr>');
document.write('        <tr><td width="52" height="20" align="left"><label class="colorWhite">验证码：</label></td>');
document.write('<td align="left" width="58"><input name="passcode" style="width:50px; height:18px; border:1px solid #B4B4B4;"></td><td align="left"><IMG src="/passcode.jsp" width="50" height="20"></td></tr>');
document.write('        <tr><td colspan="3"  height="10"></td></tr>');
//document.write('<tr><td colspan="3" height="20" align="center"><input type="radio" name="usertype" value="0" checked/>');
//document.write('                <label class="colorWhite">个人</label>');
//document.write('            <input type="radio" name="usertype" value="1"/>');
//document.write('            <label class="colorWhite">企业</label></td></tr>');
document.write('        <tr><td height="10"></td></tr>');
document.write('<tr><td align="left" height="25"><a href="javascript:Login()"><img src="/images/login.gif" border="0"/></a></td>');
document.write('<td align="left" height="25"><a href="/regiest/selType.jsp"><img src="/images/zhuce.gif" border="0"/></a></td>');
document.write('<td align="left" height="25"><label class="colorRed"><a href="/regiest/findPass.jsp">忘记密码？</a></label></td></tr>');
document.write('        <tr><td height="25"></td></tr></table>');
document.write('    </form></td></tr></table>');
	}
}

startRequest();


function Login(){
	if(formlogin.login_name.value == "" || formlogin.login_name.value == null){
		alert("请输入登录名！");
		formlogin.login_name.focus();
		return;
	}
	if(formlogin.password.value == "" || formlogin.password.value == null){
		alert("请输入密码！");
		formlogin.password.focus();
		return;
	}
	if(formlogin.passcode.value.length != 4){
		alert("请输入四位验证码！");
		formlogin.passcode.focus();
		return;
	}
	formlogin.submit();
}
        

          
        
      

  

