/*
	getCookie(name)
	参数:name
			name为欲取得的cookie的名字
	功能:取得名字为name的cookie
*/
function getCookie(name) {

  var search;

  search = name + "="
  offset = document.cookie.indexOf(search) 
  if (offset != -1) {
    offset += search.length ;
    end = document.cookie.indexOf(";", offset) ;
    if (end == -1)
      end = document.cookie.length;
    return document.cookie.substring(offset, end);
  }
  else
    return "";
}

/*
	unipro_clearCookie(name)
	参数:name
			name为欲清空cookie的名字
	功能:清除名字为name的cookie
*/
function unipro_clearCookie(name ) {
	document.cookie=name+"=; " + "domain=sina.com.cn; path=/; ";     
	//bites = document.cookie.split("; ");
}

/*
	用户登陆检测
*/
function unipro_checkdata()
{
	if ( document.unipro_head_login_form.userid.value == "" || document.unipro_head_login_form.userid.value == "null" || document.unipro_head_login_form.userid.value == null || document.unipro_head_login_form.userid.value == "undefined" )
	{
		alert("用户名不可以为空");
        return false;
	}
	if ( document.unipro_head_login_form.passcode.value == "" || document.unipro_head_login_form.passcode.value == "null" || document.unipro_head_login_form.passcode.value == null || document.unipro_head_login_form.passcode.value == "undefined" )
	{
		alert("密码不可以为空");
        return false;
	}
	return true;
}

/*
	unipro_UniProLogout()
	功能:安全退出时清除COOKIE
*/
function unipro_UniProLogout() {
	unipro_clearCookie("SINAPRO");
	unipro_clearCookie("SINA-AVATAR");
	unipro_clearCookie("SINAPROC");
	unipro_clearCookie("nick");
	unipro_clearCookie("SINA_NU");      
	unipro_clearCookie("SINA_OU");
	unipro_clearCookie("appmask");
	unipro_clearCookie("gender");
	unipro_clearCookie("UNIPROTM");
	unipro_clearCookie("UNIPROU");
	unipro_clearCookie("SINA_USER");
	unipro_clearCookie("SMS_COOKIE");
	unipro_clearCookie("SID");
	unipro_clearCookie("PAYSID");

	//清除教练自己的cookie
	var unipro_login_nickname = getCookie( "nick" );
	var unipro_login_nick = getCookie( "nick" );
	var unipro_login_first = unipro_login_nick.indexOf( "(" );
	var unipro_login_last = unipro_login_nick.indexOf( ")" );
	var unipro_login_uniqueid = "";

	if ( unipro_login_first != -1 && unipro_login_last != -1)
	{
		unipro_login_first = unipro_login_first + 1;
		unipro_login_last = unipro_login_last;
		unipro_login_uniqueid = unipro_login_nick.substring( unipro_login_first, unipro_login_last);
	}
	unipro_clearCookie("SINA_BOOKCLUB_" + unipro_login_uniqueid);	//标志符

	return true;
}

/*
	print_stand_unipro_head()
	功能:输出提示登录信息,横条,未登陆用户使用
*/
function print_stand_book_head()
{
document.write(" <table width=\"98%\" border=\"0\">");
document.write("<form name=\"unipro_head_login_form\" method=\"post\" action=\"http://club.book.sina.com.cn/login.php\" onsubmit=\"return  unipro_checkdata();\"><input type=\"hidden\" name=\"action\" value=\"login\">");
document.write( "      <tr> ");
document.write( "        <td align=\"center\" height=\"20\"> 登录名： ");
// onMouseOver=this.focus() onFocus=this.select() onClick=this.value=''
document.write( "          <input type=text style=\"padding-top:3px;height:20px;width:100px\" class=s01 size=16 name=userid maxlength=80  >");
document.write("        </td>");
document.write("      </tr>");
document.write("      <tr> ");
document.write("        <td align=\"center\">密&nbsp;&nbsp;码： ");
document.write("          <input type=password style=\"padding-top:3px;height:20px;width:100px\" class=s01 size=16 name=passcode maxlength=80>");
document.write("        </td>");
document.write("      </tr>");
document.write("      <tr> ");
document.write("        <td align=\"center\" height=\"14\" style=\"padding-top:5px\" valign=\"bottom\"> ");
document.write("          <input type=image src=http://image2.sina.com.cn/dy/images/001A.GIF name=\"image\" align=\"bottom\">");
document.write("          &nbsp;<a href=http://unipro.sina.com.cn/getpass.html target=_blank>忘记密码</a></td>");
document.write("      </tr>");
document.write("      <tr>");
document.write("        <td align=\"center\" height=\"14\" valign=\"top\"><a href=\"http://unipro.sina.com.cn/cgi-bin/new_regist0.cgi?url1=&url2=http://club.book.sina.com.cn/update.php&id1=1&id2=0&entry=clubbook&mcheck=34a134c77929f876a457541daea4bf16\" class=a03 target=_blank><img src=http://image2.sina.com.cn/dy/images/001D.GIF border=0 align=\"absmiddle\"></a>&nbsp;&nbsp;<a href=http://unipro.sina.com.cn/help/article/14.html target=_blank>使用指南</a></td>");
document.write("      </tr>");
document.write("    </form> ");
document.write("    </table> ");
}

