+// ahah for back compatibility as plugins may still use it
+function ahah( url, id ) {
+ jQuery('#'+id).load(url);
+}
+
+// only for back compatibility, please JQuery() instead
+function doOnLoad( js ) {
+ jQuery(js);
+}
+
+jQuery(function() {
+ var opts = {
+ dateFormat: 'yy-mm-dd',
+ constrainInput: false,
+ showButtonPanel: true,
+ changeMonth: true,
+ changeYear: true,
+ showOtherMonths: true,
+ selectOtherMonths: true
+ };
+ jQuery(".ui-datepicker:not(.withtime)").datepicker(opts);
+ jQuery(".ui-datepicker.withtime").datetimepicker( jQuery.extend({}, opts, {
+ stepHour: 1,
+ // We fake this by snapping below for the minute slider
+ //stepMinute: 5,
+ hourGrid: 6,
+ minuteGrid: 15,
+ showSecond: false,
+ timeFormat: 'hh:mm:ss'
+ }) ).each(function(index, el) {
+ var tp = jQuery.datepicker._get( jQuery.datepicker._getInst(el), 'timepicker');
+ if (!tp) return;
+
+ // Hook after _injectTimePicker so we can modify the minute_slider
+ // right after it's first created
+ tp._base_injectTimePicker = tp._injectTimePicker;
+ tp._injectTimePicker = function() {
+ this._base_injectTimePicker.apply(this, arguments);
+
+ // Now that we have minute_slider, modify it to be stepped for mouse movements
+ var slider = jQuery.data(this.minute_slider[0], "slider");
+ slider._base_normValueFromMouse = slider._normValueFromMouse;
+ slider._normValueFromMouse = function() {
+ var value = this._base_normValueFromMouse.apply(this, arguments);
+ var old_step = this.options.step;
+ this.options.step = 5;
+ var aligned = this._trimAlignValue( value );
+ this.options.step = old_step;
+ return aligned;
+ };
+ };
+ });
+});
+
+function textToHTML(value) {
+ return value.replace(/&/g, "&")
+ .replace(/</g, "<")
+ .replace(/>/g, ">")
+ .replace(/-- \n/g,"-- \n")
+ .replace(/\n/g, "\n<br />");
+};
+
+function ReplaceAllTextareas() {
+ var sAgent = navigator.userAgent.toLowerCase();
+ if (!CKEDITOR.env.isCompatible ||
+ sAgent.indexOf('iphone') != -1 ||
+ sAgent.indexOf('ipad') != -1 ||
+ sAgent.indexOf('android') != -1 )
+ return false;
+
+ // replace all content and signature message boxes
+ var allTextAreas = document.getElementsByTagName("textarea");
+
+ for (var i=0; i < allTextAreas.length; i++) {
+ var textArea = allTextAreas[i];
+ if (jQuery(textArea).hasClass("messagebox")) {
+ // Turn the original plain text content into HTML
+ var type = jQuery("#"+textArea.name+"Type");
+ if (type.val() != "text/html")
+ textArea.value = textToHTML(textArea.value);
+
+ // Set the type
+ type.val("text/html");
+
+ CKEDITOR.replace(textArea.name,{width:'100%',height:<% RT->Config->Get('MessageBoxRichTextHeight') |n,j%>});
+ CKEDITOR.basePath = <%RT->Config->Get('WebPath')|n,j%>+"/NoAuth/RichText/";
+
+ jQuery("#" + textArea.name + "___Frame").addClass("richtext-editor");
+ }
+ }
+};
+
+function toggle_addprincipal_validity(input, good, title) {
+ if (good) {
+ jQuery(input).nextAll(".warning").hide();
+ jQuery("#acl-AddPrincipal input[type=checkbox]").removeAttr("disabled");
+ } else {
+ jQuery(input).nextAll(".warning").css("display", "block");
+ jQuery("#acl-AddPrincipal input[type=checkbox]").attr("disabled", "disabled");
+ }
+
+ if (title == null)
+ title = jQuery(input).val();
+
+ update_addprincipal_title( title );
+}
+
+function update_addprincipal_title(title) {
+ var h3 = jQuery("#acl-AddPrincipal h3");
+ h3.text( h3.text().replace(/: .*$/,'') + ": " + title );
+}
+
+// when a value is selected from the autocompleter
+function addprincipal_onselect(ev, ui) {
+
+ // if principal link exists, we shall go there instead
+ var principal_link = jQuery(ev.target).closest('form').find('ul.ui-tabs-nav a[href="#acl-' + ui.item.id + '"]:first');
+ if (principal_link.size()) {
+ jQuery(this).val('').blur();
+ update_addprincipal_title( '' ); // reset title to blank for #acl-AddPrincipal
+ principal_link.click();
+ return false;
+ }
+
+ // pass the item's value along as the title since the input's value
+ // isn't actually updated yet
+ toggle_addprincipal_validity(this, true, ui.item.value);
+}
+
+// when the input is actually changed, through typing or autocomplete
+function addprincipal_onchange(ev, ui) {
+ // if we have a ui.item, then they selected from autocomplete and it's good
+ if (!ui.item) {
+ var input = jQuery(this);
+ // Check using the same autocomplete source if the value typed would
+ // have been autocompleted and is therefore valid
+ jQuery.ajax({
+ url: input.autocomplete("option", "source"),
+ data: {
+ op: "=",
+ term: input.val()
+ },
+ dataType: "json",
+ success: function(data) {
+ if (data)
+ toggle_addprincipal_validity(input, data.length ? true : false );
+ else
+ toggle_addprincipal_validity(input, true);
+ }
+ });
+ } else {
+ toggle_addprincipal_validity(this, true);
+ }
+}
+
+
+function escapeCssSelector(str) {
+ return str.replace(/([^A-Za-z0-9_-])/g,'\\$1');
+}