// 提交标志
var rlflag = 1;
// 会员到期前，哪些天需要提醒
var TX_DAYS = {7:1, 3:1, 2:1, 1:1, 0:1};

//页面登录信息初始化
// 需要优化： 将会员、非会员、体验会员  分开实现
// 最好能先填充文档结构，  然后填充
function initLogininfo()
{
	 recordRefer();
 	 var leftDiv = $("userinfro_leftdiv");
	 var ktDiv = $('div_kaitong');
	 if(leftDiv) leftDiv.innerHTML = buildLeftDivHTML();
	 if(ktDiv) ktDiv.innerHTML = buildKaiTongDivHTML();
	    
    
	//判断提交那个提交表单(登陆 |注册)
	//登陆框
	 if($('u')){
	 	$('u').onfocus = function(){rlflag = 1;};
	 }
	 if($('p')){
		$('p').onfocus = function(){rlflag = 1;getOnfocusVerifyCode(1);};
	 }
	 if($('verifycode') && $('vcode_p')){
		$('verifycode').onfocus = function(){
			rlflag = 1;
			getOnfocusVerifyCode(1);
		};
     }
	 
	 var sessionid = getCookie("sessionid");
	 if(sessionid== null){sessionid="";}
	 var vip_sessionid = getCookie("vip_sessionid");  
	 if(vip_sessionid== null){vip_sessionid="";}
	 //没有登录
	 if(vip_sessionid == "-1" || sessionid.length < 32){
	    if(leftDiv) showLayer(leftDiv);
		if(ktDiv) showLayer(ktDiv);
		if($('u')) $('u').focus();
		// 在其他系统退出登录后，  回到会员中心， 需要清除cookie
		if(vip_sessionid != "") clearCookie();
		return ;
	 }
	 var username = getCookie("vip_usrname");	//用户名
	 //没有在vip会员中心登陆过，必要考虑到静态页面调用
	 if(vip_sessionid == "" || (vip_sessionid!="" && sessionid!=vip_sessionid)){
		setCookie("vip_cburl",getnocacheurl(top.location.href));
		refreshVipUserInfo();
		return ;
	 }
	 var nickname = getCookie("vip_nickname");	//昵称
	 nickname = nickname.strip();
	 var memberage = getCookie("vip_growvalue");	//会员成长值
	 var deadline = getCookie("vip_expiredate");	//到期时间
	 var vip_level = getCookie("vip_level");	    //会员级别;已登陆的非会员默认为0;
	 var vip_paytype = getCookie("vip_paytype");    //支付方式
	 var vip_isvip = getCookie("vip_isvip");        // 是否是 vip
	 var usernewno = getCookie("usernewno");        // 用户号码   -1未登录，  0 老帐号，未升级
	 var trialvip = getCookie("vip_trialvip");      // 是否是体验会员
	 var trialday = getCookie("vip_trialday");      // 体验会员剩余天数
	 var vip_isgoodnum = getCookie("vip_is_good_number");
	 var growInfo = "";   
	 var nickname_class = '';
	 var levelStr = '<img src="http://img.vip.xunlei.com/img/base/vip1_0.gif" title="迅雷会员等级为VIP1"/>';
	 var vip_isyear = getCookie("vip_isyear");	//是否按年付费;已登陆的非会员默认为0:不是;
	 var isyearStr = '<img src="http://img.vip.xunlei.com/img/base/icon_nian_0.gif" title="迅雷年费会员"/>&nbsp;';
	 var isgoodnumStr = '<img src="http://img.vip.xunlei.com/img/base/icon_shuai_0.gif" title="商城号码"/>';
	 var usernameStr = '用户名:'+username;
	 if( usernewno>0 ) {
		 usernameStr = '号码:'+usernewno;
	 }
	 if(vip_paytype != null && vip_paytype != "" && vip_paytype != "0") {
	    growInfo = "您的会员正在以每日" + getGrowValueByPaytype(vip_paytype) + "点的速度成长";        
	 }
	 if(trialvip == "1") {
		 levelStr = '<img src="http://img.vip.xunlei.com/img/base/vip1.gif" title="迅雷会员等级为VIP1"/>';
	 }
	 if(vip_level!= null && vip_level != "" && vip_level !="0") {
		 var viptitle = "迅雷会员等级为VIP" + vip_level;
	    if(vip_isvip!= null && vip_isvip == "1"){
	        levelStr = '<img src="http://img.vip.xunlei.com/img/base/vip' + vip_level + '.gif" title="' + viptitle + '"/>'
	                 +'<img src="http://img.vip.xunlei.com/img/base/vip_moveup.gif" title="'+growInfo+'" />';
		} else {
		    growInfo = "您的会员成长值正在以每日5点的速度下降";
		    levelStr = '<img src="http://img.vip.xunlei.com/img/base/vip' + vip_level + '_0.gif" title="' + growInfo + '"/>'
		             +'<img src="http://img.vip.xunlei.com/img/base/vip_comedown.gif" title="'+growInfo+'" />';
		}
	 }
	 
	 if(vip_isvip == "1" || trialvip == "1") {
		 nickname_class = "c_red";
	 }
	 if(vip_isyear!= null && vip_isyear != "" && vip_isyear =="1" && vip_isvip == "1")
		 isyearStr = '<img src="http://img.vip.xunlei.com/img/base/icon_nian.gif" title="迅雷年费会员"/>&nbsp;';
	 if(vip_isgoodnum!= null && vip_isgoodnum != "" && vip_isgoodnum =="1" )
		 isgoodnumStr = '<img src="http://img.vip.xunlei.com/img/base/icon_shuai.gif" title="商城号码"/>';
	 var vip_headSP = $("vip_headSP");
	 var headP = $("userinfro_headp");
	 var lixianheadP = $("lixian_userinfro_headp");
	 if(vip_headSP){
		 vip_headSP.innerHTML = '欢迎您：' + nickname + ' [<a href="javascript:logout();">退出</a>]'; 
	 }
	 if(leftDiv){
		 var htmlStr = '<h2>会员用户直接登录</h2>'
		     + '<div class="content">'
		     +     '<div style="display:block;">'
		     +         '<div class="userinfo">'
		     +             '<a href="http://i.xunlei.com/?redirecturl=modifypic" target="_blank" title="修改头像">'
		     +             '<img src="http://imain.xunlei.com/imgus/' + username + '.gif" class="user_pic" /></a>'
		     +             '<div class="names">'
			 +                 '<p>欢迎您: '
			 +                     '<span class="'+nickname_class+'" title="'+nickname+'">' + nickname + '</span>'
			 +                 '</p>'
			 +                 '<p>' + usernameStr + '</p>'
			 +                 '<a href="javascript:logout();" class="logout">[退出]</a>'
			 +             '</div>';
		 if(levelStr!= null && levelStr != ""){
			 htmlStr = htmlStr+ '<p class="service">' + levelStr + '&nbsp;' + isyearStr + isgoodnumStr + ' </p>'
		 }
		 htmlStr = htmlStr+ '</div>';
		 if(vip_isvip!= null && vip_isvip == "1" ){
			 // 到期提醒
			 var deaddays = DateDiff(deadline);
			 if(getCookie(gettxkey()) != "1" && TX_DAYS[deaddays] === 1){
				 var deaddaysStr = '<strong class="c_red">'+deaddays+'</strong>天后';
				 if(deaddays == 0) deaddaysStr = '<strong class="c_red">今天</strong>';
				 var tixingstr = '<div class="paytips" id="xufeitxdiv">'
	         		+    '<h5>温馨提示</h5>'
	         		+    '<p>您的尊贵迅雷VIP会员身份即将于'+deaddaysStr+'到期，为了不影响您的使用，请马上续费。</p>'
	         		+    '<div class="bot"><a href="javascript:go_pay_referFrom(1001);" class="btns btn_rednormal">立即续费</a></div>'
	         		+    '<a href="javascript:closetx(\'xufeitxdiv\');" class="a_close" title="关闭提示">&times;</a>'
	         		+'</div>';
				 htmlStr = htmlStr+tixingstr; 
			 }
			 
			 // 1. 成长值达到15的不显示 加速
			 // 2. 靓号赠送的会员不显示加速
			 // 3. 悬空单导致靓号到期后回滚到老帐号时， 支付方式为 靓号赠送，但是可以加速
			 var speedup = '(加速)';
			 if( getGrowValueByPaytype(vip_paytype) == 15) speedup = '';
			 if(parseInt(vip_paytype) > 100 && vip_isgoodnum && vip_isgoodnum =="1") speedup = '';
			 // 会员信息
			 htmlStr += '<div class="secondinfo">'
				 +    '<div>'
				 +    '<dl>'
				 +        '<dt>您的会员信息</dt>'
				 +        '<dd>会员成长值：<em>' + memberage + '</em><a href="javascript:go_new(\'mygrown\');">(详情)</a></dd>'
				 +        '<dd>每日成长值：<em>' + getGrowValueByPaytype(vip_paytype) + '</em><span onmousemove="JiasuShow.show(this,40,110);"><a href="javascript:" >'+speedup+'</a></span></dd>';
			 if(deadline== null)	
				 deadline = "";
			 if(vip_paytype == "3"){
			     htmlStr += '<dd>您的支付方式：<em>手机</em><a href="http://vip.xunlei.com/help/tuiding.html" target=_blank>(更改)</a></dd>';
			 }else{
				 htmlStr += '<dd>会员期限：<em>' + deadline + '</em><a href="javascript:go_pay_loginBox();">(续费)</a></dd>';
			 }
			 htmlStr += '</dl>'
				     +  '<div class="bt"><a href="javascript:go_new(\'my_freedom_index\');" class="btns btn_redlong">会员管理</a></div>'
				     + '</div>'
				     +'</div>';
		 }
		 else{
			if(trialvip == "1") {
				 // 体验会员信息
				 htmlStr += '<div class="secondinfo">'
					 +    '<div>'
					 +    '<dl>'
					 +        '<dt>您的会员信息</dt>'
					 +        '<dd>会员成长值：<em>0</em></dd>'
					 +        '<dd>每日成长值：<em>0</em></dd>'
					 +        '<dd>会员期限：<em>'+trialday+'天</em></dd>'
					 +    '</dl>'
					 +    '</div></div>';
			} else if(vip_level!= null && vip_level != "" && vip_level !="0") {
			    // 曾经是会员
		        htmlStr += '<div class="secondinfo">'
		        	+          '<div style="display:block;">'
		        	+              '<div class="nottext">您的迅雷会员已过期，<br />暂时无法享受会员精彩特权！</div>'
		        	+              '<div class="bt"><a href="javascript:go_pay_loginBox();" class="btns btn_redlong">立即续费</a></div>'
		        	+          '</div>'
		        	+      '</div>';
		    } else {
		        htmlStr += '<div class="secondinfo">'
		        	+          '<div style="display:block;">'
		        	+              '<div class="nottext">您现在还不是迅雷会员，<br />暂时无法享受会员精彩特权！</div>'
		        	+              '<div class="bt"><a href="javascript:go_pay_loginBox();" class="btns btn_redlong">立即开通</a></div>'
		        	+          '</div>'
		        	+       '</div>';		        
		    }
		 }
		htmlStr += '</div></div>';
		leftDiv.innerHTML = htmlStr;
		showLayer(leftDiv);
	 }
	 if(headP){
		 headP.innerHTML = '<span id=""><strong class="red">注：</strong>开通即认为您同意并接受<a href="http://vip.xunlei.com/tos.html" target="_blank">迅雷会员服务条款</a>。会员按月计费，每月10元<font id="vip_period" name="vip_period">，期限为从开通当日起31天</font>。</span>'
			 + '<strong>' + nickname + ' 您好！</strong>'
			 + '<a href="javascript:logout();" class="logout">[退出]</a>'
			 + '<a href="javascript:go_new(\'my_freedom_index\')" ><strong>会员管理</strong></a>';	 
	 }
	 if(lixianheadP) {
		 var lixian_head = '<span></span>'
			 + '<strong>' + nickname + ' 您好！</strong>'
			 + '<a href="javascript:logout();" class="logout">[退出]</a>'
			 + '<a href="javascript:go_new(\'my_freedom_index\')" ><strong>会员管理</strong></a>';	 
		 lixianheadP.innerHTML = lixian_head;
	 }
	 sendHttpPack(getnocacheurl("http://login.xunlei.com/expire"));
	 
	 if(usernewno == "0") {
		 var update_tips = getCookie('vip_update_tips_'+sessionid);
		 var upgrade = getCookie('upgrade');
		 if(update_tips != '1' && upgrade == '1') {
			 setCookie('vip_update_tips_'+sessionid,"1");
			 UpdateMsgShow.showInterface(nickname);
		 }
	 }
	 
	 showXuFeiBtn(vip_isvip);
}

