//CHECKJS  C:\temp\sudoku\useraction.js 11/6/2005 12:30:11 PM
//useraction.js hansonr@stolaf.edu 7:00 AM 10/28/2005
// handles all user interaction

pageTitle = "Sudoku Assistant/Solver"
baseRef = "index.htm"
iReportChains = 1
iShowAnswers = 1
ishowdetail = 0
ishowweaklinks = true
enableUserEntry = 1
userDefinedEdges = []
userEdgeList=""

function doAll(){
	idonotstop=1
	eliminationmsg=""
	doStep(1,1)
	idonotstop=0
}

function doGetMatrix(iscondensed){
	if(!ihavemarks)showMarks(true)
	var s=(iscondensed?getRuud():get729x324())
	docWrite("<html><body>"+s+"</body></html>")
}
	
lastautorun=520
function doAutoRun(i){

	var d=document.getElementById("selection")
	var M={}
	if(i<0){
		i=d.selectedIndex
		if(i<0)i=0
		AutoMsgs = []
		MethodExamples = {}
		autoTitle = ""
		istoprun=0
		nautorun=0
		nautosolved=0
		autoPrefix = prompt("Prefix code?",autoPrefix)
	}
	if(!d[i]||istoprun||i==lastautorun){
		//don't use unShift
		AutoMsgs = AutoMsgs.reverse();AutoMsgs.push(addAutoMsg("-"));AutoMsgs.reverse()
		isautorun=0
		logMessage(AutoMsgs.join(""),1)
		return
	}
	d.selectedIndex=i
	var s=AutoMsgs.join("");
	doLoadBlock(0,d[i].text.split(": ")[1])
	isautorun=i+1
	nautorun++
	AutoMsgs = [s];
	AutoMsgs.push("<hr>Puzzle #"+isautorun +" Solving <br>\n"+getRef(1,NUMLINEARP,1)+getRef(1,NUM9x9LINES,1)+"<br>\n")
	autoTitle = getRef(1,NUMLINEAR0,0)
	doSolve()
}

var clickTrigger = 0

function doClick(i,j,n){

//alert([i,j,n,"doClick"])

	var k=0
	if(n){
		Data[i][j].N=n
		getNextStep(0)
		if(showingthisn)doShow(n)
		clickTrigger = 1;setTimeout("clickTrigger=0",100);
	}else if(onlythisn){
		var s=prompt("Do you want to delete this possibility?","yes")
		if(s!="yes")return
		k=onlythisn-1
		Data[i][j].Impossible[k]=onlythisn
		if(showingthisn){
			getNextStep(0)
			doShow(n)
		}else{
			createTable(1)
		}
	}else if(!Data[i][j].isopen && !clickTrigger){
		var ishow = ihavemarks
		if (haveopencells){
			createTable(1)
			if (ishow)showMarks(true)
		}
		Data[i][j].isopen=1
		createTable(ishow ? 3 : 2)
		document.getElementById("cell"+i+j).focus()
		document.getElementById("cell"+i+j).select()
	}
}

function doEntry(){
	saveRef()
	getValues()
	clearDivs()
	for(var i=0;i<9;i++)for(var j=0;j<9;j++)Data[i][j].isopen=!Data[i][j].fixed
	logMessage("",1)
	createTable(0)
}

function doEntryReturn(){
	createTable(1)
}

function doHint(issilent){
	ishint=1
	greenlist=bluelist=yellowlist=redlist=redlistk=""
	lastmsg=""
	getStrongChains(1)
	getWeakNodes(1)
	getWeakLinks(1)
	HintTable=[getRef(1,NUMTABLE,1),getRef(1,NUMCHAINTABLE,1),dumpWeakLinks()]
	var T=[]
	getTableRef(T)
	getNextStep(1,0,0,1)
	setMarks(T)
	var T=[]
	getTableRef(T,0,1)
	ishint=0
	document.title=lastmsg
	if(issilent)return
	if(lastmsg=="" && redlist)lastmsg="cells with only one possible value are marked in red"
	if(lastmsg)logMessage(lastmsg,1,0,"dohint")
}


function doInit(){
	doInit2()
}

