includes/clientside/static/functions.js
author Dan
Wed, 09 Jul 2008 21:02:09 -0400
changeset 617 9e4ccf67b6ea
parent 592 27377179fe58
child 628 ab6f55abb17e
permissions -rw-r--r--
Fixed missing require() on search.php in rebuild_page_index()
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
     1
// all utility functions go in here
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
     2
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
     3
function makeUrl(page, query, html_friendly)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
     4
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
     5
  url = contentPath+page;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
     6
  if(url.indexOf('?') > 0) sep = '&';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
     7
  else sep = '?';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
     8
  if(query)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
     9
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    10
    url = url + sep + query;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    11
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    12
  if(html_friendly)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    13
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    14
    url = url.replace('&', '&');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    15
    url = url.replace('<', '&lt;');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    16
    url = url.replace('>', '&gt;');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    17
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    18
  return url;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    19
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    20
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    21
function makeUrlNS(namespace, page, query, html_friendly)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    22
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    23
  var url = contentPath+namespace_list[namespace]+(page.replace(/ /g, '_'));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    24
  if(url.indexOf('?') > 0) sep = '&';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    25
  else sep = '?';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    26
  if(query)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    27
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    28
    url = url + sep + query;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    29
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    30
  if(html_friendly)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    31
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    32
    url = url.replace('&', '&amp;');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    33
    url = url.replace('<', '&lt;');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    34
    url = url.replace('>', '&gt;');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    35
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    36
  return append_sid(url);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    37
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    38
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    39
function strToPageID(string)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    40
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    41
  // Convert Special:UploadFile to ['UploadFile', 'Special'], but convert 'Image:Enano.png' to ['Enano.png', 'File']
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    42
  for(var i in namespace_list)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    43
    if(namespace_list[i] != '')
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    44
      if(namespace_list[i] == string.substr(0, namespace_list[i].length))
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    45
        return [string.substr(namespace_list[i].length), i];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    46
  return [string, 'Article'];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    47
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    48
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    49
function append_sid(url)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    50
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    51
  sep = ( url.indexOf('?') > 0 ) ? '&' : '?';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    52
  if(ENANO_SID.length > 10)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    53
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    54
    url = url + sep + 'auth=' + ENANO_SID;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    55
    sep = '&';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    56
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    57
  if ( pagepass.length > 0 )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    58
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    59
    url = url + sep + 'pagepass=' + pagepass;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    60
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    61
  return url;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    62
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    63
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    64
var stdAjaxPrefix = append_sid(scriptPath+'/ajax.php?title='+title);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    65
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    66
/**
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    67
 * Core AJAX library
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    68
 */
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    69
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    70
function ajaxMakeXHR()
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    71
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    72
  var ajax;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    73
  if (window.XMLHttpRequest) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    74
    ajax = new XMLHttpRequest();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    75
  } else {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    76
    if (window.ActiveXObject) {           
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    77
      ajax = new ActiveXObject("Microsoft.XMLHTTP");
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    78
    } else {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    79
      alert('Enano client-side runtime error: No AJAX support, unable to continue');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    80
      return;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    81
    }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    82
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    83
  return ajax;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    84
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    85
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    86
function ajaxGet(uri, f, call_editor_safe) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    87
  // Is the editor open?
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    88
  if ( editor_open && !call_editor_safe )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    89
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    90
    // Make sure the user is willing to close the editor
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    91
    var conf = confirm($lang.get('editor_msg_confirm_ajax'));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    92
    if ( !conf )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    93
    {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    94
      // Kill off any "loading" windows, etc. and cancel the request
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    95
      unsetAjaxLoading();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    96
      return false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    97
    }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    98
    // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
    99
    editor_open = false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   100
    enableUnload();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   101
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   102
  ajax = ajaxMakeXHR();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   103
  if ( !ajax )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   104
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   105
    console.error('ajaxMakeXHR() failed');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   106
    return false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   107
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   108
  ajax.onreadystatechange = f;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   109
  ajax.open('GET', uri, true);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   110
  ajax.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   111
  ajax.send(null);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   112
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   113
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   114
function ajaxPost(uri, parms, f, call_editor_safe) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   115
  // Is the editor open?
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   116
  if ( editor_open && !call_editor_safe )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   117
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   118
    // Make sure the user is willing to close the editor
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   119
    var conf = confirm($lang.get('editor_msg_confirm_ajax'));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   120
    if ( !conf )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   121
    {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   122
      // Kill off any "loading" windows, etc. and cancel the request
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   123
      unsetAjaxLoading();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   124
      return false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   125
    }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   126
    // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   127
    editor_open = false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   128
    enableUnload();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   129
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   130
  ajax = ajaxMakeXHR();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   131
  if ( !ajax )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   132
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   133
    console.error('ajaxMakeXHR() failed');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   134
    return false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   135
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   136
  ajax.onreadystatechange = f;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   137
  ajax.open('POST', uri, true);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   138
  ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   139
  // Setting Content-length in Safari triggers a warning
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   140
  if ( !is_Safari )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   141
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   142
    ajax.setRequestHeader("Content-length", parms.length);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   143
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   144
  ajax.setRequestHeader("Connection", "close");
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   145
  ajax.send(parms);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   146
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   147
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   148
/**
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   149
 * Show a friendly error message depicting an AJAX response that is not valid JSON
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   150
 * @param string Response text
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   151
 * @param string Custom error message. If omitted, the default will be shown.
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   152
 */
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   153
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   154
function handle_invalid_json(response, customerror)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   155
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   156
  var mainwin = $dynano('ajaxEditContainer').object;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   157
  mainwin.innerHTML = '';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   158
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   159
  // Title
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   160
  var h3 = document.createElement('h3');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   161
  h3.appendChild(document.createTextNode('The site encountered an error while processing your request.'));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   162
  mainwin.appendChild(h3);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   163
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   164
  if ( typeof(customerror) == 'string' )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   165
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   166
    var el = document.createElement('p');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   167
    el.appendChild(document.createTextNode(customerror));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   168
    mainwin.appendChild(el);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   169
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   170
  else
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   171
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   172
    customerror  = 'We unexpectedly received the following response from the server. The response should have been in the JSON ';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   173
    customerror += 'serialization format, but the response wasn\'t composed only of the JSON response. There are three possible triggers ';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   174
    customerror += 'for this problem:';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   175
    var el = document.createElement('p');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   176
    el.appendChild(document.createTextNode(customerror));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   177
    mainwin.appendChild(el);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   178
    var ul = document.createElement('ul');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   179
    var li1 = document.createElement('li');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   180
    var li2 = document.createElement('li');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   181
    var li3 = document.createElement('li');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   182
    li1.appendChild(document.createTextNode('The server sent back a bad HTTP response code and thus sent an error page instead of running Enano. This indicates a possible problem with your server, and is not likely to be a bug with Enano.'));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   183
    var osc_exception = ( window.location.hostname == 'demo.opensourcecms.com' ) ? ' This is KNOWN to be the case with the OpenSourceCMS.com demo version of Enano.' : '';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   184
    li2.appendChild(document.createTextNode('The server sent back the expected JSON response, but also injected some code into the response that should not be there. Typically this consists of advertisement code. In this case, the administrator of this site will have to contact their web host to have advertisements disabled.' + osc_exception));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   185
    li3.appendChild(document.createTextNode('It\'s possible that Enano triggered a PHP error or warning. In this case, you may be looking at a bug in Enano.'));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   186
      
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   187
    ul.appendChild(li1);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   188
    ul.appendChild(li2);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   189
    ul.appendChild(li3);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   190
    mainwin.appendChild(ul);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   191
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   192
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   193
  var p2 = document.createElement('p');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   194
  p2.appendChild(document.createTextNode('The response received from the server is as follows:'));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   195
  mainwin.appendChild(p2);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   196
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   197
  var pre = document.createElement('pre');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   198
  pre.appendChild(document.createTextNode(response));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   199
  mainwin.appendChild(pre);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   200
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   201
  var p3 = document.createElement('p');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   202
  p3.appendChild(document.createTextNode('You may also choose to view the response as HTML. '));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   203
  var a = document.createElement('a');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   204
  a.appendChild(document.createTextNode('View as HTML...'));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   205
  a._resp = response;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   206
  a.id = 'invalidjson_link';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   207
  a.onclick = function()
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   208
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   209
    var mb = new MessageBox(MB_YESNO | MB_ICONEXCLAMATION, 'Do you really want to view this response as HTML?', 'If the response was changed during transmission to include malicious code, you may be allowing that malicious code to run by viewing the response as HTML. Only do this if you have reviewed the response text and have found no suspicious code in it.');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   210
    mb.onclick['Yes'] = function()
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   211
    {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   212
      var html = $dynano('invalidjson_link').object._resp;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   213
      var win = window.open('about:blank', 'invalidjson_htmlwin', 'width=550,height=400,status=no,toolbars=no,toolbar=no,address=no,scroll=yes');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   214
      win.document.write(html);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   215
    }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   216
    return false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   217
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   218
  a.href = '#';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   219
  p3.appendChild(a);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   220
  mainwin.appendChild(p3);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   221
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   222
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   223
function ajaxEscape(text)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   224
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   225
  /*
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   226
  text = escape(text);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   227
  text = text.replace(/\+/g, '%2B', text);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   228
  */
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   229
  text = window.encodeURIComponent(text);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   230
  return text;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   231
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   232
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   233
/**
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   234
 * String functions
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   235
 */
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   236
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   237
// Equivalent to PHP trim() function
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   238
function trim(text)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   239
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   240
  text = text.replace(/^([\s]+)/, '');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   241
  text = text.replace(/([\s]+)$/, '');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   242
  return text;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   243
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   244
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   245
// Equivalent to PHP implode() function
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   246
function implode(chr, arr)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   247
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   248
  if ( typeof ( arr.toJSONString ) == 'function' )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   249
    delete(arr.toJSONString);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   250
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   251
  var ret = '';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   252
  var c = 0;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   253
  for ( var i in arr )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   254
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   255
    if(i=='toJSONString')continue;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   256
    if ( c > 0 )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   257
      ret += chr;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   258
    ret += arr[i];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   259
    c++;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   260
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   261
  return ret;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   262
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   263
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   264
function form_fetch_field(form, name)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   265
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   266
  var fields = form.getElementsByTagName('input');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   267
  if ( fields.length < 1 )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   268
    return false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   269
  for ( var i = 0; i < fields.length; i++ )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   270
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   271
    var field = fields[i];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   272
    if ( field.name == name )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   273
      return field;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   274
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   275
  return false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   276
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   277
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   278
function get_parent_form(o)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   279
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   280
  if ( !o.parentNode )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   281
    return false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   282
  if ( o.tagName == 'FORM' )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   283
    return o;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   284
  var p = o.parentNode;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   285
  while(true)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   286
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   287
    if ( p.tagName == 'FORM' )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   288
      return p;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   289
    else if ( !p )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   290
      return false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   291
    else
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   292
      p = p.parentNode;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   293
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   294
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   295
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   296
function findParentForm(o)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   297
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   298
  return get_parent_form(o);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   299
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   300
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   301
function domObjChangeOpac(opacity, id) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   302
    var object = id.style;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   303
    object.opacity = (opacity / 100);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   304
    object.MozOpacity = (opacity / 100);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   305
    object.KhtmlOpacity = (opacity / 100);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   306
    object.filter = "alpha(opacity=" + opacity + ")";
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   307
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   308
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   309
function getScrollOffset()
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   310
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   311
  var position;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   312
  if (self.pageYOffset)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   313
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   314
    position = self.pageYOffset;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   315
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   316
  else if (document.documentElement && document.documentElement.scrollTop)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   317
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   318
    position = document.documentElement.scrollTop;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   319
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   320
  else if (document.body)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   321
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   322
    position = document.body.scrollTop;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   323
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   324
  return position;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   325
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   326
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   327
// Function to fade classes info-box, warning-box, error-box, etc.
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   328
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   329
function fadeInfoBoxes()
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   330
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   331
  var divs = new Array();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   332
  d = document.getElementsByTagName('div');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   333
  j = 0;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   334
  for(var i in d)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   335
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   336
    if ( !d[i] )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   337
      continue;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   338
    if ( !d[i].tagName )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   339
      continue;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   340
    if(d[i].className=='info-box' || d[i].className=='error-box' || d[i].className=='warning-box' || d[i].className=='question-box')
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   341
    {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   342
      divs[j] = d[i];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   343
      j++;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   344
    }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   345
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   346
  if(divs.length < 1) return;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   347
  load_component('fat');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   348
  for(i in divs)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   349
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   350
    if(!divs[i].id) divs[i].id = 'autofade_'+Math.floor(Math.random() * 100000);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   351
    switch(divs[i].className)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   352
    {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   353
      case 'info-box':
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   354
      default:
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   355
        from = '#3333FF';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   356
        break;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   357
      case 'error-box':
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   358
        from = '#FF3333';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   359
        break;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   360
      case 'warning-box':
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   361
        from = '#FFFF33';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   362
        break;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   363
      case 'question-box':
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   364
        from = '#33FF33';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   365
        break;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   366
    }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   367
    Fat.fade_element(divs[i].id,30,2000,from,Fat.get_bgcolor(divs[i].id));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   368
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   369
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   370
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   371
addOnloadHook(fadeInfoBoxes);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   372
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   373
// Alpha fades
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   374
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   375
function opacity(id, opacStart, opacEnd, millisec)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   376
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   377
    var object = document.getElementById(id);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   378
    domOpacity(object, opacStart, opacEnd, millisec);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   379
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   380
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   381
var opacityDOMCache = new Object();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   382
function domOpacity(obj, opacStart, opacEnd, millisec) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   383
    //speed for each frame
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   384
    var speed = Math.round(millisec / 100);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   385
    var timer = 0;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   386
    
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   387
    // unique ID for this animation
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   388
    var uniqid = Math.floor(Math.random() * 1000000);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   389
    opacityDOMCache[uniqid] = obj;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   390
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   391
    //determine the direction for the blending, if start and end are the same nothing happens
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   392
    if(opacStart > opacEnd) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   393
        for(i = opacStart; i >= opacEnd; i--) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   394
            setTimeout("var obj = opacityDOMCache["+uniqid+"]; domObjChangeOpac(" + i + ",obj)",(timer * speed));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   395
            timer++;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   396
        }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   397
    } else if(opacStart < opacEnd) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   398
        for(i = opacStart; i <= opacEnd; i++)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   399
            {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   400
            setTimeout("var obj = opacityDOMCache["+uniqid+"]; domObjChangeOpac(" + i + ",obj)",(timer * speed));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   401
            timer++;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   402
        }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   403
    }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   404
    setTimeout("delete(opacityDOMCache["+uniqid+"]);",(timer * speed));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   405
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   406
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   407
// change the opacity for different browsers
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   408
function changeOpac(opacity, id)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   409
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   410
  var object = document.getElementById(id);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   411
  return domObjChangeOpac(opacity, object);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   412
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   413
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   414
// draw a white ajax-ey "loading" box over an object
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   415
function whiteOutElement(el)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   416
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   417
  var top = $(el).Top();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   418
  var left = $(el).Left();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   419
  var width = $(el).Width();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   420
  var height = $(el).Height();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   421
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   422
  var blackout = document.createElement('div');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   423
  blackout.style.position = 'absolute';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   424
  blackout.style.top = top + 'px';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   425
  blackout.style.left = left + 'px';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   426
  blackout.style.width = width + 'px';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   427
  blackout.style.height = height + 'px';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   428
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   429
  blackout.style.backgroundColor = '#FFFFFF';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   430
  domObjChangeOpac(60, blackout);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   431
  blackout.style.backgroundImage = 'url(' + scriptPath + '/includes/clientside/tinymce/themes/advanced/skins/default/img/progress.gif)';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   432
  blackout.style.backgroundPosition = 'center center';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   433
  blackout.style.backgroundRepeat = 'no-repeat';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   434
  blackout.style.zIndex = getHighestZ() + 2;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   435
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   436
  var body = document.getElementsByTagName('body')[0];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   437
  body.appendChild(blackout);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   438
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   439
  return blackout;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   440
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   441
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   442
// other DHTML functions
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   443
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   444
function fetch_offset(obj)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   445
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   446
  var left_offset = obj.offsetLeft;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   447
  var top_offset = obj.offsetTop;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   448
  while ((obj = obj.offsetParent) != null) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   449
    left_offset += obj.offsetLeft;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   450
    top_offset += obj.offsetTop;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   451
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   452
  return { 'left' : left_offset, 'top' : top_offset };
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   453
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   454
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   455
function fetch_dimensions(o) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   456
  var w = o.offsetWidth;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   457
  var h = o.offsetHeight;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   458
  return { 'w' : w, 'h' : h };
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   459
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   460
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   461
function findParentForm(o)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   462
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   463
  if ( o.tagName == 'FORM' )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   464
    return o;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   465
  while(true)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   466
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   467
    o = o.parentNode;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   468
    if ( !o )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   469
      return false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   470
    if ( o.tagName == 'FORM' )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   471
      return o;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   472
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   473
  return false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   474
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   475
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   476
function bannerOn(text)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   477
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   478
  darken(true);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   479
  var thediv = document.createElement('div');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   480
  thediv.className = 'mdg-comment';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   481
  thediv.style.padding = '0';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   482
  thediv.style.marginLeft = '0';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   483
  thediv.style.position = 'absolute';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   484
  thediv.style.display = 'none';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   485
  thediv.style.padding = '4px';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   486
  thediv.style.fontSize = '14pt';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   487
  thediv.id = 'mdgDynamic_bannerDiv_'+Math.floor(Math.random() * 1000000);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   488
  thediv.innerHTML = text;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   489
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   490
  var body = document.getElementsByTagName('body');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   491
  body = body[0];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   492
  body.appendChild(thediv);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   493
  body.style.cursor = 'wait';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   494
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   495
  thediv.style.display = 'block';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   496
  dim = fetch_dimensions(thediv);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   497
  thediv.style.display = 'none';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   498
  bdim = { 'w' : getWidth(), 'h' : getHeight() };
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   499
  so = getScrollOffset();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   500
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   501
  var left = (bdim['w'] / 2) - ( dim['w'] / 2 );
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   502
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   503
  var top  = (bdim['h'] / 2);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   504
  top  = top - ( dim['h'] / 2 );
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   505
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   506
  top = top + so;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   507
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   508
  thediv.style.top  = top  + 'px';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   509
  thediv.style.left = left + 'px';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   510
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   511
  thediv.style.display = 'block';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   512
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   513
  return thediv.id;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   514
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   515
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   516
function bannerOff(id)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   517
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   518
  e = document.getElementById(id);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   519
  if(!e) return;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   520
  e.innerHTML = '';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   521
  e.style.display = 'none';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   522
  var body = document.getElementsByTagName('body');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   523
  body = body[0];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   524
  body.style.cursor = 'default';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   525
  enlighten(true);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   526
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   527
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   528
function disableUnload(message)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   529
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   530
  if(typeof message != 'string') message = 'You may want to save your changes first.';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   531
  window._unloadmsg = message;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   532
  window.onbeforeunload = function(e)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   533
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   534
    if ( !e )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   535
      e = window.event;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   536
    e.returnValue = window._unloadmsg;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   537
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   538
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   539
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   540
function enableUnload()
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   541
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   542
  window._unloadmsg = null;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   543
  window.onbeforeunload = null;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   544
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   545
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   546
/**
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   547
 * Gets the highest z-index of all divs in the document
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   548
 * @return integer
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   549
 */
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   550
function getHighestZ()
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   551
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   552
  z = 0;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   553
  var divs = document.getElementsByTagName('div');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   554
  for(var i = 0; i < divs.length; i++)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   555
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   556
    if(divs[i].style.zIndex > z) z = divs[i].style.zIndex;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   557
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   558
  return z;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   559
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   560
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 582
diff changeset
   561
