var mySwiper = null,
	mySwiper2 = null;
var mask1 = null,
	mask2 = null; //彈窗
var interval1 = null,
	interval2 = null,
	interval3 = null;
var flag1 = true,
	flag2 = true,
	flag3 = true;


var _url = 'http://ceshi.yabolive.tv/web';
var _url2 = 'http://test.ybact.yazhaiyabo.com/';
var _url3 = 'http://ceshi.yabolive.tv';


if(location.href.indexOf('activity.yazhaiyabo.com') > -1) {
	_url = 'https://webserver.yabolive.net';
	_url2 = 'https://activity.yazhaiyabo.com/';
	_url3 = 'https://webserver.yabolive.net';
}
var cdn = 'https://big.bgp.ourpow.com/comm';

function $ajax(opt) {
	return new Promise(function(resolve, reject) {
		opt = opt || {};
		opt.method = opt.type || 'POST';
		opt.url = _url + opt.url || '';
		opt.async = opt.async || true;
		opt.data = opt.data || null;
		opt.dataType = opt.dataType || 'json';
		opt.success = opt.success || function() {};
		var xmlHttp = null;
		if(XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
		} else {
			xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
		}
		var params = ['uid=' + getRequest().uid, 'cid=web_gw', 'os=WEB', 'token=' + getRequest().token, 'lang=' + (getRequest().lang || 2)];
		for(var key in opt.data) {
			params.push(key + '=' + (opt.data[key] || ''));
		}

		var postData = params.join('&');
		if(opt.method.toUpperCase() === 'POST') {
			xmlHttp.open(opt.method, opt.url, opt.async);
			xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
			xmlHttp.send(postData);
		} else if(opt.method.toUpperCase() === 'GET') {
			xmlHttp.open(opt.method, opt.url + '?' + postData, opt.async);
			xmlHttp.send(null);
		}
		xmlHttp.onreadystatechange = function() {
			var res;
			if(this.readyState != 4)return;
			
			if( this.status == 200 || this.status == 304) {
				res = this.responseText;
				if(opt.dataType == 'json') {
					res = JSON.parse(res);
				}
				resolve(res);
			} else {
				reject(new Error(this.statusText));
			}
		};
		
		xmlHttp.onerror = function() {
	      reject(new Error(this.statusText));
	    };
	})
}

var currencyUnit = ''; //寶石 貨幣單位
var currencyImg = ''; //寶石圖片
var incomeUnit = ''; //螢火 收益單位
var incomeImg = ''; //螢火圖片
var headUrl = ''; //默認頭像url
var currencyImg2 = ''; //寶石圖片 小
var giftObjImg = '';
			
function getInit() {
	return new Promise(function(resovle, reject) {
		$ajax({
			url: '/active201904/getUserInfo.html',
		}).then(function(res) {
			if(res.vest == 41) {
				if(url_get_params().appversion < 5960) {
					currencyUnit = '樱花'; //貨幣單位
					incomeUnit = '花瓣'; //收益單位
					headUrl = 'https://app.ixiulive.com/static/images/headc.png';
					currencyImg = '<img class="current2" src="https://app.ixiulive.com/static/images/current2.png" />';
					currencyImg2 = 'https://app.ixiulive.com/static/images/current2s.png';
					incomeImg = '<img class="income2" src="https://app.ixiulive.com/static/images/income2.png" />';
					giftObjImg = 'https://app.ixiulive.com/static/images/current2.png';
				} else {
					currencyUnit = '寶石'; //貨幣單位
					incomeUnit = '羽毛'; //收益單位
					headUrl = 'https://app.ixiulive.com/static/images/head2.png';
					currencyImg = '<img class="current4" src="https://app.ixiulive.com/static/images/current4.png" />';
					currencyImg2 = 'https://app.ixiulive.com/static/images/current4s.png';
					incomeImg = '<img  class="income4" src="https://app.ixiulive.com/static/images/income4.png" />';
					giftObjImg = 'https://app.ixiulive.com/static/images/current4.png';
				}
			} else if(res.vest == 40) {
				currencyUnit = '金幣'; //貨幣單位
				incomeUnit = '金豆'; //收益單位
				headUrl = 'https://app.ixiulive.com/static/images/headp.png';
				currencyImg = '<img class="current3" src="https://app.ixiulive.com/static/images/current3.png" />';
				currencyImg2 = 'https://app.ixiulive.com/static/images/current3s.png';
				incomeImg = '<img class="income3" src="https://app.ixiulive.com/static/images/income3.png" />';
				giftObjImg = 'https://app.ixiulive.com/static/images/current3.png';
			} else if(res.vest == 50 || res.vest == 60) {
				currencyUnit = '寶石'; //貨幣單位
				incomeUnit = '羽毛'; //收益單位
				headUrl = 'https://app.ixiulive.com/static/images/head2.png';
				currencyImg = '<img class="current4" src="https://app.ixiulive.com/static/images/current4.png" />';
				currencyImg2 = 'https://app.ixiulive.com/static/images/current4s.png';
				incomeImg = '<img  class="income4" src="https://app.ixiulive.com/static/images/income4.png" />';
				giftObjImg = 'https://app.ixiulive.com/static/images/current4.png';
			} else {
				currencyUnit = '寶石'; //貨幣單位
				incomeUnit = '螢火'; //收益單位
				headUrl = 'https://zhibocdn.yabolive.net/comm/user/boy.png';
				currencyImg = '<img class="current1" src="https://app.ixiulive.com/static/images/current1.png" />';
				currencyImg2 = 'https://app.ixiulive.com/static/images/current1s.png';
				incomeImg = '<img class="income1" src="https://app.ixiulive.com/static/images/income11.png" />';
				giftObjImg = 'https://app.ixiulive.com/static/images/current1.png';
			}
			resovle(res);
		})
	})
}