// 初始化 院线、会员管理的页头登录态
function initVIPHeadSP() {
	var sessionid = getCookie("sessionid");
	if(sessionid != null && sessionid != "") {
    	var nickname = getCookie("vip_nickname");	//昵称 
    	nickname = nickname.strip();
    	var vip_headSP = $("vip_headSP");
    	if(vip_headSP){
        	vip_headSP.innerHTML = '欢迎您：' + nickname + ' [<a href="javascript:logout();">退出</a>]'; 
        }
	}
}
function recordRefer(){
	var refFrom = getParam(top.location.href, "referfrom");
	refFrom = refFrom.trim();
	if(refFrom != null && refFrom != '') {
		setCookie("vip_referfrom",refFrom);
	}
	var ucid = getParam(top.location.href, "ucid");
	ucid = ucid.trim();
	if(ucid != null && ucid != '') {
		setCookie("vip_ucid",ucid);
	}
}
function gettxkey(){
	var userid = getCookie("userid");
	return "vip_hastx_"+userid;
}
function closetx(item){
	if($(item)){$(item).style.display = 'none';}
	setCookie(gettxkey(),"1");
}

// 可能返回 0、 负数
function DateDiff(sDate1){ //sDate1是2002-12-18格式   
	var aDate, oDate1, oDate2, iDays;   
	aDate = sDate1.split("-");
	oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); //转换为12-18-2002格式   
	oDate2 = new Date();
	iDays = Math.floor((oDate1 - oDate2) / 1000 / 60 / 60 /24); //把相差的毫秒数转换为天数   
	return iDays+1; 
}