/*
	print_stand_unipro_welcome()
	功能:输出欢迎信息,横条,给不是书友会的用户来使用
*/
function print_stand_book_welcome()
{
	var unipro_login_nickname = getCookie( "nick" );
	var unipro_login_nick = getCookie( "nick" );
	var unipro_login_pos = unipro_login_nickname.indexOf( "(" );
	var unipro_login_first = unipro_login_nick.indexOf( "(" );
	var unipro_login_last = unipro_login_nick.indexOf( ")" );
	var unipro_login_uniqueid = "";

	var efootball_coach_count = getCookie("SINA_ITA_COACH_COUNT");
	var efootball_coach_score = getCookie("SINA_ITA_COACH_SCORE");
	var efootball_coach_order = getCookie("SINA_ITA_COACH_ORDER");

	if ( unipro_login_pos != -1 )
	{
		unipro_login_nickname = unipro_login_nickname.substr( 0, unipro_login_pos );
	}

	if ( unipro_login_first != -1 && unipro_login_last != -1)
	{
		unipro_login_first = unipro_login_first + 1;
		unipro_login_last = unipro_login_last;
		unipro_login_uniqueid = unipro_login_nick.substring( unipro_login_first, unipro_login_last);
	}

	if ( unipro_login_nickname!="" && unipro_login_nickname!="null" && unipro_login_nickname!=null && unipro_login_nickname!="undefined" ) 
	{
		//document.write(unipro_login_nickname+" ，您好 </td>");
	} 
	else 
	{
		unipro_login_nickname = "过客";
	}
	if ( unipro_login_uniqueid!="" && unipro_login_uniqueid!="null" && unipro_login_uniqueid!=null && unipro_login_uniqueid!="undefined" ) 
	{
		//document.write(unipro_login_uniqueid+"</td>");
	}
	else 
	{
		unipro_login_uniqueid = "未知";
	}
	
	document.write("<table width=\"98%\" border=\"0\">");
	document.write("<tr><td><div align=\"center\">");
	document.write(" 	<table width=\"100%\" border=\"0\" cellspacing=\"5\" cellpadding=\"5\">");
	document.write("	<tr><td><div align=\"center\">");
	document.write("		<p align=\"left\"><font color=\"#FF0000\" face=\"Arial, Helvetica, sans-serif\">" + unipro_login_nickname + "</font> <font color=\"#000000\">您好：</font><br>");
	document.write("		<span class=\"l14\"><font color=\"#FF0000\">　　您尚未加入新浪书友会，<br>");
	document.write("		<a href=\"http://club.sina.com.cn/update.php\">点击补充</a>少量信息您就是书友会正式会员啦！</font><font face=\"Arial, Helvetica, sans-serif\">:D</font><br>");
	document.write("		　　<a href=\"http://book.sina.com.cn/111/2005/0601/1.html\" target=\"_blank\">关于新浪书友会</a></span></p>");	
	document.write("	</div></td></tr>");
	document.write("	</table>");
	document.write("</div></td></tr>");
	document.write("      <tr> ");
	document.write("        <td align=\"center\" height=\"30\"> <a href=\"http://club.book.sina.com.cn/update.php\"><img src=\"http://image2.sina.com.cn/book/club/images/04.gif\" width=\"75\" height=\"19\" border=\"0\"></a> ");
	document.write("           <img src=\"http://image2.sina.com.cn/book/club/images/03.gif\" width=\"65\" height=\"19\" border=\"0\" onclick=\"javascript:getUniproUrl_welcome();\" style=\"cursor:hand\"> ");
	document.write("        </td>");
	document.write("      </tr>");
	document.write("    </table>");
}