function doInit2(s){
	document.getElementById("info").reset()
	if (arguments.length==0){
		s=document.location.search
		s=unescape(s.substring(1))
	}
	var is3d=(s.indexOf("MODE=3D")>=0)
	if (is3d)s=s.replace(/MODE\=3D/,"")

        var showonly = 0;
        for (var i = 1; i <= 9; i++)if(s.indexOf("SHOWONLY=" + i)>=0) {
          showonly = i;break;
        }

	var isquiet = (s.indexOf("SHH")>=0)
	if (isquiet)s = s.replace(/SHH/g,"")

	ishowweaklinks = (s.indexOf("DONTSHOWWEAKLINKS")<0)
	if (!ishowweaklinks)s = s.replace(/DONTSHOWWEAKLINKS/g,"")

	idosashimi = (s.indexOf("NOSASHIMI")<0)
	if(!idosashimi)s=s.replace(/NOSASHIMI/g,"")

	idoglyphs = (s.indexOf("GLYPHS")>=0 && s.indexOf("NOGLYPHS")<0)
	if(idoglyphs)s=s.replace(/NOGLYPHS/g,"").replace(/GLYPHS/g,"")

	idoalslarge = (s.indexOf("ALSLARGE")>=0)
	if(idoalslarge)s=s.replace(/LARGE/g,"")

	idoalscolumns = (s.indexOf("NOALSCOLUMNS")<0)
	if(!idoalscolumns)s=s.replace(/NOALSCOLUMNS/g,"")

	idoalsonly = (s.indexOf("ALSONLY")>=0)
	if(idoalsonly)s=s.replace(/ALSONLY/g,"")

	itransposemarks = (s.indexOf("TRANSPOSE")>=0)
	if(itransposemarks)s=s.replace(/TRANSPOSE/g,"")

	if (s.indexOf("ALLMARKS")>=0) {
		s.replace(/ALL/g,"")
		ishowallmarks = true
	}

	var dohint = (s.indexOf("HINT")>=0)
	if(dohint)s=s.replace(/HINT/g,"")


	var msg = ""
	if(s.indexOf("HINGE")>=0){
		s=s.replace(/HINGE/g,"")
		document.getElementById("chk_h").checked=1
		msg +="\nHinge analysis is enabled."
	}

	if(s.indexOf("ALSX")>=0){
		s=s.replace(/ALSX/g,"")
		document.getElementById("rad_ax").checked=1
		msg +="\nX-type almost-locked set analysis is enabled."
	}
	if(s.indexOf("ALSY")>=0){
		s=s.replace(/ALSY/g,"")
		document.getElementById("rad_ay").checked=1
		msg +="\nY-type almost-locked set analysis is enabled."
	}
	if(s.indexOf("ALSB")>=0){
		s=s.replace(/ALSB/g,"")
		document.getElementById("rad_ab").checked=1
		msg +="\nB-type almost-locked set analysis is enabled."
	}
	if(s.indexOf("ALS")>=0){
		s=s.replace(/ALS/g,"")
		document.getElementById("rad_ab").checked=1
		document.getElementById("rad_ax").checked=1
		document.getElementById("rad_ay").checked=1
		msg +="\nFull almost-locked set analysis is enabled."
	}
	if(s.indexOf("STRONGSETS")>=0){
		s=s.replace(/STRONGSETS/g,"")
		document.getElementById("chk_sx").checked=1
		msg += "\n3D Medusa will look for strong sets."
	}
	if(s.indexOf("STRONG")>=0){
		s=s.replace(/STRONG/g,"")
		document.getElementById("chk_s").checked=1
		msg += "\n3D Medusa will only use strong chains."
	}
	if(s.indexOf("WEAK")>=0){
		s=s.replace(/WEAK/g,"")
		document.getElementById("chk_w").checked=1
		msg += "\n3D Medusa will not hypothesize."
	}
	if(s.indexOf("COLORONLY")>=0||s.indexOf("XCYCLESONLY")>=0){
		s=s.replace(/COLORONLY/g,"").replace(/XCYCLESONLY/g,"")
		document.getElementById("chk_cx").checked=1
		msg += "\n3D Medusa will only look for X cycles (single-value coloring)."
	}
	if(s.indexOf("YCYCLESONLY")>=0){
		s=s.replace(/YCYCLESONLY/g,"")
		document.getElementById("chk_cy").checked=1
		msg += "\n3D Medusa will only look for Y cycles (cells with only two possible values)"
	}
	if(s.indexOf("EDGESONLY")>=0){
		s=s.replace(/EDGESONLY/g,"")
		document.getElementById("chk_e").checked=1
		msg += "\n3D Medusa will only look for edges (columns, rows, and blocks with only two possibilities for a given value)"
	}
	if (msg != "" && !isquiet)alert(msg)

	if(s.indexOf("EDGES=")>=0)
		userEdgeList = s.split("EDGES=")[1].split("&")[0]
	if(s.indexOf("DEMO=")>=0){
		showDemo(s.split("DEMO=")[1].split("&")[0])
	}else if(s.indexOf("LOAD=")>=0){
		s=s.split("LOAD=")[1].split("&")[0]
		if(s.indexOf("top")==0 || s.indexOf("impossible")==0){
			loadData("data/" + s.replace(/\./,".htm?"))
			return
		}
		if(s.indexOf(",")>=0){
			doLoad(s)
		}else{
			doLoadBlock(0,s)
		}
	}else if(s.indexOf("MARKS=")>=0){
		loadMarks(getField(s, "MARKS"))
		if(s.indexOf("DOSTEP=1")>=0)doStep(1,1)
		if (s.indexOf("CHAIN1=")>=0){
			ishowchain=parseInt(getField(s, "CHAIN1"))
			if (s.indexOf("CHAIN2=")>=0)ishowchain2=parseInt(getField(s, "CHAIN2"))
			doLoadBlock(-4)
		}
	}else{
		s=s.replace(/t/g,",,,")
		if(s=="")s=DEFAULTPUZZLE
		if(s.indexOf(",")<0)s=toAssistantMode(s)
		LinearData=s.split(",")
		setData()
		if(LinearData.length>1){
			getNextStep(1,0,1)
			showMarks(false)
		}else{
			doClear()
		}
	}
	if(dohint)
		doHint(true)
	else if(is3d){
		if (!isquiet)alert("After the applet has loaded, drag the model around with your mouse. The initial perspective is normal, but with the number 1 closest to you and the number 9 furthest from you.")
		doView3D(10,showonly)
	}
}window.onload=doInit