//登陆按钮触发
function login(){
	var leftDiv = $("userinfro_leftdiv");
	if( $("userinfro_leftdiv") && $('loginform') ) {
		alert('请在左侧登录区登录！');
	} else {
		onGetLogin();
	}
}

function onGetLogin(){
	Login.showInterface(refreshPage);
}

//刷新当前页面的用户会员信息
function refreshVipUserInfo(){
	top.location.href=getnocacheurl("http://dynamic.vip.xunlei.com/login/indexlogin_contr/proxy/");
}

function logout(){
	sendHttpPack(getnocacheurl("http://login.xunlei.com/unregister?sessionid="+getCookie("sessionid")));
	clearCookie();
	var url = getnocacheurl("http://dynamic.vip.xunlei.com/login/indexlogin_contr/logout/");
	new Json.Request(url,{onSuccess: refreshPage,parameters: '',method: "POST"});
}

function clearCookie() {
	var sessionid = getCookie("sessionid");
	var udate_tips_tag = 'vip_update_tips_'+sessionid;
	//清除子域名
	var ckeys = ["vip_trialvip","vip_trialday","vip_usrname","vip_num_due_time","vip_num_is_open_vip","vip_is_good_number","vip_referfrom","vip_nickname","vip_sessionid","vip_growvalue","vip_expiredate","vip_level","vip_isyear","vip_isvip","vip_paytype",udate_tips_tag];
	for(var i=0;i<ckeys.length;i++){
		setCookie(ckeys[i],"",0);
	}
	//主域名
	var ckeys1 = ["sessionid","username","nickname","userid","usertype","usernewno","raw","blogresult","vipstate","p_t"];
	for(var i=0;i<ckeys1.length;i++){
		setCookie(ckeys1[i],"",0,1);
	}	
}
//网页内按下回车触发
document.onkeydown = function(event){
    if(window.event) {
        event = window.event;
    }	
    if(event.keyCode==13 && $("login_pop_id") && $("login_pop_id").style.display != "none"){
    	if(Login.validateInput()) 
    		Login.submitForm();                              
    }
    //判断登陆框
    var flag = $('logindiv') && ($('logindiv').style.display !='none');
    if(event.keyCode==13 && ($("button_submit4reg")||flag)){
        if(Login.validateInput()) 
        	//此时只能调用html中的方法
        	//submitForm();
        	Login.submitForm();
    }    
}