function print_stand_manage_head()
{
	var unipro_login_nickname = getCookie( "nick" );
	var unipro_login_nick = getCookie( "nick" );
	var unipro_login_pos = unipro_login_nickname.indexOf( "(" );
	var unipro_login_first = unipro_login_nick.indexOf( "(" );
	var unipro_login_last = unipro_login_nick.indexOf( ")" );
	var unipro_login_uniqueid = "";

	if ( unipro_login_pos != -1 )
	{
		unipro_login_nickname = unipro_login_nickname.substr( 0, unipro_login_pos );
	}

	if ( unipro_login_first != -1 && unipro_login_last != -1)
	{
		unipro_login_first = unipro_login_first + 1;
		unipro_login_last = unipro_login_last;
		unipro_login_uniqueid = unipro_login_nick.substring( unipro_login_first, unipro_login_last);
	}

	if ( unipro_login_nickname!="" && unipro_login_nickname!="null" && unipro_login_nickname!=null && unipro_login_nickname!="undefined" ) 
	{
		//document.write(unipro_login_nickname+" ，您好 </td>");
	} 
	else 
	{
		unipro_login_nickname = "过客";
	}
	if ( unipro_login_uniqueid!="" && unipro_login_uniqueid!="null" && unipro_login_uniqueid!=null && unipro_login_uniqueid!="undefined" ) 
	{
		//document.write(unipro_login_uniqueid+"</td>");
	} 
	else 
	{
		unipro_login_uniqueid = "未知";
	}

	document.write("<table width=\"98%\" border=\"0\">");
	document.write("<tr><td><div align=\"center\">");
	document.write(" 	<table width=\"100%\" border=\"0\" cellspacing=\"5\" cellpadding=\"5\">");
	document.write("        <tr><td><div align=\"center\"><font color=\"#FF0000\">欢迎回来，<strong>" + unipro_login_nickname + " </strong><br></font> <a href=\"http://club.book.sina.com.cn/club/pmanage.php\">进入书友会</a></div></td></tr>");
	document.write("        </table>");
	document.write("</div></td></tr>");
	document.write("<tr><td>");
	document.write("        <table border=0 align=\"center\" cellpadding=0 cellspacing=0>");
	document.write("	<tr>");
	document.write("          <td width=76 height=21><input type=button style=\"background-image:url(http://image2.sina.com.cn/book/club/images/dusy_lj_18.gif);border-width:0px;width:75;height:21;padding-top:1px;cursor:hand\" value=\"我的藏书\" onClick=\"parent.window.location.href='http://club.book.sina.com.cn/club/collection.php';\" ></td>");
	document.write("          <td width=4></td>");
	document.write("          <td width=75><input type=button style=\"background-image:url(http://image2.sina.com.cn/book/club/images/dusy_lj_18.gif);border-width:0px;width:75;height:21;padding-top:1px;cursor:hand\" value=\"我的好友\" onClick=\"parent.window.location.href='http://club.book.sina.com.cn/club/friendlist.php';\"></td>");
	document.write("        </tr>");
	document.write("        <tr> <td height=4></td></tr>");
	document.write("	<tr>");
	document.write("	  <td width=76 height=21><input type=button style=\"background-image:url(http://image2.sina.com.cn/book/club/images/dusy_lj_18.gif);border-width:0px;width:75;height:21;padding-top:1px;cursor:hand\" onClick=\"parent.window.location.href='http://club.book.sina.com.cn/club/chginfo.php';\" value=\"修改信息\"></td>");
	document.write("          <td width=4></td>");
	document.write("          <td width=75><input type=button style=\"background-image:url(http://image2.sina.com.cn/book/club/images/dusy_lj_18.gif);border-width:0px;width:75;height:21;padding-top:1px;cursor:hand\" value=\"稿件管理\"  onClick=\"parent.window.location.href='http://bookreg.sina.com.cn/serialize/writing_admin.php';\"></td>");
	document.write("        </tr>");
	document.write("        <tr> <td height=4></td></tr>");
	document.write("	<tr>");
	document.write("          <td width=76 height=21><input type=button style=\"background-image:url(http://image2.sina.com.cn/book/club/images/dusy_lj_18.gif);border-width:0px;width:75;height:21;padding-top:1px;cursor:hand\" value=\"书友俱乐部\"></td>");
	document.write("          <td width=4></td>");
	document.write("          <td width=75><img src=\"http://image2.sina.com.cn/book/club/images/03.gif\" width=\"65\" height=\"19\" border=\"0\" onclick=\"javascript:getUniproUrl_welcome();\" style=\"cursor:hand\"></td>");
	document.write("        </tr>");
	document.write("        <tr> <td height=4></td></tr>");
	document.write("        </table>");
	document.write("</td></tr>");
	document.write("</table>");
	
}

