function crossword_loc2(prefix, suffix) {
    document.getElementById(prefix + suffix).focus()
}

/* This function needs a mov2 analogous to loc2 */
/* Also, tabbing is working really horribly */
function crossword_move(number) {
    if (document.getElementById("square" + number).value.length == 1) {
	document.getElementById("square" + number).value = document.getElementById("square" + number).value.toUpperCase()
	newnumber = 1 + number
	/*alert(number + " " + newnumber)*/
        document.getElementById("square" + newnumber).focus()
    }
    return true
}

function crossword_mov3(ev, row, column, changetype) {
    var e = ev ? ev : window.event
	if (!e.target) //if event obj doesn't support e.target, presume it does e.srcElement
	    e.target = e.srcElement //extend obj with custom e.target prop
    /* If xw_solution is defined, call check_square with the target element. */
		if ((typeof xw_solution != 'undefined') && (typeof document.getElementById("xwfeed1") != 'undefined') && document.getElementById("xwfeed1").checked) {
        check_square(e.target)
		}

    /* If onChange was triggered (changetype = c) and the length of the field is less than one, we don't want to move the cursor or uppercase the field, so just return. */
    if (changetype == 'c' && e.target.value.length < 1) {return true}

    /* If the key being released is Shift, Control, or Alt, don't do anything. */
    if (changetype == 'k' && (e.keyCode == 16 || e.keyCode == 17 || e.keyCode == 18)) {return true}

    /* Uppercase the value of the field. */
    e.target.value = e.target.value.toUpperCase()

    /* If the "Do nothing" button is selected, don't do anything else unless this event represents an arrow being pressed */
    if (document.getElementById("xwmoveform").xwmove[0].checked == true && (changetype != 'k' || (e.keyCode < 37 || e.keyCode > 40))) {return true}

    /* If this event represents a key press, and the key was a tab, let the browser handle it. */
    else if (changetype == 'k' && e.keyCode == 9) {return true}
    /* Determine where to move the cursor.  Check if this is an arrow key press first. */
    else if (changetype == 'k' && e.keyCode == 40) {row++} /* Down */
    else if (changetype == 'k' && e.keyCode == 39) {column++} /* Right */
    else if (changetype == 'k' && e.keyCode == 38) {row--} /* Up */
    else if (changetype == 'k' && e.keyCode == 37) {column--} /* Left */
    /* It isn't.  If there's now nothing in the field, don't do anything. */
    else if (e.target.value.length == 0) {return true}
    /* It isn't.  Check the status of the radio button. */
    else if (document.getElementById("xwmoveform").xwmove[1].checked == true) {column++} /* Move to the right */
    else if (document.getElementById("xwmoveform").xwmove[2].checked == true) {row++} /* Move down */

    /* If the target element doesn't exist, move along. */
    if (!document.getElementById("r" + row + "c" + column)){return true}

    /* Set the focus to the input element within this cell. */
    var worktext = document.getElementById("r" + row + "c" + column).innerHTML
        //alert("1: " + changetype + " " + worktext)
    worktext = worktext.substr(worktext.indexOf("id=") + 3)
	//alert("2: " + changetype + " " + worktext)
    if (worktext.substr(0, 1) == '"'){worktext = worktext.substr(1)}
    //alert("3:" + changetype + " " + worktext)
    var workstr1 = worktext.indexOf('"')
    var workstr2 = worktext.indexOf('>')
    var workstr3 = worktext.indexOf(' ')
    if (workstr1 == -1) {workstr1 = 999}
    if (workstr2 == -1) {workstr2 = 999}
    if (workstr3 == -1) {workstr3 = 999}
    var strpos = Math.min(workstr1, Math.min(workstr2, workstr3))
    worktext = worktext.substr(0, strpos)
	//	alert("4: " + changetype + " " + worktext)
    document.getElementById(worktext).focus()
    return true
}

function check_square(squareobj) {
    squareobj.style.background = ""

    /* Assume the id starts with "square". */
    var squarenumber = squareobj.id.substr(6)
    if (squareobj.value == "")
        return(0)

    if (xw_solution.substr(squarenumber - 1, 1) != squareobj.value.toUpperCase())
        squareobj.style.background = "#ff8888"
}

function fillSolution(correct_answer) {
    for (var i = 1; i <= correct_answer.length; i++) {
	document.getElementById("square" + "" + i).style.background = ""
	document.getElementById("square" + "" + i).value = correct_answer.substr(i - 1, 1)
    }
}

function check_square2(targElem) {
    if ((typeof xw_solution != 'undefined') && (typeof document.getElementById("xwfeed1") != 'undefined') && document.getElementById("xwfeed1").checked)
        check_square(targElem)
}

