var Portal=Portal||{};Portal.CitizenEngagement=function(n){var et=n.editButtonClientId,ot=n.titleContainerClientId,st=n.descriptionContainerClientId,d=n.emailAddressTextBoxClientId,g=n.trackingNumberTextBoxClientId,ht=n.viewItemButtonClientId,ct="view-item-notification",lt=n.trackersContainerClientId,nt=n.trackerWindowClientId,a=n.editPortalItemWindowClientId,f=n.titleTextBoxClientId,c=n.summaryEditorClientId,v=n.descriptionEditorClientId,u=n.otherCulture,at=n.currentCulture,e=n.titleTextBoxOtherCultureClientId,tt=n.summaryOtherCultureEditorClientId,y=n.descriptionOtherCultureEditorClientId,vt=n.editItemOtherCulture,ti=n.saveButtonClientId,r={invalidEmailAddressWarningMessageText:n.localization.invalidEmailAddressWarningMessageText,noEmailAddressOrTrackingNumberWarningMessageText:n.localization.noEmailAddressOrTrackingNumberWarningMessageText,noEmailAddressWarningMessageText:n.localization.noEmailAddressWarningMessageText,noTrackingNumberWarningMessageText:n.localization.noTrackingNumberWarningMessageText,titleTextTooLongWarning:n.localization.titleTextTooLongWarning,textTooLongWarning:n.localization.textTooLongWarning},it=n.portalItemId,p=n.trackerPortalItems,o=n.referenceNames,h=30,l=!1,s={title:"",summary:"",description:""},t=0,i=140,ii=function(n){t=0;dt();$(".edit-itemSummary-field, .edit-itemSummaryOtherCulture-field").show();ft();n.preventDefault()},yt=function(n){n.which===13&&(n.preventDefault(),b())},pt=function(n){n.which===13&&(n.preventDefault(),b())},wt=function(n){n.preventDefault();b()},ri=function(n){kt();t=parseInt($(n.target).closest("span").attr("data-id"));rt(w(t));$(".edit-itemSummary-field, .edit-itemSummaryOtherCulture-field").hide();ft();n.preventDefault()},bt=function(n){var t=null,i=parseInt($(n.target).closest("input").attr("data-tracker-id"));window.matchMedia!=null&&(t=window.matchMedia("screen and (max-width:320px), (max-device-width: 320px), (max-width:481px), (max-device-width: 481px)"));t!=null&&t.matches?window.open("/Items/Item/public.aspx?TypeId="+i.toString(),"_blank"):ut("/Items/Item/public.aspx?TypeId="+i.toString());n.preventDefault()},ui=function(n){var s=$(document.getElementById(f)).val(),p=window.$find(c),d="",b,l,k,g,nt;p&&p.set_html(d=Portal.MasterPagePage.fixEditorHtml(p.get_html(!0)));b=window.$find(v);l="";b&&b.set_html(l=Portal.MasterPagePage.fixEditorHtml(b.get_html(!0)));t>0?(k=w(t),k.title=s,k.summary=d,k.description=l,g=$('span[data-id="'+t.toString()+'"]').closest(".tracker-item"),g.find(".tracker-item-title").text(s),g.find(".tracker-item-description").html(l)):($(document.getElementById(ot)).text(s.length>0?s:r.defaultTitleText),$(document.getElementById(st)).html(l));p.get_text().length>i?alert(r.textTooLongWarning):s.length>h?alert(r.titleTextTooLongWarning):(nt=[{Id:0,ReferenceName:o.title,Value:s},{Id:0,ReferenceName:o.summary,Value:d},{Id:0,ReferenceName:o.description,Value:l}],$.ajax({url:"/Services/ItemsService.svc/items/"+(t>0?t:it).toString()+"/fieldupdate?culture="+at,contentType:"application/json",dataType:"json",async:!0,type:"POST",timeout:3e4,data:JSON.stringify(nt),success:function(){var f,s,h,p,c;if(u){var l=$(document.getElementById(e)).val(),n=window.$find(tt),v="";n&&n.set_html(v=Portal.MasterPagePage.fixEditorHtml(n.get_html(!0)));f=window.$find(y);s="";f&&f.set_html(s=Portal.MasterPagePage.fixEditorHtml(f.get_html(!0)));t>0&&(h=w(t),h.titleOtherCulture=l,h.descriptionOtherCulture=s);n.get_text().length<i?(p=[{Id:0,ReferenceName:o.title,Value:l},{Id:0,ReferenceName:o.summary,Value:v},{Id:0,ReferenceName:o.description,Value:s}],$.ajax({url:"/Services/ItemsService.svc/items/"+(t>0?t:it).toString()+"/fieldupdate?culture="+u,contentType:"application/json",dataType:"json",async:!0,type:"POST",timeout:3e4,data:JSON.stringify(p),success:function(){var n=window.$find(a);n&&n.close()},error:function(){}})):alert(r.textTooLongWarning)}else c=window.$find(a),c&&c.close()},error:function(){}}));n.preventDefault()},kt=function(){var n,t,i;l||(s.title=$(document.getElementById(f)).val(),n=window.$find(c),n&&n.set_html(s.summary=Portal.MasterPagePage.fixEditorHtml(n.get_html(!0))),t=window.$find(v),t&&t.set_html(s.description=Portal.MasterPagePage.fixEditorHtml(t.get_html(!0))),u&&(s.titleOtherCulture=$(document.getElementById(e)).val(),i=window.$find(y),i&&i.set_html(s.descriptionOtherCulture=Portal.MasterPagePage.fixEditorHtml(i.get_html(!0)))),l=!0)},dt=function(){l&&(rt(s),l=!1)},rt=function(n){var t,i,r;n&&($(document.getElementById(f)).val(n.title),t=window.$find(c),t&&t.set_html(n.summary),i=window.$find(v),i&&i.set_html(n.description),u&&($(document.getElementById(e)).val(n.titleOtherCulture),r=window.$find(y),r&&r.set_html(n.descriptionOtherCulture)))},w=function(n){var i=null,t;if(n)for(t=0;t<p.length;t++)if(n===p[t].id){i=p[t];break}return i},ut=function(n){var t=window.$find(nt);t&&(k(t,720),t.setUrl(n),t.show())},b=function(){var t=CivicWeb.Common.Notification.create(ct,CivicWeb.Common.Notification.types.warning,"",!0),i=$(document.getElementById(d)),n=i.val(),e=$(document.getElementById(g)),u=e.val(),f=null;window.matchMedia!=null&&(f=window.matchMedia("screen and (max-width:320px), (max-device-width: 320px), (max-width:481px), (max-device-width: 481px)"));n.length>0&&u.length>0?/^(-|\w)+(\.(-|\w)+)*@(-|\w)+(\.(-|\w)+)+$/i.test(n)?f!=null&&f.matches?window.open("/Items/Item/public.aspx?EmailAddress="+n+"&TrackingGuid="+u,"_blank"):ut("/Items/Item/public.aspx?EmailAddress="+n+"&TrackingGuid="+u):(i.focus(),CivicWeb.Common.Notification.show(t,CivicWeb.Common.Notification.types.warning,n+" "+r.invalidEmailAddressWarningMessageText)):n.length>0?(e.focus(),CivicWeb.Common.Notification.show(t,CivicWeb.Common.Notification.types.warning,r.noTrackingNumberWarningMessageText)):u.length>0?(i.focus(),CivicWeb.Common.Notification.show(t,CivicWeb.Common.Notification.types.warning,r.noEmailAddressWarningMessageText)):(i.focus(),CivicWeb.Common.Notification.show(t,CivicWeb.Common.Notification.types.warning,r.noEmailAddressOrTrackingNumberWarningMessageText))},k;this.PortalCloseRadTrackerWindow=function(){var n=window.$find(nt);n&&n.setUrl("/Global/Images/indicator_medium.gif")};var ft=function(){var n=window.$find(a);n&&($("#"+vt).show(),k(n,u?Math.max($(window).width()*.9,660):650),n.show(),ni(),gt())},gt=function(){var t=window.$find(c),n;setTimeout(function(){var n=t.get_text().length;$("#textCount").text(i-n);t.attachEventHandler("onkeydown",function(){var n=t.get_text().length;$("#textCount").text(i-n);n>i?$("#textCount").css({color:"red"}):$("#textCount").css({color:"#646567"})})},0);u&&(n=window.$find(tt),setTimeout(function(){var t=n.get_text().length;$("#textCountOtherCulture").text(i-t);n.attachEventHandler("onkeydown",function(){var t=n.get_text().length;$("#textCountOtherCulture").text(i-t);t>i?$("#textCountOtherCulture").css({color:"red"}):$("#textCountOtherCulture").css({color:"#646567"})})},0))},ni=function(){setTimeout(function(){var n=$(document.getElementById(f)).val();$(document.getElementById("tile-item-title-editor-characters")).text(h-n.length);$(document.getElementById(f)).off("keyup").on("keyup",function(){var n=h-$(document.getElementById(f)).val().length;$(document.getElementById("tile-item-title-editor-characters")).text(n);$(document.getElementById("tile-item-title-editor-characters")).css("color",n<0?"red":"")});if(u){n=$(document.getElementById(e)).val();$(document.getElementById("other-culture-tile-item-title-editor-characters")).text(h-n.length);$(document.getElementById(e)).off("keyup").on("keyup",function(){var n=h-$(document.getElementById(e)).val().length;$(document.getElementById("other-culture-tile-item-title-editor-characters")).text(n);$(document.getElementById("other-culture-tile-item-title-editor-characters")).css("color",n<0?"red":"")})}},0)};this.OnClientPasteHtml=function(n,t){var r=t.get_commandName(),f=t.get_value(),u;(r==="PasteFromWord"||r==="PasteFromWordNoFontsNoSizes"||r==="PastePlainText"||r==="PasteAsHtml"||r==="Paste")&&(u=n.get_text().length+f.length,u>i?$("#textCount").css({color:"red"}):$("#textCount").css({color:"#646567"}),$("#textCount").text(i-n.get_text().length))};k=function(n,t){if(n){var i=$(window);n.set_height(Math.max(i.height()*.95,600));n.set_width(t)}},function(){$(document.getElementById(d)).off("keydown").on("keydown",yt);$(document.getElementById(g)).off("keydown").on("keydown",pt);$(document.getElementById(ht)).off("click").on("click",wt);var n=$(document.getElementById(lt));if(CivicWeb.Portal&&CivicWeb.Portal.EditItemControl){$(document.getElementById(et)).off("click").on("click",CivicWeb.Portal.EditItemControl.openItem);n.find(".edit-button").off("click").on("click",CivicWeb.Portal.EditItemControl.openItem)}n.find(".tracker-submit-button").off("click").on("click",bt)}()};Portal.CitizenEngagementPage={instance:null,createInstance:function(n){this.instance&&delete this.instance;this.instance=new Portal.CitizenEngagement(n)},events:{OnClientPasteHtml:function(n,t){Portal.CitizenEngagementPage.instance.OnClientPasteHtml(n,t)},OnClientCloseRadTrackerWindow:function(){Portal.CitizenEngagementPage.instance.PortalCloseRadTrackerWindow()}}}