var jieqiUserId = 0;
var jieqiUserName = '';
var jieqiUserHonor = '';
var jieqiUserPassword = '';
var jieqiUserGroup = 0;
var jieqiNewMessage = 0;

if(document.cookie.indexOf('jieqiUserInfo') >= 0){
	
	var jieqiUserInfo = get_cookie_value('jieqiUserInfo');
	
	start = 0;
	offset = jieqiUserInfo.indexOf(',', start); 
	while(offset > 0){
		tmpval = jieqiUserInfo.substring(start, offset);
		tmpidx = tmpval.indexOf('=');
		if(tmpidx > 0){
           tmpname = tmpval.substring(0, tmpidx);
		   tmpval = tmpval.substring(tmpidx+1, tmpval.length);
		   if(tmpname == 'jieqiUserId') jieqiUserId = tmpval;
		   else if(tmpname == 'jieqiUserName_un') jieqiUserName = tmpval;
		   else if(tmpname == 'jieqiUserHonor_un') jieqiUserHonor = tmpval;
		   else if(tmpname == 'jieqiUserPassword') jieqiUserPassword = tmpval;
		   else if(tmpname == 'jieqiUserGroup') jieqiUserGroup = tmpval;
		   else if(tmpname == 'jieqiNewMessage') jieqiNewMessage = tmpval;
		}
		start = offset+1;
		if(offset < jieqiUserInfo.length){
		  offset = jieqiUserInfo.indexOf(',', start); 
		  if(offset == -1) offset =  jieqiUserInfo.length;
		}else{
          offset = -1;
		}
	}
}
if(jieqiUserId != 0 && jieqiUserName != '' && (document.cookie.indexOf('PHPSESSID') != -1 || jieqiUserPassword != '')){
  document.write('<table width="550"  border="0" cellspacing="0" cellpadding="0">');
  document.write('<tr>');
  document.write('<td style="height: 26px;">&nbsp;欢迎您回来“<font color=#ff0000>'+jieqiUserHonor+'</font>”&nbsp;<b><font color=#ff0000>'+jieqiUserName+'</font></b>');
  document.write('&nbsp;&nbsp;<a href="/userdetail.php"><font color=#800080>查看资料</font></a>');  
  document.write(' | <a href="/modules/article/bookcase.php"><font color=#800080>我的书架</font></a>');  
  	if(jieqiNewMessage>0){
		document.write(' | <a href="/message.php?box=inbox"><font color="#ff0000">您有新消息</font></a>');
		}
	else{
		document.write(' | <a href="/message.php?box=inbox"><font color=#800080>查看短信</font></a>');
	}
  document.write(' | <a href="/logout.php" target="_self" class="green_12"><font color=#800080>[退出登陆]</font></a>&nbsp;</td>');
  document.write('</tr>');
  document.write('</table>');

}else{
  var jumpurl="";
  if(location.href.indexOf("jumpurl") == -1){
    jumpurl=location.href;
  }
  document.write('<table width="550"  border="0" cellspacing="0" cellpadding="0">');
  document.write('<form name="framelogin" method="post" target="_top" action="/login.php">');
  document.write('<tr>');
  document.write('<td align=left><font color=#ff0000>您还没有登录!</font>┊<a href="/register.php">注册</a> 登陆↓ 帐号：');
  document.write('<input name="username" type="text" class="text" onkeypress="javascript: if (event.keyCode==32) return false;" value="" size="8" maxlength="30" />');
  document.write('&nbsp;&nbsp;密码：<input type="password" class="text" size="8" maxlength="30" name="password" />');
  document.write('<input type="hidden" name="action" value="login" />');
  document.write('<input type="hidden" name="jumpurl" value="'+jumpurl+'" />');
  document.write('&nbsp;&nbsp;<input type="checkbox" class="mycheckbox" name="usecookie" value="1" />');
  document.write('&nbsp;记录cookie&nbsp;');
  document.write('<input  name="submit" type="image"  src="/images/tt/login.gif" align="middle" />');
  document.write('</td>');
  document.write('</tr>');
  document.write('</form>');
  document.write('</table>');
}


function get_cookie_value(Name) { 
  var search = Name + "=";
　var returnvalue = ""; 
　if (document.cookie.length > 0) { 
　  offset = document.cookie.indexOf(search) 
　　if (offset != -1) { 
　　  offset += search.length 
　　  end = document.cookie.indexOf(";", offset); 
　　  if (end == -1) 
　　  end = document.cookie.length; 
　　  returnvalue=unescape(document.cookie.substring(offset, end));
　　} 
　} 
　return returnvalue; 
}

//search
function setsrch(c){
	for(i=0;i<=2;i++){
		document.getElementById("stab"+i).className = "";
	}
	c.className = "so1";
	if(c.id=="stab0"){
	document.getElementById("searchq").style.display="";
	document.getElementById("searchq1").style.display="none";
	document.getElementById("searchq2").style.display="none";
		document.getElementById("stab10").innerHTML='书籍名称';
		document.getElementById("stab11").innerHTML='<a title="按作者名称搜索书籍"  href="javascript:void(0);" target=_self class="so2">作者名称</a>';
		document.getElementById("stab12").innerHTML='<a title="按主角名称搜索书籍"  href="javascript:void(0);" target=_self class="so2">主角名称</a>';
		document.srchfrm.action="name";document.srchfrm.q.value="请输入书籍名称关键字！";
		 if(document.srchfrm.q.value=='请请输入书籍名称关键字！'){
			 document.srchfrm.q.style.color='#989797';
		}
	}
	if(c.id=="stab1"){
	document.getElementById("searchq").style.display="none";
	document.getElementById("searchq1").style.display="";
	document.getElementById("searchq2").style.display="none";
		document.getElementById("stab10").innerHTML='<a title="按书籍名称搜索"  href="javascript:void(0);" target=_self class="so2">书籍名称</a>';
		document.getElementById("stab11").innerHTML='作者名称';
		document.getElementById("stab12").innerHTML='<a title="按主角名称搜索书籍"  href="javascript:void(0);" target=_self class="so2">主角名称</a>';
		document.srchfrm.action="author";document.srchfrm.q1.value="请输入作者名称关键字！";
		 if(document.srchfrm.q1.value=='请输入作者名称关键字！'){
			document.srchfrm.q1.style.color='#989797';
		}
	}

	if(c.id=="stab2"){
	document.getElementById("searchq").style.display="none";
	document.getElementById("searchq1").style.display="none";
	document.getElementById("searchq2").style.display="";
		document.getElementById("stab10").innerHTML='<a title="按书籍名称搜索"  href="javascript:void(0);" target=_self class="so2">书籍名称</a>';
		document.getElementById("stab11").innerHTML='<a title="按作者名称搜索书籍"  href="javascript:void(0);" target=_self class="so2">作者名称</a>';
		document.getElementById("stab12").innerHTML='主角名称';
		document.srchfrm.action="director";document.srchfrm.q2.value="请输入主角名称关键字！";
		 if(document.srchfrm.q2.value=='请输入主角名称关键字！'){
			document.srchfrm.q2.style.color='#989797';
		}
	}
}

function submitForm(){
	if(document.srchfrm.action=='director'){
		top.location.href= "/modules/article/search.php?searchtype=author&searchkey="+document.srchfrm.q2.value+"";
	}else if(document.srchfrm.action=='author'){
		top.location.href= "/modules/article/search.php?searchtype=author&searchkey="+document.srchfrm.q1.value+"";
	}else {
		top.location.href= "/modules/article/search.php?searchtype=articlename&searchkey="+document.srchfrm.q.value+"";	
	}
}
