var xmlhttp = false;
try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e) {
  xmlhttp = false;
  }
}
if(!xmlhttp && typeof (XMLHttpRequest != 'undefined')) {
  xmlhttp = new XMLHttpRequest();
}

window.onload = initialise;
function initialise() {
  newWindowLinks();
  if(document.getElementById('filterResults')) {
    document.getElementById('filterResults').onclick = function() {
      filterResults();
      return false;
    }
  }
}
function newWindowLinks() { 
  if(!document.getElementsByTagName) {
    return;
  } else { 
    var anchors = document.getElementsByTagName("a"); 
    for(var i=0; i<anchors.length; i++) { 
      var anchor = anchors[i]; 
      if(anchor.getAttribute("href") && anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "external nofollow") { 
        anchor.target = "_blank";
      }
    }
  } 
}
function regenerateCaptcha(imageID, viewName) {
  xmlhttp.open("GET", "ajax/generatecaptcha.php?imageid=" + imageID + "&viewname=" + viewName);
  xmlhttp.onreadystatechange = function() {
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      document.getElementById(imageID).src = xmlhttp.responseText;
    }
  }  
  xmlhttp.send(null);
}
function filterResults() {
  var getString = '';
  if(document.getElementById('filterResultsForm')) {
    for(x=0;x<document.getElementById('filterResultsForm').elements.length;x++) {
      getString = getString + document.getElementById('filterResultsForm').elements[x].name + '=' + document.getElementById('filterResultsForm').elements[x].value + '&';
    }
  }
  getString = getString.substring(0, getString.length - 1);
  window.location = document.getElementById('filterResultsForm').action + '?' + getString;
}
function navigate(url) {
  window.location = url; 
}