var  Login = {
	popDiv:null,
	loginRet:false,
	callBackFunc:function(){},
	showInterface: function(callBackFunc){
		if(Login.popDiv==null){
			Login.popDiv = document.createElement("DIV");
			Login.popDiv.id = "login_pop_id";
			Login.popDiv.innerHTML = '<div class="mod layer" id="login_popinner_id" style="width:340px;position:absolute;">'
				+ '<h2>用户登录<a href="javascript:Login.exit();void(0);" class="close">关闭</a></h2>'
				+ '<div class="content"><div class="login_form">'
				+ '<form id="loginform" action="http://login.xunlei.com/login/"  method="post" >'
				+ '<p><label>迅雷号码：</label><input id="u" name="u" value="" type="text" class="ip_txt" tabindex="1"/></p>'
				+ '<p><label>密码：</label><input id="p" name="p" type="password" class="ip_txt" tabindex="2"/></p>'
				+ '<p class="forget"><a href="http://aq.xunlei.com/?redirecturl=forgot_pwd" target="_blank">忘记密码？</a></p>'
				+ '<p><label>验证码：</label><input id="verifycode" name="verifycode" type="text" class="ip_txt" style="width:70px; IME-MODE: disabled" tabindex="3" autocomplete="off" maxLength="4"/>'
				+ '<img id="verify_code" style="height:20px;width:50px;"/> <a href="#" onclick="$(\'verify_code\').src=\'http://verify.xunlei.com/image?cachetime=\'+new Date().getTime();return false;" class="btn_refresh">刷新</a></p>'
				+ '<p><a href="javascript:if(Login.validateInput())Login.submitForm();" class="btn_login" tabindex="4">登录</a></p>'
				+ '<input id="u1" name="u1" type="hidden" value="http://dynamic.vip.xunlei.com/login/indexlogin_contr/proxy" />'
				+ '</form></div>'
				+ '<p class="t_c">还没有注册迅雷？<a href="http://i.xunlei.com/?redirecturl=regist" target="_blank" class="c_red">现在就注册！</a></p>'				
				+ '</div></div>';		
			//Insertion.bottom(document.body, Login.popDiv);	
			document.body.appendChild(Login.popDiv);
			Login.popDiv.style.position = "absolute";
			
			Login.backDiv = document.createElement("DIV");
			Login.backDiv.style.backgroundColor = "Black";
			Login.backDiv.style.filter = "alpha(opacity=40)";
			Login.backDiv.style.MozOpacity="0.4";
			Login.backDiv.style.position = "absolute";
			Login.backDiv.style.left = "0px";
			Login.backDiv.style.top = "0px";
	
			document.body.appendChild(Login.backDiv);
			//Insertion.bottom(document.body,Login.backDiv);
			Login.backDiv.style.zIndex =1000;
			Login.popDiv.style.zIndex  = 1001;
		}
		else
		{
			Login.popDiv.style.display =Login.backDiv.style.display ="";
			if($('login_popinner_id'))
				$('login_popinner_id').style.zIndex = Login.popDiv.style.zIndex;
		}
		
		if(! isUndef(callBackFunc))
			Login.callBackFunc = callBackFunc;	
		if(window.attachEvent){
			window.attachEvent("onresize",this.setPos);
			window.attachEvent("onscroll",this.setPos);
		}else{
			window.addEventListener("onresize",this.setPos,false);
			window.addEventListener("onscroll",this.setPos,false);
		}
		//window.onscroll =window.onresize=this.setPos;
		this.setPos();
		$('verify_code').src = 'http://verify.xunlei.com/image?cachetime='+new Date().getTime();
		$('u').focus();	
	},
	validateInput: function(){
		$('loginform').u.value = $('loginform').u.value.trim();
		$('loginform').p.value = $('loginform').p.value.trim();
		if($('loginform').u.value.length == 0){alert("请您输入用户名!"); $('loginform').u.focus(); return false;}
		if($('loginform').p.value.length == 0){alert("请您输入密码!"); $('loginform').p.focus(); return false;}
		if($('loginform').verifycode.value.length == 0){alert("请您输入验证码!"); $('loginform').verifycode.focus(); return false;}	

		this.disablePopDiv(true);
		Login.loginRet = true;
		return true;
	},
	submitForm: function(){
		if($('button_submit4reg')) $('button_submit4reg').disabled = true;
		setCookie("vip_cburl",getnocacheurl(top.location.href));
		Login.submitFormOpr();
	},
	
	submitFormOpr: function(){
	    try {
	        if(window.external) {window.external.AutoCompleteSaveForm($('loginform'));}} catch (e) {}	    
        //*md5 login
		var md5Pwd = hex_md5($('loginform').p.value);
		md5Pwd = hex_md5(md5Pwd);
		
		var params="u="+encodeURIComponent($('loginform').u.value);
		params+="&p="+encodeURIComponent(md5Pwd);
		params+="&verifycode="+encodeURIComponent($('loginform').verifycode.value);
		new Json.Request("http://login.xunlei.com/secbloglogin/",{onSuccess: Login.onIndexLogin,parameters: params,method: "POST"});
		return false;
	},
	
	onIndexLogin: function (){
		var result = getCookie("blogresult");
		if(!result||''==result)return;
		var login_error = {1: "验证码错误",2: "密码错误",3: "服务器忙",4: "帐号不存在",5: "帐号不存在",6: "帐号被锁定",
							7: "服务器忙",8: "服务器忙",9: "非法验证码",10: "非法验证码",11: "验证码超时",12: "未知错误"};
		if(result!="0")
		{
			alert( login_error[result] );
			if($('button_submit4reg')) $('button_submit4reg').disabled = false;
			if($('verifycode')) $('verifycode').value = '';
			if($('verify_code'))$('verify_code').src = 'http://verify.xunlei.com/image?cachetime='+new Date().getTime();
			return false;
		}
		//success
		if($('u1').value.trim() == '')$('u1').value = getnocacheurl("http://dynamic.vip.xunlei.com/login/indexlogin_contr/proxy/1/");
		else $('u1').value = getnocacheurl($('u1').value);
		top.location.href = $('u1').value;
	},
	
	setPos:function(){
		Login.popDiv.style.left = (document.documentElement.clientWidth/2 + document.documentElement.scrollLeft -207) +"px";
		Login.popDiv.style.top = (document.documentElement.clientHeight/2 + document.documentElement.scrollTop-142 + 43) +"px";
		Login.backDiv.style.width = Math.max(document.body.scrollWidth, document.documentElement.clientWidth) +"px";
		Login.backDiv.style.height = Math.max(document.body.scrollHeight, document.documentElement.clientHeight)+"px";
	},
	
	exit: function(){
		$('loginform').reset();		
		if($('flashplay'))
			$('flashplay').style.display = "block";
	
		Login.popDiv.style.display =Login.backDiv.style.display ="none";
		this.disablePopDiv(false);
		if(window.detachEvent){
			window.detachEvent("onresize",this.setPos);
			window.detachEvent("onscroll",this.setPos);
		}else{
			window.removeEventListener("onresize",this.setPos,false);
			window.removeEventListener("onscroll",this.setPos,false);
		}
	},
	
	disablePopDiv: function(tag){
	}	
}
//首次获得焦点时获取验证码
function getOnfocusVerifyCode(){
	var	ver = $('verify_code');
	var	p = $('vcode_p');
	if(ver && ver.src == "") {
		 ver.src = 'http://verify.xunlei.com/image?cachetime='+new Date().getTime();
		 ver.style.display = '';
	}
	if(p) showLayer(p);
}
//获取验证码
function getVerifyCode(){
	if($('verify_code')) $('verify_code').src = 'http://verify.xunlei.com/image?cachetime='+new Date().getTime();
}