//跳转到规则
function goRule(){
	window.location.href = 'rule.html' + location.search;
}

//关闭弹窗
function closeMasking(){
	layer.closeAll();
}

function getTime(time) {
	var timezone = 8; //目标时区时间,东八区
	var offset_GMT = new Date(time).getTimezoneOffset(); // 本地时间和格林威治的时间差,单位为分钟
	var nowDate = new Date(time).getTime(); // 本地时间距 1970 年 1 月 1 日午夜(GMT 时间)之间的毫秒数
	var data = new Date(nowDate + offset_GMT * 60 * 1000 + timezone * 60 * 60 * 1000);

	var year = data.getFullYear();
	var month = data.getMonth() + 1;
	var day = data.getDate();
	var hour = data.getHours();
	var minute = data.getMinutes();
	var sec = data.getSeconds();

	var obj = {
		"year": year,
		"month": add0(month),
		"day": add0(day),
		"hour": add0(hour),
		"minute": add0(minute),
		"sec": add0(sec),
	}

	return obj;
}

//加0
function add0(m) {
	return m < 10 ? '0' + m + "" : m + ""
}


//多語言
var langList = [
	{
		"upright1":"活動",
		"upright2":"客服",
		"upright3":"說明",
		"upright4":"記錄",
		"upright5":"分享",
		"upright6":"在線客服",
		"upright7":"Hi,請問有什麼可以幫到您?",
	},
	{
		"upright1":"Activity",
		"upright2":"Online service",
		"upright3":"Rules",
		"upright4":"Record",
		"upright5":"Share",
		"upright6":"Customer service",
		"upright7":"Hi, what can I do for you?",
	}
]
var langType = 0;
var langCon = getRequest().lang;
if(langCon==undefined || langCon == 'undefined'){
	langCon = sessionStorage.lang;
}
//当没有语言参数时 默认为繁体
if(langCon==undefined || langCon == 'undefined'){
	langCon = 2;
}

if(langCon == 2){
	langType = 0;
} else {
	langType = 1;
}

try{
	if(getRequest().appversion>=6130){
				var obj = {
		          "cid": 29,
		          "reqCode": new Date().getTime(),
		          "data": {
		              "msg":"h5网页右上角显示图标",
		              "info":[
		                  {
		                      "imgUrl":'https://app.ixiulive.com/static/app/img/2.png?v=202107211759',
		                      "explain":langList[langType].upright1,
		                       "cid":"12",
		                       "data": {
						          "msg":"跳转集合功能", 
						          "jumptype":"3",
						          "url":_url2+'/active2021/activityCenter/index.html'+location.search,
						      }
		                  },
		                  {
		                      "imgUrl":'https://app.ixiulive.com/static/app/img/kf.gif',
	                        	"explain":langList[langType].upright2,
		                      "cid": "4",
		                      "data":{
					              "msg": langList[langType].upright7,
					              'title':langList[langType].upright6,
					              "customerLayer":"1",
					              "uid":"1001",
					              "face":cdn+"/img/appicon/yqzx_icon_v1.png?x-oss-process=image/resize,h_100,w_100",
					              "nickname":langList[langType].upright6,
					         	 }
		                     },
		                  
		              ]
		          }
		      }
		      var obj2 = JSON.stringify(obj);
		      appCollaboration(obj2)
			
		}
}catch(e){
	//TODO handle the exception
}

//获取url参数
function getRequest() {
	var url = location.href;
	var theRequest = new Object();
	if(url.indexOf("?") != -1) {
		var str = url.substr(url.indexOf("?") + 1);
		strs = str.split("&");
		for(var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest;
}

function close() {
	var obj = {
		"cid": 14,
		"reqCode": new Date().getTime(),
		"data": {
			"msg": '關閉半屏網頁',
		}
	}
	var obj2 = JSON.stringify(obj);
	appCollaboration(obj2);
}

function appCollaboration(msg) {
	var sUserAgent = navigator.userAgent.toLowerCase();
	var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
	var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
	var bIsMidp = sUserAgent.match(/midp/i) == "midp";
	var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
	var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
	var bIsAndroid = sUserAgent.match(/android/i) == "android";
	var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
	var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
	if(!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM)) {} else if(bIsAndroid) {
		window.yazhai.appCollaboration(msg);
	} else if(bIsIphoneOs || bIsIpad) {
		window.webkit.messageHandlers.appCollaboration.postMessage(msg);
	}
}
//客户端回调结果
function appCallback(msg) {
	console.log(msg);
}