
function DecompileQueryString() {
  var r = new Array();
  var qs = unescape(location.search).substr(1).split("&");
  var pair = new Array();
  for (i = 0; i < qs.length; i++)
    {pair = qs[i].split("="); r[pair[0]] = pair[1] ? pair[1] : "";}
  return r;
}

function ActivationForm() {
  document.writeln("<h2>Welcome!</h2>");
  document.writeln(
    "<p>In order to obtain activation permissions from the server you " +
    "have to specify your license key along with the computer key.</p>"
  );
  document.writeln(
    '<form method = "get" ' +
    'action = "http://www.nt2000hosting.com/argentum/activate.asp" ' +
    'onSubmit = "return CheckInput(this);">'
  );
  document.writeln(
    '<p>Please specify your <b>license</b> key:<br/> ' +
    '<input name = "lk" size = "35" class = "ff"/></p>'
  );
  document.writeln(
    '<p>Please specify your <b>computer</b> key:<br/> ' + 
    '<input name = "ck" size = "35" class = "ff"/></p>'
  );
  document.writeln(
    '<p><input type = "submit" value = "Submit" class = "ff"/></p></form>'
  );
}

function DisplayServerResponse() {
  vars = DecompileQueryString();
  preface =
    "<b><big>Argentum</big></b>. There is more to it than just a " +
    "good company. It is authentic. It is argentic.";
  response = "";
  advice =
    "Please, use links to the <b>left</b> and to the <b>bottom</b> of " +
    "this page to navigate to the required area of our web-site.";
  if (typeof(vars["p"]) != "undefined") {
    preface =
      "The activation server has returned the following response " +
      "to your request:";
    switch (vars["p"]) {
      case "1":
        response = "The license key supplied is invalid. Please try again.";
        advice =
          "This is most probably due to a typing error. " +
          "Please check your input and resubmit.";
        break;
      case "2":
        response = "The computer key supplied is invalid. Please try again.";
        advice =
          "This is most probably due to a typing error. " +
          "Please check your input and resubmit.";
        break;
      case "3":
        response = "The license key supplied is disabled. Access is denied.";
        advice =
          "This is a permanent error. " +
          "You do not need to resubmit your request.";
        break;
      default:
        response =
          "There was a problem processing your request. " +
          "Please try again later.";
        advice = "";
    }
  }
  if (vars["ak"]) {
    preface =
      "The activation server has issued the following activation key for you:";
    response = vars["ak"];
    advice =
      "All you have to do now is to copy the above key to the " +
      "activation dialog box of your software product. " +
      "<br>That will activate the software on your computer " +
      "and convert it to a licensed, fully-functional one.";
  }
  if (vars["ak"]) document.writeln("<h2>Done!</h2>");
  document.writeln("<p>" + preface + "</p>");
  document.writeln("<p>" + response.bold().big() + "</p>");
  document.writeln("<p>" + advice + "</p>");
  document.writeln("<p>Thank you!<br><br></p>");
  if (vars["ak"]) NoteOnTyping();
}

function NoteOnTyping() {
  document.writeln("<h2>Note</h2>");
  document.writeln(
    "<p>To avoid possible typing errors it is recommended that you use " +
    "a combination of select, copy and paste, when you fill in the fields.</p>"
  );
}

function IsLicenseKeyCorrect(lk) {
  if (lk) {
    lkp = new RegExp("^\\s*(\\w+-){1,2}[\\da-f]{8}-[\\da-f]{4}\\s*$");
    return lkp.test(lk.toLowerCase());
  }
}

function IsComputerKeyCorrect(ck) {
  if (ck) {
    ckp = new RegExp("^\\s*computer-[\\da-f]{8}-[\\da-f]{8}\\s*$");
    return ckp.test(ck.toLowerCase());
  }
}

function CheckInput(form) {
  if (!IsLicenseKeyCorrect(form.lk.value)) {
    alert
      ("The license key is invalid. Please make a correction and try again.");
    return false;
  }
  if (!IsComputerKeyCorrect(form.ck.value)) {
    alert
      ("The computer key is invalid. Please make a correction and try again.");
    return false;
  }
  return true;
}

function CheckQueryString() {
  vars = DecompileQueryString();
  if (IsLicenseKeyCorrect(vars["lk"]) && IsComputerKeyCorrect(vars["ck"])) {
    if (document.getElementById)
      document.getElementById("body").style.visibility = "hidden";
    location =
      "http://www.nt2000hosting.com/argentum/activate.asp" + location.search;
  }
}