// 构建 未登录时的左边框 html
function buildLeftDivHTML() {
    htmlStr = '<h2>会员用户直接登录</h2>'
			+ '<div class="content">'
			+     '<div style="display:block;">'
            +         '<form id="loginform" action="http://login.xunlei.com/login/"  method="post">'
            +         '<div class="intryform">'
            +             '<p><label>迅雷号码：</label><input tabindex="1"  id="u" name="u" value="" type="text" class="ip_txt" autocomplete="on"/></p>'
            +             '<p><label>迅雷密码：</label><input id="p" name="p" type="password" type="text" class="ip_txt" tabindex="2"/></p>'
            +             '<p><label>验&nbsp;证&nbsp;码：</label><input id="verifycode" name="verifycode" type="text" class="ip_txt" style="IME-MODE: disabled;" onfocus="getOnfocusVerifyCode()" tabindex="3" autocomplete="off" maxLength="4"/></p>'
            +             '<p id="vcode_p" style="display:none;"><img id="verify_code" style="height:20px;width:50px;"/> <a href="#" onclick="getVerifyCode();return false;" class="btn_refresh" >刷新</a></p>'
            +             '<p><label><a href="http://aq.xunlei.com/?redirecturl=forgot_pwd" target="_blank">忘记密码?</a>&nbsp;</label>'
            +                '<button id="button_submit4reg" type="button" onclick="if(Login.validateInput())Login.submitForm();" class="btn_login" tabindex="4">登录</button></p>'
            +             '<input id="u1" name="u1" type="hidden" value="http://dynamic.vip.xunlei.com/login/indexlogin_contr/proxy/1/" />	'
            +         '</div></form>'
            +         '<div class="opens">'
            +             '<a href="http://i.xunlei.com/?redirecturl=regist&referfrom=VIP_01">还没有迅雷号码？<strong>立刻注册</strong></a>'         
            +         '</div>'
            +     '</div>'
            + '</div>';
     return htmlStr;
}

// 构建未登录时的 快速注册 html
function buildKaiTongDivHTML() {
    htmlStr = '<h2><a href="javascript:go_pay_loginBox(\'ktframe\');" title="开通会员">开通会员</a></h2>'
            + '<ul>'
			+     '<li><a href="javascript:go_pay_loginBox(\'ktframe\');">网银/支付宝<strong>8.8折</strong>开通会员</a></li>'
            +     '<li><a href="javascript:go_pay_loginBox(\'ktframe\', \'wy\', 12);">年费会员独享<strong>15点/天</strong>成长值</a></li>'
            +     '<li><a href="javascript:go_pay_loginBox(\'ktframe\');">会员尽享<strong>经验值加速</strong></a></li>'
			+ '</ul>';
    
    return htmlStr;
} 

function getGrowValueByPaytype(paytype) {
	var ptype = parseInt(paytype); 
	if(ptype > 100 && ptype != 105) {
		return 10;  // 靓号赠送
	}
    switch(paytype) {
        case "1" : return 10;    // 雷点
        case "2" : return 5;     // sina 无线
        case "3" : return 5;     // 手机
        case "4" : return 12;    // 网银
        case "5" : return 15;    // 年费
        case "6" : return 10;    // 声讯  
        case "7" : return 10;    // 齐顺声讯
        case "8" : return 5;     // 手机钱包
        case "9" : return 10;    // 嗖付支付
        case "105" : return 15;  // 靓号年费
        default  : return 0;         
    }
}

