﻿document.domain="xunlei.com"

function initCommon(){
	initKfzx();
	initKstd();
	initMenu();
	initBannerAD();
	initAdvs();
	initFooter();
}

function initKfzx(){
	var kfdiv = document.getElementById('kfzxdiv');
	if(kfdiv){
		kfdiv.innerHTML = '<p>游戏客户服务请咨询：<br/>021-61454815</p><p>帐号注册及雷点充值请咨询：<br/>0755-26035666</p><p>迅雷商务：<br/>0755-26035888-8264 </p>';
	}
}

function initKstd(){
	var kfdiv = document.getElementById('kstddiv');
	if(kfdiv){
		kfdiv.innerHTML = '<h3 class="kstd">快速通道</h3><ul><li><a href="http://gongfu.xunlei.com/reg/" target="_blank" >注册账号</a></li><li><a href="http://gongfu.xunlei.com/download.html" target="_blank" >游戏下载</a></li><li><a href="http://gongfu.xunlei.com/website/info/index.html" target="_blank" >游戏资料</a></li><li><a href="http://pay.xunlei.com/ourproducts_gfsj.html" target="_blank" >快速充值</a></li><li><a href="http://gamebbs.xunlei.com/forumdisplay.php?fid=232" target="_blank" >火爆论坛</a></li></ul>';
	}
}

function initMenu(){
	var topmenu = document.getElementById('top_menu');
	if(topmenu){
		topmenu.innerHTML = '<div class="menu"><a href="http://gongfu.xunlei.com" id="a_home" >首页</a><a href="http://gongfu.xunlei.com/c/0000070001-0000070002-0000070003_1.html" id="a_news">新闻公告</a><a href="http://gongfu.xunlei.com/website/info/index.html" id="a_yxzl">游戏资料</a><a href="http://gongfu.xunlei.com/download.html" id="a_xzzx">下载中心</a><a href="http://gongfu.xunlei.com/id_man.html" id="a_zhgl">账号管理</a><a href="http://gongfu.xunlei.com/help.html" id="a_kfzx">客服中心</a><a href="http://gamebbs.xunlei.com/forumdisplay.php?fid=232" id="a_bbs" target="_blank">火爆论坛</a><a href="http://pay.xunlei.com/ourproducts_gfsj.html" target="_blank" id="a_pay" class="up">充值中心</a></div>';
	}
}

function initBannerAD(){
	var bannerad = document.getElementById('bannerad');
	if(bannerad && _bannerAdvs){
		var bc = '';
		for(var i = 0; i < _bannerAdvs.length; i++){
			bc+='<li class="ad2"><a href="'+_bannerAdvs[i].url+'" target="_blank" title="'+_bannerAdvs[i].title+'"><img width="194" height="100" src="'+_bannerAdvs[i].img+'" alt="'+_bannerAdvs[i].title+'" /></a></li>';
		}
		bannerad.innerHTML = '<div class="left_p"></div><div class="right_p"></div><ul>'+bc+'</ul>';
	}
}


function initFooter(){
	var footer = document.getElementById('footer');
	if(footer){
		var footerc = '<p><a href="http://www.xunlei.com" title="迅雷" class="xlLogo"><img src="http://img.gongfu.xunlei.com/img_v2/xl_gongfu.jpg" alt="迅雷" /></a></p><a href="http://hr.xunlei.com/" target="_blank">加盟迅雷</a> | <a href="http://pstatic.xunlei.com/about/about.htm" target="_blank">关于迅雷</a> | <a href="http://bbs.xunlei.com" target="_blank">官方论坛</a> | <a href="http://www.gougou.com/code.html" target="_blank">搜索代码</a> | <a href="http://union.xunlei.com" target="_blank">迅雷联盟</a> | <a href="http://i.xunlei.com/top/total_1.htm" target="_blank">雷友排行</a> | <a href="http://pstatic.xunlei.com/about/other/duty.htm" target="_blank">免责声明</a> | <a href="http://pstatic.xunlei.com/about/other/banner.html" target="_blank">广告服务</a><br /><strong>迅雷公司 版权所有</strong><div class="safe08"><a href="http://www.sznet110.gov.cn/webrecord/innernet/Welcome.jsp?bano=4403302010122" target="_blank"><img src="http://moyu.xunlei.com/commonfooter/1.gif" alt="" /></a> <a href="http://www.sznet110.gov.cn" target="_blank"><img src="http://moyu.xunlei.com/commonfooter/2.gif" alt="" /></a></div>';
		footer.innerHTML = footerc;
	}
}


