
/* Copyright (c) 2004 Timothy Sakharov, Alexander Sakharov */

  var itemText;
  var itemVal;
  var ind;
  var i;
  var j;
  var sum;
  var vol;
  var tmp;
  var arr;


function load_f() {
  arr = new Array(3);
  for ( i = 0; i < 3; i++ ) {
    arr[i] = new Array(3);
	for ( j = 0; j < 3; j++ ) {
	  arr[i][j] = -1000;
	}
  }
}

function check_f() {

    ind = document.theForm.check11.selectedIndex;
    itemValue = document.theForm.check11.options[ind].value;
    if ( itemValue.charAt(0) == '-' ) {
      return;
    } else {
      arr[0][0] = parseInt(itemValue);
    }
    ind = document.theForm.check12.selectedIndex;
    itemValue = document.theForm.check12.options[ind].value;
    if ( itemValue.charAt(0) == '-' ) {
      return;
    } else {
      arr[0][1] = parseInt(itemValue);
    }
    ind = document.theForm.check13.selectedIndex;
    itemValue = document.theForm.check13.options[ind].value;
    if ( itemValue.charAt(0) == '-' ) {
      return;
    } else {
      arr[0][2] = parseInt(itemValue);
    }
    ind = document.theForm.check21.selectedIndex;
    itemValue = document.theForm.check21.options[ind].value;
    if ( itemValue.charAt(0) == '-' ) {
      return;
    } else {
      arr[1][0] = parseInt(itemValue);
    }
    ind = document.theForm.check22.selectedIndex;
    itemValue = document.theForm.check22.options[ind].value;
    if ( itemValue.charAt(0) == '-' ) {
      return;
    } else {
      arr[1][1] = parseInt(itemValue);
    }
    ind = document.theForm.check23.selectedIndex;
    itemValue = document.theForm.check23.options[ind].value;
    if ( itemValue.charAt(0) == '-' ) {
      return;
    } else {
      arr[1][2] = parseInt(itemValue);
    }
    ind = document.theForm.check31.selectedIndex;
    itemValue = document.theForm.check31.options[ind].value;
    if ( itemValue.charAt(0) == '-' ) {
      return;
    } else {
      arr[2][0] = parseInt(itemValue);
    }
    ind = document.theForm.check32.selectedIndex;
    itemValue = document.theForm.check32.options[ind].value;
    if ( itemValue.charAt(0) == '-' ) {
      return;
    } else {
      arr[2][1] = parseInt(itemValue);
    }
    ind = document.theForm.check33.selectedIndex;
    itemValue = document.theForm.check33.options[ind].value;
    if ( itemValue.charAt(0) == '-' ) {
      return;
    } else {
      arr[2][2] = parseInt(itemValue);
    }

    sr = location.search;
    sr = sr.substring(sr.indexOf("SRC="));
    if ( sr.length < 12 || sr.charAt(6) != 'k' || sr.charAt(7) != 'h' ||
    sr.charAt(9) != 'r' || sr.charAt(11) != 'v' ) {
          return;
    }

    for ( i = 0; i < 3; i++ ) {
    	sum = 0;
        vol = 0;
	for ( j = 0; j < 3; j++ ) {
	  sum += arr[i][j];
	}
	if ( sum != 7 ) {
		alert("Incorrect!");
		return;
	}
	vol += 2*arr[i][0];
	vol += arr[i][1];
	if ( vol != 7 ) {
		alert("Incorrect!");
		return;
	}
        sum = 0;
	for ( j = 0; j < 3; j++ ) {
	  sum += arr[j][i];
	}
	if ( sum != 7 ) {
		alert("Incorrect!");
		return;
	}
    }

    location.replace("http://sakharov.net/puzzle/fairsharesolved.html?SEL=" + arr[0][0] + arr[0][1] + arr[0][2] + arr[1][0] + arr[1][1] + arr[1][2] + arr[2][0] + arr[2][1] + arr[2][2]);

}

function load_solved_f() {

  var dim = location.search;
  var n = dim.indexOf("SEL=");

  tmp = parseInt(dim.charAt(n+4));
  //alert (tmp);
  document.theForm.check11.options[0]
        = new Option(tmp, tmp, false, false);
  tmp = parseInt(dim.charAt(n+5));
  document.theForm.check12.options[0]
        = new Option(tmp, tmp, false, false);
  tmp = parseInt(dim.charAt(n+6));
  document.theForm.check13.options[0]
        = new Option(tmp, tmp, false, false);
  tmp = parseInt(dim.charAt(n+7));
  document.theForm.check21.options[0]
        = new Option(tmp, tmp, false, false);
  tmp = parseInt(dim.charAt(n+8));
  document.theForm.check22.options[0]
        = new Option(tmp, tmp, false, false);
  tmp = parseInt(dim.charAt(n+9));
  document.theForm.check23.options[0]
        = new Option(tmp, tmp, false, false);
  tmp = parseInt(dim.charAt(n+10));
  document.theForm.check31.options[0]
        = new Option(tmp, tmp, false, false);
  tmp = parseInt(dim.charAt(n+11));
  document.theForm.check32.options[0]
        = new Option(tmp, tmp, false, false);
  tmp = parseInt(dim.charAt(n+12));
  document.theForm.check33.options[0]
        = new Option(tmp, tmp, false, false);

}




