home *** CD-ROM | disk | FTP | other *** search
/ db.tidbits.com / db.tidbits.com.tar / db.tidbits.com / javascript / tb.js < prev   
Text File  |  2010-08-05  |  38KB  |  1,243 lines

  1. var t_right = '/images/nav_triangle_closed.gif';
  2. var t_open = '/images/nav_triangle_open.gif';
  3. var b_right = '/images/summary_triangle_right.gif';
  4. var b_open = '/images/summary_triangle_down.gif';
  5. var host_prefix = '';
  6. if (location.hostname.match(/staging/)) {
  7.     host_prefix = "_staging";
  8. }
  9.  
  10. // toggle image display on print friendly pages
  11. function toggle_print_images (image_ids) {
  12.      var shp = document.getElementById('show_hide_print');
  13.      var showhide;
  14.     if (shp.innerHTML == 'Off') {
  15.         shp.innerHTML = 'On';
  16.         showhide = 1;
  17.     } else {
  18.         shp.innerHTML = 'Off';
  19.     }
  20.     var image_ids_array = image_ids.split(",");
  21.     for (var loop=0; loop < image_ids_array.length; loop++) {
  22.         var b = document.getElementById('image_show_' + image_ids_array[loop]);
  23.         var c = document.getElementById('image_link_' + image_ids_array[loop]);
  24.         // alert ("Image: " + b.style.display);
  25.         if (showhide == 1) {
  26.             b.style.display = 'block';
  27.             c.style.display = 'none';
  28.         } else {
  29.             b.style.display = 'none';
  30.             c.style.display = 'block';
  31.         }
  32.  
  33.     }
  34.     return false;
  35. }
  36.  
  37. // generic box show/hide
  38. function generic_show_hide(place) {
  39.     if ($(place).style.display == 'none') {
  40.         $(place).style.display = '';
  41.     } else {
  42.         $(place).style.display = 'none';
  43.     }
  44.     return false;
  45. }
  46.  
  47. // generic box visible invisible
  48. function generic_visibility(place) {
  49.     if ($(place).style.visibility == 'visible') {
  50.         $(place).style.visibility = 'hidden';
  51.     } else {
  52.         $(place).style.visibility = 'visible';
  53.     }
  54.     return false;
  55. }
  56.  
  57. // open on a clickthrough from home or section page
  58. function open_if_linked(article_link) {
  59.     if (window.location.search.match(/follow_link/)) {
  60.         window.open(article_link, 'new_tidbits_link');
  61.     }
  62.     return;
  63. }
  64.  
  65. // swap out class for link hover boxes
  66. function link_hover_swap(getbits, inout, search) {
  67.  
  68.     var summary = document.cookie.match(/showsumm\=([^;]+)/);
  69.     if (summary > 0 && summary[1] ==0) { return; }
  70.  
  71.     var search_add = '';
  72.     if (search == 's') {
  73.         search_add = "_s";
  74.     }
  75.     var place = 'link_box_right_' + getbits;
  76.     generic_visibility(place);
  77.     var enc = 'link_box_full_' + getbits;
  78.     var title = 'link_hover_title_' + getbits;
  79.     var styleHover;
  80.     var styleLink;
  81.     if (inout == 'out') {
  82.         styleHover = 'link_hover' + search_add;
  83.         styleLink = '#000';
  84.     } else {
  85.         styleHover = 'link_hover_over' + search_add;
  86.         styleLink = '#990000';
  87.     }
  88.     $(enc).className = styleHover;
  89.     $(title).style.color = styleLink;
  90. }
  91.  
  92. // toggle blurb results with summary text
  93. function blurb_show(id) {
  94.     var b = document.getElementById('blurb_' + id);
  95.     var s = document.getElementById('blurb_show_text_' + id);
  96.     if (b.style.display == 'none') {
  97.         b.style.display = 'block';
  98.         s.innerHTML = 'Hide summary';
  99.     } else {
  100.         b.style.display = 'none';
  101.         s.innerHTML = 'Show summary';
  102.     }
  103.     return false;
  104. }
  105.  
  106. // toggle blurb results with triangle (search results)
  107. function blurb_triangle_show(id) {
  108.     var b = document.getElementById('blurb_' + id);
  109.     var s = document.getElementById('blurb_show_text_' + id);
  110.     if (b.style.display == 'none') {
  111.         s.setAttribute("src", b_open);
  112.         b.style.display = 'block';
  113.     } else {
  114.         s.setAttribute("src", b_right);
  115.         b.style.display = 'none';
  116.     }
  117.     return false;
  118. }
  119.  
  120. // toggle summary
  121. function set_summary_show(load) {
  122.     var summary = document.cookie.match(/showsumm\=([^;]+)/);
  123.     var show;
  124.     if (!summary) {
  125.         if (load) {
  126.             set_cookie('showsumm', '1', '3650', '/', '.tidbits.com', '');
  127.             show = 1;
  128.         }
  129.     } else {
  130.         if (load) {
  131.             show = summary[1]; 
  132.         } else { 
  133.             show = (summary[1] == 1) ? 0 : 1;
  134.         }
  135.         set_cookie('showsumm', show, '3650', '/', '.tidbits.com', '');
  136.     }
  137.     
  138.     var display = 'none';
  139.     if (show == 1) {
  140.         display = '';
  141.         $('blurb_toggle_line').innerHTML = 'Hide summaries of articles';
  142.     } else {
  143.         $('blurb_toggle_line').innerHTML = 'Show summaries of articles';
  144.     }
  145.     
  146.     var elem = document.getElementsByTagName('div'), i = 0, e;
  147.     var pattern = /^blurb_(\d+)/;
  148.     var j = 1;
  149.     var cc = '';
  150.     while (e = elem[i++]) {
  151.         if (e.className == 'article_preview') { 
  152.             var result = e.id.match(pattern);
  153.             if (result != 'undefined') {
  154. //                 if ($('blurb_link_' + result[1]) != null) {
  155. //                     setTimeout("$('blurb_link_' + " + result[1] + ").style.display == '" + display + "';", 5000);
  156. //                 }
  157.                 $('blurb_' + result[1]).style.display = display;
  158.             }
  159.         }
  160.     }
  161. }
  162.  
  163. // slide down/up blurb
  164. function blurb_slide(id, sh) {
  165.     var summary = document.cookie.match(/showsumm\=([^;]+)/);
  166.     if (summary) { 
  167.         var summary = document.cookie.match(/showsumm\=([^;]+)/);
  168.         if (summary[1] == 1) { return; }
  169.     }
  170.  
  171.     var b = 'blurb_' + id;
  172.     var pb = 'blurb_popup_box';
  173.     var pr = 'blurb_popup_right';
  174.     var ab = 'article_item_box_' + id;
  175. //     var bl_link = 'blurb_link_' + id;
  176.     if (sh == 'hide') { 
  177. //         if ($(bl_link) != null) { 
  178. //             $(bl_link).style.display = '';
  179. //         }
  180.         $(pb).style.display = 'none';
  181.         // $(ab).style.backgroundColor = '';
  182.         // $(ab).style.paddingTop = '';
  183.     } else {
  184.         // $(ab).style.backgroundColor = '#dcd4e3';
  185. //         if ($(bl_link) != null) { 
  186. //             $(bl_link).style.display = 'none';
  187. //         }
  188.         var lbr =  $('link_box_right_' + id);
  189.         var binner = $(b).innerHTML;
  190.         var pr_rep;
  191.         if (lbr) { 
  192.             pr_rep = "<div class='pop_link'><div class='lbr_pop'>" + lbr.innerHTML + "</div>" + binner + "</div>";
  193.         } else { 
  194.             pr_rep = binner;
  195.         }        
  196.         $(pr).innerHTML = pr_rep;
  197.         $('popup_inner_' + id).className = 'blurb_popup_text';
  198.         var vis = $(pb).style.display;
  199.         if (vis == 'none') {
  200.             $(pb).style.display = '';
  201.             // $(pb).style.left = curX + "px";
  202.         }
  203.         // var half = $(pr).offsetHeight / 2; 
  204.         var newtop = ($(ab).offsetTop - $(pb).offsetHeight + 25);
  205.         //if (newtop < 0) { newtop = "325"; }
  206.         newtop = newtop + "px";
  207.         $(pb).style.top = newtop;
  208.     }
  209.     return false;
  210. }
  211.  
  212.  
  213. function set_cookie(name, value, expires, path, domain, secure) {
  214.     var today = new Date();
  215.     today.setTime( today.getTime() );
  216.     
  217.     if (expires) {
  218.         expires = expires * 1000 * 60 * 60 * 24;
  219.     }
  220.     var expires_date = new Date( today.getTime() + (expires) );
  221.     
  222.     var new_cook = name + "=" + escape( value ) +
  223.     ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
  224.     ( ( path ) ? ";path=" + path : "" ) +
  225.     ( ( domain ) ? ";domain=" + domain : "" ) +
  226.     ( ( secure ) ? ";secure" : "" );
  227.     document.cookie = new_cook;
  228.     
  229. }
  230.  
  231. // swap triangle for summaries and articles
  232. function triangle_blurb(id) {
  233.  
  234.     var tri = document.getElementById("blurb_show_text_" + id);
  235.     var b = document.getElementById('blurb_' + id);
  236.     if (b.style.display == 'none') {
  237.         b.style.display = 'block';
  238.         tri.setAttribute("src", t_open);
  239.     } else {
  240.         b.style.display = 'none';
  241.         tri.setAttribute("src", t_right);
  242.     }
  243. }
  244.  
  245. // toggle blurb results
  246. function arbitrary_showhide(id) {
  247.     $(id).style.display = ($(id).style.display == 'none') ? 'block' : 'none';
  248.     return false;
  249. }
  250.  
  251. // toggle search parameters
  252. function toggle_search_text(id, text_id) {
  253.     $(text_id).innerHTML = ($(id).style.display == 'none') ? 'Hide search parameters' : 'Show search parameters';
  254.     return arbitrary_showhide(id);
  255. }
  256.  
  257. // toggle full article/blurb
  258. function showhide_article(id) {
  259.     var blurb = document.getElementById('article_blurb_' + id);
  260.     var art = document.getElementById('article_text_' + id);
  261.     var artbot = document.getElementById('article_text_bottom_' + id);
  262.     if (art.style.display == 'none') {
  263.         art.style.display = 'block';
  264.         artbot.style.display = 'block';
  265.         blurb.style.display = 'none';
  266.     } else {
  267.         art.style.display = 'none';
  268.         artbot.style.display = 'none';
  269.         blurb.style.display = 'block';
  270.     }
  271.     return false;
  272. }
  273.  
  274. // show all or hide all search result blurbs
  275. function showhidesearchdetail(count_ids, triangle) {
  276.     var count_ids_array = count_ids.split(",");
  277.     var showhide;
  278.     var shs = document.getElementById('showhideall');
  279.     if (shs.innerHTML.match(/Show/)) {
  280.         showhide = 1;
  281.         shs.innerHTML = "Hide all summaries";
  282.     } else {
  283.         showhide = 0;
  284.         shs.innerHTML = "Show all summaries";
  285.     }
  286.  
  287.     for (var loop=0; loop < count_ids_array.length; loop++) {
  288.         var b = document.getElementById('blurb_' + count_ids_array[loop]);
  289.         var s = document.getElementById('blurb_show_text_' + count_ids_array[loop]);
  290.         if (showhide == 1) {
  291.             b.style.display = 'block';
  292.             if (triangle == 1) {
  293.                 s.setAttribute("src", b_open);
  294.             } else {
  295.                 s.innerHTML = 'Hide summary';
  296.             }
  297.         } else {
  298.             b.style.display = 'none';
  299.             if (triangle == 1) {
  300.                 s.setAttribute("src", b_right);
  301.             } else {
  302.                 s.innerHTML = 'Show summary';
  303.             }
  304.         }
  305.     }
  306.     return false;
  307. }
  308.  
  309. // show all articles/show all blurbs for series/issue
  310. function showhide_all_articles(shart) {
  311. //    if (!shart.match(/,/)) { return false; }
  312.     var shart_array = shart.split(",");
  313.     var showhide;
  314.     var shs = document.getElementById('showhide_arts_top');
  315.     var shsb = document.getElementById('showhide_arts_bottom');
  316.     if (shs.innerHTML.match(/Show/)) {
  317.         showhide = 1;
  318.         shs.innerHTML = "Hide the full text of all articles";
  319.         shsb.innerHTML = "Hide the full text of all articles";
  320.     } else {
  321.         showhide = 0;
  322.         shs.innerHTML = "Show the full text of all articles";
  323.         shsb.innerHTML = "Show the full text of all articles";
  324.     }
  325.  
  326.     for (var loop=0; loop < shart_array.length; loop++) {
  327.         var b = document.getElementById('article_blurb_' + shart_array[loop]);
  328.         var s = document.getElementById('article_text_' + shart_array[loop]);
  329.         var sb = document.getElementById('article_text_bottom_' + shart_array[loop]);
  330.         if (showhide == 1) {
  331.             b.style.display = 'none';
  332.             s.style.display = 'block';
  333.             sb.style.display = 'block';
  334.         } else {
  335.             b.style.display = 'block';
  336.             s.style.display = 'none';
  337.             sb.style.display = 'none';
  338.         }
  339.     }
  340.     return false;
  341. }
  342.  
  343.  
  344.  
  345. function showhide(id, display) {
  346.     var sidebars = new Array(3);
  347.     sidebars[0] = "articleslist";
  348.     sidebars[1] = "stafflist";
  349.     sidebars[2] = "abouttidbits";
  350.     sidebars[3] = "issuelist";
  351.     sidebars[4] = "tidbitstalklist";
  352.     // + _triangle is the triangle span
  353.     
  354.     var d = document.getElementById(id); 
  355.     if (!d) {
  356.         d = document.getElementById('articleslist');
  357.         id = 'articleslist';
  358.         
  359.     }
  360.     if (d.style.display == 'none' || display == 'show') { 
  361.         //new Effect.SlideDown(d);
  362.         d.style.display = 'block';
  363.         triangle(id + '_tri_image', "open");
  364.     } else {
  365.         //new Effect.SlideUp(d);
  366.         d.style.display = 'none';
  367.         triangle(id + '_tri_image', "close");
  368.     }
  369.     var i = 0;
  370.     for (x = 0; x <= 4; x++) {
  371.         if (id != sidebars[x]) { 
  372.             var h = document.getElementById(sidebars[x]);
  373.             if (h) {
  374. //            if (h.style.display != 'none') { 
  375.                 // new Effect.SlideUp(h, { queue: 'end'});
  376.                 h.style.display = 'none';
  377.                 triangle(sidebars[x] + "_tri_image", "close");
  378.             }
  379.         }
  380.     }
  381.     return false;
  382. }
  383.  
  384. function triangle(location, direction) {
  385.     var t_right = '/images/nav_triangle_closed.gif'
  386.     var t_mid = '/images/nav_triangle_mid.gif'
  387.     var t_open = '/images/nav_triangle_open.gif'
  388.  
  389.     var tri = document.getElementById(location);
  390. //    var tri = document.location;
  391.     if (direction == 'close') {
  392.         tri.setAttribute("src", t_right);
  393. //        tri.innerHTML = '<img border="0" src="' + t_right + '" class=\"navtriangle\" />';
  394.         return;
  395.     } else if (direction == 'open') {
  396.         tri.setAttribute("src", t_open);
  397. //        tri.innerHTML = '<img border="0" src="' + t_open + '" class=\"navtriangle\" />';
  398.         return;
  399.     }
  400.     
  401. /*    if (direction == 'close_2') {
  402.         tri.innerHTML = '<img border="0" src="' + t_right + '" />';
  403.         return;
  404.     } else if (direction == 'open_2') {
  405.         tri.innerHTML = '<img border="0" src="' + t_open + '" />';
  406.         return;
  407.     } else {
  408.         tri.innerHTML = '<img border="0" src="' + t_mid + '" />';
  409.         setTimeout("triangle('" + location + "','" + direction + "_2');", 300);
  410.         return;
  411.     } */
  412. }
  413.  
  414. function markdown_copy(at, ad, gb) { 
  415.     var brackets = "\"[" + unescape(at) + "][*],\" " + ad + "\n\n[*]: http://db.tidbits.com/article/" + gb;
  416.     $('article_ref_box').value = brackets;
  417.     ShowPopupContent('article_reference', 50)
  418.     return false;
  419. }
  420.  
  421. function recommend_this(thumb_rec) {
  422.     var url = '/short.cgi?command=thumb&id=' + thumb_rec;
  423.     var r_ref = 'recommend_' + thumb_rec;
  424.     var rb_ref = 'recommend_eoac_' + thumb_rec;
  425.     var c_ref = 'count_' + thumb_rec;
  426.     var cb_ref = 'count_eoac_' + thumb_rec;
  427.  
  428.     var r = document.getElementById(r_ref);
  429.     var c = document.getElementById(c_ref);
  430.     var rb = document.getElementById(rb_ref);
  431.     var cb = document.getElementById(cb_ref);
  432.  
  433.     new Ajax.Request(url, {
  434.         method: 'get',
  435.         onSuccess: function(transport) {
  436.             var thumbs = transport.responseText.match(/thumb\: (\d+),(.+)/);
  437.             if(thumbs) {
  438.                 // not 0, but 1... see javascript regex docs
  439.                 c.innerHTML = ' +' + thumbs[1];
  440.                 if (cb) { cb.innerHTML = thumbs[1]; }
  441.                 r.innerHTML= "Thanks!";
  442.                 //if (rb) { rb.innerHTML= "Thanks!"; }
  443.             }
  444.         },
  445.         onFailure: function() {
  446.             r.innerHTML = " +0";
  447.             if (rb) { rb.innerHTML = "0"; }
  448.         }
  449.     });
  450.     return false;
  451. }
  452.  
  453. function email_article(captcha_block) {
  454.     var url = '/short.cgi';
  455.     return false;    
  456. }
  457.  
  458. function load_votes(count_ids) {
  459.     var url = '/short.cgi?command=count&id=' + count_ids;
  460.     if (count_ids.match(/^A/)) { count_ids = count_ids.substr(1); }
  461.     
  462.     new Ajax.Request(url, {
  463.         method: 'get',
  464.         onSuccess: function(transport) {
  465.             var count_ids_array = count_ids.split(",");
  466.             for (var loop=0; loop < count_ids_array.length; loop++) {
  467.                 var count_m = new RegExp('count: ' + count_ids_array[loop] + ',(\\d+)');
  468.                 var counts = transport.responseText.match(count_m);
  469.                 if(counts) {
  470.                     // not 0, but 1... see javascript regex docs
  471.                     var c_ref = 'count_' + count_ids_array[loop];
  472.                     var c = document.getElementById(c_ref);
  473.                     c.innerHTML = " +" + counts[1];
  474.                     var cb_ref = 'count_eoac_' + count_ids_array[loop];
  475.                     var cb = document.getElementById(cb_ref);
  476.                     if (cb) { cb.innerHTML = "" + counts[1]; }
  477.                  } else {
  478.                     var c_ref = 'count_' + count_ids_array[loop];
  479.                     var c = document.getElementById(c_ref);
  480.                     c.innerHTML = " +0";
  481.                     var cb_ref = 'count_eoac_' + count_ids_array[loop];
  482.                     var cb = document.getElementById(cb_ref);
  483.                     if (cb) { cb.innerHTML = "0"; }
  484.                 }            
  485.             }
  486.         },
  487.         onFailure: function() {
  488.         }
  489.     });
  490.     return false;
  491. }    
  492.  
  493. function tb_talk(getbits, tbtalk_tag, tbtalk_title, text_display, article_id) {
  494.     var a = '';
  495.     var b = '';
  496.     if (tbtalk_tag != '') { 
  497.         a = " <a class='tbtalk' href='http://db.tidbits.com/discuss/" + getbits + "'>";
  498.         b = "http://db.tidbits.com/discuss/" + getbits;
  499.     } else {
  500.         //if (article_id == '') {
  501.             a  = "<a href='mailto:tidbits-talk@tidbits.com?subject=" + tbtalk_title + "'>"; 
  502.         //} else { 
  503.         //    a = "<a href='javascript:void(0)' onClick=\"document.check_human_" + article_id + ".submit_type.value='comment'; ShowTipBox(\'hc_" + article_id + "\', \'hc_recaptcha_" + article_id + "\')\">";
  504.         //}
  505.         b  = "mailto:tidbits-talk@tidbits.com?subject=" + tbtalk_title;
  506.     }
  507.     if (!text_display) { document.write(a + "Comment</a> | "); }
  508.     else { return (b); }
  509. }
  510.  
  511. function open_podcast_window(url) {
  512.     newwindow=window.open(url,'TidBITS Podcast','height=200,width=200');
  513.     if (window.focus) {newwindow.focus()}
  514. }
  515.  
  516.  
  517. // box popup code
  518. // Thanks to Geoff Duncan!
  519. var curX = 0; var curY = 0; var cliY = 0; var rX = 0; var rY = 0;
  520.  
  521. function UpdateCursorPosition(e) {
  522.     // relative location
  523.     if (typeof(e.pageX) == 'number') {
  524.         curX = e.pageX; 
  525.         curY = e.pageY; 
  526.     } else {
  527.         curX = e.clientX; 
  528.         curY = e.clientY; 
  529.     }
  530.     cliY = e.clientY    
  531. }
  532.  
  533. document.onmousemove = UpdateCursorPosition;
  534.  
  535. function AssignPosition(d, offset) {
  536.     
  537.     var width, height;
  538.     if (navigator.appName.indexOf("Microsoft")!=-1) {
  539.         width = document.body.offsetWidth;
  540.         // height = document.body.offsetHeight;
  541.     } else {
  542.         width = window.innerWidth;
  543.         // height = window.innerHeight;
  544.     }
  545.  
  546.     var add_width = offset;
  547.     if (curX < 270) { add_width = 50; }
  548.     var new_left = (curX - 250 + add_width);
  549.     if (new_left < 50) { new_left = 50; }
  550.     if (new_left > 450) { new_left = 450; }
  551.     d.style.left = new_left + "px";
  552.     d.style.top = (curY - cliY + 40) + "px";
  553.  
  554.     return (curY - cliY + 40);
  555.     // alert(d.style.left + "," + d.style.top);
  556. }
  557.  
  558.  
  559. function HidePopupContent(d, base_ref, base_id) {
  560.     if (d.length < 1) {
  561.         return;
  562.     }
  563.     fade_background();
  564.     $('big_ole_background').style.top = "0px";
  565.  
  566.     document.getElementById(d).style.display = "none";
  567.     if (base_id > 0) { 
  568.         base_id = "_" + base_id;
  569.         var inn = document.getElementById(base_ref + "_innards" + base_id);
  570.         var inn_alt = document.getElementById(base_ref + "_innards_alt" + base_id);
  571.         var s = document.getElementById(base_ref + "_message_box" + base_id);
  572.         s.style.display = 'none';
  573.         inn.style.display = "block";
  574.         inn_alt.style.display = "none";
  575.     }
  576. }
  577. function fade_background() {
  578.     Effect.Fade('big_ole_background', { duration: 0.7, from: 0.65 });
  579. }
  580.  
  581. function ShowPopupContent(d, offset) {
  582.     if (d.length < 1) {
  583.         return;
  584.     }
  585.     var dd = document.getElementById(d);
  586.     var bigtop = AssignPosition(dd, 0);
  587.     if (bigtop > 400) { 
  588.         $('big_ole_background').style.top = (bigtop - 200) + "px";
  589.     }
  590.     Effect.Appear('big_ole_background', { duration: 0.7, from: 0.2, to: 0.65 });
  591.     dd.style.display = "block";
  592. }
  593.  
  594. function ReversePopupDisplay(d) {
  595.     if (d.length < 1) {
  596.         return;
  597.     }
  598.     var dd = document.getElementById(d);
  599.     AssignPosition(dd);
  600.     if (dd.style.display == "none") {
  601.         dd.style.display = "block";
  602.     }
  603.     else {
  604.         dd.style.display = "none";
  605.         Effect.Fade('big_ole_background', { duration: 0.7, from: 0.65 });
  606.         $('big_ole_background').style.top = "0px";
  607.     }
  608. }
  609. // end box popup code
  610.  
  611. // show popup box and insert recaptcha
  612. function ShowTipBox(tip_pop, tip_recapt, offset, field_focus) {
  613.  
  614.     Recaptcha.create("6LfmTwAAAAAAAHtrfswVZ8P0bZEnLXe27PNMXXME",
  615.     tip_recapt, {
  616.        theme: "red"
  617.     });
  618.     ShowPopupContent(tip_pop, offset);
  619.     if (field_focus) {
  620.         $(field_focus).focus();
  621.     }
  622.     return false;
  623. }
  624.  
  625. function handle_tip_submission(base_ref, base_id, form, type) {
  626.  
  627.     var fail = 0;
  628.     var msg_box;
  629.     var msg_contents;
  630.     
  631.     if (base_id > 0) { 
  632.         base_id = "_" + base_id;
  633.     } else {
  634.         base_id = '';
  635.     }
  636.     var tip_recapt = base_ref + "_recaptcha" + base_id;
  637.     var d = document.getElementById(base_ref + "_top_message" + base_id);
  638.     var s = document.getElementById(base_ref + "_message_box" + base_id);
  639.     var inn = document.getElementById(base_ref + "_innards" + base_id);
  640.     var inn_alt = document.getElementById(base_ref + "_innards_alt" + base_id);
  641.     inn.style.display = "block";
  642.     if (inn_alt) { 
  643.         inn_alt.style.display = "none";
  644.     }
  645.     var small_response = document.getElementById(base_ref + "_small_response" + base_id);
  646.     var url = '/tipsubmit.cgi?challenge=' + escape(form.recaptcha_challenge_field.value) + '&response=' + escape(form.recaptcha_response_field.value);
  647.  
  648.     // reset embedded innards
  649.     s.style.display = 'none';
  650.     
  651.     if (type == 'tip') {
  652.         if (form.tip_title.value == '' || form.tip_text.value == '' || form.tip_reader_email.value == '' || form.tip_reader_name.value == '') {
  653.             d.innerHTML = 'You did not enter a required field. Please check your input.';
  654.             s.style.display = "block";
  655.             return false;
  656.         }
  657.             
  658.         var email = escape(form.tip_reader_email.value);
  659.         email = email.replace(new RegExp( "\\+", "g" ),"%2B");
  660.     
  661.         url = url + '&tip_title=' + escape(form.tip_title.value) + '&tip_reader_name=' + escape(form.tip_reader_name.value) + '&tip_reader_email=' + email + '&tip_text=' + escape(form.tip_text.value) + '&tip_link_label=' + escape(form.tip_link_label.value) + '&tip_link_url=' + escape(form.tip_link_url.value);
  662.         
  663.     } else if (type == 'comment') {
  664.         if (form.article_id == '') { 
  665.             d.innerHTML = 'Something is wrong with our system. Please report this error with the URL you\'re viewing to <a href="mailto:glenn@tidbits.com">our system administrator</a>.';
  666.             s.style.display = "block";
  667.             return false;
  668.         }
  669.         url = url + "&tbtalk=" + form.getbits.value;
  670.     } else if (type == 'email') { 
  671.         url = url + "&email=" + form.author_id.value;
  672.     }
  673.  
  674.     new Ajax.Request(url, {
  675.         method: 'get',
  676.         onSuccess: function(transport) {
  677.             var message;
  678.             var invalid = transport.responseText.match(/bad_captcha/);
  679.             var bademail = transport.responseText.match(/bad_email/);
  680.             var general_bad = transport.responseText.match(/bad_response/);
  681.  
  682.             if(invalid) {
  683.                 message = 'The text you entered does not match the text in the image. Please try again.';
  684.             } else if (bademail) {
  685.                 message = 'The email address you entered does not appear to be a valid address. Please re-enter';
  686.             } else if (general_bad) {
  687.                 message = 'Something went wrong that we can\'t determine. Sorry.';
  688.             }
  689.             if (invalid || bademail || general_bad) {
  690.                 d.innerHTML = message;
  691.                 display_captcha(1, tip_recapt);
  692.                 s.style.display = "block";
  693.             } else {
  694.                 s.style.display = "block";
  695.                 display_captcha(0, tip_recapt);
  696.                 if (type == 'tip') {
  697.                     d.innerHTML = '';
  698.                     d.style.background = '#000000';
  699.                     //Effect.Appear(d, { duration: 0.7, from: 1.0, to: 0.3 });
  700.                     form.tip_title.value = '';
  701.                     form.tip_text.value = '';
  702.                     form.tip_link_label.value = '';
  703.                     form.tip_link_url.value = '';
  704.                     display_captcha(1, tip_recapt);
  705.                     Effect.Appear('popup_box_thanks', { duration: 0.7, from: 0.0, to: 1.0 });
  706.                     Effect.Fade('ts_innards', { duration: 0.7, from: 1.0, to: 0.4 });
  707.                 } else if (type == 'comment') {
  708.                     d.innerHTML = 'Your thread has been created. Please wait and you will be redirected to our discussion site.';
  709.                     display_captcha(0, tip_recapt);
  710.                     if (location.hostname.match(/staging/)) {
  711.                         hn = "staging";
  712.                     } else { 
  713.                         hn = "db";
  714.                     }
  715.                     window.location = "http://" + hn + ".tidbits.com/discuss/" + form.getbits.value;
  716.                 } else if (type == 'email') {
  717.                     display_captcha(0, tip_recapt);
  718.                     var e = transport.responseText;
  719.                     var ae = e.match(/(.+)\:(.+)/);
  720.                     s.style.display = "none";
  721.                     var f = ae[1].replace(/[\n\s]+/g, '');
  722.                     inn.style.display = "none";
  723.                     inn_alt.style.display = "block";
  724.                     small_response.innerHTML = 'Click <a href="mailto:' + f + '" onClick="HidePopupContent(\'' + base_ref + base_id + '\')">' + f + '</a> to send email to ' + ae[2] + '.';
  725.                 }
  726.             }
  727.         },
  728.         onFailure: function() {
  729.             d.innerHTML = "<p><span class='required_field'>An unknown error has occurred</span></p>";
  730.             display_captcha(1, tip_recapt);
  731.         }
  732.     });
  733.     return false;
  734. }
  735.  
  736. function close_popup_thanks(tnx, prefix) {
  737.     if ($(tnx).style.display == 'visible' || $(tnx).style.display == '') {
  738.         Effect.Fade(tnx, { duration: 0.7, from: 1.0, to: 0.0 });
  739.         if (prefix == 'ts') {
  740.             var innards = prefix + "_innards";
  741.             Effect.Appear(innards, { duration: 0.7, from: 0.4, to: 1.0 });
  742.         } else {
  743.             Effect.Fade(prefix, { duration: 0.7, from: 1.0, to: 0.0 });
  744.             Effect.Fade('big_ole_background', { duration: 0.5, from: 0.65 });
  745.             $('big_ole_background').style.top = "0px";
  746.         }
  747.     }
  748. }
  749.  
  750. function check_tip_close() {
  751.     if ($('ts').style.display == 'visible' || $('ts').style.display == '') {
  752.         Effect.Fade('big_ole_background', { duration: 0.7, from: 0.65 });
  753.         document.getElementById('ts').style.display = "none";
  754.     }
  755. }        
  756.  
  757. function display_captcha(fail, tip_recapt) {
  758.  
  759.     if (fail == 1) {
  760.         Recaptcha.create("6LfmTwAAAAAAAHtrfswVZ8P0bZEnLXe27PNMXXME",
  761.             tip_recapt, {
  762.                theme: "red",
  763.                callback: Recaptcha.focus_response_field
  764.             });
  765.     } else {
  766.         var tr = document.getElementById(tip_recapt);
  767.         tr.style.display = 'none';
  768.     }
  769.     return true;
  770.  
  771. }
  772.  
  773. function fill_preview(new_box, old_box, form) {
  774.     var ob = document.getElementById(old_box);
  775.     var nb = document.getElementById(new_box);
  776.  
  777.     $('p_tips_title').innerHTML = form.tip_title.value;
  778.     var tips_text = form.tip_text.value;
  779.     $('p_tips_text').innerHTML = '<p>' + tips_text.replace(/[\n\r]+/g, "</p><p>") + '</p>';
  780.     $('p_url').href = form.tip_link_url.value;
  781.     $('p_label').innerHTML = form.tip_link_label.value;
  782.     $('p_reader').innerHTML = form.tip_reader_name.value;
  783.     
  784.     preview_box(new_box, old_box);
  785.     return false;
  786. }
  787.  
  788. function preview_box(new_box, old_box) {
  789.     var ob = document.getElementById(old_box);
  790.     var nb = document.getElementById(new_box);
  791.     nb.style.left = ob.style.left;
  792.     nb.style.top = ob.style.top;
  793. //     ob.style.display = 'none';
  794. //      nb.style.display = 'block';
  795.     
  796.     Effect.SlideUp(old_box, { duration: 1.2 });
  797.     Effect.SlideDown(new_box, { duration: 1.2 });
  798.     return false;
  799. }
  800.  
  801. function search_tipbits(field, show) {
  802.     var url = '/short.cgi?command=search_tipbits&id=' + escape($(field).value);
  803.     
  804.     new Ajax.Request(url, {
  805.         method: 'get',
  806.         onSuccess: function(transport) {
  807.             var text_results = "<div id='tip_insert'><div id='tip_pagehead2'>TipBITS Search Results</div>" + transport.responseText + "</div>";
  808.             if (show == "") {
  809.                 $('center_ajax_sub').innerHTML = text_results;
  810.             } else {
  811.                 $('center_ajax_sub').innerHTML = text_results;
  812.                 $(show).style.display = '';
  813.             }
  814.             window.scrollTo(0,0) 
  815.         },
  816.         onFailure: function() {
  817.             alert ('A problem occurred from which no recovery seems possible.');
  818.         }
  819.     });
  820.     return false;
  821.  
  822. }
  823.  
  824. function redirect_issue(form) {
  825.     var num = form.issue_number.value; 
  826.     if (num > 0) {
  827.         window.location = 'http://db.tidbits.com/issue/' + num; 
  828.     } 
  829. }
  830.  
  831. function expand_textarea(form, id) {
  832.     if (id == 'new') {
  833.         var t_name = 'cb_item_add_' + id;
  834.         var cbf = $(t_name);
  835.         cbf.rows = 4; 
  836.         if (cbf.value == 'What do you think?') { 
  837.             cbf.value = '';
  838.         }
  839.         cbf.style.color = 'black'; 
  840.         cbf.style.fontStyle = 'normal'; 
  841.     }
  842.     $('cb_add_dropdown_' + id).style.display = '';
  843. }
  844. function contract_textarea(form, id) {
  845.     var t_name = 'cb_item_add_' + id;
  846.     var cbf = $(t_name);
  847.     if (cbf.value == '') { 
  848.         cbf.rows = 1; 
  849.     }
  850.     // $('cb_add_dropdown_' + id).style.display = 'none';
  851. }
  852.  
  853. function swap_cb_dropdown(form,id) {
  854.     var drop = $('cb_add_dropdown_' + id);
  855.     var t_name = 'cb_item_add_' + id;
  856.     if (drop.style.display == 'none') { 
  857.         drop.style.display = ''; 
  858.         $(t_name).rows = 4;
  859.     } else { 
  860.         drop.style.display = 'none'; 
  861.     }
  862. }
  863.  
  864. function count_insert(field, counter) {
  865.     var cbf = $(field);
  866.     var b = cbf.value.length;
  867.     if (b < 1) { b = 0; }
  868.     // need to add token or authentication test here, of course
  869.     if (b >= 1000) { 
  870.         cbf.value = cbf.value.substring(0,1000);
  871.         $(counter).style.color = 'red';
  872.         $(counter).style.fontStyle = 'italic';
  873.     } else {
  874.         $(counter).style.color = 'black';
  875.         $(counter).style.fontStyle = 'normal';
  876.     }
  877.     if (b > 1000) { b = 1000; }
  878.     $(counter).innerHTML = (1000-b);
  879.  
  880. }
  881.  
  882. function cb_post_submit() {
  883.  
  884.     // shorten form
  885.     var f = $('post_comment');
  886.  
  887.     // check for empty comment
  888.     var cb_text = f.cb_item_add.value;
  889.     if (cb_text == '') { 
  890.         alert("Please enter a comment before submitting."); 
  891.         return false;
  892.     }
  893.     // escape line endings
  894.     cb_text = cb_text.replace(/(\r\n|\r|\n)/g, "<br />");
  895.     cb_text = cb_text.replace(/\&/g, "&");
  896.     // cb_text = clean_unicode(cb_text);
  897.  
  898.     // increment nesting level, checking for NaN
  899.     var nest = f.comment_nest.value;
  900.     if (nest != nest || nest == undefined || isNaN(nest)) { nest = 0; }
  901.     nest = Number(nest) + 1;
  902.  
  903.     // token if stored in cookie for commenter
  904.     var token_cookie = document.cookie.match(/tbcomm\=([^;]+)/);
  905.     var token;
  906.     // ignore null array returns
  907.     if (token_cookie === null) { token = 0; } else { token = token_cookie[1]; }
  908.  
  909.     // name of commenter, email
  910.     var cb_name;
  911.     if (f.cb_add_name != null && f.cb_add_name != undefined) {
  912.         cb_name = f.cb_add_name.value;
  913.     }
  914.     var cb_email;
  915.     if (f.cb_add_email != null && f.cb_add_email != undefined) { 
  916.         cb_email = f.cb_add_email.value;
  917.     }
  918.     
  919.     // check for empty name or no token
  920.     if (!cb_name && !token) { 
  921.         alert ("Please enter your name to be associated with this comment.");
  922.         return false;
  923.     }
  924.     if (!cb_email && !token) {
  925.         alert ("You must enter an email address to post this comment.");
  926.         return false;
  927.     }
  928.     
  929.     $('comm_post_comment').disabled = true;
  930.     $('comm_post_comment').value = 'Please Wait';
  931.     
  932.     var uni_cb_text;
  933.     var uni_cb_name;
  934.     if (encodeURIComponent) {
  935.         uni_cb_text = encodeURIComponent(cb_text);
  936.         uni_cb_name = encodeURIComponent(cb_name);
  937.     } else {
  938.         uni_cb_text = escape(cb_text);
  939.         uni_cb_name = escape(cb_name);
  940.     }
  941.     
  942.     var url = '/short.cgi?command=post_comment&article_id=' + escape(f.article_id.value) + '&token=' + escape(token) + '&cb_name=' + uni_cb_name + '&cb_email=' + escape(cb_email) + '&cb_text=' + uni_cb_text + '&parent_id=' + escape(f.comment_id.value) + '&nest=' + escape(nest) + "&edit=" + escape(f.edit.value);
  943.     var dd = 'comm_message_box';
  944.     var ct = 'comment_thanks';
  945.  
  946.     new Ajax.Request(url, {
  947.         method: 'get',
  948.         onSuccess: function(transport) {
  949.             var held = transport.responseText.match(/held/);
  950.             var banned = transport.responseText.match(/banned/);
  951.             var post = transport.responseText.match(/post\|(.*)\|(.*)\|(.*)\|(.*)/);
  952.             var edited = transport.responseText.match(/edited/);
  953.             if (post || edited) { 
  954.                 // close down comments box and remove background
  955.                 $(dd).style.display = '';
  956.                 Effect.Fade('comm', { duration: 0.7, from: 1.0, to: 0.0 });
  957.                 fade_background();
  958.                 $('big_ole_background').style.top = "0px";
  959.  
  960.                 // insert new comment in the right place
  961.                 var pid = f.comment_id.value;
  962.                 var insert_block = 'cb_item_insert_' + pid;
  963.                 
  964.                 if (post) {
  965.                     var new_date = post[1];
  966.                     var cid = post[2];
  967.                     var ib = post[3];
  968.                     var urlok = post[4];
  969.                     if (pid == 'new' && !ib) { ib = 'new'; }
  970.                     //alert ("cid " + cid + ", new insertion before " + ib + ", nest " + nest);
  971.                     
  972.                     var new_cb_text = cb_text;
  973.                     if (urlok > 0) { 
  974.                         var urlexp = /(http:\/\/\S+)(\s+|$)/gm;
  975.                         new_cb_text = cb_text.replace(urlexp, "<a href=\"$1\">$1<\/a>$2");
  976.                         //alert(new_cb_text);
  977.                     }
  978.                             
  979.                     var new_text = '<div class="cb_item_meta"><span class="cb_item_author">' + $('commenter_name_inserted').innerHTML + '</span> <span class="cb_item_date" id="cb_item_date_insert_' +  cid + '">' + new_date + '</span></div><div class="cb_buttons_offset"><div class="cb_item_text" id="cb_item_text_' + cid + '" style="padding-left: 10px;">' + new_cb_text + '</div><div class="cb_buttons_offset" style="padding-left: 10px"><span class="cb_reply_icon"><span class="cb_action" onClick="ShowCommentPopup(\'' + cid + '\', \'' + nest + '\', \'' + f.article_id.value + '\')">Reply</span><span  class="cb_action" onClick="EditComment(\'' + cid + '\')">Edit</span></div>';
  980.                     
  981.                     // insert new comment
  982.                     var new_row = document.createElement("div");
  983.                     var new_id = 'cb_item_' + cid;
  984.                     new_row.setAttribute("id", new_id);
  985.                     $('insert_before_' + ib).appendChild(new_row);
  986.                     $(new_id).style.display = 'none';
  987.                     $(new_id).innerHTML = "<div>" + new_text + "</div>";
  988.                     $(new_id).style.paddingBottom = '22px';
  989.                     $(new_id).className = 'cb_indent_' + nest;
  990.                     Effect.BlindDown(new_id, { duration: 0.7 });
  991.  
  992.                     // insert new node into which to insert another comment
  993.                     var new_row2 = document.createElement("div");
  994.                     var new_id2 = 'insert_before_' + cid;
  995.                     new_row2.setAttribute("id", new_id2);
  996.                     $('insert_before_' + ib).appendChild(new_row2);
  997.                     $(new_id2).innerHTML = '';
  998.                     
  999.                     // delete no comments message if comments are added
  1000.                     if ($('no_comments')) {
  1001.                         $('no_comments').innerHTML = '';
  1002.                     }
  1003.                     $('comm_post_comment').value = 'Post Comment';
  1004.                     $('comm_post_comment').disabled = false;
  1005.                     
  1006.                     Effect.ScrollTo(new_id2);
  1007.  
  1008.                 } else {
  1009.                     $('cb_item_text_' + pid).innerHTML = cb_text;
  1010.                 }
  1011.                     
  1012.             } else if (held) { 
  1013.                 $('comm_innards').style.display = 'none';
  1014.                 new Effect.Appear('comment_thanks', { duration: 0.3, from: 0.0, to: 1.0 });
  1015.                 setTimeout('fade_comm()', 5000);
  1016.                 
  1017.             } else if (banned) {
  1018.                 $(dd).style.display = '';
  1019.                 $(dd).innerHTML = 'Your ability to post comments has been disabled. Contact us for more information.';
  1020.                 var hn;
  1021.                 if (location.hostname.match(/staging/)) {
  1022.                     hn = "staging";
  1023.                 } else { 
  1024.                     hn = "db";
  1025.                 }
  1026.                 set_cookie('tbcomm', '', '.00001', '/', hn + '.tidbits.com', '');
  1027.             } else {
  1028.                 $(dd).style.display = '';
  1029.                 $(dd).innerHTML = 'Something went wrong when you attempted to post a comment. You have our sincere apologies.';
  1030.             }
  1031.         },
  1032.         onFailure: function() {
  1033.             $(dd).style.display = '';
  1034.             $(dd).innerHTML = 'Our commenting system isn\'t working correctly at the moment. Please try again later.';
  1035.         }
  1036.     });
  1037.     
  1038.     $('comm_post_comment').name = "Thanks!";
  1039.     $('comm_post_comment').onClick = '';
  1040.     return false;
  1041. }
  1042.  
  1043. function fade_comm() {
  1044.     Effect.Fade('comm', { duration: 0.7, from: 1.0, to: 0.0 }),
  1045.     fade_background();
  1046.     $('big_ole_background').style.top = "0px";
  1047. }
  1048.  
  1049.  
  1050. function ShowCommentPopup(cid, nest, aid) {
  1051.     var f = $('post_comment'); 
  1052.     $('comm_post_comment').name = "Post Comment";
  1053.     $('comm_post_comment').onClick = 'cb_post_submit(); return false;';
  1054.     $('comm_headline').innerHTML = "Post Comment";
  1055.     $('comment_thanks').style.display = 'none';
  1056.     $('comm_innards').style.display = '';
  1057.     $('comm_post_comment').value = 'Post Comment';
  1058.     $('comm_post_comment').disabled = false;
  1059.     
  1060.     new Draggable('comm', { snap: false } );
  1061.  
  1062.     f.comment_id.value = cid;
  1063.     f.comment_nest.value = nest;
  1064.     f.edit.value = '';
  1065.     f.cb_item_add.value = '';
  1066.     if (f.cb_add_name != null && f.cb_add_name != undefined) {
  1067.         f.cb_add_name.value = '';
  1068.         f.cb_add_email.value = '';
  1069.     }    
  1070.     var cb_quote = 'cb_item_text_' + cid;
  1071.     if (cid == 'new') {
  1072.         $('cb_quoted').innerHTML = $('article_blurb_for_insert').innerHTML;
  1073.     } else {
  1074.         $('cb_quoted').innerHTML = $(cb_quote).innerHTML;
  1075.     }
  1076.     $('comm_message_box').innerHTML = '';
  1077.     ShowPopupContent('comm', 100);
  1078.     count_insert('cb_item_add','cb_char_count');
  1079.     f.cb_item_add.focus();
  1080. }
  1081.  
  1082. function EditComment(cid) {
  1083.     ShowCommentPopup(cid, '', '');
  1084.     var cb_text = 'cb_item_text_' + cid;
  1085.     var cb_text_inner = $(cb_text).innerHTML.replace(/<br>/g, "\n\n");
  1086.     cb_text_inner = cb_text_inner.replace(/[\n\s\r]{2}$/gm, "");
  1087.     cb_text_inner = cb_text_inner.replace(/[\n\s\r]+$/g, "");
  1088.     $('cb_item_add').value = cb_text_inner;
  1089.     $('post_comment').edit.value = 1;
  1090.     $('comm_headline').innerHTML = "Edit Comment";
  1091. }
  1092.  
  1093. function DeleteComment(cid) {
  1094.  
  1095.     var yes = confirm("Are you sure you want to delete this comment?");
  1096.     if (yes == false) {
  1097.         return false; 
  1098.     }
  1099.     var token_regexp = new RegExp("token" + host_prefix + "\=([^;]+)", "");
  1100.     var token = document.cookie.match(token_regexp);
  1101.     var url = '/short.cgi?command=delete_comment&cid=' + cid + '&token=' + escape(token[1]);
  1102.  
  1103.     new Ajax.Request(url, {
  1104.         method: 'get',
  1105.         onSuccess: function(transport) {
  1106.             var success = transport.responseText.match(/success/);
  1107.  
  1108.             if (success) {
  1109.                 var c = 'cb_item_' + cid;
  1110.                 $(c).style.display = 'none';
  1111.                 $(c).style.textDecoration = line-through;
  1112.                 $(c).color = 'Gray';
  1113.             } else {
  1114.                 alert("The system failed in deleting the comment. Tell Glenn!");
  1115.             }
  1116.         },
  1117.         onFailure: function() {
  1118.             alert("The system failed in deleting the comment. Tell Glenn!");
  1119.         }
  1120.     });
  1121.     return false;
  1122. }
  1123.  
  1124. function BanUser(cer_id) {
  1125.  
  1126.     var yes = confirm("Are you sure you want to ban this user? All comments by this user ever made will be unpublished (but not deleted from our database).");
  1127.     if (yes == false) {
  1128.         return false; 
  1129.     }
  1130.     var token_regexp = new RegExp("token" + host_prefix + "\=([^;]+)", "");
  1131.     var token = document.cookie.match(token_regexp);
  1132.     var url = '/short.cgi?command=ban_user&cer_id=' + cer_id + '&token=' + escape(token[1]);
  1133.  
  1134.     new Ajax.Request(url, {
  1135.         method: 'get',
  1136.         onSuccess: function(transport) {
  1137.             var success = transport.responseText.match(/success/);
  1138.  
  1139.             if (success) {
  1140.                 alert("This user's comments have all been unpublished from TidBITS. Reload the page to see his or her comments removed here.");
  1141.             } else {
  1142.                 alert("The system failed in deleting the comment. Tell Glenn!");
  1143.             }
  1144.         },
  1145.         onFailure: function() {
  1146.             alert("The system failed in deleting the comment. Tell Glenn!");
  1147.         }
  1148.     });
  1149.     return false;
  1150. }
  1151.  
  1152. function PauseUser(cid, cer_id) {
  1153.  
  1154.     if (!cer_id) {
  1155.         alert ("A user ID is missing. Please alert Glenn, as this shouldn't happen.");
  1156.         return false;
  1157.     }
  1158.     var yes;
  1159.     var action;
  1160.     var cstatus = 'cb_pause_user_' + cid;
  1161.     if ($(cstatus).innerHTML.match(/Resume/)) {
  1162.         yes = confirm("Are you sure you want to allow this user to resume commenting?");
  1163.         action = 'start';
  1164.     } else {
  1165.         yes = confirm("Are you sure you want to prevent this user from commenting in the future?");
  1166.         action = 'pause';
  1167.     }
  1168.     if (yes == false) {
  1169.         return false; 
  1170.     }
  1171.     var token_regexp = new RegExp("token" + host_prefix + "\=([^;]+)", "");
  1172.     var token = document.cookie.match(token_regexp);
  1173.     var url = '/short.cgi?command=pause_user&status=' + action + '&cer_id=' + cer_id + '&token=' + escape(token[1]);
  1174.  
  1175.     new Ajax.Request(url, {
  1176.         method: 'get',
  1177.         onSuccess: function(transport) {
  1178.             var success = transport.responseText.match(/success/);
  1179.  
  1180.             if (success) {
  1181.                 if (action == 'start') {
  1182.                     $(cstatus).innerHTML = "Pause User";
  1183.                 } else {
  1184.                     $(cstatus).innerHTML = "Resume User";
  1185.                 }
  1186.             } else {
  1187.                 alert("The system failed to pause this user's ability to comment. Tell Glenn!");
  1188.             }
  1189.         },
  1190.         onFailure: function() {
  1191.             alert("The system failed to pause this user's ability to comment. Tell Glenn!");
  1192.         }
  1193.     });
  1194.     return false;
  1195. }
  1196.  
  1197. function UpdateNames(cer_id, new_name) {
  1198.     
  1199.     var classElements = new Array();
  1200.     var els = document.getElementsByTagName('span');
  1201.     var elsLen = els.length;
  1202.     var q = 0;
  1203.     var pattern = new RegExp('(^|\\\\s)'+'cb_item_author'+'(\\\\s|$)');
  1204.     for (i = 0, j = 0; i < elsLen; i++) {
  1205.         if ( pattern.test(els[i].className) ) {
  1206.             var cirs = els[i].id.match(/cb_item_author_edit_(\d+)_/);
  1207.             if (cirs[1] == cer_id) {
  1208.                 $(els[i]).innerHTML = new_name.innerHTML;
  1209.             }
  1210.         }
  1211.     }
  1212.  
  1213. }
  1214.  
  1215. function clean_unicode(text) {
  1216.  
  1217.     return text;
  1218.     
  1219.     // this is now handled by UTF8 encoding in the AJAX script
  1220.     var replacements = new Array;
  1221.     replacements = {
  1222.         "\u00a9": "(c)",
  1223.         "\u201c": '"',
  1224.         "\u201d": '"',
  1225.         "\u2026": "...",
  1226.         "\u2002": " ",
  1227.         "\u2003": " ",
  1228.         "\u2009": " ",
  1229.         "\u2013": "-",
  1230.         "\u2014": "--",
  1231.         "\u2018": "'",
  1232.         "\u2019": "'",
  1233.         "\u2122": "(tm)"    
  1234.     };
  1235.     var regex = new Array;
  1236.  
  1237.     for (var key in replacements) {
  1238.         regex[key] = new RegExp(key, 'g');
  1239.         text.replace(regex[key], replacements[key]);
  1240.     }
  1241.     
  1242.     return text;
  1243. }