
/* Copyright (c) 2004 Timothy Sakharov, Alexander Sakharov */

  var itemText;
  var itemVal;
  var ind;

  var i;
  var tmp;
  var sr;
  var currentVal;
  var incVal;
  var newVal;
  var keys = new Array(9);
  var flag;
  var state;

function load_f() {
	state = 0;
	keys[0] = 1;
	keys[1] = 12;
	keys[2] = 23;
	keys[3] = 34;
	keys[4] = 45;
	keys[5] = 56;
	keys[6] = 67;
	keys[7] = 78;
	keys[8] = 89;
}

function increase_f() {

    if ( state == 1 ) {
      alert("Please wait");
      document.theForm.increase.selectedIndex = 0;
      return false;
    }

    curVal = parseInt(document.theForm.current.options[0].value);

    ind = document.theForm.increase.selectedIndex;
    itemText = document.theForm.increase.options[ind].text;
    itemValue = document.theForm.increase.options[ind].value;
    if ( itemValue.charAt(0) == '-' ) {
      alert("Incorrect selection");
      return false;
    }
    incVal = parseInt(itemValue);

    newVal = curVal + incVal;
    //alert(newVal);
    if ( newVal > 100 ) {
      alert("You called number > 100");
      return false;
    }

    sr = location.search;
    sr = sr.substring(sr.indexOf("SRC="));

    if ( sr.length < 12 || sr.charAt(5) != 'a' || sr.charAt(7) != 'h' ||
    sr.charAt(8) != 'a' || sr.charAt(11) != 'v' ) {
          return false;
    }

    if ( newVal == 100 ) {
	location.replace("http://sakharov.net/puzzle/reach100solved.html?SRC=sakharov");
   	return true;
    }

    document.theForm.current.options[0] = null;
    document.theForm.current.options[0]
        	= new Option("*"+newVal+"*", "*"+newVal+"*", false, false);

    document.theForm.increase.selectedIndex = 0;
    state = 1;
    setTimeout("computer_f();", 3000);
}

function computer_f() {
	curVal = newVal; //parseInt(document.theForm.current.options[0].value);
	//alert(curVal);
	for ( i = 0; i < 9; i++ ) {
		if ( curVal == keys[i] ) {
			newVal = curVal + Math.floor((Math.random()-0.001)*10) + 1;
			document.theForm.current.options[0] = null;
    			document.theForm.current.options[0]
        			= new Option(newVal, newVal, false, false);
			state = 0;
			return true;
		} else if ( curVal > keys[i] ) {
			if ( i < 8 && curVal >= keys[i+1] )
				continue;
			if ( i == 8 ) {
				document.theForm.current.options[0] = null;
    				document.theForm.current.options[0]
        				= new Option(100, 100, false, false);
				state = 0;
				return true;
			} else {
				newVal = keys[i+1];
				document.theForm.current.options[0] = null;
    				document.theForm.current.options[0]
        				= new Option(newVal, newVal, false, false);
				state = 0;
				return true;
			}
		}
	}
}

function startover_f() {
	state = 0;
	document.theForm.increase.selectedIndex = 0;
	document.theForm.current.options[0] = null;
	document.theForm.current.options[0]
        	= new Option(0, 0, false, false);
}