function getUniproUrl_welcome(){
	unipro_UniProLogout();
	window.location='http://book.sina.com.cn';
	return false;	
}
/*
	获得URL参数的值
*/
function getParamter(name)
{
	if (typeof(name) == 'undefined')
	{
		return "";
	}

	search = name + "="
	offset = document.URL.indexOf(search) 
	if (offset != -1) 
	{
		offset += search.length ;
		end = document.URL.indexOf("&", offset) ;
		if (end == -1)
			end = document.URL.length;
		return document.URL.substring(offset, end);
	}
	else
		return "";
}

function print_stand_book_welcome2()
{
	document.write("<p><font color=\"#333333\">");
	document.write(" 　　您尚未加入新浪书友会，<a href=\"http://club.book.sina.com.cn/update.php\" class=\"a17\">点击这里添加</a>少量信息您将成为新浪书友会正式会员！<br>");
	document.write(" 　　 　　 　<a href=\"http://club.book.sina.com.cn/update.php\" class=\"a17\">立刻加入</a></font></p>");
	
}

function print_stand_book_head2(entry)
{
	
	document.write("                    <p><form action=\"http://club.book.sina.com.cn/login.php\" METHOD=POST name=\"unipro_head_login_form\" onsubmit=\"return  unipro_checkdata();\">");
	document.write("<input type=\"hidden\" name=\"action\" value=\"login\"><input type=\"hidden\" name=\"entry\" value="+entry+">");
	document.write(" 新浪会员名：<INPUT NAME=\"userid\" TYPE=\"text\" size=\"15\"><br>");
	document.write(" 　　密　码：<INPUT NAME=\"passcode\" TYPE=\"Password\" size=\"15\"> <br>");
	document.write("<div align=center><input name=\"submit2\" type=submit style=\"width:35;height:20;padding-top:1px;color:#\" value=\"登录\"> &nbsp;&nbsp;<a href=\"http://unipro.sina.com.cn/getpass.html\" target=\"_blank\" class=\"a17\">忘记密码</a> <a href=\"http://unipro.sina.com.cn/cgi-bin/new_regist0.cgi?url1=&url2=http://club.book.sina.com.cn/update.php&id1=1&id2=0&entry=clubbook&mcheck=34a134c77929f876a457541daea4bf16\" target=\"_blank\" class=\"a17\">注册</a> </div></form></p>");
}