function initAdvs(){
	var leftadtop = document.getElementById('leftadtop');
	if(leftadtop && _leftAdvs && _leftAdvs[0]){
		leftadtop.innerHTML = '<a href="'+_leftAdvs[0].url+'" target="_blank" title="'+_leftAdvs[0].title+'"><img width="180" height="57" src="'+_leftAdvs[0].img+'" alt="'+_leftAdvs[0].title+'" /></a>';
	}

	var leftadbot = document.getElementById('leftadbot');
	if(leftadbot  && _leftAdvs){
		var lc = '';
		for(var i = 1; i < _leftAdvs.length; i++){
			lc+='<li><a href="'+_leftAdvs[i].url+'" target="_blank" title="'+_leftAdvs[i].title+'"><img width="180" height="57" src="'+_leftAdvs[i].img+'" alt="'+_leftAdvs[i].title+'" /></a></li>';
		}
		leftadbot.innerHTML = '<ul>'+lc+'</ul>';
	}

	var rightad = document.getElementById('rightad');
	if(rightad  && _rightAdvs){
		var rc = '';
		for(var i = 0; i < _rightAdvs.length; i++){
			rc+='<div class="right_ad"><a href="'+_rightAdvs[i].url+'" target="_blank" title="'+_rightAdvs[i].title+'"><img width="191" height="68" src="'+_rightAdvs[i].img+'" alt="'+_rightAdvs[i].title+'" /></a></div>';
		}
		rightad.innerHTML = rc;
	}
}

function download(){
	window.open("http://sx.xunlei.com/download.html"+getSearch());
}
function register(){
	showRegPnl();
}
function chongzhi(){
	window.open("http://pay.xunlei.com/ourproducts_sx.html"+getSearch());
}
function aiqin(){
	window.open("http://sx.xunlei.com/zt/xs/index.html"+getSearch());
}
function getSearch(){
	var loc = location.search;
	return loc;
}
function addEventSimple(obj,evt,fn){
	if(obj.addEventListener){
		obj.addEventListener(evt,fn,false);	
	}else if(obj.attachEvent){
		obj.attachEvent('on'+evt,fn);
	}
}
function appendParams(){
	var exp = /^(http\:\/\/gongfu\.xunlei\.com\/|\/).*/;
	var as = document.getElementsByTagName("a");
	var search = getSearch();
	for(var i = 0; i < as.length; i++){
		if(exp.test(as[i].href) && as[i].href != (location+'#') && !(as[i].getAttribute('reseqid'))){
			as[i].href += search;
		}
	}
}

addEventSimple(window,'load',appendParams);



//投票部分开始
document.write("<script type='text/javascript' src='http://mygame.xunlei.com/jsdata/votevar/netgame/000007.js' charset='utf-8'><\/script>");
document.write("<script type='text/javascript' src='http://mygame.xunlei.com/js/vote.js' charset='utf-8'><\/script>");