function getField(s, what) {
	return (s.indexOf(what + "=") >= 0 ? s.split(what + "=")[1].split("&")[0] : "")
}

function doLearn(ishow){
	if(!ishow){
		document.getElementById("learn").style.display="none"
		document.getElementById("credits").style.display="block"
		document.getElementById("sudoku").style.display="block"
		document.getElementById("chains").style.display="block"
		document.getElementById("glyphs").style.display="block"
		document.getElementById("appbuttons").style.display="block"
		return
	}
	document.getElementById("numberblock").style.display="none"
	document.getElementById("selectspan").style.display="none"
	document.getElementById("apphere").style.display="none"
	document.getElementById("sudoku").style.display="none"
	document.getElementById("credits").style.display="none"
	document.getElementById("chains").style.display="none"
	document.getElementById("glyphs").style.display="none"
	document.getElementById("appbuttons").style.display="none"
	document.getElementById("learn").style.display="block"
}

function doLoad(s){
	isdemo=0
	isjmolreset=1
	thisslicen=0
	thisr_or_c=0
	lastdisplay=lastmsg=""
	if (s.indexOf("MARKS=")==0) {
		loadMarks(s.substring(6))
		return
	}
	LinearData=s.replace(/t/g,",,,").split(",")
	setData()
	getNextStep(1,0,1)
	if(!isautorun)showMarks(false)
}

prevBlock=""
function doLoadPreviousBlock(){
	document.getElementById("blockinput").value=prevBlock
}
	
