(.*?) #(\d+) \(([^\)]+)\)\: (.+?)<\/a>/gi);
+
+ var result;
+ var similarhtml = '';
+ while ((result = pat.exec(response)) != null)
+ {
+ similarhtml = similarhtml+ "" + result[3] + " #" + result[2]+" "+result[6]+" "+result[5]+" ";
+ }
+
+ // NOTE: IE seems to have issues updating elements with HTML and prototype, so this is the only way I could make it work
+ if (simelement !== null)
+ {
+ simelement.remove();
+ }
+
+ simelement = new Element("div")
+ element.insert({after:simelement });
+
+
+ if (similarhtml)
+ {
+ var divhtml = "Did you mean?These issues already exist ";
+ simelement.insert(divhtml);
+ }
+}
+
+function scheduleDupIssueSearch(element)
+{
+ var thisquery = element.getValue();
+
+ if (thisquery == null || thisquery == undefined || lastquery == thisquery)
+ {
+ return;
+ }
+
+ lastquery = thisquery;
+
+ clearTimeout(timSearchSimilar);
+ timSearchSimilar = setTimeout(function() { searchDupIssues(element); }, 400);
+}
+
+function searchDupIssues(element)
+{
+ var proj = location.href.replace(/^.*\/projects\/([^\/]+)\/issues.*$/, '$1');
+ var url = "../../../search/index/"+proj+"?issues=1&q="+escape(element.getValue());
+ new Ajax.Request(url, {
+ method: 'get',
+ onSuccess: function(transport)
+ {
+ updateSimilarIssues(element, transport.responseText);
+ }
+ });
+
+}
+
+function findDupIssues()
+{
+
+ $$(".new-issue-form #issue_subject").each(function(element)
+ {
+ element.setAttribute("autocomplete", "off");
+ element.observe('keyup', function() {
+ scheduleDupIssueSearch(element);
+ });
+
+
+ element.observe('change', function() {
+ scheduleDupIssueSearch(element);
+ });
+
+ });
+
+}
+
+document.observe('dom:loaded', function(){
+ findDupIssues();
+});
+
+
+