var cboxs;
function initVote(){
	if(document.getElementById('votediv')){
		var content='<h3 class="zxdc">在线调查</h3><dl>'
		content += '<dt>'+votetitle+'</dt>'
		content += '<dd><ul>';
		for (var i=0;i<voteoptions.length;i++){
			content+="<li><input name=\"choose\" type=\"radio\" value="+voteoptionids[i]+" /> <label for=\"choose\">"+voteoptions[i]+"</label></li>";
		}
		content += '</ul></dd></dl>';
		content+='<p><input type="image" alt="提交" id="submitBtn" src="http://img.gongfu.xunlei.com/img_v2/submit_btn.jpg"/><input type="image" alt="查看" id="resultBtn" src="http://img.gongfu.xunlei.com/img_v2/ck_btn.jpg"/></p>';
		document.getElementById('votediv').innerHTML = content;	
		document.getElementById('submitBtn').onclick=submitVote;
		document.getElementById('resultBtn').onclick=showVote;
		cboxs=document.getElementsByName("choose");
	}
}
function submitVote(){
	if(typeof(_preSubmit) == "function"){
			if(!_preSubmit()){
				return ;
			}
	}
	var url = votesvr+"?gameid="+gameid+"&titleid="+titleid+"&rtntype=script&optionid=";
	var isChecked = false;
	for(var i=0;i<voteoptionids.length;i++){
		if (cboxs[i].checked) {
			url += voteoptionids[i];
			isChecked = true;
			break;
		}
	}
	if(isChecked)
		webGame.acrossDomain.request(url,submitVoteAction,false);
	else
		alert("请选择");
}
function submitVoteAction(rtn){
	if(rtn.voteSubmitStatus==0){
		if(typeof(_sucSubmit)=='function'){
			_sucSubmit();
		}
		alert("投票成功 谢谢您的参与");
	}else if(rtn.voteSubmitStatus==2){
		alert("一天只能投票一次");
	}else{
		alert("投票失败 请重试");
	}
}
function showVote(){
	var url = voteressvr+"?gameid="+gameid+"&titleid="+titleid+"&rtntype=script";
	webGame.acrossDomain.request(url,showVoteAction,false);
}
function showVoteAction(rtn){
	var params = "";
	for(var i=0;i<voteoptions.length;i++){
		params += "r"+voteoptionids[i]+"=" + rtn.resultMap[voteoptionids[i]];
		if(i != voteoptions.length-1){
			params += "&";
		}
	}
	window.open('http://gongfu.xunlei.com/vote_result.html?' + params);
}

addEventSimple(window,'load',initVote);

//vote
var webGame;
if (!webGame){webGame = {};}
if(!webGame.acrossDomain){webGame.acrossDomain = {};}
	 
var scriptBlock = document.createElement("script");
webGame.acrossDomain.request = function(vPath,func,isDebug){
    scriptBlock = document.createElement("script"); 
	if(isDebug)
        alert(vPath); 
	scriptBlock.src = vPath;
	scriptBlock.type = "text/javascript";
	scriptBlock.language = "javascript";
	
	if(webGame.acrossDomain.getBrowseName().toLocaleLowerCase() == "ie"){
		scriptBlock.onreadystatechange = function(){
			if(isDebug)
				alert(scriptBlock.readyState);
			webGame.acrossDomain.cleanStatus();
			if("loaded" == scriptBlock.readyState || "complete" == scriptBlock.readyState){
				func(votertn);
			}
			webGame.acrossDomain.resetStatus();
		}
	}else{
		scriptBlock.onload = function(){
			webGame.acrossDomain.cleanStatus(); 
			try{ 
				func(votertn);
			}catch(e){ 
			}  
			webGame.acrossDomain.resetStatus();
		}
	}
	document.getElementsByTagName("head")[0].appendChild(scriptBlock);
}
	webGame.acrossDomain.getBrowseName = function(){
	if (window.navigator.userAgent.indexOf("MSIE")>=1){
		 return 'IE';
	}else{
		if (window.navigator.userAgent.indexOf("Firefox")>=1){
			 return 'firefox';
		}else{
			 return 'unknow';
		}
	}
} 
webGame.acrossDomain.cleanStatus = function(txt){
	if(!txt){txt='Loading ... ...';}
	try{
		window.status=txt;
	}catch(e){
		alert('Debug:Status='+e);
	}
}
webGame.acrossDomain.resetStatus = function(){
	try{
		window.status="";
	}catch(e){
	}
}

//投票部分结束