function doLoadBlock(issolution,sblock){
	var s=""
	var sout=""
	var isnew=!sblock
	isjmolreset=1
	thisslicen=0
	thisr_or_c=0
	if(issolution==-2){ //number block
		showDataBlock()
		document.getElementById("numberblock").style.display="block"
		document.getElementById("selectspan").style.display="block"
		document.getElementById("sudoku").style.display="none"
		document.getElementById("glyphs").style.display="none"
		document.getElementById("chains").style.display="none"
		document.getElementById("apphere").style.display="none"
		document.getElementById("learn").style.display="none"
		thisviewmode="input"
		return
	}else if(issolution==-1){ //standard view
		if(thisviewmode=="sudoku")doShow(0)
		document.getElementById("numberblock").style.display="none"
		document.getElementById("selectspan").style.display="none"
		document.getElementById("apphere").style.display="none"
		document.getElementById("sudoku").style.display="block"
		document.getElementById("glyphs").style.display="block"
		document.getElementById("chains").style.display="block"
		document.getElementById("learn").style.display="none"
		if(thisviewmode=="jmol" && thisslicen){
			thisviewmode="sudoku"	
			doShow(thisslicen>=0?thisslicen:0)
		}
		thisviewmode="sudoku"
		return
	}else if(issolution==-3 || issolution==-4){ //chain view
		greenlist=(issolution == -3 ? "NOSHOW" : "")
		redlist=redlistk=yellowlist=""
		if(thisviewmode=="sudoku"){
			doShow(0)
		}else if(thisviewmode=="jmol"){
			thisslicen=0
			thisr_or_c=0
			isjmolreset=0
			dorotatemodel=0
			create3DModel()
			return
		}else if(thisviewmode=="input"){
			doLoadBlock(-1)
		}
		if(ishowchain==0)return
		document.title=s="Chain "+ishowchain+": "+getChainListing(ishowchain)
		logMessage(s+"<br>",0,1)
		return
	}
	if(isnew)prevBlock=sblock=document.getElementById("blockinput").value
	if(sblock.indexOf("[Puzzle]")>=0){
		sout=readSDKdata(sblock)
		doLoadBlock(-1)
		showMarks(true)
		loadMarks(sout)
		doLoadBlock(-1)
		return
	}
	if("\n\r".indexOf(sblock.charAt(0))>=0)sblock=sblock.substring(1,sblock.length)
	if(issolution){
		s=sblock.replace(/\D/g,"")
		if(s.length!=81){
			alert(s.length+" is not the 9x9 numbers required for a solution:" +s)
			return
		}
	}
	if(sblock.indexOf("MARKS=")==0){
		loadMarks(sblock.split("=")[1])
		return
	}
	sout=toAssistantMode(sblock,issolution)
	if(sout.indexOf("[")==0){
		doLoadBlock(-1)
		showMarks(true)
		loadMarks(sout)
	}else{
		doLoad(sout)
	}
	if(isnew)doLoadBlock(-1)
}

function doLoadSelection(n){
	var d=document.getElementById("selection")
	var i=(n ? n - 1 : d.selectedIndex)
	if(i<0 || i>=d.length)i=0
	doLoadBlock(0,d[i].text.split(": ")[1])
}

function doNumberFormat(n){
	numberformat=n
	showDataBlock()
}

function doClear(){
	LinearData=[]
	RefList=[]
	setData()
	saveRef()
	doEntry()
}

function doSet(){
	if (haveopencells) {
		var ishow = ihavemarks
		createTable(1)
		if (ishow)showMarks(true)
		return
	}
	clearDivs()
	setPuzzle()
	userdisallowslist=""
	createTable(isdemo?0:1)
}

function doSetValues(){
	if(!createTable(1))showMarks(true)
}

function doSetFullAnalysis(isall){
	document.getElementById("rad_c").checked=isall
	document.getElementById("rad_s").checked=isall
	document.getElementById("chk_x").checked=isall
	document.getElementById("chk_c").checked=1
	document.getElementById("chk_h").checked=1
	document.getElementById("chk_cxy").checked=1
	document.getElementById("chk_l").checked=1
	document.getElementById("chk_ld1").checked=1
	document.getElementById("chk_ld2").checked=1
}

function doShow(n){
	if(n>0)greenlist=bluelist=yellowlist=redlist=redlistk=lastmsg=""
	if(n < 0){
		document.getElementById('nselect').selectedIndex=0
		redlist=redlistk=""
		n=0
	}
	thisslicen=n
	thisr_or_c=0
	isjmolreset=0
	dorotatemodel=0
	if(thisviewmode=="jmol"){
		create3DModel(n)
		return
	}
	createTable(-n)
	showingthisn=n
}

