function DialogQueue(){var a=this;a._containerprefix="mdldlg_";a._dialogcounter=0;a._items=[];a._background=undefined}DialogQueue.prototype.handleDialogKeyPress=function(b){if(dialogQueue._items.length<=0)return;b.which==27&&dialogQueue.removeDialog(dialogQueue._items[dialogQueue._items.length-1]);if(b.which==13||b.which==89||b.which==78){var c=dialogQueue._items[dialogQueue._items.length-1];if(c!=undefined)if(b.which!=78){var a=c.dialog().find(".onenterpressed");a.length>0&&a.get(0).clickaction&&a.get(0).clickaction(b,c,a)}else{var a=c.dialog().find(".oncancelpressed");if(a.length>0)if(a.get(0).clickaction)a.get(0).clickaction(b,c,a);else a.trigger("click")}}dialogQueue._items.length<=0&&$(document).unbind("keydown.dialog")};DialogQueue.prototype.isAppleMobile=function(){return navigator.userAgent.toLowerCase().match(/(iphone|ipod|ipad)/)};DialogQueue.prototype.addDialog=function(a){var c="resize.dialog",b=this;if(a.isModal())a.zIndex(b.moveBackgroundToTop());else a.zIndex(b.topZIndex());if(a.id()==undefined){a.id(b.nextId());a.loadContent();b._items.push(a)}else{a.loadContent();b.findDialog(a.id())==null&&b._items.push(a)}var d=b;if(b._items.length>0){$(window).unbind(c,d.onModalWindowChange);$(window).bind(c,d.onModalWindowChange);$(document).bind("keydown.dialog",b.handleDialogKeyPress)}return a};DialogQueue.prototype.repositionDialogs=function(){var a=this;if(a._items.length>0)for(var b=0;b<a._items.length;b++)a._items[b].centerDialog();else{var c=a;$(window).unbind("resize",c.onModalWindowChange)}};DialogQueue.prototype.onModalWindowChange=function(){dialogQueue&&dialogQueue.repositionDialogs()};DialogQueue.prototype.removeDialog=function(c){var b="z-index",a=this,d=a.findDialogIndex(c.id());if(d>=0){a._items.splice(d,1);if(a._items.length<=0)a.removeBackground();else{var f=$("#"+a._containerprefix+"background"),e=a._items[a._items.length-1];if(parseInt(f.css(b),10)>=parseInt(e.dialog().css(b),10)){var g=a.moveBackgroundToTop();e.dialog().css(b,a.topZIndex())}}c.remove()}};DialogQueue.prototype.removeDialogById=function(b){var a=this.findDialog(b);a!=null&&this.removeDialog(a)};DialogQueue.prototype.findDialogIndex=function(b){b=b.toLowerCase();for(var a=0;a<this._items.length;a++)if(this._items[a].id()==b)return a;return -1};DialogQueue.prototype.findDialog=function(b){b=b.toLowerCase();for(var a=0;a<this._items.length;a++)if(this._items[a].id()==b)return this._items[a];return null};DialogQueue.prototype.nextId=function(){this._dialogcounter++;return this._containerprefix+this._dialogcounter};DialogQueue.prototype.topZIndex=function(){if(this._items.length<=0)return $.topZIndex()+100;else return $.topZIndex()+1};DialogQueue.prototype.removeBackground=function(){$("#"+this._containerprefix+"background").remove()};DialogQueue.prototype.moveBackgroundToTop=function(){var a=this,e=a.isAppleMobile()?$(document).width():$(window).width(),d=a.isAppleMobile()?$(document).height():$(window).height(),c=a._containerprefix+"background",b=$("#"+c);if(b.length<=0){b=$('<div id="'+c+'" class="modalBackground" style="z-index:'+a.topZIndex()+";width:"+e+"px;height:"+d+'px"></div>').css("opacity",.3);$("body").append(b)}else b.css("z-index",a.topZIndex());return parseInt(b.css("z-index"),10)+1};var dialogQueue=new DialogQueue;function DialogItem(b){var a=this;a._dialog=undefined;a._zindex=undefined;a._id=b.id?b.id:undefined;a._parameters=b?b:{};a.isModal(b.modal!=null&&b.modal!=undefined?b.modal:true);a.isDraggable(b.draggable!=null&&b.draggable!=undefined?b.draggable:false);a._oncomplete=b.oncomplete?b.oncomplete:undefined;if(!a._parameters.title)a._parameters.title="";if(!a._parameters.values)a._parameters.values={};if(!a._parameters.items)a._parameters.items={};if(!a._parameters.buttons)a._parameters.buttons={}}DialogItem.prototype.onComplete=function(a){if(a!=null&&a!=undefined)this._oncomplete=a;return this._oncomplete};DialogItem.prototype.isModal=function(a){if(a!=null&&a!=undefined)this._modal=a;return this._modal};DialogItem.prototype.isDraggable=function(a){if(a!=null&&a!=undefined)this._draggable=a;return this._draggable};DialogItem.prototype.parameters=function(a){if(a!=null&&a!=undefined)this._parameters=a;return this._parameters};DialogItem.prototype.dialog=function(a){if(a!=null&&a!=undefined)this._dialog=a;return this._dialog};DialogItem.prototype.zIndex=function(a){if(a!=null&&a!=undefined)this._zindex=a;return this._zindex};DialogItem.prototype.id=function(b){var a=this;if(b!=null&&b!=undefined)a._id=b;if(a._id!=undefined)return a._id.toLowerCase();return a._id};DialogItem.prototype.isAppleMobile=function(){return navigator.userAgent.toLowerCase().match(/(iphone|ipod|ipad)/)};DialogItem.prototype.reset=function(){var a=this;if(a._id==undefined)throw"Dialog has not been added to the queue";if(a._dialog==undefined){var b=$("#"+a._id);if(b.length<=0){a._dialog=$('<div id="'+a._id+'"></div>');$("body").append(a._dialog)}else a._dialog=b}a._dialog.hide();a._dialog.addClass("modalDialog").css({"z-index":a._zindex,width:"",height:""});a._dialog.html('<div class="modalContainer"><div class="modalTitle"><div class="modalTitleText" style="width:75%; display:inline-block;"></div><a class="modalTitleClose" style="float:right;font-weight:bold; cursor:pointer;">X</a><div class="clr"></div></div><div class="modalContent"></div></div><div class="clr"></div>');a._parameters.title&&a._dialog.find(".modalTitle .modalTitleText").html(a._parameters.title);a._dialog.find(".modalContent").html("").css({height:"",overflow:""});a._dialog.find(".modalContainer .modalTitle .modalTitleClose").unbind().click(function(){dialogQueue.removeDialogById($(this).parents(".modalDialog:first").attr("id"))});a._dialog.show();a.centerDialog(false)};DialogItem.prototype.centerDialog=function(){var a=this;if(a._dialog&&a._dialog.length>0&&a._dialog.is(":visible")){var b=a._dialog.width(),c=a._dialog.height(),e=a.isAppleMobile()?$(document).width():$(window).width(),d=a.isAppleMobile()?$(document).height():$(window).height();if(b>e||c>d){var m=c;if(c>d){c=d-50;b+=20}if(b>e)b=e-50;a._dialog.css({width:b,height:c});var j=a._dialog.find(".modalTitle").outerHeight(),i=a._dialog.find(".modalButtons").outerHeight(),h=c-j-i-25;a._dialog.find(".modalContent").css({height:h,overflow:"auto"})}if(a._parameters.width){b=a._dialog.width();if(b<parseInt(a._parameters.width,10)){b=parseInt(a._parameters.width,10);a._dialog.css({width:b+"px"})}}var l=jQuery(window).scrollTop(),k=jQuery(window).scrollLeft(),g=(d-c)/2+l,f=(e-b)/2+k;if(a._parameters.animate)a._dialog.stop().animate({top:g,left:f,opacity:1},2500);else a._dialog.stop().css({top:g,left:f})}};DialogItem.prototype.loadContentComplete=function(e){var g=".modalDialog:first",j=".modalButtons .modalTitleClose",f=".modalButtons",i=".modalContainer .modalTitle .modalTitleText",a;if(e.success()){a=e.request().items().dialogItem;a.dialog().find(i).html(a.parameters().title);if(a.parameters().buttons&&a.parameters().buttons.length>0){var d=a.parameters().buttons;if(d.length>0){var n=a.dialog().find(f);n.length<=0&&a.dialog().find(".modalContent").append($('<div class="modalButtons"></div>'))}for(var c=0;c<d.length;c++){var b=d[c],m=b.id?b.id:"btn_"+a.id()+"_"+c,l=b.text?b.text:"button",k=b.cssclass?b.cssclass:"btnsecondary150",h=$('<a class="'+k+'" id="'+m+'">'+l+"</a>");a.dialog().find(f).append(h);if(d[c].action&&h.length==1){h.get(0).clickaction=d[c].action;h.unbind().click(function(b){$(this).get(0).clickaction(b,a,$(this))})}}a.dialog().find(f).append('<div class="clear"></div>')}else a.dialog().find(f).hide();a.dialog().find(j).unbind().click(function(){dialogQueue.removeDialogById($(this).parents(g).attr("id"))});a.isDraggable()&&a.dialog().draggable({handle:a.dialog().find(".modalTitle")});a.onComplete()&&a.onComplete()(a);a.centerDialog()}else{a=e.request().items().dialogItem;if(a){a.dialog().find(i).html("An error has occurred");a.dialog().find(".modalContainer .modalContent").html(e.content());a.dialog().find(j).unbind().click(function(){dialogQueue.removeDialogById($(this).parents(g).attr("id"))});a.centerDialog()}else dialogQueue.addDialog(new DialogItem({title:"Error",content:e.content()}))}};DialogItem.prototype.escapeContent=function(a){return a.replace(/\'/gi,"\\'").replace(/\r/gi," ").replace(/\n/gi,"</br>")};DialogItem.prototype.escapeContentA=function(a){return a.replace(/\"/gi,'\\"').replace(/\r/gi," ").replace(/\n/gi,"</br>")};DialogItem.prototype.loadContent=function(){var b=".modalContainer .modalContent",a=this;a.reset();if(a._dialog.length>0){var c=a;a._parameters.items.dialogItem=a;if(a._parameters.action)AjaxReplacer.prototype.perform({action:a._parameters.action,oncomplete:c.loadContentComplete,target:a._dialog.find(b),values:a._parameters.values,items:a._parameters.items});else if(a._parameters.content){var d=new AjaxReplacer({target:a._dialog.find(b),action:"",values:a._parameters.values,items:a._parameters.items,oncomplete:c.loadContentComplete}),e=new AjaxRequest(d);e.onAjaxSuccess('{"Success":"true","Content":"'+a.escapeContentA(a._parameters.content)+'", "Parameters":{} }',"Success")}}};DialogItem.prototype.remove=function(){this.isDraggable()&&this._dialog.draggable("destroy");this._dialog.remove()};DialogItem.prototype.findControlName=function(f,a){var c="controlname";for(var e=0;e<f.length;e++){var b=$(f[e]);if(b.attr("name")==a)if(b.attr(c)!=null&&b.attr(c).length>0)return b.attr(c);else{if(a.indexOf("$")>=0){var d=$('[name="'+a+'"]');if(d&&d.length>0)return d.attr("id")}return a}}return a};DialogItem.prototype.toObject=function(){var b={};node=this.dialog();if(node.length>0){var c=node.find(":input, select"),a=c.serializeArray();for(ndx in a)if(b[a[ndx].name]==undefined)b[this.findControlName(c,a[ndx].name)]=a[ndx].value;else b[this.findControlName(c,a[ndx].name)]+=","+a[ndx].value}return b};function CreateConfirmDialog(b,c,a){var b="<div class='dialogmessage'>"+b+"</div>",d=dialogQueue.addDialog(new DialogItem({id:"confirmYesNoDialog",title:"Please confirm",content:b,buttons:[{id:"btnDialogYes",text:"Yes",action:c,cssclass:"btn btnalternate onenterpressed"},{id:"btnDialogNo",text:"No",action:a,cssclass:"btn btnprimary oncancelpressed"}]}));d.dialog().find(".modalTitleClose").unbind().click(a)}function CreateMessageDialog(a){var a='<div class="dialogmessage">'+a+"</div>",b=dialogQueue.addDialog(new DialogItem({id:"messageDialog",title:"Please note",content:a}))}