function getPwayByPaytype(paytype) {
	paytype = parseInt(paytype);
	if(paytype > 100) return "靓号赠送";
    switch(paytype) {
        case 1 : return "雷点";        // 雷点
        case 2 : return "sina 无线";   // sina 无线
        case 3 : return "手机";        // 手机
        case 4 : return "网银";        // 网银
        case 5 : return "年费";        // 年费
        case 6 : return "固定电话";    // 声讯  
        case 7 : return "齐顺声讯";    // 齐顺声讯
        case 8 : return "手机钱包";    // 手机钱包
        case 9 : return "嗖付";        // 嗖付支付
        case 105 : return "靓号赠送";  // 靓号年费
        default  : return "其他";         
    }
}

function conrectcut(srcStr, length) {
	while(srcStr.bytesLength() > length) {
		srcStr = srcStr.substring(0,srcStr.length-1);
	}
	return srcStr;
}

var UpdateMsgShow  = {
		popDiv:null,
		showInterface: function(nickname){
			if(UpdateMsgShow.popDiv==null){
				UpdateMsgShow.popDiv = document.createElement("DIV");
				UpdateMsgShow.popDiv.id = "update_pop_id";
				UpdateMsgShow.popDiv.innerHTML = '<div class="mod layer" id="update_popinner_id" style="width:340px;position:absolute;">'
					+ '<h2>升级提示<a href="javascript:UpdateMsgShow.exit();void(0);" class="close">关闭</a></h2>'
					+ '<div class="content">'
					+ '<h4>亲爱的迅雷用户：'+nickname+' 您好！</h4>'
					+ '<p>&nbsp;&nbsp;&nbsp;&nbsp;为了提高迅雷帐号安全性和稳定性，让各位雷友享受更好的服务，迅雷公司将对帐号系统进行升级，为了不影响您的使用，请马上升级您的帐号。</p>'
					+ '<p/><p style="text-align:center;padding:8px;"><a href="http://i.xunlei.com/?redirecturl=upgrade_digit" target="_blank" class="btn_login" >立即升级</a></p>'
					+ '</div></div>';		
				
				document.body.appendChild(UpdateMsgShow.popDiv);
				UpdateMsgShow.popDiv.style.display = "";
				UpdateMsgShow.popDiv.style.position = "absolute";
				
				UpdateMsgShow.backDiv = document.createElement("DIV");
				UpdateMsgShow.backDiv.style.backgroundColor = "Black";
				UpdateMsgShow.backDiv.style.filter = "alpha(opacity=40)";
				UpdateMsgShow.backDiv.style.MozOpacity="0.4";
				UpdateMsgShow.backDiv.style.position = "absolute";
				UpdateMsgShow.backDiv.style.left = "0px";
				UpdateMsgShow.backDiv.style.top = "0px";
		     
				document.body.appendChild(UpdateMsgShow.backDiv);
				UpdateMsgShow.backDiv.style.zIndex =1000;
				UpdateMsgShow.popDiv.style.zIndex  = 1001;
			}else
			{
				UpdateMsgShow.popDiv.style.position = "absolute";			
				UpdateMsgShow.popDiv.style.display =UpdateMsgShow.backDiv.style.display ="";
				if($('update_popinner_id'))$('update_popinner_id').style.zIndex = UpdateMsgShow.popDiv.style.zIndex;				
			}
			if(window.attachEvent){
				window.attachEvent("onresize",this.setPos);
				window.attachEvent("onscroll",this.setPos);
			}else{
				window.addEventListener("onresize",this.setPos,false);
				window.addEventListener("onscroll",this.setPos,false);
			}
			this.setPos();
		},
		submitForm: function(){
		},
		
		setPos:function(){
			UpdateMsgShow.popDiv.style.left = (document.documentElement.clientWidth/2 + document.documentElement.scrollLeft -207) +"px";
			UpdateMsgShow.popDiv.style.top = (document.documentElement.clientHeight/2 + document.documentElement.scrollTop-142 + 43) +"px";
			UpdateMsgShow.backDiv.style.width = Math.max(document.body.scrollWidth, document.documentElement.clientWidth) +"px";
			UpdateMsgShow.backDiv.style.height = Math.max(document.body.scrollHeight, document.documentElement.clientHeight)+"px";
		},
		
		exit: function(){
			UpdateMsgShow.popDiv.style.display =UpdateMsgShow.backDiv.style.display ="none";
			if(window.detachEvent){
				window.detachEvent("onresize",this.setPos);
				window.detachEvent("onscroll",this.setPos);
			}else{
				window.removeEventListener("onresize",this.setPos,false);
				window.removeEventListener("onscroll",this.setPos,false);
			}
		}
	} 