function doShowLogicTable(stable,hypothesis,conclusion,isave,coord){
	var ch0=hypothesis.substring(0,1)
	var ch1=conclusion.substring(0,1)
	var T=stable.split(",")
	var s=getNumericalTable(T,ch0,ch1,coord)
	s="<pre style='font-size:12pt'>"+s+"</pre>"
	s="<font color=blue>"+hypothesis+"</font><br /><font color=red>"+conclusion+"</font>"+s
	s+=getMarkLink("load this puzzle",T)
	s+=LogicSave[isave]
	docWrite("<html><body>"+s+"</body></html>")
}

function doShowChain(ichain){
	var i = parseInt(document.getElementById("chainselect")[document.getElementById("chainselect").selectedIndex].value)

	var isweak = ishowweaklinks//document.getElementById("chainweak").checked
	idontshowchain=0
	ishowchain2=0
	if(arguments.length == 0) {
		ichain=i
	} else if(ichain == -1) {
		//off
		document.getElementById('chainselect').selectedIndex=0
		ichain = 0;
	} 
	if (isweak)idontshowchain=ichain
	if (isNaN(ichain))ichain=0
	ishowchain=ichain
	doLoadBlock(-3)
}

function doShowMarks() {
	showMarks(!ihavemarks || onlythisn)
}

function doShowRunLog(){
	var x="~"//prompt("Identifying character for summary table?",tableid)
	if(!x)x="~"
	tableid=x=x.charAt(0)
	docWrite((isautorun?addAutoMsg("-",x):"")+AutoMsgs.join("").replace(/a href/g,"a name"))
}

function doShowTextDiv(){
	docWrite(document.getElementById("logmsg").innerHTML.replace(/href/g,"name"))
}

function doShowTable(ischaintable){
	if(!ihavemarks)showMarks(true)
	var s=(HintTable.length?HintTable[ischaintable]:getRef(1,(ischaintable?NUMCHAINTABLE:NUMTABLE),1))
	var s2=(ischaintable && HintTable.length?HintTable[2]:"")
	if(ischaintable && !HintTable.length){
		getWeakNodes(1)
		getWeakLinks(1)
		s2=dumpChainList()+dumpWeakLinks()+dumpImpliedWeakLinks()
		if(idostronggroups)s2="<br>NOTE: chain node sets indicated in {} below are not shown on the table above"+s2
		if(StrongChains.length>26)s=" NOTE: There are more than 26 chains. Some letters may represent two different chains. "+s
	}
	docWrite("<html><body>"
		+s+getMarkLink("load this puzzle")
		+s2
		+"<pre>"+getRef(true,NUMSDK,false)+"</pre>"
		+"</body></html>")
}

function doShowSnapShot(i){
	var s=getNumericalTable(SnapShot[i],0,0,0,0)
	var s2=getMarkLink("[load snapshot"+(i?" #"+i:"")+"]<br />",SnapShot[i])
	docWrite("<html><body><pre>"+s+"</pre>"+s2+" solving "+ref0+"</body></html>")
}


function doSolve(){
	if(!isautorun)AutoMsgs = []
	addAutoMsg("")
	RefList=[]
	lastdisplay=lastmsg=""
	solving=1
	FullMsgs=[]
	logMessage("",1)
	isdone=0
	doStep(1)
}

function doStep(iscontinuation,isuserclick){

	document.getElementById("outertable").style.bgColor = "red"
	lastmsg=""
	if(nsteps==0 && solving && !ihavechecked){
		getNextStep(0,0,1)
		solving=1
	}
	if(FullMsgs.length==0){
		ref0=getRef(1,0,1)
	}
	nsteps++
	var n=updateAllowed(iscontinuation)
	if(isuserclick){
		isautorun=0
		AutoMsgs = []
		logMessage("",1,0,"dostep1")
		addAutoMsg("")
	}
	if(n && !solving){
		greenlist=bluelist=yellowlist=redlist=redlistk=""
		crossCheckAll() //set the Possible[] array
		createTable(0)
	}else if(!solving && !ihavechecked){
		doHint(1)
	}else{
	//			testchain=ishowchain
		saveRef()
		ishowchain=0
		getNextStep(1,iscontinuation)
	}
	if(isuserclick)showLastMessage()
	if(solving)setTimeout("doStep(1)",10)
}

