var gg = "</br>1.官方限制每天最多领取5个棒棒糖</br>2.一周最多领取20个棒棒糖";
function submit() {
	layer.open({type: 2});
	var b = document.getElementById("url").value;
	if (null == b.match(/^http:\/\/dwz\.cn\/\w+$/) && null == b.match(/^http:\/\/t\.cn\/\w+$/)){
		layer.closeAll();
		$.Confirm("", "您输入的链接不正确，请重新输入!", 1);
		return ;
	}
	$.ajax({
		url: "./php/do.php?url=" + b,
		dataType: "json",
		success: function(a) {
			layer.closeAll();
			var text = null;
			switch (a.code) {
			case "0":
				$.Confirm("", "尊敬的："+a['account']+"["+a['id']+"]，您好！<br />您的棒棒糖已刷取完毕，请前往游戏查看！</br><img border=\"0\" src=\"Mao/images/ok.gif\">" + gg + "", 1);
			break;
			case "1":
				$.Confirm("", "尊敬的："+a['account']+"["+a['id']+"]，您好！<br />今天已经为你点过链接了,明天再来吧！</br><img border=\"0\" src=\"Mao/images/no.gif\">" + gg + "", 1);
			break;
			case "2":
				$.Confirm("", "尊敬的："+a['account']+"["+a['id']+"]，您好！<br />今天已经为你点过链接了,明天再来吧！</br><img border=\"0\" src=\"Mao/images/no.gif\">" + gg + "", 1);
			break;
			case "3":
				$.Confirm("", "尊敬的："+a['account']+"["+a['id']+"]，您好！<br />今天已经为你点过链接了,明天再来吧！</br><img border=\"0\" src=\"Mao/images/no.gif\">" + gg + "", 1);
			break;
			case "-1":
				$.Confirm("", "您还没有输入邀请链接！请打开球球大作战游戏->点击右上角加号->点击获取棒棒糖->点击复制链接，粘贴到本站即可！" + gg + "", 1);
			break;
			case "-2":
			case "-5":
				$.Confirm("", "解析邀请链接地址失败！请重试！\n或者您的邀请链接输错了，请打开球球大作战游戏->点击右上角加号->点击获取棒棒糖->点击复制链接，粘贴到本站即可！" + gg + "", 1);
			break;
			case "-3000":
				$.Confirm("", "-3000！刷棒棒糖失败！请联系站长！" + gg + "", 1);
			break;
			case "-7":
				$.Confirm("", "请求超时,数据异常！请联系站长！" + gg + "", 1);
			break;
			default:
				if(a.code == "vcode"){
					layer.open({
						title: "<b style='color: #666699;'>检测到您频繁提交链接</b>",
						closeBtn: 0,
						shadeClose: true,
						content: "<p style='color: #66CCFF; font-weight: bold; font-family: 微软雅黑;'>你需要证明你是一个真的人:)</p><br /><div style='text-align: center;'><img src='./vcode.php?type=1&rand="+Math.random()+"' onclick=\"this.src='./vcode.php?type=1&rand='+Math.random();\"></img><br /><input type=\"text\" class=\"vcode\" id=\"vcode_code\" onkeydown='if(event.keyCode==13){get_vocde()}' placeholder=\"请输入验证码\"><div id='vcode_res'></div></div>",
						btn: ["提交"],
						yes: function (){
							get_vocde();
						}
					});	
				}
			}
		},
		error: function(a) {
			layer.closeAll();
			$.Confirm("", "与服务器的连接失败，请重试！" + gg + "",1);
		}
	})
}
function get_vocde(){
	var vcode = document.getElementById("vcode_code").value;
	var b = document.getElementById("url").value;
	if(vcode == ""){
		document.getElementById("vcode_res").innerHTML = "<span style='font-weight: bold; color: red;'>请填写验证码！</span>";
	}
	else if(vcode.length != 4){
		document.getElementById("vcode_res").innerHTML = "<span style='font-weight: bold; color: red;'>验证码填写错误！</span>";
	}
	else{
		layer.closeAll();
		layer.open({type: 2});
		$.ajax({
			url: "./php/do.php?url=" + b + "&vcode=" + vcode,
			dataType: "json",
			success: function(data){
				layer.closeAll();
				if(data.code != undefined){
					var api_text = null;
					switch (data.code){
						case "0":
							api_text = "尊敬的："+data['account']+"["+data['id']+"]，您好！<br />您的棒棒糖已刷取完毕，请前往游戏查看！</br><img border=\"0\" src=\"Mao/images/ok.gif\">" + gg + "";
						break;
						case "1":
							api_text = "尊敬的："+data['account']+"["+data['id']+"]，您好！<br />今天已经为你点过链接了，明天再来吧！</br><img border=\"0\" src=\"Mao/images/no.gif\">" + gg + "";
						break;
						case "2":
							api_text = "尊敬的："+data['account']+"["+data['id']+"]，您好！<br />今天已经为你点过链接了，明天再来吧！</br><img border=\"0\" src=\"Mao/images/no.gif\">" + gg + "";
						break;
						case "3":
							api_text = "尊敬的："+data['account']+"["+data['id']+"]，您好！<br />今天已经为你点过链接了，明天再来吧！</br><img border=\"0\" src=\"Mao/images/no.gif\">" + gg + "";
						break;
						case "-1":
							api_text = "您还没有输入邀请链接！请打开球球大作战游戏->点击右上角加号->点击获取棒棒糖->点击复制链接，粘贴到本站即可！" + gg + "";
						break;
						case "-2":
						case "-5":
							api_text = "链接错误了！\n请打开球球大作战游戏->点击右上角加号->点击获取棒棒糖->点击复制链接，粘贴到本站即可！" + gg + "";
						break;
						case "-3000":
							api_text = "-3000！刷棒棒糖失败！请联系站长！" + gg + "";
						break;
						case "-7":
							api_text = "请求超时,数据异常！请联系站长！" + gg + "";
						break;
						case "vcode error":
							api_text = "验证码错误！" + gg + "";
						break;
						default:
							api_text = "发生未知错误，请刷新页面！若连续出现未知情况，请联系站长" + gg + "";
					}
					
					$.Confirm("", api_text,1);
				}
			},
			error: function(){
				layer.closeAll()
				$.Confirm("", "与服务器的连接失败，请重试！" + gg + "",1);
			}
		});
	}
}
function daidian() {
	var key = document.getElementById("ddkey").value;
	var url = document.getElementById("ddurl").value;
	var qq = document.getElementById("ddqq").value;
	if(key == "" && url == "" && qq == ""){
		$.Confirm("",'请输入正确的球球链接!',1);
		return ;
	}
	layer.open({
		type: 3
	});
	$.ajax({
		url: "/Charge/api.php?action=yes&key=" + key + "&url=" + url + "&qq=" + qq ,
		dataType: "json",
		success: function(a) {
			layer.closeAll();
			if (a.action == "1"){
				if(a.type == "2"){
					if(a.msg == "0"){
						$.Confirm("","恭喜你，续费成功！<br /><br />到期时间：<b style='color: red;'>" + a.dateday +"</b><br /><br />若有问题请联系站长",1);
					}
					else if(a.msg == "1"){
						$.Confirm("","恭喜你，续费成功，但是遇到一些小问题<br /><br />到期时间：" + a.dateday +"<br /><br />原因：" + a.account + "<br /><br />若有问题请联系站长",1);
					}
					else if(a.msg == "-1"){
						$.Confirm("","续费失败，请重试，若有问题请联系站长",1);
					}
					else if(a.msg == "stop"){
						$.Confirm("","该id已被封禁，禁止续费.",1);
					}
				}
				else if(a.type == "1"){
					if(a.msg == "0"){
						$.Confirm("","恭喜你，开通成功！<br /><br />到期时间：<b style='color: red;'>" + a.dateday +"</b><br /><br />若有问题请联系站长",1);
					}
					else if(a.msg == "1"){
						$.Confirm("","恭喜你，开通成功，但是遇到一些小问题<br /><br />到期时间：" + a.dateday +"<br /><br />原因：" + a.account + "<br /><br />若有问题请联系站长",1);
					}
					else if(a.msg == "-1"){
						$.Confirm("","开通失败，请重试，若有问题请联系站长",1);
					}
					else if(a.msg == "-3000"){
						$.Confirm("","提交异常，请联系站长解决",1);
					}
				}
				else{
					if(a.msg == '404'){
						$.Confirm("","Key不存在,或Key已被使用!",1);
					}
					else if(a.msg == "-3"){
						$.Confirm("","未查询到该链接的id",1);
					}
				}
			}
			else if(a.action == "2"){
				if(a.msg == "0"){
					$.Confirm("", "<p><b style='font-size: 17px;'>用户名</b><br /><b style='color: red;'>" + a.username + "</b><br /><hr /><b style='font-size: 17px;'>您的链接</b><br /><b style='color: red;'>" + a.url + "</b><br /><hr /><b style='font-size: 17px;'>使用的CDKey</b><br /><b style='color: red;'>" + a.cdk + "</b><br /><hr /><b style='font-size: 17px;'>到期时间</b><br /><b style='color: red;'>" + a.datetime + "</b><br /><hr /><b style='font-size: 17px;'>服务器状态</b><br />" + a.server + "</p>",1);
				}
				else if(a.msg == "-3"){
					$.Confirm("", "抱歉！查询失败,请重试！若频繁出现此问题,请联系站长!",1);
				}
				else if(a.msg == "404"){
					$.Confirm("", "抱歉！没有查询到记录~",1);
				}
				else if(a.msg == "-3000"){
					$.Confirm("",  "数据异常，请联系站长解决",1);
				}
				else if(a.msg == "500"){
					$.Confirm("", "数据库连接失败，请联系站长解决",1);
				}
			}
			else if(a.action == "3"){
				if(a.msg == "0"){
					$.Confirm("",  "<p><b style='font-size: 17px;'>用户名</b><br /><b style='color: red;'>" + a.username + "</b><br /><hr /><b style='font-size: 17px;'>您的链接</b><br /><b style='color: red;'>" + a.url + "</b><br /><hr /><b style='font-size: 17px;'>使用的CDKey</b><br /><b style='color: red;'>" + a.cdk + "</b><br /><hr /><b style='font-size: 17px;'>到期时间</b><br /><b style='color: red;'>" + a.datetime + "</b><br /><hr /><b style='font-size: 17px;'>服务器状态</b><br />" + a.server + "</p>",1);
				}
				else if(a.msg == "-1"){
					$.Confirm("", "未查询到该链接的id",1);
				}
				else if(a.msg == "-3"){
					$.Confirm("", "抱歉！查询失败,请重试！若频繁出现此问题,请联系站长!",1);
				}
				else if(a.msg == "404"){
					$.Confirm("", "抱歉！没有查询到记录~",1);
				}
				else if(a.msg == "-3000"){
					$.Confirm("", "数据异常，请联系站长解决</p>",1);
				}
				else if(a.msg == "500"){
					$.Confirm("", "数据库连接失败，请联系站长解决",1);
				}
			}
		},
		error: function(a) {
			layer.closeAll()
			$.Confirm("", "连接服务器失败，请重试！",1);
		}
	})
}
function lyz() {
	var key = document.getElementById("lyzkey").value;
	var url = document.getElementById("lyzurl").value;
	var nc = document.getElementById("lyznc").value;
	var nr = document.getElementById("lyznr").value;
	var qq = document.getElementById("lyzqq").value;
	if(key == "" && url == "" && nc == "" && nr == "" && qq == ""){
		$.Confirm("",'请输入正确的订单信息!',1);
		return ;
	}
	layer.open({
		type: 3
	});
	$.ajax({
		url: "/lyz-api/api.php?action=yes&key=" + key + "&url=" + url + "&nc=" + nc + "&nr=" + nr + "&qq=" + qq ,
		dataType: "json",
		success: function(a) {
			layer.closeAll();
			if (a.action == "1"){
				if(a.type == "1"){
					if(a.msg == "0"){
						$.Confirm("","提交成功.订单会在当天执行！",1);
					}
					else if(a.msg == "1"){
						$.Confirm("","提交成功.但是遇到一些小问题.请联系站长",1);
					}
					else if(a.msg == "-1"){
						$.Confirm("","提交失败，请重试，若请联系站长",1);
					}
					else if(a.msg == "-3000"){
						$.Confirm("","提交异常，请联系站长解决",1);
					}
				}
				else{
					if(a.msg == '404'){
						$.Confirm("","Key不存在,或Key已被使用!",1);
					}
					else if(a.msg == "-3"){
						$.Confirm("","未查询到该链接的id",1);
					}
				}
			}
			
		},
		error: function(a) {
			layer.closeAll()
			$.Confirm("", "连接服务器失败，请重试！",1);
		}
	})
}
$.extend({
	Confirm: function(){
		var template = multiline(function(){/*!@preserve
			<style>
			    .jquery-confirm-content {width:360px;}
				.jquery-confirm-content p{margin:.7em 0 0;padding:0;}
				.jquery-confirm-cancel:hover,.jquery-confirm-ok:hover{background:#f0f0f0;}
                @media screen and (max-width: 430px) { 
                .jquery-confirm-content {width:300px;text-align:center;} 
                }
                @media screen and (max-width: 380px) { 
                .jquery-confirm-content {width:270px;text-align:center;} 
                }
                @media screen and (max-width: 350px) { 
                .jquery-confirm-content {width:210px;text-align:center;} 
                }
                @media screen and (max-width: 280px) { 
                .jquery-confirm-content {width:100%;text-align:center;} 
                }				
			</style>
			<div style="position:fixed;width:100%;height:100%;display:table;text-align:center;z-index:100001;top:0;left:0;">
            <div style="position:absolute;width:100%;height:100%;top:0;left:0;background:#000;opacity:0.2;filter: alpha(opacity=40);"></div>
            <div style="position:relative;display:table-cell;vertical-align:middle;">
                <div style="display:inline-block;background:#fff;border-radius:3px;text-align:left;overflow:hidden;max-width:97%;">
                    <div style="padding:30px;line-height:1.5;border-bottom:1px solid #F2F2F2;">
                        <div class="jquery-confirm-content" style="font-size:16px;margin-top:.7em; text-align:center; color:#777777;"></div>
                    </div>
                    <div style="display:inline-table;width:100%;line-height:40px;height:40px;font-size:17px;text-align:center;">
                        <a class="jquery-confirm-cancel" href="javascript:;" style="display:table-cell;box-sizing:border-box;color:#3498DB;text-decoration:none;text-align:center;">取消</a>
                        <a class="jquery-confirm-ok" href="javascript:;" style="display:table-cell;box-sizing:border-box;color:#33CC33;text-decoration:none;text-align:center;">确定</a>
                    </div>
                </div>
            </div>
		</div>
		*/console.log()});
	
		return function(title,content,btns_num){
			var title = title||'',
				content = content||'',
				btns_num = btns_num||2,
				ok,cancel,result = {
					ok:function(func){ok=func;return result;},
					cancel:function(func){cancel=func;return result;}
				};

			var dom = $('<div>').html(template);

			btns_num==1
				? dom.find('.jquery-confirm-cancel').remove()
				: dom.find('.jquery-confirm-ok').css('border-left','1px solid #F2F2F2');
	
			dom.on('touchmove',function(){return false;});
			dom.find('.jquery-confirm-title').html(title);
			dom.find('.jquery-confirm-content').html(content);
			dom.find('.jquery-confirm-ok').on('click',function(){
				ok && ok();
				dom.remove();
			});
			dom.find('.jquery-confirm-cancel').on('click',function(){
				cancel && cancel();
				dom.remove();
			});
			dom.appendTo( $('body') );

			return result;
		}
	
		function multiline(fn){ //https://github.com/sindresorhus/multiline
			var reCommentContents = /\/\*!?(?:\@preserve)?[ \t]*(?:\r\n|\n)([\s\S]*?)(?:\r\n|\n)[ \t]*\*\//;
			if(typeof fn !== 'function'){throw new TypeError('Expected a function');}
			var match = reCommentContents.exec(fn.toString());
			if(!match){throw new TypeError('Multiline comment missing.');}
			return match[1];
		};
	}()
});