function Dialog(t){
function e(t, e) {
var i = l.outerWidth(!0), n = l.outerHeight(!0), o = $(window).width(), c = $(window).height();
switch(t) {
case"center":
if("t"==e) return c/2-n/2;
if("l"==e)return o/2-i/2;
break;
case"top":
case"left":return 0;
case"bottom":return c-n;
case"right":return o-i
}
}
function i() {
var t = s.position.split(","), i = $.trim(t[0]), n = $.trim(t[1]);
l.css({position:"absolute", top:parseInt(i)?i:e(i, "t"), left:parseInt(n)?n:e(n, "l")})
}
function n() {
l.draggable({containment:"window", handle:".dialog-header"})
}
function o() {
$.each(s.buttons, function(t, e) {
e = $.isFunction(e)?{click:e, value:t}:e, e = $.extend({type:"button"}, e);
var i = e.click;
e.click = function() {
i.apply(this, r, l, arguments)
}, $(" ", e).appendTo(p)
})
}
function c(t) {
var e, i = ["", 0, null, void 0];
for(e in i)
if(t == i[e])return!0; return!1
}
if(!jQuery)return alert("Для работы диалогов требуется jQuery библиотека."), !1;
var r = this, a = {position:"center,center", style:{}, title:"", content:"", template:['
"], onopen:$.noop, onclose:$.noop, buttons:!1, autoopen:!0, draggable:!0}, s = $.extend(a, t), l = $(s.template.join("")), d = l.find(".dialog-header"), u = d.find(".dialog-title"), k = l.find(".dialog-content"), p = l.find(".dialog-buttons"), f = d.find(".dialog-close-button"); return 0 == u.length || 0 == d.length || 0 == k.length || 0 == p.length || 0 == f.length ? void alert("Error css classes: dialog-title, dialog-header, dialog-content, dialog-buttons, dialog-close-button not found!"):(this.open =!1,
this.set = function(t, e) {
switch(t) {
case"content":
s.content = e, k.html(e);
break;
case"title":
s.title=e, u.text(e);
break;
case"position":
s.position = e, this.rePosition();
break;
case"onopen":
$.isFunction(e) && (s.onopen = e);
break;
case"onclose":$.isFunction(e)&&(s.onclose=e);break;case"draggable":"enable"==e?n():"disable"==e&&l.draggable("destroy");break;case"buttons":$.isPlainObject(e)&&!$.isEmptyObject(e)&&(p.show(),s.buttons=e,o())}},this.get=function(t){return s[t]||null},this.rePosition=function(){i()},this.close=function(){r.open=!1,s.onclose.call(r,l),l.hide()},this.show=function(){r.open=!0,s.onopen.call(r,l),l.show()},$("body").append(l),l.hide(),l.css(s.style),c(s.title)||u.html(s.title),f.click(function(){return r.close(),!1}),c(s.content)||k.html(s.content),($.isPlainObject(s.buttons)&&!$.isEmptyObject(s.buttons)||$.isArray(s.buttons)&&s.buttons.length>0)&&o(),$.isEmptyObject(s.buttons)&&p.hide(),i(),s.draggable&&void 0!==$.fn.draggable&&n(),void(s.autoopen&&this.show()))}jQuery&&($.extend({isEmpty:function(t){var e,i=["",0,null,void 0,!1,"null","undefined","false"];for(e in i)if(t==i[e])return!0;return!1},random:function(t,e){return void 0==t||void 0==e?Math.random():Math.ceil(Math.random()*(e-t))+t},isTrue:function(t){return t>$.random(0,1e4)/100},parseTime:function(t){var e=t.split("-");if(e.length>1){var i=e[0]<1?1:e[0],n=e[1]<1?1:e[1];return n=i>n?i+1:n,1e3*$.random(parseInt(i),parseInt(n))}return 1e3*parseInt(e[0]<1?1:e[0])},getButton:function(t,e,i){return e=e||document,i?i&&$(t,e).length>1?$(t,e).eq(i):!1:$(t,e)},getLink:function(t,e,i){return e=e||document,i?i&&$('a:contains("'+t+'")').length>1?$('a:contains("'+t+'")').eq(i):!1:$('a:contains("'+t+'")')}}),$.fn.findInput=function(t){var e=null;return this.each(function(){var i=$(this),n=i.val();-1!==n.search(t)&&(e=i)}),e});var Kicker=function(){function t(){return-1!=top.frames.main.document.location.href.search("battle")}function e(){var t=$("#"+x+"kick-r").is(":checked"),e=$("#"+x+"block-r").is(":checked"),n=0,o={},c=0,r={},a="",s=i($("#"+x+"waittime").val());t?o[0]="r":($("."+x+"kick:checked").each(function(){var t=$(this),e=t.attr("id").split("-").pop(),i=parseInt($("#"+x+"kick-perc-"+e).val());o[e]=i,n+=i}),n>=0&&100>n?a+=''+m.err_low_perc_kick+"
":n>100&&(a+=''+m.err_big_perc_kick+"
")),e?r[0]="r":($("."+x+"block:checked").each(function(){var t=$(this),e=t.attr("id").split("-").pop(),i=parseInt($("#"+x+"block-perc-"+e).val());r[e]=i,c+=i}),c>=0&&100>c?a+=''+m.err_low_perc_block+"
":c>100&&(a+=''+m.err_big_perc_block+"
")),$.isEmpty(s)&&(a+=''+m.err_no_waittime+"
"),$.isEmpty(a)?(O.waittime=s,O.kick=o,O.block=r,O.ontimeout=$("#"+x+"ontimeout").val(),f[x+"setting"]=JSON.stringify(O),$("#"+x+"errors").show().html('Настройки сохранены
').fadeOut(5e3)):$("#"+x+"errors").show().html(a).fadeOut(3e3)}function i(t){var e=t.split("-");if(e.length>1){var i=Math.ceil(e[0])||1,n=Math.ceil(e[1])||i+1;return n=i>=n?i+1:n,i+"-"+n}var i=Math.ceil(e[0])||1;return""+i}function n(){if($.isPlainObject(O.kick)&&!$.isEmpty(O.kick[0])&&($("#"+x+"kick-r").attr("checked",!0),$("."+x+"kick").attr("disabled",!0)),$.isPlainObject(O.block)&&!$.isEmpty(O.block[0])&&($("#"+x+"block-r").attr("checked",!0),$("."+x+"block").attr("disabled",!0)),$.isPlainObject(O.kick)&&!$.isEmptyObject(O.kick)&&$.isEmpty(O.kick[0])){$("#"+x+"kick-r").attr("checked",!1),$("."+x+"kick").attr("disabled",!1);for(var t in O.kick){var e=O.kick[t];$("#"+x+"kick-"+t).attr("checked",!0),$("#"+x+"kick-perc-"+t).val(e)}}if($.isPlainObject(O.block)&&!$.isEmptyObject(O.block)&&$.isEmpty(O.block[0])){$("#"+x+"block-r").attr("checked",!1),$("."+x+"block").attr("disabled",!1);for(var t in O.block){var e=O.block[t];$("#"+x+"block-"+t).attr("checked",!0),$("#"+x+"block-perc-"+t).val(e)}}$("#"+x+"ontimeout").val(O.ontimeout)}function o(){for(var t,e="off"==h.power?"red":"green",i=' Случайно
',n=' Случайно
',o="",c=0;c '+v[c]+" ",n+=' '+g[c]+"
";for(t in w)o+=''+t+" ";var r=['Состояние: '+m["stat_"+h.power]+"
",' ','
','Время на удар: сек.
','По тайму: '+o+"
",'',"","Удар ","Блок "," ","",""+i+" ",""+n+" "," ","
"];return r.join("")}function c(){if("off"==h.power)return void clearTimeout(_);var e=$(".m",top.frames.main.document).length;s=$(I,top.frames.main.document).findInput(y.KICK),l=$(I,top.frames.main.document).findInput(y.WIN),d=$(I,top.frames.main.document).findInput(y.DRAW),u=$(I,top.frames.main.document).findInput(y.EXIT),k=$(I,top.frames.main.document).findInput(y.REFRESH);var i=$.parseTime(O.waittime),n=Date.now(),o=n-E;if(t()&&0==e){if($.isEmpty(s))$.isEmpty(l)||"win"!=O.ontimeout?$.isEmpty(d)||"draw"!=O.ontimeout?!$.isEmpty(k)&&o>=i&&(k.click(),E=n):d.click():l.click();else if(o>=i){var p=r(),f=a();$("#A"+p,top.frames.main.document).attr("checked",!0),$("#D"+f,top.frames.main.document).attr("checked",!0),s.click(),E=n}$.isEmpty(u)||u.click()}_=setTimeout(function(){c()},1e3)}function r(){if($.isEmpty(O.kick[0])){var t=!1,e=null;for(var i in O.kick)$.isTrue(O.kick[i])&&(t=!0,e=i);return t?e:r()}return $.random(0,4)}function a(){if(!$.isEmpty(O.block[0]))return $.random(0,4);var t=!1,e=null;for(var i in O.block)$.isTrue(O.block[i])&&(t=!0,e=i);return t?e:a()}var s,l,d,u,k,p=this,f=localStorage,b=(top.frames.main,{myLogin:"",myClass:null,kickScheme:{},kick:{0:"r"},block:{0:"r"},waittime:"1-5",ontimeout:"win"}),h={version:"0.3",power:"off"},m={err_low_perc_kick:"Сумма % ударов меньше 100%.",err_big_perc_kick:"Сумма % ударов больше 100%.",err_low_perc_block:"Сумма % блоков меньше 100%.",err_big_perc_block:"Сумма % блоков больше 100%.",err_kick_len:"Вы не выбрали куда бить.",err_block_len:"Вы не выбрали места блоков.",err_no_waittime:"Вы не указали время на удар.",set_saved:"Настройки сохранены.",stat_on:"Включен",stat_off:"Выключен",status:"Состояние"},v=["в голову","в корпус","в пояс(пах)","по ногам"],g=["головы и корпуса","корпуса и пояса","пояса и ног","головы и ног"],w={"Победа":"win","Ничья":"draw","Ждать":"wait"},y={KICK:"Вперед",WIN:"Я победил",DRAW:"Ничья",EXIT:"Вернуться",REFRESH:"Обновить"},_=-1,E=0,I='input[type="button"], input[type="submit"]',x="kicker-",j=$.isEmpty(f[x+"setting"])?"":JSON.parse(f[x+"setting"]),O=$.extend({},b,j),T=new Dialog({position:"top,left",title:"Автоудар",content:"",onopen:function(){this.set("content",o()),n(),$("#"+x+"status").click(function(){switch(h.power){case"off":h.power="on",$("#"+x+"status").removeClass("red").addClass("green").text("Включен."),c();break;case"on":h.power="off",$("#"+x+"status").removeClass("green").addClass("red").text("Выключен."),clearTimeout(_)}}),$("#"+x+"kick-r").click(function(){$("."+x+"kick").attr("disabled",$(this).is(":checked"))}),$("#"+x+"block-r").click(function(){$("."+x+"block").attr("disabled",$(this).is(":checked"))})},autoopen:!1,buttons:{"Сохранить":function(){e()}}});return this.ShowDialog=function(){T.open||T.show()},p};