var JiasuShow  = {
		popDiv:null,
		ref:null,
		show: function(parent, top, left, ref){
	        var paytype = getCookie("vip_paytype");
	        var vip_isgoodnum = getCookie("vip_is_good_number");
	        var pway = getPwayByPaytype(paytype);
	        var grown = getGrowValueByPaytype(paytype);
	        if(grown == 15) return ;
	        // 靓号赠送的会员不能加速
	        if(parseInt(paytype) > 100 && vip_isgoodnum && vip_isgoodnum == '1') return;
			if(JiasuShow.popDiv==null){
				JiasuShow.popDiv = document.createElement("DIV");
				JiasuShow.popDiv.id = "jiasu_pop_id";
				JiasuShow.popDiv.innerHTML = '<ul class="ct">'
					+ '<li>'
					+     '<p class="p1"><strong class="c_import">·您的开通方式为：<font id="jiasu_pway"></font></strong></p>'
					+     '<p class="p2"><span class="c_import">成长值<font id="jiasu_grown"></font>点/天</span></p>'
					+ '</li>'
					+ '<li>'
					+     '<p class="p1">·开通年费会员</p>'
					+     '<p class="p2">成长值15点/天</p>'
					+     '<p class="p3"><a href="javascript:JiasuShow.jiasu(1);">加速</a></p>'
					+'</li>'
					+'</ul>';
				
				//document.body.appendChild(JiasuShow.popDiv);
				parent.appendChild(JiasuShow.popDiv);
				
				JiasuShow.popDiv.onmouseout = function(){
					$('jiasu_pop_id').style.display = 'none';
				};
			}
			
			if(JiasuShow.popDiv.parentNode != parent) {
				JiasuShow.popDiv = JiasuShow.popDiv.parentNode.removeChild(JiasuShow.popDiv);
				parent.appendChild(JiasuShow.popDiv);
			}
			
//			$('jiasu_pway').innerHTML = pway.escapeHTML();
			$('jiasu_pway').innerHTML = pway;
			$('jiasu_grown').innerHTML = grown;
			
			JiasuShow.popDiv.className = "tips_jiasu";
			JiasuShow.popDiv.style.top = top + 'px';
			JiasuShow.popDiv.style.left = left + 'px';
			JiasuShow.popDiv.style.display = "";
			JiasuShow.ref = ref;
		},
        jiasu: function(type) {
			var paytype = getCookie("vip_paytype");
			if(paytype == '3') {
				go_new_np('sjtuiding');
			} else {
				switch(type) {
				    case 1 : 
				    	if(JiasuShow.ref == "mygrown") {
				    		go_pay_referFrom(758, 'wy', 12);
				    	} else {
				    		go_pay_loginBox('', 'wy', 12);
				    	}
				    	break;
				}
			}
		}
	} 

function LeftSidetool(){}
LeftSidetool.setFreedomList = function(index){
	  document.write( "<div class='mod_privilege'>"
			  	+ "<h2>会员特权</h2>"
			  	+ "<div class='content'>"
			  	+ "    <dl>"
			  	+ "        <dt>会员独享</dt>"
			  	+ "        <dd><a href='http://lixian.vip.xunlei.com'>离线下载<img src='http://img.vip.xunlei.com/img/base/hot.gif' title='hot' class='hot_new' /></a></dd>"
			  	+ "        <dd><a id='index_exclusive_channel' href=\"javascript:go_new('vipchannel')\" >会员专属下载通道<img src='http://img.vip.xunlei.com/img/base/new.gif' title='new' class='hot_new' /></a></dd>"
			  	+ "        <dd><a id='index_score_improve' href='http://vip.xunlei.com/freedom/score_improve.html'>升级加速</a></dd>"
			  	+ "        <dd><a id='index_nickname' href='http://vip.xunlei.com/freedom/nickname.html'>个性昵称展示</a></dd>"
                + "        <dd><a id='index_vip_forums' href='http://vip.xunlei.com/freedom/vip_forums.html'>会员专属论坛</a></dd>"
                + "        <dd><a id='index_exclusive_server' href='http://vip.xunlei.com/freedom/exclusive_server.html'>会员专属服务器</a></dd>"
			  	+ "    </dl>"
			  	+ "    <dl>"
			  	+ "        <dt>与众不同</dt>"
			  	+ "        <dd><a id='index_account_retention' href=\"javascript:go_new('account_retention')\">帐号永久保留</a></dd>"
                //+ "        <dd><a id='index_exclusive_skin' href='http://vip.xunlei.com/freedom/exclusive_skin.html'>炫目皮肤</a></dd>"
                + "        <dd><a id='index_freedom_skinad' href='http://vip.xunlei.com/freedom/freedom_skinad.html'>去除广告</a></dd>"
			  	+ "    </dl>"		
			  	+ "    <dl>"
			  	+ "        <dt>安全无忧</dt>"
                + "        <dd><a id='index_safety_service' href='http://vip.xunlei.com/freedom/safety_service.html'>专属安全服务</a></dd>"
			  	+ "    </dl>"	
			  	+ "    <dl>"
			  	+ "        <dt>多彩生活</dt>"
                + "        <dd><a id='index_vipmovie' href='http://vip.xunlei.com/freedom/vip_ticket.html'>5折通票 尊享大片</a></dd>"
                + "        <dd><a id='index_game_present' href='http://vip.xunlei.com/freedom/game_present.html'>网游礼包</a></dd>"
                + "        <dd><a id='index_blue_stone' href='http://vip.xunlei.com/freedom/blue_stone.html'>游戏蓝宝石</a></dd>"
			  	+ "    </dl>"			  	
                + "</div>"
                + "</div>"
     );
	 if($(index))$(index).className = "on";
}