function print_stand_manage_head2()
{
	var unipro_login_nickname = getCookie( "nick" );
	var unipro_login_nick = getCookie( "nick" );
	var unipro_login_pos = unipro_login_nickname.indexOf( "(" );
	var unipro_login_first = unipro_login_nick.indexOf( "(" );
	var unipro_login_last = unipro_login_nick.indexOf( ")" );
	var unipro_login_uniqueid = "";

	if ( unipro_login_pos != -1 )
	{
		unipro_login_nickname = unipro_login_nickname.substr( 0, unipro_login_pos );
	}

	if ( unipro_login_first != -1 && unipro_login_last != -1)
	{
		unipro_login_first = unipro_login_first + 1;
		unipro_login_last = unipro_login_last;
		unipro_login_uniqueid = unipro_login_nick.substring( unipro_login_first, unipro_login_last);
	}

	if ( unipro_login_nickname!="" && unipro_login_nickname!="null" && unipro_login_nickname!=null && unipro_login_nickname!="undefined" ) 
	{
		//document.write(unipro_login_nickname+" ，您好 </td>");
	} 
	else 
	{
		unipro_login_nickname = "过客";
	}
	if ( unipro_login_uniqueid!="" && unipro_login_uniqueid!="null" && unipro_login_uniqueid!=null && unipro_login_uniqueid!="undefined" ) 
	{
		//document.write(unipro_login_uniqueid+"</td>");
	} 
	else 
	{
		unipro_login_uniqueid = "未知";
	}
	
	document.write("<p align=center><font color=\"#333333\">");
	document.write("欢迎回来，<font color=red><b> " + unipro_login_nickname + "</b></font></font><br>");
	document.write("<a href=\"http://club.book.sina.com.cn/club/pmanage.php\" class=\"a17\">进入书友会</a><br><img src=\"http://image2.sina.com.cn/book/club/images/03.gif\" width=\"65\" height=\"19\" border=\"0\" onclick=\"javascript:getUniproUrl_welcome();\" style=\"cursor:hand\"></p>");
}

function isEnglish(name)
{
	if(name.length == 0)
	{
		return false;
	}
	for(i=0; i<name.length; i++)
	{
		if(name.charCodeAt(i) > 128)
		{
			return false;
		}
	}
	return true;
}

function isMail(name)
{
	if(name.length == 0)  //Email为空
	{
		return true;
	}
	if(!isEnglish(name))
	{
		return false;
	}
	var i = name.indexOf("@");
	var j = name.lastIndexOf("@");
	if(i == -1 || i != j || i == name.length-1 || i == 0)
	{
		return false;
	}
	return true;
}

function isNull(name)
{
	if(name.length == 0)
	{
		return true;
	}
	for(i=0; i<name.length; i++)
	{
		if(name.charAt(i) != ' ')
		{
			return false;
		}
	}
	return true;
}

function isDigit(name)
{
	if(name.length == 0)
	{
		return false;
	}
	for(i=0; i<name.length; i++)
	{
		if(name.charCodeAt(i) > 57 || name.charCodeAt(i) < 48)
		{
			if(name.charCodeAt(i) != 45)
			{
				return false;
			}
			
		}
	}
	return true;
}

function check_form()
{
	if(isNull(document.memberform.nick.value))
        {
        	alert("请输入您的昵称！");
		document.memberform.nick.focus();
		return false;
        }
        if(isNull(document.memberform.realname.value))
        {
        	alert("请输入您的真实姓名！");
		document.memberform.realname.focus();
		return false;
        }
        if(document.memberform.province.selectedIndex == 0 || document.memberform.city.selectedIndex == 0)
        {
        	alert("请选择您所在地区！");
		document.memberform.province.focus();
		return false;
        }
        var email = document.memberform.email.value;
        if(isNull(email))
        {
        	alert("请输入一个有效email地址！");
		document.memberform.email.focus();
		return false;
        }
	else
	{
		if(!isMail(email))
        	{
	        	alert("电子邮件不合法！");
	        	document.memberform.email.focus();
	        	return false;
       		}
	}
	var phone = document.memberform.phone.value;
	if(!isNull(phone))
	{
		if(!isDigit(phone))
		{
			alert("电话号码包含非法字符！");
	        	document.memberform.phone.focus();
	        	return false;
		}
	}
        if(isNull(document.memberform.tool_id.value))
        {
        	alert("请输入一种即时通讯工具联系方式！");
		document.memberform.tool_id.focus();
		return false;
        }
        if(isNull(document.memberform.sign.value))
        {
        	alert("请输入您的读书心得！");
		document.memberform.sign.focus();
		return false;
        }
        var flag=0;
	for (i=0; i<document.memberform.elements.length; i++)
	{
		if(document.memberform.elements[i].type == "checkbox" && document.memberform.elements[i].name != "recv_flag" && document.memberform.elements[i].checked)
		{
			flag = 1;
		}
	}
	if(flag==0)
	{
		if(isNull(document.memberform.otherhobby.value))
		{
			alert("请选择兴趣爱好！");
			return false;
		}
		flag = 1;
		
	}
	
        return true;
      
}

