includes/clientside/static/autofill.js
author Dan
Sat, 20 Oct 2007 21:51:26 -0400
changeset 183 eec079676fe7
parent 174 d74ff822acc9
child 212 d57af0b0302e
permissions -rw-r--r--
Merging in changes from db8a849ad4c9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
174
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
     1
/**
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
     2
 * Javascript auto-completion for form fields.
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
     3
 */
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
     4
 
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
     5
var af_current = false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
     6
 
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
     7
function AutofillUsername(parent, event, allowanon)
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
     8
{
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
     9
  // if this is IE, use the old code
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    10
  if ( IE )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    11
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    12
    ajaxUserNameComplete(parent);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    13
    return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    14
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    15
  if ( parent.afobj )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    16
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    17
    parent.afobj.go();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    18
    return true;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    19
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    20
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    21
  parent.autocomplete = 'off';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    22
  parent.setAttribute('autocomplete', 'off');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    23
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    24
  this.repeat = false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    25
  this.event = event;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    26
  this.box_id = false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    27
  this.boxes = new Array();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    28
  this.state = false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    29
  this.allowanon = ( allowanon ) ? true : false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    30
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    31
  if ( !parent.id )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    32
    parent.id = 'afuser_' + Math.floor(Math.random() * 1000000);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    33
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    34
  this.field_id = parent.id;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    35
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    36
  // constants
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    37
  this.KEY_UP    = 38;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    38
  this.KEY_DOWN  = 40;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    39
  this.KEY_ESC   = 27;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    40
  this.KEY_TAB   = 9;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    41
  this.KEY_ENTER = 13;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    42
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    43
  // response cache
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    44
  this.responses = new Object();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    45
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    46
  // ajax placeholder
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    47
  this.process_dataset = function(resp_json)
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    48
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    49
    // window.console.info('Processing the following dataset.');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    50
    // window.console.debug(resp_json);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    51
    var autofill = this;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    52
    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    53
    if ( typeof(autofill.event) == 'object' )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    54
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    55
      if ( autofill.event.keyCode )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    56
      {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    57
        if ( autofill.event.keyCode == autofill.KEY_ENTER && autofill.boxes.length < 1 && !autofill.box_id )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    58
        {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    59
          // user hit enter after accepting a suggestion - submit the form
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    60
          var frm = findParentForm($(autofill.field_id).object);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    61
          frm._af_acting = false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    62
          frm.submit();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    63
          // window.console.info('Submitting form');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    64
          return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    65
        }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    66
        if ( autofill.event.keyCode == autofill.KEY_UP || autofill.event.keyCode == autofill.KEY_DOWN || autofill.event.keyCode == autofill.KEY_ESC || autofill.event.keyCode == autofill.KEY_TAB || autofill.event.keyCode == autofill.KEY_ENTER )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    67
        {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    68
          autofill.keyhandler();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    69
          // window.console.info('Control key detected, called keyhandler and exiting');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    70
          return true;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    71
        }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    72
      }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    73
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    74
    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    75
    if ( this.box_id )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    76
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    77
      this.destroy();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    78
      // window.console.info('already have a box open - destroying and exiting');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    79
      //return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    80
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    81
    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    82
    var users = new Array();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    83
    for ( var i = 0; i < resp_json.users_real.length; i++ )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    84
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    85
      try
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    86
      {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    87
        var user = resp_json.users_real[i].toLowerCase();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    88
        var inp  = $(autofill.field_id).object.value;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    89
        inp = inp.toLowerCase();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    90
        if ( user.indexOf(inp) > -1 )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    91
        {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    92
          users.push(resp_json.users_real[i]);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    93
        }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    94
      }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    95
      catch(e)
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    96
      {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    97
        users.push(resp_json.users_real[i]);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    98
      }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
    99
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   100
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   101
    // This was used ONLY for debugging the DOM and list logic    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   102
    // resp_json.users = resp_json.users_real;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   103
    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   104
    // construct table
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   105
    var div = document.createElement('div');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   106
    div.className = 'tblholder';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   107
    div.style.clip = 'rect(0px,auto,auto,0px)';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   108
    div.style.maxHeight = '200px';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   109
    div.style.overflow = 'auto';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   110
    div.style.zIndex = '9999';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   111
    var table = document.createElement('table');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   112
    table.border = '0';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   113
    table.cellSpacing = '1';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   114
    table.cellPadding = '3';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   115
    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   116
    var tr = document.createElement('tr');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   117
    var th = document.createElement('th');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   118
    th.appendChild(document.createTextNode('Username suggestions'));
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   119
    tr.appendChild(th);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   120
    table.appendChild(tr);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   121
    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   122
    if ( users.length < 1 )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   123
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   124
      var tr = document.createElement('tr');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   125
      var td = document.createElement('td');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   126
      td.className = 'row1';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   127
      td.appendChild(document.createTextNode('No suggestions'));
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   128
      td.afobj = autofill;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   129
      tr.appendChild(td);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   130
      table.appendChild(tr);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   131
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   132
    else
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   133
      
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   134
      for ( var i = 0; i < users.length; i++ )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   135
      {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   136
        var user = users[i];
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   137
        var tr = document.createElement('tr');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   138
        var td = document.createElement('td');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   139
        td.className = ( i == 0 ) ? 'row2' : 'row1';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   140
        td.appendChild(document.createTextNode(user));
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   141
        td.afobj = autofill;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   142
        td.style.cursor = 'pointer';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   143
        td.onclick = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   144
        {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   145
          this.afobj.set(this.firstChild.nodeValue);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   146
        }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   147
        tr.appendChild(td);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   148
        table.appendChild(tr);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   149
      }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   150
      
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   151
    // Finalize div
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   152
    var tb_top    = $(autofill.field_id).Top();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   153
    var tb_height = $(autofill.field_id).Height();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   154
    var af_top    = tb_top + tb_height - 9;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   155
    var tb_left   = $(autofill.field_id).Left();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   156
    var af_left   = tb_left;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   157
    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   158
    div.style.position = 'absolute';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   159
    div.style.left = af_left + 'px';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   160
    div.style.top  = af_top  + 'px';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   161
    div.style.width = '200px';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   162
    div.style.fontSize = '7pt';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   163
    div.style.fontFamily = 'Trebuchet MS, arial, helvetica, sans-serif';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   164
    div.id = 'afuserdrop_' + Math.floor(Math.random() * 1000000);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   165
    div.appendChild(table);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   166
    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   167
    autofill.boxes.push(div.id);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   168
    autofill.box_id = div.id;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   169
    if ( users.length > 0 )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   170
      autofill.state = users[0];
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   171
    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   172
    var body = document.getElementsByTagName('body')[0];
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   173
    body.appendChild(div);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   174
    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   175
    autofill.repeat = true;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   176
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   177
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   178
  // perform ajax call
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   179
  this.fetch_and_process = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   180
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   181
    af_current = this;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   182
    var processResponse = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   183
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   184
      if ( ajax.readyState == 4 )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   185
      {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   186
        var afobj = af_current;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   187
        af_current = false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   188
        // parse the JSON response
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   189
        var response = String(ajax.responseText) + ' ';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   190
        if ( response.substr(0,1) != '{' )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   191
        {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   192
          new messagebox(MB_OK|MB_ICONSTOP, 'Invalid response', 'Invalid or unexpected JSON response from server:<pre>' + ajax.responseText + '</pre>');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   193
          return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   194
        }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   195
        if ( $(afobj.field_id).object.value.length < 3 )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   196
          return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   197
        var resp_json = parseJSON(response);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   198
        var resp_code = $(afobj.field_id).object.value.toLowerCase().substr(0, 3);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   199
        afobj.responses[resp_code] = resp_json;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   200
        afobj.process_dataset(resp_json);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   201
      }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   202
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   203
    var usernamefragment = ajaxEscape($(this.field_id).object.value);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   204
    ajaxGet(stdAjaxPrefix + '&_mode=fillusername&name=' + usernamefragment + '&allowanon=' + ( this.allowanon ? '1' : '0' ), processResponse);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   205
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   206
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   207
  this.go = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   208
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   209
    if ( document.getElementById(this.field_id).value.length < 3 )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   210
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   211
      this.destroy();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   212
      return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   213
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   214
    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   215
    if ( af_current )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   216
      return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   217
    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   218
    var resp_code = $(this.field_id).object.value.toLowerCase().substr(0, 3);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   219
    if ( this.responses.length < 1 || ! this.responses[ resp_code ] )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   220
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   221
      // window.console.info('Cannot find dataset ' + resp_code + ' in cache, sending AJAX request');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   222
      this.fetch_and_process();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   223
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   224
    else
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   225
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   226
      // window.console.info('Using cached dataset: ' + resp_code);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   227
      var resp_json = this.responses[ resp_code ];
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   228
      this.process_dataset(resp_json);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   229
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   230
    document.getElementById(this.field_id).onkeyup = function(event)
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   231
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   232
      this.afobj.event = event;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   233
      this.afobj.go();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   234
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   235
    document.getElementById(this.field_id).onkeydown = function(event)
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   236
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   237
      var form = findParentForm(this);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   238
      if ( typeof(event) != 'object' )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   239
        var event = window.event;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   240
      if ( typeof(event) == 'object' )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   241
      {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   242
        if ( event.keyCode == this.afobj.KEY_ENTER && this.afobj.boxes.length < 1 && !this.afobj.box_id )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   243
        {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   244
          // user hit enter after accepting a suggestion - submit the form
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   245
          form._af_acting = false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   246
          return true;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   247
        }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   248
      }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   249
      form._af_acting = true;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   250
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   251
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   252
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   253
  this.keyhandler = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   254
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   255
    var key = this.event.keyCode;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   256
    if ( key == this.KEY_ENTER && !this.repeat )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   257
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   258
      var form = findParentForm($(this.field_id).object);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   259
        form._af_acting = false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   260
      return true;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   261
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   262
    switch(key)
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   263
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   264
      case this.KEY_UP:
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   265
        this.focus_up();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   266
        break;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   267
      case this.KEY_DOWN:
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   268
        this.focus_down();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   269
        break;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   270
      case this.KEY_ESC:
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   271
        this.destroy();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   272
        break;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   273
      case this.KEY_TAB:
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   274
        this.destroy();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   275
        break;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   276
      case this.KEY_ENTER:
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   277
        this.set();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   278
        break;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   279
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   280
    
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   281
    var form = findParentForm($(this.field_id).object);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   282
      form._af_acting = false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   283
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   284
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   285
  this.get_state_td = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   286
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   287
    var div = document.getElementById(this.box_id);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   288
    if ( !div )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   289
      return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   290
    if ( !this.state )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   291
      return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   292
    var table = div.firstChild;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   293
    for ( var i = 1; i < table.childNodes.length; i++ )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   294
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   295
      // the table is DOM-constructed so no cruddy HTML hacks :-)
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   296
      var child = table.childNodes[i];
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   297
      var tn = child.firstChild.firstChild;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   298
      if ( tn.nodeValue == this.state )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   299
        return child.firstChild;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   300
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   301
    return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   302
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   303
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   304
  this.focus_down = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   305
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   306
    var state_td = this.get_state_td();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   307
    if ( !state_td )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   308
      return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   309
    if ( state_td.parentNode.nextSibling )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   310
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   311
      // Ooh boy, DOM stuff can be so complicated...
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   312
      // <tr>  -->  <tr>
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   313
      // <td>       <td>
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   314
      // user       user
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   315
      
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   316
      var newstate = state_td.parentNode.nextSibling.firstChild.firstChild.nodeValue;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   317
      if ( !newstate )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   318
        return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   319
      this.state = newstate;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   320
      state_td.className = 'row1';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   321
      state_td.parentNode.nextSibling.firstChild.className = 'row2';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   322
      
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   323
      // Exception - automatically scroll around if the item is off-screen
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   324
      var height = $(this.box_id).Height();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   325
      var top = $(this.box_id).object.scrollTop;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   326
      var scroll_bottom = height + top;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   327
      
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   328
      var td_top = $(state_td.parentNode.nextSibling.firstChild).Top() - $(this.box_id).Top();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   329
      var td_height = $(state_td.parentNode.nextSibling.firstChild).Height();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   330
      var td_bottom = td_top + td_height;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   331
      
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   332
      if ( td_bottom > scroll_bottom )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   333
      {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   334
        var scrollY = td_top - height + 2*td_height - 7;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   335
        // window.console.debug(scrollY);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   336
        $(this.box_id).object.scrollTop = scrollY;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   337
        /*
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   338
        var newtd = state_td.parentNode.nextSibling.firstChild;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   339
        var a = document.createElement('a');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   340
        var id = 'autofill' + Math.floor(Math.random() * 100000);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   341
        a.name = id;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   342
        a.id = id;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   343
        newtd.appendChild(a);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   344
        window.location.hash = '#' + id;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   345
        */
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   346
        
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   347
        // In firefox, scrolling like that makes the field get unfocused
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   348
        $(this.field_id).object.focus();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   349
      }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   350
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   351
    else
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   352
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   353
      return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   354
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   355
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   356
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   357
  this.focus_up = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   358
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   359
    var state_td = this.get_state_td();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   360
    if ( !state_td )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   361
      return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   362
    if ( state_td.parentNode.previousSibling && state_td.parentNode.previousSibling.firstChild.tagName != 'TH' )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   363
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   364
      // Ooh boy, DOM stuff can be so complicated...
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   365
      // <tr>  <--  <tr>
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   366
      // <td>       <td>
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   367
      // user       user
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   368
      
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   369
      var newstate = state_td.parentNode.previousSibling.firstChild.firstChild.nodeValue;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   370
      if ( !newstate )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   371
      {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   372
        return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   373
      }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   374
      this.state = newstate;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   375
      state_td.className = 'row1';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   376
      state_td.parentNode.previousSibling.firstChild.className = 'row2';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   377
      
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   378
      // Exception - automatically scroll around if the item is off-screen
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   379
      var top = $(this.box_id).object.scrollTop;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   380
      
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   381
      var td_top = $(state_td.parentNode.previousSibling.firstChild).Top() - $(this.box_id).Top();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   382
      
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   383
      if ( td_top < top )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   384
      {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   385
        $(this.box_id).object.scrollTop = td_top - 10;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   386
        /*
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   387
        var newtd = state_td.parentNode.previousSibling.firstChild;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   388
        var a = document.createElement('a');
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   389
        var id = 'autofill' + Math.floor(Math.random() * 100000);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   390
        a.name = id;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   391
        a.id = id;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   392
        newtd.appendChild(a);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   393
        window.location.hash = '#' + id;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   394
        */
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   395
        
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   396
        // In firefox, scrolling like that makes the field get unfocused
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   397
        $(this.field_id).object.focus();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   398
      }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   399
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   400
    else
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   401
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   402
      $(this.box_id).object.scrollTop = 0;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   403
      return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   404
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   405
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   406
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   407
  this.destroy = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   408
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   409
    this.repeat = false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   410
    var body = document.getElementsByTagName('body')[0];
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   411
    var div = document.getElementById(this.box_id);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   412
    if ( !div )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   413
      return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   414
    setTimeout('var body = document.getElementsByTagName("body")[0]; body.removeChild(document.getElementById("'+div.id+'"));', 20);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   415
    // hackish workaround for divs that stick around past their welcoming period
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   416
    for ( var i = 0; i < this.boxes.length; i++ )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   417
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   418
      var div = document.getElementById(this.boxes[i]);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   419
      if ( div )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   420
        setTimeout('var body = document.getElementsByTagName("body")[0]; var div = document.getElementById("'+div.id+'"); if ( div ) body.removeChild(div);', 20);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   421
      delete(this.boxes[i]);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   422
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   423
    this.box_id = false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   424
    this.state = false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   425
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   426
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   427
  this.set = function(val)
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   428
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   429
    var ta = document.getElementById(this.field_id);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   430
    if ( val )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   431
      ta.value = val;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   432
    else if ( this.state )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   433
      ta.value = this.state;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   434
    this.destroy();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   435
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   436
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   437
  this.sleep = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   438
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   439
    if ( this.box_id )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   440
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   441
      var div = document.getElementById(this.box_id);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   442
      div.style.display = 'none';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   443
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   444
    var el = $(this.field_id).object;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   445
    var fr = findParentForm(el);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   446
    el._af_acting = false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   447
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   448
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   449
  this.wake = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   450
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   451
    if ( this.box_id )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   452
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   453
      var div = document.getElementById(this.box_id);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   454
      div.style.display = 'block';
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   455
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   456
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   457
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   458
  parent.onblur = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   459
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   460
    af_current = this.afobj;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   461
    window.setTimeout('if ( af_current ) af_current.sleep(); af_current = false;', 50);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   462
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   463
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   464
  parent.onfocus = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   465
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   466
    af_current = this.afobj;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   467
    window.setTimeout('if ( af_current ) af_current.wake(); af_current = false;', 50);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   468
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   469
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   470
  parent.afobj = this;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   471
  var frm = findParentForm(parent);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   472
  if ( frm.onsubmit )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   473
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   474
    frm.orig_onsubmit = frm.onsubmit;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   475
    frm.onsubmit = function(e)
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   476
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   477
      if ( this._af_acting )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   478
        return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   479
      this.orig_onsubmit(e);
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   480
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   481
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   482
  else
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   483
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   484
    frm.onsubmit = function()
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   485
    {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   486
      if ( this._af_acting )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   487
        return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   488
    }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   489
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   490
  
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   491
  if ( parent.value.length < 3 )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   492
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   493
    this.destroy();
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   494
    return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   495
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   496
}
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   497
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   498
function findParentForm(o)
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   499
{
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   500
  if ( o.tagName == 'FORM' )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   501
    return o;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   502
  while(true)
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   503
  {
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   504
    o = o.parentNode;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   505
    if ( !o )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   506
      return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   507
    if ( o.tagName == 'FORM' )
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   508
      return o;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   509
  }
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   510
  return false;
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   511
}
d74ff822acc9 Replaced autocompleting username with a much more efficient algorithm and caching system
Dan
parents:
diff changeset
   512