LeftSidetool.setHeader = function(index){
	  document.write( "<div class='logo'><a href=\"javascript:go_new('index')\" title='迅雷会员快乐不停下'>迅雷会员快乐不停下</a></div>"
			  	+"	<ul id='navigater_ul' class='greatmenu'>"
			  	+"		<li id='navigater_help' onmouseover=\"javascript:LeftSidetool.submouseOver('help')\" onmouseout=\"javascript:LeftSidetool.submouseout(event, this, 'help')\">"
			  	+"          <a href=\"javascript:go_new('help')\" class='a_help' >帮助</a>"
			  	+"          <ul id='subhelp' name='subhelp' class='submenu' style='display:none;'>"
			  	+"              <li><a id='sub_a_helpindx' href=\"javascript:go_new('help')\">帮助手册</a></li>"
			  	+"              <li><a id='sub_a_scoreimprove' href='http://helpbbs.xunlei.com/thread.php?fid=33' target='_blank'>客服论坛</a></li>"
			  	+"          </ul>"				  	
			  	+"      </li>"
			  	+"		<li id='navigater_active' onmouseover=\"javascript:LeftSidetool.submouseOver('active')\" onmouseout=\"javascript:LeftSidetool.submouseout(event, this, 'active')\">"
			  	+"          <a href='http://vip.xunlei.com/freedom/blue_stone.html' class='a_active'>会员活动</a>"
			  	+"          <ul id='subactive' name='submenu' class='submenu' style='display:none;'>"
			  	+"              <li><a id='sub_a_vipmovie' href=\"javascript:go_new1('vipmovie')\">会员电影票</a></li>"
			  	+"              <li><a id='sub_a_bluestone' href=\"javascript:go_new('bluestone')\" >游戏蓝宝石</a></li>"
			  	+"              <li><a id='sub_a_yuanxun' href=\"javascript:go_new_np('yuanxun')\" >会员团购</a></li>"
			  	+"              <li><a id='sub_a_yxrank' href=\"javascript:go_new('yxrank')\" >元勋榜</a></li>"			  	
			  	+"          </ul>"			  	
			  	+"      </li>"
			  	+"		<li id='navigater_freedom' onmouseover=\"javascript:LeftSidetool.submouseOver('freedom')\" onmouseout=\"javascript:LeftSidetool.submouseout(event, this, 'freedom')\">"
			  	+"          <a href=\"javascript:go_new('freedom_set')\" class='a_freedom'>特权与功能</a>"
			  	+"          <ul id='subfreedom' name='submenu' class='submenu' style='display:none;'>"
			  	+"              <li class='hot'><a id='sub_a_lixian' href='http://lixian.vip.xunlei.com' >离线下载</a></li>"
			  	+"              <li class='new'><a id='sub_a_channel' href=\"javascript:go_new('vipchannel')\" >会员通道</a></li>"
			  	+"              <li><a id='sub_a_nickname' href=\"javascript:go_new('nickname')\">个性昵称</a></li>"
			  	+"              <li><a id='sub_a_scoreimprove' href=\"javascript:go_new('score_improve')\">升级加速</a></li>"
			  	+"              <li><a id='sub_a_skinad' href=\"javascript:go_new('freedom_skinad')\">去除广告</a></li>"
			  	+"              <li><a id='sub_a_retention' href=\"javascript:go_new('account_retention')\">帐号保留</a></li>"
			  	+"          </ul>"			  	
			  	+"      </li>"
			  	+"		<li id='navigater_roundinto' onmouseover=\"javascript:LeftSidetool.submouseOver('roundinto')\" onmouseout=\"javascript:LeftSidetool.submouseout(event, this, 'roundinto')\">"
			  	+"          <a href=\"javascript:go_new('my_freedom_index')\" class='a_roundinto' >会员成长</a>"
			  	+"          <ul id='subroundinto' name='submenu' class='submenu' style='display:none;'>"
			  	+"              <li><a id='sub_a_grownintro' href=\"javascript:go_new('my_freedom_index')\">成长值介绍</a></li>"
			  	+"              <li><a id='sub_a_mygrown' href=\"javascript:go_new('mygrown')\">我的成长值</a></li>"
			  	+"          </ul>"				  	
			  	+"      </li>"
			  	+"		<li id='navigater_index' onmouseover=\"javascript:LeftSidetool.submouseOver('index')\" onmouseout=\"javascript:LeftSidetool.submouseout(event, this, 'index')\"><a href=\"javascript:go_new('index')\" class='a_index' >首页</a></li>"
			  	+"	</ul>"
		        +"  <div class='state'>"
	            +"      <a href='javascript:go_pay_loginBox(\"head\")' class='kaitong' title='开通会员享受特权生活'>开通会员享受特权生活</a>"
	            +"  </div>"
	            +"  <div class='topuser'><span id='vip_headSP'>[<a href='javascript:login();'>登录</a>] [<a href='http://i.xunlei.com/?redirecturl=regist&referfrom=VIP_02' target='_blank'>注册</a>]</span></div>"
   );
	  
   var arIndex = index.split('.');
   var topindex = 'navigater_'+arIndex[0];
   var subul = 'sub'+arIndex[0];
   if($(topindex)) $(topindex).className = "selected";
   if($('navigater_ul')) $('navigater_ul').setAttribute('selectedli', arIndex[0]);
   if($(subul)) $(subul).style.display = 'block';
   if(arIndex.length > 1) {
	   var sub_a = 'sub_a_' + arIndex[1];
	   if($(sub_a)) $(sub_a).className = 'on';
   }
}

LeftSidetool.submouseOver = function (index) {	
	var topindex = 'navigater_'+index;
	if($(topindex) && $(topindex).className != "selected") $(topindex).className = "onhover";
	
	if($('navigater_ul')) {
		var allsubs = $('navigater_ul').getElementsByTagName('UL');
		for(var i in allsubs) {
			if(allsubs[i].style)
				allsubs[i].style.display = 'none';
		}
	}
	var subul = 'sub'+index;
	if($(subul)) $(subul).style.display = 'block';		
}
LeftSidetool.submouseout = function (e, o, index) {
	var select_li = '';
	if($('navigater_ul')) select_li = $('navigater_ul').getAttribute('selectedli');
	if(index == select_li)  return ;
		
	var topindex = 'navigater_'+index;
	var subul = 'sub'+index;
	if($(topindex)) $(topindex).className = "";
	if($(subul)) $(subul).style.display = 'none';	
	
	var selected_subul = 'sub'+select_li;
	if($(selected_subul)) $(selected_subul).style.display = 'block';
}

// 如果已经是会员， 则显示续费按钮， 
function showXuFeiBtn(isvip) {
	if(isvip == "1") {
		var btns = document.getElementsByTagName("A");
		var len = btns.length;
		for(var i=0; i<len; i++) {
			if(btns[i].className == "kaitong" || btns[i].className == "a_kt_long") {
				btns[i].className = "xufei";
			}
		}
	}
}
