
/* Copyright (c) 2003 Timothy Sakharov, Alexander Sakharov */

var arr = new Array();
var i;
var total;
var a1; var a2; var a3;

function submit_f () {
  total = 0;
  for (i = 0; i < 9; i++) {
    arr[i] = 0;
  }
  arr[document.theForm.num1.value - 1] = 1;
  arr[document.theForm.num2.value - 1] = 1;
  arr[document.theForm.num3.value - 1] = 1;
  arr[document.theForm.num4.value - 1] = 1;
  arr[document.theForm.num5.value - 1] = 1;
  arr[document.theForm.num6.value - 1] = 1;
  arr[document.theForm.num7.value - 1] = 1;
  arr[document.theForm.num8.value - 1] = 1;
  arr[document.theForm.num9.value - 1] = 1;
  for (i = 0; i < 9; i++) {
    total += arr[i];
  }
  if ( total != 9 ) {
    alert("Incorrect!");
    /*
    document.theForm.num1.value = '';
    document.theForm.num2.value = '';
    document.theForm.num3.value = '';
    document.theForm.num4.value = '';
    document.theForm.num5.value = '';
    document.theForm.num6.value = '';
    document.theForm.num7.value = '';
    document.theForm.num8.value = '';
    document.theForm.num9.value = '';
    */
    return;
  }

  arr[0] = document.theForm.num1.value;
  arr[1] = document.theForm.num2.value;
  arr[2] = document.theForm.num3.value;
  arr[3] = document.theForm.num4.value;
  arr[4] = document.theForm.num5.value;
  arr[5] = document.theForm.num6.value;
  arr[6] = document.theForm.num7.value;
  arr[7] = document.theForm.num8.value;
  arr[8] = document.theForm.num9.value;

  a1 = arr[0]*100 + arr[1]*10 + arr[2]*1;
  a2 = arr[3]*100 + arr[4]*10 + arr[5]*1;
  a3 = arr[6]*100 + arr[7]*10 + arr[8]*1;
  //alert (a1 + "-" + a2 + "-" + a3);
  if ( a1*1 + a2*1 == a3 ) {
    location.replace("http://sakharov.net/puzzle/digitsolved.html?SOLUTION=" + arr[0] + arr[1] + arr[2] + arr[3] + arr[4] + arr[5] + arr[6] + arr[7] + arr[8] );
  } else {
    alert("Incorrect!");
    /*
    document.theForm.num1.value = '';
    document.theForm.num2.value = '';
    document.theForm.num3.value = '';
    document.theForm.num4.value = '';
    document.theForm.num5.value = '';
    document.theForm.num6.value = '';
    document.theForm.num7.value = '';
    document.theForm.num8.value = '';
    document.theForm.num9.value = '';
    */
  }
}

function load_f() {

  var solution = location.search;
  var n = solution.indexOf("SOLUTION=");
  solution = solution.substring(n+9);

      document.theForm.num1.value = solution.charAt(0);
      document.theForm.num2.value = solution.charAt(1);
      document.theForm.num3.value = solution.charAt(2);
      document.theForm.num4.value = solution.charAt(3);
      document.theForm.num5.value = solution.charAt(4);
      document.theForm.num6.value = solution.charAt(5);
      document.theForm.num7.value = solution.charAt(6);
      document.theForm.num8.value = solution.charAt(7);
      document.theForm.num9.value = solution.charAt(8);

}
