/*
 requires:
  firefly_lib.js (for tripcode_fast.js)
  javacrypt.js (for tripcode_fast.js)
  tripcode_fast.js (process_tripcode)
*/

var start_search;
var stop_search;

(function(){
 var tripcache=new Object();
 var search=false;
 var tripchars=" !#$%()*+-./0123456789:;=?ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~".split(new RegExp());
 var saltchars="./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(new RegExp());

 start_search=function(){
  if(search!=false)
   stop_search();
  var regex=new RegExp(document.getElementById('regex').value,
                        document.getElementById('case').checked?'':'i');
  var ms=/MSIE/.test(navigator.userAgent)?1:0;
  search=setInterval(function(){
   var results=document.getElementById('results');
   var cap=tripchars[Math.round(Math.random()*88)]+
    saltchars[Math.round(Math.random()*63)]+
    saltchars[Math.round(Math.random()*63)]+
    tripchars[Math.round(Math.random()*86)]+
    tripchars[Math.round(Math.random()*86)]+
    tripchars[Math.round(Math.random()*86)]+
    tripchars[Math.round(Math.random()*86)]+
    tripchars[Math.round(Math.random()*86)];
   var trip=tripcache[cap];
   if(!trip){
    trip=process_tripcode(cap);
    tripcache[cap]=trip;
   }
   if(regex.test(trip)){
    cap=cap.replace(/&/g,'&amp;');
    cap=cap.replace(/>/g,'&gt;');
    cap=cap.replace(/</g,'&lt;');
    results.innerHTML+=cap+' -&gt; '+trip+'<br />';
   }
  },ms);
 }

 stop_search=function(){
  clearInterval(search);
  search=false;
 }
})();

function clear_results(){
 document.getElementById('results').innerHTML='<!-- -->';
}