//返回头像avatar串
function get_avatar()
{
	var avatar = getCookie("SINA-AVATAR");
	var gender = getCookie("gender");
	if(avatar == "")
	{
		if(gender == 1)
		{
			avatar = "0|0|0|0|1|1|1|1|0|1|0|0|1|0|0|0|1|0|0|0|0|0|0|0|0|0";  //男性默认头像
		}
		else
		{
			avatar = "0|0|0|0|2|2|6|2|0|2|0|0|2|0|0|0|2|0|0|0|0|0|0|0|0|0";  //女性默认头像
		}
	}
	avatar = unescape(avatar);
	//document.write(avatar);
	return avatar;
	
}

function search_submit()
{
	var tmp = 1;

	for(var i =0;i<document.search_form.types.length;i++)
	{
		if(document.search_form.types[i].checked)
		{
			tmp = document.search_form.types[i].value;
		}
	}

	if(tmp == 0)
	{	
		document.search_form.action="http://bookreg.sina.com.cn/search/book_result.php";
		document.search_form.submit();			
	} 
	else
	if(tmp == 1)
	{	
		document.search_form.action="http://club.book.sina.com.cn/yuanchuang/search.php";
		document.search_form.submit();			
	}
	else
	{	
		document.search_form.action="http://club.book.sina.com.cn/club/search.php";
		document.search_form.submit();			
	} 
	return false;
}

function check_data()
{
	if(document.myform.saidContent.value == "" )
	{
		alert("请输入你对好友说的话");
		return false;
	}
	return true;
}

function check_data2()
{
	var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$"
	var re = new RegExp(regu);
	if( document.myform.acceptMail.value == "" )
	{
		alert("请输入需要发送的邮件地址");
		return false;
	}
	else
	{
		var email = document.myform.acceptMail.value;
		var emails = email.split(",");	
		for( var i=0; i < emails.length; i++ )
		{
		        if (emails[i].search(re) == -1) 
		        {
			 alert (emails[i]+"邮件地址不合法!");
			 return false;
		        }
		}
	}
	if( document.myform.copyMail.value != "" )
	{
		var copymail = document.myform.copyMail.value;
		var copymails = copymail.split(",");
		for( var j=0; j < copymails.length; j++ )
		{
		        if (copymails[j].search(re) == -1) 
		        {
			 alert (copymails[j]+"邮件地址不合法!");
			 return false;
		        }
		}
	}
	if(document.myform.userMail.value =="" )
	{
		alert("请输入你的EMAIL地址");
		return false;
	}
	else
	{
		var userMail = document.myform.userMail.value;
		if ( userMail.search(re) == -1 ) 
		{
			 alert (userMail+"邮件地址不合法!");
			 return false;
		 }
	}
	
	if(document.myform.saidContent.value == "" )
	{
		alert("请输入你对朋友说的话");
		return false;
	}
	return true;
}

function show_kw(oSender)
{
	if(oSender.options[oSender.selectedIndex].value == "gender")
	{
		document.all('book4').style.display='none';
		document.all('book5').style.display='';
		document.all('book6').style.display='none';
	}
	else if(oSender.options[oSender.selectedIndex].value == "area")
	{
		document.all('book4').style.display='none';
		document.all('book5').style.display='none';
		document.all('book6').style.display='';
	}
	else
	{
		document.all('book4').style.display='';
		document.all('book5').style.display='none';
		document.all('book6').style.display='none';
	}
}

function autofit()
{
	parent.document.all("menu").style.height=document.body.scrollHeight+0
}

function del_confirm(sid)
{
	if(confirm('您确定要删除吗?'))
	{
		window.open("/club/del_sms.php?sid="+sid);
	}
	
}

function del_confirm2(sid)
{
	if(confirm('您确定要删除吗?'))
	{
		window.location="/club/del_sms.php?sid="+sid;
	}
	
}