function showLastMessage(){
	document.title=lastmsg
}

function doUndo(){
	//logMessage(RefList.join("\n"))
	if (RefList.length==1)return;
	thisStepRef=RefList.pop();
	isdemo=0
	isjmolreset=1
	thisslicen=0
	thisr_or_c=0
	lastdisplay=lastmsg=""
	loadMarks(thisStepRef)
	RefList.pop()
}

function doUnset(){
	clearData()
	createTable(1)
	logMessage("",1)
}

// user interface methods

function doGoFast() {
	return (document.getElementById("chk_f").checked?1:0)
}

function getSudokuValue(i, j) {
	return document.getElementById("cell"+i+j).value
}

function setSelectBox(s) {
	document.getElementById("selectspan").innerHTML=s
}

function showDataBlock(){
	var s = getRef(1)
	document.getElementById("blockinput").value=s
	document.getElementById("blockinput").style.fontSize = 
		(s.indexOf("================") >=0 ? "5pt" : "10pt")
}

function showRef(){
	//note -- duplicated in useractiona.js (analysis.htm) and useractionp.js (popup.htm)
	//theref=(userdisallowslist=="" ? getRef(1,NUMBEST) : "MARKS=" + getRef(1,NUMMARKSFIXED))
	theref= getCheckBoxOptions()
		+ (userEdgeList!=""? "EDGES="+userEdgeList+"&" : "") 
		+ (ihavemarks ? "MARKS=" + getRef(1,NUMMARKSENCODED) : getRef(1,NUMBEST))
	if(theref.replace(/\,/g,"")=="" && theref.indexOf("0")<0){
		theref=""
	}else{
		while(theref.charAt(theref.length-1)==",")theref=theref.substring(0,theref.length-1)
		theref="?"+theref
	}
	document.getElementById("analystlink").href="analyst.htm"+theref.replace(/,,,/g,"t")+"&CHECK=1"
	theref="index.htm"+theref
	document.getElementById("savelink").href=theref
	var s = "http://www.scanraid.com/sudoku.htm?bd=" + getRef(true, NUMLINEAR0, false)
	document.getElementById("andrewStuartLink").href=s
}

function checkOptions(){

	icheckcross=1
	icheckranges=(document.getElementById("rad_c").checked?1:0)
	ichecksubs=(document.getElementById("rad_s").checked?1:0)
	icheckgrids=(document.getElementById("chk_x").checked?1:0)
	igetalmostlockedy=(ichecksubs && document.getElementById("rad_ay").checked?1:0)
	igetalmostlockedx=(icheckgrids && document.getElementById("rad_ax").checked?1:0)
	igetalmostlockedb=(icheckranges && document.getElementById("rad_ab").checked?1:0)

	icheckmedusa=(document.getElementById("chk_c").checked?1:0)
	icheckweaklinks=(icheckmedusa && document.getElementById("chk_w").checked?1:0)
	icheckhinge=(icheckmedusa && document.getElementById("chk_h").checked?1:0)
	ishowtimings=(document.getElementById("chk_t").checked?1:0)
	icheckmagic=(document.getElementById("chk_m").checked?1:0)


	icheckforwardlogic=(icheckmedusa && document.getElementById("chk_l").checked?1:0)
	icheckreverselogic=(icheckmedusa && document.getElementById("chk_lr").checked?1:0)
	if(icheckreverselogic||icheckforwardlogic)icheckweaklinks=1

	isedgesonly=(document.getElementById("chk_e").checked?1:0)
	idostronggroups=(document.getElementById("chk_sx").checked?1:0)
	ijustcolor=(document.getElementById("chk_cx").checked?1:0)
	isjustycycles=(document.getElementById("chk_cy").checked?1:0)
	if(icheckreverselogic)document.getElementById("chk_ld2").checked=document.getElementById("chk_ld1").checked=0
	ichecklogicsubsets=(document.getElementById("chk_ld2").checked?1:0)
	if(ichecklogicsubsets)document.getElementById("chk_ld1").checked=1 //radio emulation, sort of
	ichecklockedcandidates=(document.getElementById("chk_ld1").checked?1:0)
 	idolog=(document.getElementById("chk_log").checked?1:0)


	iclearlog=(document.getElementById("chk_f").checked?1:0)
	ishowdetail=(document.getElementById("chk_d").checked?1:0)

}


