var g_strUrl = "";
on_focus_verify = function()
{
	if( $('_img_verify').src=="" ) {
		on_another_verify();
		$('_img_verify').style.display='';
		$('_span_refresh').style.display='';
	}
}
on_another_verify = function()
{
	loginAct.refreshVerify(document.forms['_form_login']);
}
_login_succeeded = function()
{
	var _isvip_url = 'http://idynamic.xunlei.com/cgi-bin/cgi_tmp_vip';
	var _isvip_callback = function(rr)
	{
		//统计用户登陆的类型
		if(0==rr.result)
		{
			var vipstate = parseInt(rr.msg);
			if(isNaN(vipstate)||vipstate<=0||vipstate>6)
			{
				vipstate = 0;
				g_xl_stat_init(Browser.getCookie('userid'), vipstate);
				i_stat(STAT_LOGIN_USER);
			}
			else
			{
				Browser.setCookie('vipstate', vipstate);
				g_xl_stat_init(Browser.getCookie('userid'), vipstate);
				i_stat(STAT_LOGIN_VIP);
			}
		}
	};
	//取是否vip的过程放到个人中心的后台登录中去
//	var _isvip_loader = new BufferedLoader(_isvip_url, _isvip_callback);
//	_isvip_loader.load();
	checkPwdProtect( function() {
					if(1==Browser.getCookie('upgrade')&&g_strUrl.indexOf('upgrade')<0)
						g_popUpgradeDigit.pop(g_strUrl);//提示升级
					else 
						if(1==Browser.getCookie('usertype')&&0==Browser.getCookie('logintype'))
							g_popNewloginAlert.pop(g_strUrl);//如果已经升级过的帐号，但是还用旧帐号登录，提示使用新帐号
						else
							window.location.href=(g_strUrl);//else
				}//end of functoin
	);
	return false;
}
_login_failded = function(msg, msgcode)
{
	on_focus_verify();
	on_another_verify();
	alert(msg);
	if(msgcode == '1'){
		$('verifycode').value = '';
		$('verifycode').focus();
	}else if(msgcode == '2'){
		$('p').value = '';
		$('p').focus();
	}
}
checkPwdProtect = function(goon)
{
	new Ajax.Request("http://idynamic.xunlei.com/fcg-bin/cgi_notify_pwd_protect.fcg?userno="+Browser.getCookie("userid")+"&cachetime="+new Date().getTime(), 
		{
			response: "Object",
			onSuccess: function(evt){
					var rr=evt.response;
					if(rr.result=="0") {
						g_popNotifyPwdProtect.pop( goon );
					}
					else 
						goon();
				}//onSuccess
		}
	);
}
pre_check = function()
{
	try{g_strUrl=decodeURIComponent($P('url'))}catch(ex){g_strUrl='';}
	if(!_REG_REDIRECT_.test(g_strUrl))
	{
		g_strUrl = "http://i.xunlei.com/user/index/";
	}
	else if(!g_strUrl||''==g_strUrl)
	{
		g_strUrl = "http://i.xunlei.com/user/index/";
	}
	var sessionid = Browser.getCookie("sessionid");
	if ( sessionid && sessionid.length>=32 )//看起来是有效登录cookie
	{
		var check_url = 'http://idynamic.xunlei.com/fcg-bin/cgi_checklogin.fcg';
		var check_func = function(rr)
		{
			if(rr.result==0)
			{
				window.location.href=(g_strUrl);
			}
			else
			{
				clearSession();
				window.location.reload();
			}
			return;
		}
		//var checkLoginLoader = new BufferedLoader(check_url,check_func);
		//checkLoginLoader.load();
	}else{clearSession();}
	//login.xunlei.com登录成功,这时到用户中心后台登录
	g_strUrl = Browser.getnocacheurl(g_strUrl);
	Browser.setCookie("uc_cburl",g_strUrl);
	//Browser.setCookie("uc_notshowpaopao",'');
	g_strUrl = Browser.getnocacheurl('http://dynamic.i.xunlei.com/login/indexlogin_contr/login/');
}
var PicSlider = {
	_curr_id:0,
	_interval_id:null,
	_array:[],
	AddPic:function(src,href)
	{
		this._array.push({'src':src, 'href':href, 'idx':this._array.length, 'show':this._array.length+1});
	},
	Play:function()
	{
		this._interval_id = setTimeout(Delegate.create(this,this.PlayNext),4500);
	},
	Stop:function()
	{
		clearTimeout(this._interval_id);
	},
	PlayNext:function()
	{
		var idx = this._curr_id;
		if(idx>=(this._array.length-1) ) idx = 0;
		else idx++;
		this.Set(idx);
		this.Play();
	},
	Set:function(idx)
	{
		var obj = this._array[idx];
		if(!obj) return false;
		var htmlObj = null;
		/*
		htmlObj = $('_a_slide_ad');
		if(htmlObj)htmlObj.href=obj.href;
		htmlObj = $('_img_slide_ad')
		if(htmlObj)
		{
			htmlObj.src=obj.src;
			htmlObj.style.visibility = '';
		}*/
		if(!isNaN(this._curr_id))
		{
			htmlObj = $('_a_slide_ad_'+this._curr_id);
			if(htmlObj) htmlObj.style.display = 'none';
			htmlObj = $('_a_slide_ctrl_'+this._curr_id);
			if(htmlObj) htmlObj.className = '';
		}
		this._curr_id = idx;
		if(!isNaN(this._curr_id))
		{
			htmlObj = $('_a_slide_ad_'+this._curr_id);
			if(htmlObj) htmlObj.style.display = '';
			htmlObj = $('_a_slide_ctrl_'+this._curr_id);
			if(htmlObj) htmlObj.className = 'on';
		}
		return false;
	}
};
init = function()
{
	$("_form_login").u.focus();
	pre_check();
	on_focus_verify();
	PicSlider.AddPic('http://i.xunlei.com/img/stylev4/banner_1.jpg','http://i.xunlei.com/?redirecturl=regist');
	PicSlider.AddPic('http://i.xunlei.com/img/stylev4/banner_2.jpg','http://hao.xunlei.com/');
	PicSlider.AddPic('http://i.xunlei.com/img/stylev4/banner_3.jpg','http://vip.xunlei.com/active/nianfei.html?referfrom=HD_092410');
	PicSlider.AddPic('http://i.xunlei.com/img/stylev4/banner_4.jpg','http://mediapv.xunlei.com/fcg-bin/statextend?id=2244&url=http://shop.xunlei.com/');
	var rpt = HtmlRepeater.getInstance('_div_slide_container');
	rpt.insertArray('slider', PicSlider._array);
	rpt.run();
	var purl = $P('url');
	if(purl.indexOf('leiyan.xunlei.com') >= 0 || purl.indexOf('gouwu.vip.xunlei') >= 0 ) {
		PicSlider.Set(3);
	} else {
		PicSlider.Set(0);
	}
	PicSlider.Play();
}

