/*
	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_nick = getCookie( "nick" );
	var unipro_login_first = unipro_login_nick.indexOf( "(" );
	var unipro_login_last = unipro_login_nick.indexOf( ")" );
	unipro_login_first = unipro_login_first + 1;
	unipro_login_uniqueid = unipro_login_nick.substring( unipro_login_first, unipro_login_last);

	unipro_clearCookie("SINA_TENNIS_COACH_" + unipro_login_uniqueid);	//标志符

	return true;
}

/*
	print_stand_unipro_head()
	功能:输出提示登录信息,横条,未登陆用户使用
*/
function print_stand_unipro_head()
{

document.write("	<table width=176 cellspacing=0>");
document.write("	<tr bgcolor=#D9D9D7><td width=106 height=28 align=center><img src=\"http://image2.sina.com.cn/ty/masterscupfantasy/images/wqatp_lp_004.gif\" width=\"84\" height=\"15\"></td>");
document.write("	<td width=70 class=nav01 style=\"padding-top:5px\"><a href=http://unipro.sina.com.cn/register.html target=_blank><font color=#0A5142>新用户注册</font></a></td>");
document.write("	</tr>");
document.write("	<tr><td colspan=2 height=134 bgcolor=#BDC3B8 align=center>");
document.write("		<form name=\"unipro_head_login_form\" method=\"post\" action=\"http://masterscupfantasy.sports.sina.com.cn/login.php\" onsubmit=\"return  unipro_checkdata();\">");
document.write("		<table cellspacing=0 class=login>");
document.write("		<tr><td>会员名:</td>");
document.write("		<td><input type=text name=\"userid\" size=12></td>");
document.write("		</tr>");
document.write("		<tr><td height=4></td></tr>");
document.write("		<tr>");
document.write("		<td>密　码:</td>");
document.write("		<td><input type=password name=\"passcode\" size=12></td></tr>");
document.write("		<tr><td height=8></td></tr>");
document.write("		<tr><td height=21><a href=\"http://unipro.sina.com.cn/getpass.html\" target=_blank>忘记密码</a></td>");
//document.write("		<td align=right><img src=\"http://image2.sina.com.cn/ty/masterscupfantasy/images/wqatp_lp_006.gif\" width=\"76\" height=\"21\" style=\"cursor:pointer\" onclick=\"document.unipro_head_login_form.submit()\"></td>");
document.write("		<td align=right><input type=\"image\" src=\"http://image2.sina.com.cn/ty/masterscupfantasy/images/wqatp_lp_006.gif\" width=\"76\" height=\"21\" style=\"cursor:pointer\" ></td>");
document.write("		</tr>");
document.write("		<tr><td height=8></td></tr>");
document.write("		<tr><td colspan=2 align=center><a href=uri# target=_blank><img src=\"http://image2.sina.com.cn/ty/masterscupfantasy/images/wqatp_lp_005.gif\" width=\"134\" height=\"21\"></a></td></tr>");
document.write("		</table>");
document.write("		</form>");
document.write("	</td></tr>");
document.write("	</table>");
/**/
}

/*
	print_stand_unipro_welcome()
	功能:输出欢迎信息,横条,未使用
*/
function print_stand_unipro_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 = "";


	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);
	}


	var coach_score = getCookie("SINA_TENNIS_COACH_SCORE_" + unipro_login_uniqueid);
	var coach_order = getCookie("SINA_TENNIS_COACH_ORDER_" + unipro_login_uniqueid);
	var coach_money = getCookie("SINA_TENNIS_COACH_MONEY_" + unipro_login_uniqueid);
	var coach_players = getCookie("SINA_TENNIS_COACH_PLAYERS_" + unipro_login_uniqueid);

	if (coach_players == '')
	{
		coach_players = '0';
	}
	else
	{
		coach_players = coach_players.split('|');
		coach_players = coach_players.length;
	}

	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=176 cellspacing=0>");
	document.write("	<tr bgcolor=#D9D9D7><td width=176 height=28 align=center><img src=\"http://image2.sina.com.cn/ty/masterscupfantasy/images/wqatp_lp_020.gif\" width=\"56\" height=\"14\"></td>");
	document.write("	</tr>");
	document.write("	<tr><td colspan=2 height=150 bgcolor=#BDC3B8 align=center>");
	document.write("		<table width=135 cellspacing=0 class=login>");
	document.write("		<tr><td width=18 height=19><img src=\"http://image2.sina.com.cn/ty/masterscupfantasy/images/wqatp_lp_021.gif\" width=\"10\" height=\"9\"></td>");
	document.write("		<td width=117>会员名： " + unipro_login_nickname + "</td>");
	document.write("		</tr>");
	document.write("		<tr><td height=19><img src=\"http://image2.sina.com.cn/ty/masterscupfantasy/images/wqatp_lp_021.gif\" width=\"10\" height=\"9\"></td>");
	document.write("		<td>排　名： " + coach_order + "</td>");
	document.write("		</tr>");
	document.write("		<tr><td height=19><img src=\"http://image2.sina.com.cn/ty/masterscupfantasy/images/wqatp_lp_021.gif\" width=\"10\" height=\"9\"></td>");
	document.write("		<td>积　分： " + coach_score + "</td>");
	document.write("		</tr>");
	document.write("		<tr><td height=19><img src=\"http://image2.sina.com.cn/ty/masterscupfantasy/images/wqatp_lp_021.gif\" width=\"10\" height=\"9\"></td>");
	document.write("		<td>金　钱： " + coach_money + "</td>");
	document.write("		</tr>");
	document.write("		<tr><td height=19><img src=\"http://image2.sina.com.cn/ty/masterscupfantasy/images/wqatp_lp_021.gif\" width=\"10\" height=\"9\"></td>");
	document.write("		<td>已购入队员：" + coach_players + "个</td>");
	document.write("		</tr>");
	document.write("		<tr><td height=30></td>");
	document.write("		<td align=right valign=bottom><img src=\"http://image2.sina.com.cn/ty/masterscupfantasy/images/wqatp_lp_022.gif\" width=\"76\" height=\"21\" onclick=\"unipro_UniProLogout();location.href='http://masterscupfantasy.sports.sina.com.cn/';\" style=\"cursor:hand\"></td>");
	document.write("		</tr>");
	document.write("		</table>");
	document.write("	</td></tr>");
	document.write("	</table>");
}


/*
	获得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 "";
}