var shift = false;
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   562
function isKeyPressed(event)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   563
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   564
  if (event.shiftKey==1)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   565
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   566
    shift = true;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   567
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   568
  else
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   569
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   570
    shift = false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   571
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   572
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   573
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   574
function moveDiv(div, newparent)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   575
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   576
  var backup = div;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   577
  var oldparent = div.parentNode;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   578
  oldparent.removeChild(div);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   579
  newparent.appendChild(backup);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   580
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   581
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   582
var busyBannerID;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   583
function goBusy(msg)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   584
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   585
  if(!msg) msg = 'Please wait...';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   586
  body = document.getElementsByTagName('body');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   587
  body = body[0];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   588
  body.style.cursor = 'wait';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   589
  busyBannerID = bannerOn(msg);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   590
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   591
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   592
function unBusy()
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   593
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   594
  body = document.getElementsByTagName('body');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   595
  body = body[0];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   596
  body.style.cursor = 'default';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   597
  bannerOff(busyBannerID);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   598
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   599
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   600
function setAjaxLoading()
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   601
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   602
  if ( document.getElementById('ajaxloadicon') )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   603
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   604
    document.getElementById('ajaxloadicon').src=ajax_load_icon;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   605
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   606
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   607
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   608
function unsetAjaxLoading()
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   609
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   610
  if ( document.getElementById('ajaxloadicon') )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   611
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   612
    document.getElementById('ajaxloadicon').src=scriptPath + '/images/spacer.gif';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   613
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   614
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   615
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   616
function readCookie(name) {var nameEQ = name + "=";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++){var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length);if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}return null;}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   617
function createCookie(name,value,days){if (days){var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = name+"="+value+expires+"; path=/";}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   618
function eraseCookie(name) {createCookie(name,"",-1);}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   619
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   620
/*
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   621
 * AJAX login box (experimental)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   622
 * Moved / rewritten in login.js
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   623
 */
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   624
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   625
// Included only for API-compatibility
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   626
function ajaxPromptAdminAuth(call_on_ok, level)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   627
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   628
  ajaxLogonInit(call_on_ok, level);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   629
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   630
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   631
/**
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   632
 * Insert a DOM object _after_ the specified child.
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   633
 * @param object Parent node
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   634
 * @param object Node to insert
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   635
 * @param object Node to insert after
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   636
 */
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   637
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   638
function insertAfter(parent, baby, bigsister)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   639
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   640
  try
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   641
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   642
    if ( parent.childNodes[parent.childNodes.length-1] == bigsister )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   643
      parent.appendChild(baby);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   644
    else
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   645
      parent.insertBefore(baby, bigsister.nextSibling);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   646
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   647
  catch(e)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   648
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   649
    alert(e.toString());
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   650
    if ( window.console )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   651
    {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   652
      // Firebug support
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   653
      window.console.warn(e);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   654
    }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   655
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   656
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   657
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   658
/**
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   659
 * Validates an e-mail address.
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   660
 * @param string E-mail address
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   661
 * @return bool
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   662
 */
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   663
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   664
function validateEmail(email)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   665
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   666
  return ( email.match(/^(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*|(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037]*(?:(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037]*)*<[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*(?:,[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*)*:[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)?(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*>)$/) ) ? true : false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   667
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   668
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   669
/**
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   670
 * Validates a username.
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   671
 * @param string Username to test
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   672
 * @return bool
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   673
 */
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   674
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   675
function validateUsername(username)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   676
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   677
  var regex = new RegExp('^[^<>&\?\'"%\n\r/]+$', '');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   678
  return ( username.match(regex) ) ? true : false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   679
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   680
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   681
/*
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   682
 * Utility functions, moved from windows.js
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   683
 */
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   684
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   685
function getHeight() {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   686
  var myHeight = 0;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   687
  if( typeof( window.innerWidth ) == 'number' ) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   688
    myHeight = window.innerHeight;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   689
  } else if( document.documentElement &&
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   690
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   691
    myHeight = document.documentElement.clientHeight;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   692
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   693
    myHeight = document.body.clientHeight;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   694
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   695
  return myHeight;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   696
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   697
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   698
function getWidth() {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   699
  var myWidth = 0;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   700
  if( typeof( window.innerWidth ) == 'number' ) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   701
    myWidth = window.innerWidth;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   702
  } else if( document.documentElement &&
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   703
      ( document.documentElement.clientWidth || document.documentElement.clientWidth ) ) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   704
    myWidth = document.documentElement.clientWidth;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   705
  } else if( document.body && ( document.body.clientWidth || document.body.clientWidth ) ) {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   706
    myWidth = document.body.clientWidth;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   707
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   708
  return myWidth;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   709
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   710
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   711
/**
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   712
 * Sanitizes a page URL string so that it can safely be stored in the database.
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   713
 * @param string Page ID to sanitize
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   714
 * @return string Cleaned text
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   715
 */
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   716
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   717
function sanitize_page_id(page_id)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   718
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   719
  // Remove character escapes
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   720
  page_id = dirtify_page_id(page_id);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   721
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   722
  var regex = new RegExp('[A-Za-z0-9\\[\\]\./:;\(\)@_-]', 'g');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   723
  pid_clean = page_id.replace(regex, 'X');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   724
  var pid_dirty = [];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   725
  for ( var i = 0; i < pid_clean.length; i++ )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   726
    pid_dirty[i] = pid_clean.substr(i, 1);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   727
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   728
  for ( var i = 0; i < pid_dirty.length; i++ )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   729
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   730
    var chr = pid_dirty[i];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   731
    if ( chr == 'X' )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   732
      continue;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   733
    var cid = chr.charCodeAt(0);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   734
    cid = cid.toString(16).toUpperCase();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   735
    if ( cid.length < 2 )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   736
    {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   737
      cid = '0' + cid;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   738
    }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   739
    pid_dirty[i] = "." + cid;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   740
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   741
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   742
  var pid_chars = [];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   743
  for ( var i = 0; i < page_id.length; i++ )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   744
    pid_chars[i] = page_id.substr(i, 1);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   745
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   746
  var page_id_cleaned = '';
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   747
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   748
  for ( var id in pid_chars )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   749
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   750
    var chr = pid_chars[id];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   751
    if ( pid_dirty[id] == 'X' )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   752
      page_id_cleaned += chr;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   753
    else
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   754
      page_id_cleaned += pid_dirty[id];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   755
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   756
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   757
  return page_id_cleaned;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   758
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   759
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   760
/**
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   761
 * Removes character escapes in a page ID string
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   762
 * @param string Page ID string to dirty up
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   763
 * @return string
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   764
 */
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   765
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   766
function dirtify_page_id(page_id)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   767
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   768
  // First, replace spaces with underscores
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   769
  page_id = page_id.replace(/ /g, '_');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   770
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   771
  var matches = page_id.match(/\.[A-Fa-f0-9][A-Fa-f0-9]/g);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   772
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   773
  if ( matches != null )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   774
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   775
    for ( var i = 0; i < matches.length; i++ )
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   776
    {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   777
      var match = matches[i];
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   778
      var byt = (match.substr(1)).toUpperCase();
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   779
      var code = eval("0x" + byt);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   780
      var regex = new RegExp('\\.' + byt, 'g');
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   781
      page_id = page_id.replace(regex, String.fromCharCode(code));
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   782
    }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   783
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   784
  
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   785
  return page_id;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   786
}
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   787
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   788
/**
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   789
 * Equivalent to PHP's in_array function.
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   790
 */
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   791
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   792
function in_array(needle, haystack)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   793
{
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   794
  for(var i in haystack)
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   795
  {
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   796
    if(haystack[i] == needle) return i;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   797
  }
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   798
  return false;
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff changeset
   799
}