
if (top.location != self.location) top.location.href = self.location.href;

// common ajax function to set http request
function setRequest() {
  var http = false;
  try {
    http = new XMLHttpRequest();
  } catch (e) {
    try {
      http = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {
      // nothing to do here
    }
  }
  return http;
}

// used in search field
function focusInput(el) {
  if (document.getElementById(el).defaultValue==document.getElementById(el).value) document.getElementById(el).value = "";
}
function blurInput(el) {
  if (!document.getElementById(el).value.match(/\w+/)) document.getElementById(el).value = document.getElementById(el).defaultValue;
}

// used for faq & terms
function dim() {
  document.getElementById('container1').style.opacity = '0.5';
  document.getElementById('container1').style.filter = 'alpha(opacity=50)';
  document.getElementById('container2').style.opacity = '0.5';
  document.getElementById('container2').style.filter = 'alpha(opacity=50)';
}
function bright() {
  document.getElementById('container1').style.opacity = '1.0';
  document.getElementById('container1').style.filter = 'none';
  document.getElementById('container2').style.opacity = '1.0';
  document.getElementById('container2').style.filter = 'none';
}

// used in rating-form.php
function stars(x) {
  if (x == "one") document.getElementById('one').src = "star1.gif";
  if (x == "two") { document.getElementById('one').src = "star1.gif"; document.getElementById('two').src = "star1.gif"; }
  if (x == "three") { document.getElementById('one').src = "star1.gif"; document.getElementById('two').src = "star1.gif"; document.getElementById('three').src = "star1.gif"; }
  if (x == "four") { document.getElementById('one').src = "star1.gif"; document.getElementById('two').src = "star1.gif"; document.getElementById('three').src = "star1.gif";  document.getElementById('four').src = "star1.gif"; }
  if (x == "five") { document.getElementById('one').src = "star1.gif"; document.getElementById('two').src = "star1.gif"; document.getElementById('three').src = "star1.gif"; document.getElementById('four').src = "star1.gif"; document.getElementById('five').src = "star1.gif"; }
}
function noStars() {
  document.getElementById('one').src = "star0.gif";
  document.getElementById('two').src = "star0.gif";
  document.getElementById('three').src = "star0.gif";
  document.getElementById('four').src = "star0.gif";
  document.getElementById('five').src = "star0.gif";
}
function rate(x) {
  document.getElementById('rating').style.display = "none";
  document.getElementById('thankyou').style.display = "block";
// the var tip is loaded in the main script using php
  http = setRequest();
  if (http == false) {
    document.getElementById('generatedPswd').innerHTML = "Your browser is not supported";
    return;
  }
  var params = "tip="+tip+"&rating="+x;
  http.open("POST","/ajax-scripts/rate.php",true);
  http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  http.send(params);
}

// fedback form
function sending() {
  http = setRequest();
  if (http == false) {
    document.getElementById('generatedPswd').innerHTML = "Your browser is not supported";
    return;
  }
  content1 = escape(document.getElementById('content').value);
  captcha1 = document.getElementById('captcha').value;
  var re = /[a-zA-Z]{4,}/;
  if (!re.test(content1)) {
    document.getElementById('message').innerHTML = "Your message was not sent<br />What is your feedback?";
    document.getElementById('captcha').value = "";
    document.getElementById('capImage').src='/captcha.php?'+Math.random();
    return;
  }
  var re = /^[a-zA-Z]{6}$/;
  if (!re.test(captcha1)) {
    document.getElementById('message').innerHTML = "Your message was not sent<br />Invalid Captcha value";
    document.getElementById('captcha').value = "";
    document.getElementById('capImage').src='/captcha.php?'+Math.random();
    return;
  }
  document.getElementById('message').innerHTML = "Processing . . . &nbsp; <img src='/ajax-scripts/loading.gif' alt='' />";
  var params = "content="+content1+"&captcha="+captcha1;
  http.open("POST","/ajax-scripts/mail.php",true);
  http.onreadystatechange = function() {
    if (http.readyState == 4 && http.status == 200) {
      document.getElementById('message').innerHTML = http.responseText;
      document.getElementById('captcha').value = "";
      document.getElementById('capImage').src='/captcha.php?'+Math.random();
    }
  }
  http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  http.send(params);
}

/////////////////////
// B&T's Toolbox
/////////////////////

// generate password
function genPassword() {
  http = setRequest();
  if (http == false) {
    document.getElementById('generatedPswd').innerHTML = "Your browser is not supported";
    return;
  }
  length1 = escape(document.getElementById('length').value);
  numbers1 = document.getElementById('numbers').value;
  special1 = document.getElementById('special').value;
  upper1 = document.getElementById('upper').value;
  lower1 = document.getElementById('lower').value;
  document.getElementById('generatedPswd').innerHTML = "Processing . . . &nbsp;<img src='/ajax-scripts/loading.gif' alt='' />";
  var params = "length="+length1+"&numbers="+numbers1+"&special="+special1+"&upper="+upper1+"&lower="+lower1;
  http.open("POST","/ajax-scripts/password.php",true);
  http.onreadystatechange = function() {
    if (http.readyState == 4 && http.status == 200) {
      document.getElementById('generatedPswd').innerHTML = http.responseText;
    }
  }
  http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  http.send(params);
}

// hex rgb color conversion
function colorConvert() {
  http = setRequest();
  if (http == false) {
    document.getElementById('generatedPswd').innerHTML = "Your browser is not supported";
    return;
  }
  hex1 = escape(document.getElementById('hex').value);
  r1 = document.getElementById('r').value;
  g1 = document.getElementById('g').value;
  b1 = document.getElementById('b').value;
  if (hex1 == "" && r1 == "") { document.getElementById('colorMsg').innerHTML = "Invalid Input"; return; }
  document.getElementById('colorMsg').innerHTML = "Processing . . . &nbsp;<img src='/ajax-scripts/loading.gif' alt='' />";
  var params = "hex="+hex1+"&r="+r1+"&g="+g1+"&b="+b1;
  http.open("POST","/ajax-scripts/color.php",true);
  http.onreadystatechange = function() {
    if (http.readyState == 4 && http.status == 200) {
      document.getElementById('colorMsg').innerHTML = "&nbsp;";
      var result = http.responseText;
      if (result == "Invalid Values") document.getElementById('colorMsg').innerHTML = result;
        else {
          var colors = result.split("/");
          document.getElementById('hex').value = colors[0];
          document.getElementById('r').value = colors[1];
          document.getElementById('g').value = colors[2];
          document.getElementById('b').value = colors[3];
        }
    }
  }
  http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  http.send(params);
}

// generate htpassword string
function genHtPassword() {
  http = setRequest();
  if (http == false) {
    document.getElementById('generatedPswd').innerHTML = "Your browser is not supported";
    return;
  }
  document.getElementById('htpassword').style.fontSize = "16px";
  htuser1 = escape(document.getElementById('htuser').value);
  htpass1 = document.getElementById('htpass').value;
  if (htuser1 == "") { document.getElementById('htpassword').innerHTML = "Invalid Entry"; return; }
  if (htpass1 == "") { document.getElementById('htpassword').innerHTML = "Invalid Entry"; return; } 
  document.getElementById('htpassword').innerHTML = "Processing . . . &nbsp;<img src='/ajax-scripts/loading.gif' alt='' />";
  var params = "htuser="+htuser1+"&htpass="+htpass1;
  http.open("POST","/ajax-scripts/htpassword.php",true);
  http.onreadystatechange = function() {
    if (http.readyState == 4 && http.status == 200) {
      document.getElementById('htpassword').style.fontSize = "10px";
      document.getElementById('htpassword').innerHTML = http.responseText;
    }
  }
  http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  http.send(params);
}

// domain ip resolution
function resolution() {
  http = setRequest();
  if (http == false) {
    document.getElementById('generatedPswd').innerHTML = "Your browser is not supported";
    return;
  }
  domain1 = escape(document.getElementById('domain').value);
  if (domain1 == "") { document.getElementById('resolution').innerHTML = "Invalid Input"; return; }
  document.getElementById('resolution').innerHTML = "Processing . . . &nbsp;<img src='/ajax-scripts/loading.gif' alt='' />";
  var params = "domain="+domain1;
  http.open("POST","/ajax-scripts/resolve.php",true);
  http.onreadystatechange = function() {
    if (http.readyState == 4 && http.status == 200) {
      document.getElementById('resolution').innerHTML = http.responseText;
    }
  }
  http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  http.send(params);
}

// status
function status() {
  http = setRequest();
  if (http == false) {
    document.getElementById('generatedPswd').innerHTML = "Your browser is not supported";
    return;
  }
  url1 = escape(document.getElementById('url').value);
  if (url1 == "") { document.getElementById('status').innerHTML = "Invalid Input"; return; }
  document.getElementById('status').innerHTML = "Processing . . . &nbsp;<img src='/ajax-scripts/loading.gif' alt='' />";
  var params = "url="+url1;
  http.open("POST","/ajax-scripts/status.php",true);
  http.onreadystatechange = function() {
    if (http.readyState == 4 && http.status == 200) {
      document.getElementById('status').innerHTML = http.responseText;
    }
  }
  http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  http.send(params);
}

