includes/clientside/static/ajax.js
changeset 582 a38876c0793c
parent 581 5e8fd89c02ea
child 585 35e91d16ecf5
equal deleted inserted replaced
581:5e8fd89c02ea 582:a38876c0793c
     1 /*
     1 /*
     2  * AJAX applets
     2  * AJAX applets
     3  */
     3  */
     4  
     4  
     5 function ajaxMakeXHR()
     5 window.ajaxReset = function()
     6 {
       
     7   var ajax;
       
     8   if (window.XMLHttpRequest) {
       
     9     ajax = new XMLHttpRequest();
       
    10   } else {
       
    11     if (window.ActiveXObject) {           
       
    12       ajax = new ActiveXObject("Microsoft.XMLHTTP");
       
    13     } else {
       
    14       alert('Enano client-side runtime error: No AJAX support, unable to continue');
       
    15       return;
       
    16     }
       
    17   }
       
    18   return ajax;
       
    19 }
       
    20 
       
    21 function ajaxGet(uri, f, call_editor_safe) {
       
    22   // Is the editor open?
       
    23   if ( editor_open && !call_editor_safe )
       
    24   {
       
    25     // Make sure the user is willing to close the editor
       
    26     var conf = confirm($lang.get('editor_msg_confirm_ajax'));
       
    27     if ( !conf )
       
    28     {
       
    29       // Kill off any "loading" windows, etc. and cancel the request
       
    30       unsetAjaxLoading();
       
    31       return false;
       
    32     }
       
    33     // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
       
    34     editor_open = false;
       
    35     enableUnload();
       
    36   }
       
    37   ajax = ajaxMakeXHR();
       
    38   if ( !ajax )
       
    39   {
       
    40     console.error('ajaxMakeXHR() failed');
       
    41     return false;
       
    42   }
       
    43   ajax.onreadystatechange = f;
       
    44   ajax.open('GET', uri, true);
       
    45   ajax.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
       
    46   ajax.send(null);
       
    47 }
       
    48 
       
    49 function ajaxPost(uri, parms, f, call_editor_safe) {
       
    50   // Is the editor open?
       
    51   if ( editor_open && !call_editor_safe )
       
    52   {
       
    53     // Make sure the user is willing to close the editor
       
    54     var conf = confirm($lang.get('editor_msg_confirm_ajax'));
       
    55     if ( !conf )
       
    56     {
       
    57       // Kill off any "loading" windows, etc. and cancel the request
       
    58       unsetAjaxLoading();
       
    59       return false;
       
    60     }
       
    61     // The user allowed the editor to be closed. Reset flags and knock out the on-close confirmation.
       
    62     editor_open = false;
       
    63     enableUnload();
       
    64   }
       
    65   ajax = ajaxMakeXHR();
       
    66   if ( !ajax )
       
    67   {
       
    68     console.error('ajaxMakeXHR() failed');
       
    69     return false;
       
    70   }
       
    71   ajax.onreadystatechange = f;
       
    72   ajax.open('POST', uri, true);
       
    73   ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
       
    74   // Setting Content-length in Safari triggers a warning
       
    75   if ( !is_Safari )
       
    76   {
       
    77     ajax.setRequestHeader("Content-length", parms.length);
       
    78   }
       
    79   ajax.setRequestHeader("Connection", "close");
       
    80   ajax.send(parms);
       
    81 }
       
    82 
       
    83 /**
       
    84  * Show a friendly error message depicting an AJAX response that is not valid JSON
       
    85  * @param string Response text
       
    86  * @param string Custom error message. If omitted, the default will be shown.
       
    87  */
       
    88 
       
    89 function handle_invalid_json(response, customerror)
       
    90 {
       
    91   var mainwin = $dynano('ajaxEditContainer').object;
       
    92   mainwin.innerHTML = '';
       
    93   
       
    94   // Title
       
    95   var h3 = document.createElement('h3');
       
    96   h3.appendChild(document.createTextNode('The site encountered an error while processing your request.'));
       
    97   mainwin.appendChild(h3);
       
    98   
       
    99   if ( typeof(customerror) == 'string' )
       
   100   {
       
   101     var el = document.createElement('p');
       
   102     el.appendChild(document.createTextNode(customerror));
       
   103     mainwin.appendChild(el);
       
   104   }
       
   105   else
       
   106   {
       
   107     customerror  = 'We unexpectedly received the following response from the server. The response should have been in the JSON ';
       
   108     customerror += 'serialization format, but the response wasn\'t composed only of the JSON response. There are three possible triggers ';
       
   109     customerror += 'for this problem:';
       
   110     var el = document.createElement('p');
       
   111     el.appendChild(document.createTextNode(customerror));
       
   112     mainwin.appendChild(el);
       
   113     var ul = document.createElement('ul');
       
   114     var li1 = document.createElement('li');
       
   115     var li2 = document.createElement('li');
       
   116     var li3 = document.createElement('li');
       
   117     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.'));
       
   118     var osc_exception = ( window.location.hostname == 'demo.opensourcecms.com' ) ? ' This is KNOWN to be the case with the OpenSourceCMS.com demo version of Enano.' : '';
       
   119     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));
       
   120     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.'));
       
   121       
       
   122     ul.appendChild(li1);
       
   123     ul.appendChild(li2);
       
   124     ul.appendChild(li3);
       
   125     mainwin.appendChild(ul);
       
   126   }
       
   127   
       
   128   var p2 = document.createElement('p');
       
   129   p2.appendChild(document.createTextNode('The response received from the server is as follows:'));
       
   130   mainwin.appendChild(p2);
       
   131   
       
   132   var pre = document.createElement('pre');
       
   133   pre.appendChild(document.createTextNode(response));
       
   134   mainwin.appendChild(pre);
       
   135   
       
   136   var p3 = document.createElement('p');
       
   137   p3.appendChild(document.createTextNode('You may also choose to view the response as HTML. '));
       
   138   var a = document.createElement('a');
       
   139   a.appendChild(document.createTextNode('View as HTML...'));
       
   140   a._resp = response;
       
   141   a.id = 'invalidjson_link';
       
   142   a.onclick = function()
       
   143   {
       
   144     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.');
       
   145     mb.onclick['Yes'] = function()
       
   146     {
       
   147       var html = $dynano('invalidjson_link').object._resp;
       
   148       var win = window.open('about:blank', 'invalidjson_htmlwin', 'width=550,height=400,status=no,toolbars=no,toolbar=no,address=no,scroll=yes');
       
   149       win.document.write(html);
       
   150     }
       
   151     return false;
       
   152   }
       
   153   a.href = '#';
       
   154   p3.appendChild(a);
       
   155   mainwin.appendChild(p3);
       
   156 }
       
   157 
       
   158 function ajaxEscape(text)
       
   159 {
       
   160   /*
       
   161   text = escape(text);
       
   162   text = text.replace(/\+/g, '%2B', text);
       
   163   */
       
   164   text = window.encodeURIComponent(text);
       
   165   return text;
       
   166 }
       
   167 
       
   168 function ajaxAltEscape(text)
       
   169 {
       
   170   text = escape(text);
       
   171   text = text.replace(/\+/g, '%2B', text);
       
   172   return text;
       
   173 }
       
   174 
       
   175 function ajaxDiscard()
       
   176 {
       
   177   // IE <6 pseudo-compatibility
       
   178   if ( KILL_SWITCH )
       
   179     return true;
       
   180   c = confirm($lang.get('editor_msg_discard_confirm'));
       
   181   if(!c) return;
       
   182   ajaxReset();
       
   183 }
       
   184 
       
   185 function ajaxReset()
       
   186 {
     6 {
   187   // IE <6 pseudo-compatibility
     7   // IE <6 pseudo-compatibility
   188   if ( KILL_SWITCH )
     8   if ( KILL_SWITCH )
   189     return true;
     9     return true;
   190   var ns_id = strToPageID(physical_title);
    10   var ns_id = strToPageID(physical_title);
   205   });
    25   });
   206 }
    26 }
   207 
    27 
   208 // Miscellaneous AJAX applets
    28 // Miscellaneous AJAX applets
   209 
    29 
   210 function ajaxProtect(l) {
    30 window.ajaxProtect = function(l) {
   211   // IE <6 pseudo-compatibility
    31   // IE <6 pseudo-compatibility
   212   if ( KILL_SWITCH )
    32   if ( KILL_SWITCH )
   213     return true;
    33     return true;
       
    34   load_component('l10n');
       
    35   
   214   if(shift) {
    36   if(shift) {
   215     r = 'NO_REASON';
    37     r = 'NO_REASON';
   216   } else {
    38   } else {
   217     r = prompt($lang.get('ajax_protect_prompt_reason'));
    39     r = prompt($lang.get('ajax_protect_prompt_reason'));
   218     if(!r || r=='') return;
    40     if(!r || r=='') return;
   241       alert(ajax.responseText);
    63       alert(ajax.responseText);
   242     }
    64     }
   243   }, true);
    65   }, true);
   244 }
    66 }
   245 
    67 
   246 function ajaxRename()
    68 window.ajaxRename = function()
   247 {
    69 {
   248   // IE <6 pseudo-compatibility
    70   // IE <6 pseudo-compatibility
   249   if ( KILL_SWITCH )
    71   if ( KILL_SWITCH )
   250     return true;
    72     return true;
   251   
    73   
   252   // updated - 1.1.4 to use miniPrompt
    74   // updated - 1.1.4 to use miniPrompt
       
    75   load_component('l10n');
       
    76   load_component('messagebox');
   253   miniPrompt(ajaxRenameConstructDialog);
    77   miniPrompt(ajaxRenameConstructDialog);
   254 }
    78 }
   255 
    79 
   256 var ajaxRenameConstructDialog = function(div)
    80 var ajaxRenameConstructDialog = function(div)
   257 {
    81 {
   317     {
   141     {
   318       box.focus();
   142       box.focus();
   319     }, 200);
   143     }, 200);
   320 }
   144 }
   321 
   145 
   322 function ajaxRenameSubmit(obj)
   146 window.ajaxRenameSubmit = function(obj)
   323 {
   147 {
   324   var box = miniPromptGetParent(obj);
   148   var box = miniPromptGetParent(obj);
   325   if ( !box )
   149   if ( !box )
   326     return false;
   150     return false;
   327   
   151   
   370         }
   194         }
   371       }
   195       }
   372     }, true);
   196     }, true);
   373 }
   197 }
   374 
   198 
   375 function ajaxRenameDoClientTransform(newname)
   199 window.ajaxRenameDoClientTransform = function(newname)
   376 {
   200 {
   377   var obj = document.getElementById('h2PageName');
   201   var obj = document.getElementById('h2PageName');
   378   if ( obj )
   202   if ( obj )
   379   {
   203   {
   380     obj.firstChild.nodeValue = newname;
   204     obj.firstChild.nodeValue = newname;
   381   }
   205   }
   382   document.title = newname;
   206   document.title = newname;
   383 }
   207 }
   384 
   208 
   385 function ajaxMakePage()
   209 window.ajaxDeletePage = function()
   386 {
   210 {
   387   // IE <6 pseudo-compatibility
   211   // IE <6 pseudo-compatibility
   388   if ( KILL_SWITCH )
   212   if ( KILL_SWITCH )
   389     return true;
   213     return true;
   390   setAjaxLoading();
   214   load_component('l10n');
   391   ajaxPost(ENANO_SPECIAL_CREATEPAGE, ENANO_CREATEPAGE_PARAMS, function() {
       
   392     if ( ajax.readyState == 4 && ajax.status == 200 ) {
       
   393       unsetAjaxLoading();
       
   394       window.location.reload();
       
   395     }
       
   396   });
       
   397 }
       
   398 
       
   399 function ajaxDeletePage()
       
   400 {
       
   401   // IE <6 pseudo-compatibility
       
   402   if ( KILL_SWITCH )
       
   403     return true;
       
   404   var reason = prompt($lang.get('ajax_delete_prompt_reason'));
   215   var reason = prompt($lang.get('ajax_delete_prompt_reason'));
   405   if ( !reason || reason == '' )
   216   if ( !reason || reason == '' )
   406   {
   217   {
   407     return false;
   218     return false;
   408   }
   219   }
   419       window.location.reload();                                                                           
   230       window.location.reload();                                                                           
   420     }
   231     }
   421   });
   232   });
   422 }
   233 }
   423 
   234 
   424 function ajaxDelVote()
   235 window.ajaxDelVote = function()
   425 {
   236 {
       
   237   load_component('l10n');
       
   238   load_component('messagebox');
       
   239   
   426   // IE <6 pseudo-compatibility
   240   // IE <6 pseudo-compatibility
   427   if ( KILL_SWITCH )
   241   if ( KILL_SWITCH )
   428     return true;
   242     return true;
   429   miniPromptMessage({
   243   miniPromptMessage({
   430       title: $lang.get('ajax_delvote_confirm_title'),
   244       title: $lang.get('ajax_delvote_confirm_title'),
   457         }
   271         }
   458       ]
   272       ]
   459     });
   273     });
   460 }
   274 }
   461 
   275 
   462 function ajaxResetDelVotes()
   276 window.ajaxResetDelVotes = function()
   463 {
   277 {
       
   278   load_component('l10n');
       
   279   load_component('messagebox');
       
   280   
   464   // IE <6 pseudo-compatibility
   281   // IE <6 pseudo-compatibility
   465   if ( KILL_SWITCH )
   282   if ( KILL_SWITCH )
   466     return true;
   283     return true;
   467   miniPromptMessage({
   284   miniPromptMessage({
   468       title: $lang.get('ajax_delvote_reset_confirm_title'),
   285       title: $lang.get('ajax_delvote_reset_confirm_title'),
   501         }
   318         }
   502       ]
   319       ]
   503     });
   320     });
   504 }
   321 }
   505 
   322 
   506 function ajaxSetWikiMode(val) {
       
   507   // IE <6 pseudo-compatibility
       
   508   if ( KILL_SWITCH )
       
   509     return true;
       
   510   setAjaxLoading();
       
   511   document.getElementById('wikibtn_0').style.textDecoration = 'none';
       
   512   document.getElementById('wikibtn_1').style.textDecoration = 'none';
       
   513   document.getElementById('wikibtn_2').style.textDecoration = 'none';
       
   514   document.getElementById('wikibtn_'+val).style.textDecoration = 'underline';
       
   515   ajaxGet(stdAjaxPrefix+'&_mode=setwikimode&mode='+val, function() {
       
   516     if ( ajax.readyState == 4 && ajax.status == 200 ) {
       
   517       unsetAjaxLoading();
       
   518       if(ajax.responseText!='GOOD')
       
   519       {
       
   520         alert(ajax.responseText);
       
   521       }
       
   522     }
       
   523   });
       
   524 }
       
   525 
       
   526 // Editing/saving category information
   323 // Editing/saving category information
   527 // This was not easy to write, I hope enjoy it, and dang I swear I'm gonna
   324 // This was not easy to write, I hope enjoy it, and dang I swear I'm gonna
   528 // find someone to work on just the Javascript part of Enano...
   325 // find someone to work on just the Javascript part of Enano...
   529 
   326 
   530 function ajaxCatEdit()
   327 window.ajaxCatEdit = function()
   531 {
   328 {
   532   // IE <6 pseudo-compatibility
   329   // IE <6 pseudo-compatibility
   533   if ( KILL_SWITCH )
   330   if ( KILL_SWITCH )
   534     return true;
   331     return true;
   535   setAjaxLoading();
   332   setAjaxLoading();
   540       eval(ajax.responseText);
   337       eval(ajax.responseText);
   541     }
   338     }
   542   });
   339   });
   543 }
   340 }
   544 
   341 
   545 function ajaxCatSave()
   342 window.ajaxCatSave = function()
   546 {
   343 {
   547   // IE <6 pseudo-compatibility
   344   // IE <6 pseudo-compatibility
   548   if ( KILL_SWITCH )
   345   if ( KILL_SWITCH )
   549     return true;
   346     return true;
   550   if(!catlist)
   347   if(!catlist)
   570   });
   367   });
   571 }
   368 }
   572 
   369 
   573 // History stuff
   370 // History stuff
   574 
   371 
   575 function ajaxHistory()
   372 window.ajaxHistory = function()
   576 {
   373 {
   577   // IE <6 pseudo-compatibility
   374   // IE <6 pseudo-compatibility
   578   if ( KILL_SWITCH )
   375   if ( KILL_SWITCH )
   579     return true;
   376     return true;
   580   setAjaxLoading();
   377   setAjaxLoading();
   588       buildDiffList();
   385       buildDiffList();
   589     }
   386     }
   590   });
   387   });
   591 }
   388 }
   592 
   389 
   593 function ajaxHistView(oldid, ttl) {
   390 window.ajaxHistView = function(oldid, ttl) {
   594   // IE <6 pseudo-compatibility
   391   // IE <6 pseudo-compatibility
   595   if ( KILL_SWITCH )
   392   if ( KILL_SWITCH )
   596     return true;
   393     return true;
   597   if(!ttl) ttl=title;
   394   if(!ttl) ttl=title;
   598   setAjaxLoading();
   395   setAjaxLoading();
   603       document.getElementById('ajaxEditContainer').innerHTML = ajax.responseText;
   400       document.getElementById('ajaxEditContainer').innerHTML = ajax.responseText;
   604     }
   401     }
   605   });
   402   });
   606 }
   403 }
   607 
   404 
   608 function ajaxRollback(id) {
   405 window.ajaxRollback = function(id) {
   609   // IE <6 pseudo-compatibility
   406   // IE <6 pseudo-compatibility
   610   if ( KILL_SWITCH )
   407   if ( KILL_SWITCH )
   611     return true;
   408     return true;
   612   setAjaxLoading();
   409   setAjaxLoading();
   613   ajaxGet(stdAjaxPrefix+'&_mode=rollback&id='+id, function() {
   410   ajaxGet(stdAjaxPrefix+'&_mode=rollback&id='+id, function() {
   639       }
   436       }
   640     }
   437     }
   641   });
   438   });
   642 }
   439 }
   643 
   440 
   644 function ajaxClearLogs()
   441 window.ajaxClearLogs = function()
   645 {
   442 {
   646   // IE <6 pseudo-compatibility
   443   // IE <6 pseudo-compatibility
   647   if ( KILL_SWITCH )
   444   if ( KILL_SWITCH )
   648     return true;
   445     return true;
       
   446   
       
   447   load_component('l10n');
       
   448   load_component('messagebox');
   649   
   449   
   650   miniPromptMessage({
   450   miniPromptMessage({
   651       title: $lang.get('ajax_clearlogs_confirm_title'),
   451       title: $lang.get('ajax_clearlogs_confirm_title'),
   652       message: $lang.get('ajax_clearlogs_confirm_body'),
   452       message: $lang.get('ajax_clearlogs_confirm_body'),
   653       buttons: [
   453       buttons: [
   679         }
   479         }
   680       ]
   480       ]
   681     });
   481     });
   682 }
   482 }
   683 
   483 
   684 var timelist;
   484 window.buildDiffList = function()
   685 
       
   686 function buildDiffList()
       
   687 {
   485 {
   688   arrDiff1Buttons = getElementsByClassName(document, 'input', 'clsDiff1Radio');
   486   arrDiff1Buttons = getElementsByClassName(document, 'input', 'clsDiff1Radio');
   689   arrDiff2Buttons = getElementsByClassName(document, 'input', 'clsDiff2Radio');
   487   arrDiff2Buttons = getElementsByClassName(document, 'input', 'clsDiff2Radio');
   690   var len = arrDiff1Buttons.length;
   488   var len = arrDiff1Buttons.length;
   691   if ( len < 1 )
   489   if ( len < 1 )
   702     if ( i >= timelist.length ) break;
   500     if ( i >= timelist.length ) break;
   703     arrDiff2Buttons[i].style.display = 'none';
   501     arrDiff2Buttons[i].style.display = 'none';
   704   }
   502   }
   705 }
   503 }
   706 
   504 
   707 function selectDiff1Button(obj)
   505 window.selectDiff1Button = function(obj)
   708 {
   506 {
   709   var this_time = obj.id.substr(6);
   507   var this_time = obj.id.substr(6);
   710   var index = parseInt(in_array(this_time, timelist));
   508   var index = parseInt(in_array(this_time, timelist));
   711   for ( var i = 0; i < timelist.length - 1; i++ )
   509   for ( var i = 0; i < timelist.length - 1; i++ )
   712   {
   510   {
   719       // alert("Debug:\nIndex: "+index+"\nState: "+state+"\ni: "+i);
   517       // alert("Debug:\nIndex: "+index+"\nState: "+state+"\ni: "+i);
   720     }
   518     }
   721   }
   519   }
   722 }
   520 }
   723 
   521 
   724 function selectDiff2Button(obj)
   522 window.selectDiff2Button = function(obj)
   725 {
   523 {
   726   var this_time = obj.id.substr(6);
   524   var this_time = obj.id.substr(6);
   727   var index = parseInt(in_array(this_time, timelist));
   525   var index = parseInt(in_array(this_time, timelist));
   728   for ( var i = 1; i < timelist.length; i++ )
   526   for ( var i = 1; i < timelist.length; i++ )
   729   {
   527   {
   736       // alert("Debug:\nIndex: "+index+"\nState: "+state+"\ni: "+i);
   534       // alert("Debug:\nIndex: "+index+"\nState: "+state+"\ni: "+i);
   737     }
   535     }
   738   }
   536   }
   739 }
   537 }
   740 
   538 
   741 function ajaxHistDiff()
   539 window.ajaxHistDiff = function()
   742 {
   540 {
   743   // IE <6 pseudo-compatibility
   541   // IE <6 pseudo-compatibility
   744   if ( KILL_SWITCH )
   542   if ( KILL_SWITCH )
   745     return true;
   543     return true;
   746   var id1=false;
   544   var id1=false;
   765     });
   563     });
   766 }
   564 }
   767 
   565 
   768 // Change the user's preferred style/theme
   566 // Change the user's preferred style/theme
   769 
   567 
   770 function ajaxChangeStyle()
   568 window.ajaxChangeStyle = function()
   771 {
   569 {
   772   // IE <6 pseudo-compatibility
   570   // IE <6 pseudo-compatibility
   773   if ( KILL_SWITCH )
   571   if ( KILL_SWITCH )
   774     return true;
   572     return true;
       
   573   load_component('l10n');
       
   574   load_component('messagebox');
       
   575   
   775   var inner_html = '';
   576   var inner_html = '';
   776   inner_html += '<p><label>' + $lang.get('ajax_changestyle_lbl_theme') + ' ';
   577   inner_html += '<p><label>' + $lang.get('ajax_changestyle_lbl_theme') + ' ';
   777   inner_html += '  <select id="chtheme_sel_theme" onchange="ajaxGetStyles(this.value);">';
   578   inner_html += '  <select id="chtheme_sel_theme" onchange="ajaxGetStyles(this.value);">';
   778   inner_html += '    <option value="_blank" selected="selected">' + $lang.get('ajax_changestyle_select') + '</option>';
   579   inner_html += '    <option value="_blank" selected="selected">' + $lang.get('ajax_changestyle_select') + '</option>';
   779   inner_html +=      ENANO_THEME_LIST;
   580   inner_html +=      ENANO_THEME_LIST;
   781   inner_html += '</label></p>';
   582   inner_html += '</label></p>';
   782   var chtheme_mb = new MessageBox(MB_OKCANCEL|MB_ICONQUESTION, $lang.get('ajax_changestyle_title'), inner_html);
   583   var chtheme_mb = new MessageBox(MB_OKCANCEL|MB_ICONQUESTION, $lang.get('ajax_changestyle_title'), inner_html);
   783   chtheme_mb.onbeforeclick['OK'] = ajaxChangeStyleComplete;
   584   chtheme_mb.onbeforeclick['OK'] = ajaxChangeStyleComplete;
   784 }
   585 }
   785 
   586 
   786 function ajaxGetStyles(id)
   587 window.ajaxGetStyles = function(id)
   787 {
   588 {
   788   // IE <6 pseudo-compatibility
   589   // IE <6 pseudo-compatibility
   789   if ( KILL_SWITCH )
   590   if ( KILL_SWITCH )
   790     return true;
   591     return true;
   791   var thediv = document.getElementById('chtheme_sel_style_parent');
   592   var thediv = document.getElementById('chtheme_sel_style_parent');
   842         
   643         
   843       }
   644       }
   844     }, true);
   645     }, true);
   845 }
   646 }
   846 
   647 
   847 function ajaxChangeStyleComplete()
   648 window.ajaxChangeStyleComplete = function()
   848 {
   649 {
   849   // IE <6 pseudo-compatibility
   650   // IE <6 pseudo-compatibility
   850   if ( KILL_SWITCH )
   651   if ( KILL_SWITCH )
   851     return true;
   652     return true;
   852   var theme = $dynano('chtheme_sel_theme');
   653   var theme = $dynano('chtheme_sel_theme');
   890   
   691   
   891   return false;
   692   return false;
   892   
   693   
   893 }
   694 }
   894 
   695 
   895 function themeid_to_title(id)
   696 window.ajaxSwapCSS = function()
   896 {
       
   897   if ( typeof(id) != 'string' )
       
   898     return false;
       
   899   id = id.substr(0, 1).toUpperCase() + id.substr(1);
       
   900   id = id.replace(/_/g, ' ');
       
   901   id = id.replace(/-/g, ' ');
       
   902   return id;
       
   903 }
       
   904 
       
   905 function ajaxSwapCSS()
       
   906 {
   697 {
   907   // IE <6 pseudo-compatibility
   698   // IE <6 pseudo-compatibility
   908   if ( KILL_SWITCH )
   699   if ( KILL_SWITCH )
   909     return true;
   700     return true;
   910   setAjaxLoading();
   701   setAjaxLoading();
   917   }
   708   }
   918   unsetAjaxLoading();
   709   unsetAjaxLoading();
   919   menuOff();
   710   menuOff();
   920 }
   711 }
   921 
   712 
   922 function ajaxSetPassword()
   713 window.ajaxSetPassword = function()
   923 {
   714 {
   924   // IE <6 pseudo-compatibility
   715   // IE <6 pseudo-compatibility
   925   if ( KILL_SWITCH )
   716   if ( KILL_SWITCH )
   926     return true;
   717     return true;
       
   718   load_component('crypto');
   927   pass = hex_sha1(document.getElementById('mdgPassSetField').value);
   719   pass = hex_sha1(document.getElementById('mdgPassSetField').value);
   928   setAjaxLoading();
   720   setAjaxLoading();
   929   ajaxPost(stdAjaxPrefix+'&_mode=setpass', 'password='+pass, function()
   721   ajaxPost(stdAjaxPrefix+'&_mode=setpass', 'password='+pass, function()
   930     {
   722     {
   931       unsetAjaxLoading();
   723       unsetAjaxLoading();
   934         alert(ajax.responseText);
   726         alert(ajax.responseText);
   935       }
   727       }
   936     }, true);
   728     }, true);
   937 }
   729 }
   938 
   730 
   939 function ajaxStartLogin()
   731 window.ajaxDisableEmbeddedPHP = function()
   940 {
       
   941   ajaxLogonToMember();
       
   942 }
       
   943 
       
   944 function ajaxStartAdminLogin()
       
   945 {
       
   946   // IE <6 pseudo-compatibility
       
   947   if ( KILL_SWITCH )
       
   948     return true;
       
   949   if ( auth_level < USER_LEVEL_ADMIN )
       
   950   {
       
   951     ajaxLoginInit(function(k) {
       
   952       ENANO_SID = k;
       
   953       auth_level = USER_LEVEL_ADMIN;
       
   954       var loc = makeUrlNS('Special', 'Administration');
       
   955       if ( (ENANO_SID + ' ').length > 1 )
       
   956         window.location = loc;
       
   957     }, USER_LEVEL_ADMIN);
       
   958     return false;
       
   959   }
       
   960   var loc = makeUrlNS('Special', 'Administration');
       
   961   window.location = loc;
       
   962 }
       
   963 
       
   964 function ajaxAdminPage()
       
   965 {
       
   966   // IE <6 pseudo-compatibility
       
   967   if ( KILL_SWITCH )
       
   968     return true;
       
   969   if ( auth_level < USER_LEVEL_ADMIN )
       
   970   {
       
   971     ajaxPromptAdminAuth(function(k) {
       
   972       ENANO_SID = k;
       
   973       auth_level = USER_LEVEL_ADMIN;
       
   974       var loc = String(window.location + '');
       
   975       window.location = append_sid(loc);
       
   976       var loc = makeUrlNS('Special', 'Administration', 'module=' + namespace_list['Admin'] + 'PageManager&source=ajax&page_id=' + ajaxEscape(title));
       
   977       if ( (ENANO_SID + ' ').length > 1 )
       
   978         window.location = loc;
       
   979     }, 9);
       
   980     return false;
       
   981   }
       
   982   var loc = makeUrlNS('Special', 'Administration', 'module=' + namespace_list['Admin'] + 'PageManager&source=ajax&page_id=' + ajaxEscape(title));
       
   983   window.location = loc;
       
   984 }
       
   985 
       
   986 var navto_ns;
       
   987 var navto_pg;
       
   988 var navto_ul;
       
   989 
       
   990 function ajaxLoginNavTo(namespace, page_id, min_level)
       
   991 {
       
   992   // IE <6 pseudo-compatibility
       
   993   if ( KILL_SWITCH )
       
   994     return true;
       
   995   navto_pg = page_id;
       
   996   navto_ns = namespace;
       
   997   navto_ul = min_level;
       
   998   if ( auth_level < min_level )
       
   999   {
       
  1000     ajaxPromptAdminAuth(function(k) {
       
  1001       ENANO_SID = k;
       
  1002       auth_level = navto_ul;
       
  1003       var loc = makeUrlNS(navto_ns, navto_pg);
       
  1004       if ( (ENANO_SID + ' ').length > 1 )
       
  1005         window.location = loc;
       
  1006     }, min_level);
       
  1007     return false;
       
  1008   }
       
  1009   var loc = makeUrlNS(navto_ns, navto_pg);
       
  1010   window.location = loc;
       
  1011 }
       
  1012 
       
  1013 function ajaxAdminUser(username)
       
  1014 {
       
  1015   // IE <6 pseudo-compatibility
       
  1016   if ( KILL_SWITCH )
       
  1017     return true;
       
  1018   if ( auth_level < USER_LEVEL_ADMIN )
       
  1019   {
       
  1020     ajaxPromptAdminAuth(function(k) {
       
  1021       ENANO_SID = k;
       
  1022       auth_level = USER_LEVEL_ADMIN;
       
  1023       var loc = String(window.location + '');
       
  1024       window.location = append_sid(loc);
       
  1025       var loc = makeUrlNS('Special', 'Administration', 'module=' + namespace_list['Admin'] + 'UserManager&src=get&user=' + ajaxEscape(username));
       
  1026       if ( (ENANO_SID + ' ').length > 1 )
       
  1027         window.location = loc;
       
  1028     }, 9);
       
  1029     return false;
       
  1030   }
       
  1031   var loc = makeUrlNS('Special', 'Administration', 'module=' + namespace_list['Admin'] + 'UserManager&src=get&user=' + ajaxEscape(username));
       
  1032   window.location = loc;
       
  1033 }
       
  1034 
       
  1035 function ajaxDisableEmbeddedPHP()
       
  1036 {
   732 {
  1037   // IE <6 pseudo-compatibility
   733   // IE <6 pseudo-compatibility
  1038   if ( KILL_SWITCH )
   734   if ( KILL_SWITCH )
  1039     return true;
   735     return true;
  1040   if ( !confirm($lang.get('ajax_killphp_confirm')) )
   736   if ( !confirm($lang.get('ajax_killphp_confirm')) )
  1071     });
   767     });
  1072 }
   768 }
  1073 
   769 
  1074 var catHTMLBuf = false;
   770 var catHTMLBuf = false;
  1075 
   771 
  1076 function ajaxCatToTag()
   772 window.ajaxCatToTag = function()
  1077 {
   773 {
  1078   if ( KILL_SWITCH )
   774   if ( KILL_SWITCH )
  1079     return false;
   775     return false;
  1080   setAjaxLoading();
   776   setAjaxLoading();
  1081   ajaxGet(stdAjaxPrefix + '&_mode=get_tags', function()
   777   ajaxGet(stdAjaxPrefix + '&_mode=get_tags', function()
  1133     });
   829     });
  1134 }
   830 }
  1135 
   831 
  1136 var addtag_open = false;
   832 var addtag_open = false;
  1137 
   833 
  1138 function ajaxAddTagStage1()
   834 window.ajaxAddTagStage1 = function()
  1139 {
   835 {
  1140   if ( addtag_open )
   836   if ( addtag_open )
  1141     return false;
   837     return false;
  1142   var catbox = document.getElementById('mdgCatBox');
   838   var catbox = document.getElementById('mdgCatBox');
  1143   var adddiv = document.createElement('div');
   839   var adddiv = document.createElement('div');
  1165   addtag_open = true;
   861   addtag_open = true;
  1166 }
   862 }
  1167 
   863 
  1168 var addtag_nukeme = false;
   864 var addtag_nukeme = false;
  1169 
   865 
  1170 function ajaxAddTagStage2(tag, nukeme)
   866 window.ajaxAddTagStage2 = function(tag, nukeme)
  1171 {
   867 {
  1172   if ( !addtag_open )
   868   if ( !addtag_open )
  1173     return false;
   869     return false;
  1174   if ( addtag_nukeme )
   870   if ( addtag_nukeme )
  1175     return false;
   871     return false;
  1231         }
   927         }
  1232       }
   928       }
  1233     });
   929     });
  1234 }
   930 }
  1235 
   931 
  1236 function ajaxDeleteTag(parentobj, tag_id)
   932 window.ajaxDeleteTag = function(parentobj, tag_id)
  1237 {
   933 {
  1238   var arrDelete = [ parentobj, parentobj.previousSibling, parentobj.previousSibling.previousSibling ];
   934   var arrDelete = [ parentobj, parentobj.previousSibling, parentobj.previousSibling.previousSibling ];
  1239   var parent = parentobj.parentNode;
   935   var parent = parentobj.parentNode;
  1240   var writeNoTags = false;
   936   var writeNoTags = false;
  1241   if ( parentobj.previousSibling.previousSibling.previousSibling.nodeValue == ', ' )
   937   if ( parentobj.previousSibling.previousSibling.previousSibling.nodeValue == ', ' )
  1275         }
   971         }
  1276       }
   972       }
  1277     });
   973     });
  1278 }
   974 }
  1279 
   975 
  1280 function ajaxTagToCat()
   976 window.ajaxTagToCat = function()
  1281 {
   977 {
  1282   if ( !catHTMLBuf )
   978   if ( !catHTMLBuf )
  1283     return false;
   979     return false;
  1284   var catbox = document.getElementById('mdgCatBox');
   980   var catbox = document.getElementById('mdgCatBox');
  1285   if ( !catbox )
   981   if ( !catbox )
  1292   catHTMLBuf = false;
   988   catHTMLBuf = false;
  1293 }
   989 }
  1294 
   990 
  1295 var keepalive_interval = false;
   991 var keepalive_interval = false;
  1296 
   992 
  1297 function ajaxPingServer()
   993 window.ajaxPingServer = function()
  1298 {
   994 {
  1299   ajaxGet(stdAjaxPrefix + '&_mode=ping', function()
   995   ajaxGet(stdAjaxPrefix + '&_mode=ping', function()
  1300     {
   996     {
  1301     });
   997     });
  1302 }
   998 }
  1303 
   999 
  1304 function ajaxToggleKeepalive()
  1000 window.ajaxToggleKeepalive = function()
  1305 {
  1001 {
  1306   if ( readCookie('admin_keepalive') == '1' )
  1002   if ( readCookie('admin_keepalive') == '1' )
  1307   {
  1003   {
  1308     createCookie('admin_keepalive', '0', 3650);
  1004     createCookie('admin_keepalive', '0', 3650);
  1309     if ( keepalive_interval )
  1005     if ( keepalive_interval )
  1338     var span = document.getElementById('keepalivestat');
  1034     var span = document.getElementById('keepalivestat');
  1339     span.firstChild.nodeValue = $lang.get('adm_btn_keepalive_off');
  1035     span.firstChild.nodeValue = $lang.get('adm_btn_keepalive_off');
  1340   }
  1036   }
  1341 };
  1037 };
  1342 
  1038 
  1343 function aboutKeepAlive()
  1039 window.aboutKeepAlive = function()
  1344 {
  1040 {
  1345   new MessageBox(MB_OK|MB_ICONINFORMATION, $lang.get('user_keepalive_info_title'), $lang.get('user_keepalive_info_body'));
  1041   new MessageBox(MB_OK|MB_ICONINFORMATION, $lang.get('user_keepalive_info_title'), $lang.get('user_keepalive_info_body'));
  1346 }
  1042 }
  1347 
  1043 
  1348 function ajaxShowCaptcha(code)
  1044 window.ajaxShowCaptcha = function(code)
  1349 {
  1045 {
  1350   var mydiv = document.createElement('div');
  1046   var mydiv = document.createElement('div');
  1351   mydiv.style.backgroundColor = '#FFFFFF';
  1047   mydiv.style.backgroundColor = '#FFFFFF';
  1352   mydiv.style.padding = '10px';
  1048   mydiv.style.padding = '10px';
  1353   mydiv.style.position = 'absolute';
  1049   mydiv.style.position = 'absolute';
  1374   domObjChangeOpac(0, mydiv);
  1070   domObjChangeOpac(0, mydiv);
  1375   var body = document.getElementsByTagName('body')[0];
  1071   var body = document.getElementsByTagName('body')[0];
  1376   body.appendChild(mydiv);
  1072   body.appendChild(mydiv);
  1377 }
  1073 }
  1378 
  1074 
  1379 function ajaxUpdateCheck(targetelement)
  1075 window.ajaxUpdateCheck = function(targetelement)
  1380 {
  1076 {
  1381   if ( !document.getElementById(targetelement) )
  1077   if ( !document.getElementById(targetelement) )
  1382   {
  1078   {
  1383     return false;
  1079     return false;
  1384   }
  1080   }
  1545         }
  1241         }
  1546       }
  1242       }
  1547     });
  1243     });
  1548 }
  1244 }
  1549 
  1245 
  1550 function ajaxPluginAction(action, plugin_filename, btnobj)
  1246 window.ajaxPluginAction = function(action, plugin_filename, btnobj)
  1551 {
  1247 {
  1552   // if installing, uninstalling, or re-importing, confirm
  1248   // if installing, uninstalling, or re-importing, confirm
  1553   if ( action == 'install' || action == 'uninstall' || action == 'reimport' )
  1249   if ( action == 'install' || action == 'uninstall' || action == 'reimport' )
  1554   {
  1250   {
  1555     var prompt = miniPrompt(function(div)
  1251     var prompt = miniPrompt(function(div)
  1660               });
  1356               });
  1661           }, 750);
  1357           }, 750);
  1662       }
  1358       }
  1663     });
  1359     });
  1664 }
  1360 }
       
  1361 
       
  1362 window.ajaxReverseDNS = function(o, text)
       
  1363 {
       
  1364   if(text) var ipaddr = text;
       
  1365   else var ipaddr = o.innerHTML;
       
  1366   rDnsObj = o;
       
  1367   rDnsBannerObj = bannerOn('Retrieving reverse DNS info...');
       
  1368   ajaxGet(stdAjaxPrefix+'&_mode=rdns&ip='+ipaddr, function() {
       
  1369       if ( ajax.readyState == 4 && ajax.status == 200 )
       
  1370       {
       
  1371         off = fetch_offset(rDnsObj);
       
  1372         dim = fetch_dimensions(rDnsObj);
       
  1373         right = off['left'] + dim['w'];
       
  1374         top = off['top'] + dim['h'];
       
  1375         var thediv = document.createElement('div');
       
  1376         thediv.className = 'info-box';
       
  1377         thediv.style.margin = '0';
       
  1378         thediv.style.position = 'absolute';
       
  1379         thediv.style.top  = top  + 'px';
       
  1380         thediv.style.display = 'none';
       
  1381         thediv.style.zIndex = getHighestZ() + 2;
       
  1382         thediv.id = 'mdgDynamic_rDnsInfoDiv_'+Math.floor(Math.random() * 1000000);
       
  1383         thediv.innerHTML = '<b>Reverse DNS:</b><br />'+ajax.responseText+' <a href="#" onclick="elem = document.getElementById(\''+thediv.id+'\'); elem.innerHTML = \'\'; elem.style.display = \'none\';return false;">Close</a>';
       
  1384         var body = document.getElementsByTagName('body');
       
  1385         body = body[0];
       
  1386         bannerOff(rDnsBannerObj);
       
  1387         body.appendChild(thediv);
       
  1388         thediv.style.display = 'block';
       
  1389         left = fetch_dimensions(thediv);
       
  1390         thediv.style.display = 'none';
       
  1391         left = right - left['w'];
       
  1392         thediv.style.left = left + 'px';
       
  1393         thediv.style.display = 'block';
       
  1394         fadeInfoBoxes();
       
  1395       }
       
  1396     });
       
  1397 }
       
  1398 
       
  1399 function themeid_to_title(id)
       
  1400 {
       
  1401   if ( typeof(id) != 'string' )
       
  1402     return false;
       
  1403   id = id.substr(0, 1).toUpperCase() + id.substr(1);
       
  1404   id = id.replace(/_/g, ' ');
       
  1405   id = id.replace(/-/g, ' ');
       
  1406   return id;
       
  1407 }