function isDone() {
	//no action
}


function doShowStrongChains() {
	if(StrongChains.length && iReportChains)logAddMessage((StrongChains.length-1)+" strong chains")
	if(ishowdetail)dumpChains(0,1)
}


function showStepSelect(marks) {
	var s = ""
	var n = 0
	for (var i = 1; i < SnapShot.length; i++){
		var t = compressMarks(SnapShot[i])
		s+="<option value='"+i+"'"+(t==marks ? " selected ":"")+">Step "+(++n)+"</option>"
	}

/*

	if(thisPt == 1)thisPt=2
	for (var i=thisPt;i < RefList.length; i++){
		var t = RefList[i]
		var pt = list.indexOf(t)
		if (pt>=0) {
			pt = s.indexOf(t)
			if (t == marks && s.indexOf("selected") < 0)
				s=s.substring(0, pt + t.length + 1) + " selected" + s.substring(pt + t.length + 1)
		} else {
			s+="<option value='"+t+"'>Step "+(++n)+"</option>"
			list += t + "|"
		}
	}

*/
	s = "<select id='stepselect' style='width:80px' onkeyup=\"setTimeout('loadSnapShot('+value+')',100)\" onchange=\"loadSnapShot(value)\"><option value='x'>"+n+" step"+(n == 1 ? "":"s")+"</option>" + s + "</select>"
	document.getElementById("stepselectspan").innerHTML = s

}

function showChainSelect() {
	var n = Math.max(StrongChains.length - 1, 0)
	var s="<select id='chainselect' style='width:80px' onkeyup=\"setTimeout('doShowChain()',100)\" onchange=doShowChain()><option value='0'>"+n+" chain"+(n==1 ? "" : "s")+"</option>"
	var n=0
	for(var i=1;i<StrongChains.length;i++){
		s+="<option value='"+i+"'>Chain "+i+"</option>"
		n++
	}
	s += "</select> <a href=javascript:doShowChain(-1)>off</a> "
//	s += "</select> <label><input type='checkbox' id='chainweak' onclick=\"setTimeout('doShowChain()',100)\">weak</label> "
	s += getNSelect()
	document.getElementById("chainselectspan").innerHTML = s
}

function getNSelect() {return ""}

function getYAdjust() {
  var y = document.getElementById("jmol").offsetHeight
  y += document.getElementById("credits").offsetHeight
  y += document.getElementById("bottominfo").offsetHeight
  y += document.getElementById("glyphs").offsetHeight
  return y
}

function clearDivs(){
	thisLogMessage = ""
	ishowchain=0
	ishowchain2=0
	document.getElementById("chains").innerHTML=""
	document.getElementById("chains").style.display="block"
	SnapShot = new Array()
	StrongChains=new Array()
	showStepSelect("XX")
	showChainSelect()
}


function setUserEdges(slist){
 // rck_rck;rck_rck;rck_rck....
	userDefinedEdges=[]
	var S = slist.split(";")
	for (var i = 0; i < S.length; i++)setUserEdge(S[i])
}

function setUserEdge(ijk_ijk){
	if (ijk_ijk.length < 7)return
	userDefinedEdges[userDefinedEdges.length] = [
		dataNode(parseInt(ijk_ijk.charAt(0)),parseInt(ijk_ijk.charAt(1)),parseInt(ijk_ijk.charAt(2))),
		dataNode(parseInt(ijk_ijk.charAt(4)),parseInt(ijk_ijk.charAt(5)),parseInt(ijk_ijk.charAt(6)))
	]
}

var ihaveglyphtable = false

function setSudoku(s) {
	document.getElementById("sudoku").innerHTML=s
	d = document.getElementById("glyphs")
	if (!d || d.style.display!="block")return
	if (!ihaveglyphtable) {
		d.innerHTML=getGlyphTable()
		ihaveglyphtable = true
	}
	setGlyphs(ihavemarks)
	for(var k=0;k<9;k++){
		d=document.getElementById("s"+(k+1))
		if (d)d.title=Possible.N[k]+" possibilit"+(Possible.N[k]==1?"y":"ies")
	}
}


