function changeOnclick() {
// Get all links on page
 rawlinks=document.getElementsByTagName("a");
// Loop through all links
 for(i=0; i<rawlinks.length; i++) {
// Get href attribute of link
   prechange = rawlinks[i].href
   newchange = prechange.replace("http://www.bestbarter.org", "");
   hrefs=rawlinks[i].href;
// If the href does not begin with http://
if(hrefs.indexOf("search?q") != -1) {
// Put a span in each link, with the onclick attribute
// Yes, I kno i could have done this much more elegantly, but it works, so w/e
     innerlinks=rawlinks[i].innerHTML
     rawlinks[i].innerHTML="&nbsp;<span class='fakelink' onclick=AjaxReq('http://www.google.com/" + newchange + "');>&nbsp;&nbsp;" + innerlinks + "&nbsp;&nbsp;</span>";
// Remove the offending href attribute    
	 rawlinks[i].removeAttribute("href");
    } 
  }
  elems = document.getElementsByName("q");
  for(i=0; i<elems.length; i++) {
  elems[i].style.display="none"; }
  
  imgelems = document.getElementsByTagName("img");
  for(i=0; i<imgelems.length; i++) {
  imgelems[i].style.display="none"; }
  
    butelems = document.getElementsByName("btnG");
  for(i=0; i<butelems.length; i++) {
  butelems[i].style.display="none"; }
  }

function AjaxReq(query)
{ 
 queryinfo = query.indexOf("http://");
// Create the xmlhttp object, named xhr
 var xhr; 
    try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e) 
    {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2) 
        {
          try {  xhr = new XMLHttpRequest();     }
          catch (e3) {  xhr = false;   }
        }
     }
// Function to execute when the state changes
    xhr.onreadystatechange  = function()
    { 
// When the request is complete...
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
// ...output the gotten data to the output div (contents)
                  output = xhr.responseText; 
				  document.getElementById("contents").innerHTML = output
// change the status span to reflect the current search

                  if(queryinfo != 0) {
                  document.getElementById("count").innerHTML=document.getElementById("input").value; } }
              else {
// ...or if there is an error, output the error code
                 output = "Error code " + xhr.status;
				 document.getElementById("contents").innerHTML = output 
				 document.getElementById("count").innerHTML=query; }
         }
    }; 
// Send the request
   nderf = document.getElementById("nderf.org");
   neardeath = document.getElementById("near-death.com");
   iands = document.getElementById("iands.org");
   aleroy = document.getElementById("aleroy.org");
   
// Check if boxes are checked, if true: return value, if false: return blanksite.com  
  if(nderf.checked != true) {
   nderf = "nderf.com";   }
   else {
   nderf = nderf.value;   }
   
      if(neardeath.checked != true) {
   neardeath = "nderf.com";   }
   else {
   neardeath = neardeath.value;   }
   
      if(iands.checked != true) {
   iands = "nderf.com";   }
   else {
   iands = iands.value;   }
   
      if(aleroy.checked != true) {
   aleroy = "nderf.com";   }
   else {
   aleroy = aleroy.value;   }
   
// Construct query
queryinfo = query.indexOf("http://");
if(queryinfo != 0) {
   myquery = query + " " + nderf + " OR " + neardeath + " OR " + iands + " OR " + aleroy;
   mygetvar = "http://www.google.com/search?hl=en&safe=off&q=" + myquery + "&btnG=Search";
   myesc = encodeURIComponent(mygetvar); }
else {
myesc = encodeURIComponent(query); }
// Send query  
  getvar = "filecontents.php?x=" + myesc;
   xhr.open("get",getvar,true); 
   xhr.send(null);
   
setTimeout('changeOnclick()', 1500);
scroll(0,0);
} 


