/*
 * author : smallfish <smallfish.xy@gmail.com>
 * file   : by.web.login.js
 * desc   : web login form
 */

writeCookie("cookieOpen","1",1000000);

function check_login(formname){
    if (formname.username.value == ""){
        alert("百阅号不能为空！");
        formname.username.focus();
        return false;	
    }
    if(formname.password.value==""){
        alert("密码不能为空！");
        formname.password.focus();
        return false;	
    }
    if(formname.randimg.value==""){
        alert("验证码不能为空！");
        formname.randimg.focus();
        return false;	
    }
    return true;
}

// output the login form
if (readCookie("cookieOpen") != ""){
    if(readCookie("userName") != ""){
        pout('<table width="100%" border="0" cellspacing="4" cellpadding="4" align="center">');
        pout('<tr>');
        pout('<td height="25">' + decode(readCookie("userName")) + "（" + decode(readCookie("byId")) + '）您好！<br>');
        pout('头衔：' + decode(readCookie("titleName")) + '</td>');
        pout('</tr>');
        pout('<tr>');
        pout('<td><a href="http://www.byread.com/userinfo.do">我的信息</a> | <a href="http://www.byread.com/edituserinfo.do">修改资料</a></td>');
        pout('</tr>');
        pout('<tr>');
        pout('<td><input type="button" onclick="window.location.href=\'http://www.byread.com/logout.do\'" value="退出登录"> </td>');
        pout('</tr>');
        pout('</table>');       
    } else {
        pout('<table width="100%" border="0" cellspacing="4" cellpadding="4" align="left">');
        pout('<form method="post" action="http://www.byread.com/loginbyid.do" onsubmit="return check_login(this)">');
        pout('<tr>');
        pout('<td width="40%" height="25" align="right">百阅号：</td>');
        pout('<td width="60%" align="left"><input type="text" name="username" size="12" /></td>');
        pout('</tr>');
        pout('<tr> ');
        pout('<td height="25" align="right">密 码：</td>');
        pout('<td align="left"><input type="password" name="password" size="12" /></td>');
        pout('</tr>');
        pout('<tr>');
        pout('<td height="25" align="right">验证码：</td>');
        pout('<td align="left"><input type="text" name="randimg" size="4" /> <img src="http://www.byread.com/public/randimg.jsp" align="absmiddle" /></td>');
        pout('</tr>');
        pout('<tr>');
        pout('<td height="25" align="right">Cookie：</td>');
        pout('<td align="left"><select name="CookieDate">');
        pout('<option value="0" selected>不保存</option>');
        pout('<option value="1">保存一天</option>');
        pout('<option value="2">保存一月</option>');
        pout('<option value="3">保存一年</option>');
        pout('</select>');
        pout('</td>');
        pout('</tr>');
        pout('<tr>');
        pout('<td height="25" align="right"><input type="submit" value="登录"></td>');
        pout('<td align="left"><a href="http://www.byread.com/reg_01.htm">注册</a></td>');
        pout('</tr>');
        pout('</form>');
        pout('</table>');
    }
}else{
    pout("请打开浏览器Cookie选项");
}
