﻿(function(a){a.extend({darker:function(b){(typeof b).toLowerCase()!="object"&&(b={key:b});var c=b.context,d=b.classes||"",e=b.html||"",f=b.color&&/^([#0-9a-z]{4,7}|[a-z]+)$/i.test(b.color)?b.color:"black",g=b.key||(new Date).getTime(),h,i;if(c)a("body").children(".darker-div").remove(),h=a(c).height(),i=a(c).width();else{c=document.body;var j=a(window).height(),k=document.body.clientHeight,h=j>k?j:k;i=document.body.clientWidth}a("<div/>",{height:h,width:i,html:e,css:{backgroundColor:f},time:g+""}).addClass(d+" darker-div").appendTo(c),c=null},popUpLayout:function(b){if(!b||(typeof b).toLowerCase()!="object")return!1;var c=a.extend({context:document.body,classes:"",height:"auto",width:400,key:(new Date).getTime(),darker:!1,removeLayouts:!0},b),d=a("<div/>",{height:c.height,width:c.width,time:c.key+""}).addClass(c.classes+" pop-up-wrapper"),e=a("<div/>").addClass("pop-up-head").html(a("<div/>").addClass("pop-up-title").text(c.title)),f=function(){return a('.darker-div[time="'+c.key+'"], .pop-up-wrapper[time="'+c.key+'"]').remove(),c=null,!1};a("<a/>",{click:function(){c.closeCallback&&c.closeCallback(),f()}}).addClass("pop-up-closer").appendTo(e),e.appendTo(d),a("<div/>").append(c.html).addClass("pop-up-body").css(c.css||{}).appendTo(d),c.html=null;if(c.buttonYes){var g=a("<div/>").addClass("pop-up-foot");a('<button type="submit">').html('<span class="l"><span class="r">'+c.buttonYes+"</span></span>").click(function(){var a;c.buttonYesCallback&&(a=c.buttonYesCallback()),a!="noClose"&&f()}).addClass("btn").appendTo(g),c.buttonNo&&a('<button type="submit">').html('<span class="l"><span class="r">'+c.buttonNo+"</span></span>").click(function(){c.buttonNoCallback&&c.buttonNoCallback(),f()}).addClass("btn").appendTo(g),g.appendTo(d),g=null}d.css("marginLeft","-"+c.width/2+"px"),c.removeLayouts&&a(".darker-div,.pop-up-wrapper").remove();if(c.height!="auto")d.css("marginTop","-"+c.height/2+"px").appendTo(c.context);else{d.addClass("popUpLayoutHeightFixing").appendTo(c.context);var h=a(".popUpLayoutHeightFixing"),i=h.height()/2;h.css("marginTop","-"+i+"px").removeClass("popUpLayoutHeightFixing")}c.drag&&d.drag({handler:d.find(".pop-up-head")}),c.darker&&a.darker(c.key),!d.hasClass("prompt-pop-up")&&!d.hasClass("pareta-pop-up")&&d.find(".btn").first().focus(),d=e=null},alert:function(b){(typeof b).toLowerCase()!="object"&&(b={message:b}),a.popUpLayout(a.extend({classes:"",darker:!0,title:pamm_locales.pamm_alert_title,html:a("<div/>").addClass("alert-text").html(b.message),buttonYes:pamm_locales.pamm_button_ok,buttonYesCallback:b.callback,removeLayouts:!0},b))},prompt:function(b,c){a.isPlainObject(b)||(b={callback:b}),c&&!a.isPlainObject(c)&&(c={options:{valid_rule:c}});var d=(new Date).getTime(),e=a("<div/>").addClass("prompt-text").html(b.message||""),f=a("<div/>").addClass("prompt-input"),g=a('<input type="text" value=""/>').keyup(function(b){b.keyCode==13&&a(this).closest(".prompt-pop-up").find(".pop-up-foot").find(".btn").first().trigger("click")});b.maxLength&&!isNaN(b.maxLength)&&g.attr("maxlength",b.maxLength),c&&(g.addClass("need-validation").addValidOptions(c.options,c.callback),c.template&&g.val(c.template).addTemplate(c.template)),g.appendTo(f),e=e.add(f),a.popUpLayout(a.extend({key:d,classes:"prompt-pop-up",darker:!0,title:pamm_locales.pamm_prompt_title,html:e,buttonYes:pamm_locales.pamm_button_ok,buttonNo:pamm_locales.pamm_button_cancel,buttonYesCallback:function(){var c=a('.pop-up-wrapper[time="'+d+'"]').find(".prompt-input").children("input"),e=a.trim(c.val());if(c.hasClass("need-validation")&&!c.isValid())return c.validate(),"noClose";b.callback&&e&&b.callback(e,c),c=null},removeLayouts:!0},b)),e=f=g=null},pareta:function(b,c){switch((typeof b).toLowerCase()){case"string":c&&c==!0?b={value:b}:b={message:b};break;case"function":b={callback:b};break;case"undefined":b={callback:""}}var d=(new Date).getTime(),e=a("<div/>").addClass("prompt-text").html(b.message||""),f=a("<div/>").addClass("prompt-input"),g=a("<textarea/>",{cols:50,rows:5}).height(b.textAreaHeight||"auto").text(b.value||"").keyup(function(b){b.keyCode==13&&a(this).closest(".pareta-pop-up").find(".pop-up-foot").find(".btn").first().trigger("click")});c&&(typeof c).toLowerCase()=="object"&&(g.addClass("need-validation").addValidOptions(c.options,c.callback),c.template&&(g.addClass("gray-text")[0]._template=c.template)),g.appendTo(f),e=e.add(f),a.popUpLayout(a.extend({key:d,classes:"pareta-pop-up",darker:!0,title:pamm_locales.pamm_prompt_title,html:e,buttonYes:pamm_locales.pamm_button_ok,buttonNo:pamm_locales.pamm_button_cancel,buttonYesCallback:function(){var c=a('.pop-up-wrapper[time="'+d+'"]').find(".prompt-input").children("textarea").val();b.callback&&c&&b.callback(c)},removeLayouts:!0},b)),e=f=g=null},confirm:function(b){(typeof b).toLowerCase()!="object"&&(b={message:b}),a.popUpLayout(a.extend({classes:"",darker:!0,title:pamm_locales.pamm_confirm_title,html:a("<div/>").addClass("confirm-text").html(b.message),buttonYes:pamm_locales.pamm_confirm_yes,buttonNo:pamm_locales.pamm_confirm_no,buttonYesCallback:b.callback,buttonNoCallback:b.noCallback,removeLayouts:!0},b))}}),a.fn.extend({hasDarker:function(){return this.children(".darker-div")[0]},removeDarker:function(){return this.children(".darker-div").remove()},stopHandlers:function(b){return this.each(function(){var c=a.data(this,"events"),d=this;b=b||"click",d._handlers=d._handlers||[];if(a.cache&&a.cache[1].events&&a.cache[1].events[b])for(var e in a.cache)if(a.cache[e].events)for(var f in a.cache[e].events[b])a.cache[e].events[b][f].origHandler&&a(a.cache[e].events[b][f].selector).index(a(d))>-1&&d._handlers.push(a.cache[e].events[b][f].origHandler);if(c&&c[b])for(var g in c[b])c[b][g].handler&&d._handlers.push(c[b][g].handler);a(d).die(b).unbind(b)})},confirm:function(b){var c=b.eType||"click";return(typeof b).toLowerCase()!="object"&&(b={message:b}),this.stopHandlers(c).each(function(){var d=this;a(this).bind(c,function(c){c.preventDefault(),c.stopImmediatePropagation(),a.popUpLayout(a.extend({classes:"",darker:!0,title:pamm_locales.pamm_confirm_title,html:a("<div/>").addClass("confirm-text").html(b.message),buttonYes:pamm_locales.pamm_confirm_yes,buttonNo:pamm_locales.pamm_confirm_no,buttonYesCallback:function(){b.callback&&b.callback.apply(d,arguments);for(var a in d._handlers)d._handlers[a]&&d._handlers[a].apply(d,arguments)},buttonNoCallback:b.noCallback,eType:"click",removeLayouts:!0},b))})})}})})(jQuery),$(window).resize(function(){var a=$(window).height(),b=document.body.clientHeight,c=a>b?a:b;$("body").children(".darker-div").width(document.body.clientWidth).height(c)}).keyup(function(a){var b=$(this).children(".pop-up-wrapper").last();a.keyCode==27&&b.add(b.next()).remove(),b=null})
