<!-- 
function Initialize_Hanoi(){
}


for(j=1;j<4;j++){
for(i=1;i<13;i++){
eval('Gold_' + j + '_' + i + '= new Image()')}}

for(j=1;j<=12;j++){
eval("Gold_" + j + '=new Image()')
eval("Gold_" + j + '.src= "img/gold_' + j +'.gif"')
}

Gold_Base = new Image()
Gold_Base.src="img/gold_base.gif"
Gold_Blank = new Image()
Gold_Blank.src="img/max_blank.gif"

PAUSE = false
MAX_REPORT = false
RUNNING = false

function Max_Solve(){
if(PAUSE){document.forms.max.max_status.value="The module is in a PAUSE mode!";return}
RUNNING = true
PLATFORMS_MAX = new Array("","Origin","Spare","Destination")
TXT =""
Max_Accept()
Max_Arrange()
if(Mode_max == 'min'){Solve_Max_Min();return}
Solve_Max_Max()
}

function Solve_Max_Min(){
Initialize_Max_Min()
DOIT_Max_Min()
}

function Initialize_Max_Min(){
N = Math.pow(2,n) -1
TXT =""	
a = 1
A =PLATFORMS_MAX[a]
b = 3
B = PLATFORMS_MAX[b]
c = 2
C = PLATFORMS_MAX[c]

var n2 = n%2
if(n2 == 0){
	parity = 'Even'
	PATTERN = '(' + A + ',' + C + ',' + B + ',' + A+', ......)'
	Next_1 = new Array()
	Next_2 = new Array()
	Next_1[a] = c
	Next_1[b] = a
	Next_1[c] = b
         Next_2[a] = b
	Next_2[b] = c
	Next_2[c] = a
   		}

else {parity = 'Odd'
	PATTERN = '(' + A + ',' + B + ',' + C + ','+ A + ', ......)'
	Next_1 = new Array()
	Next_2 = new Array()
	Next_1[a] = b
	Next_1[b] = c
	Next_1[c] = a
	Next_2[a] = c
	Next_2[b] = a
	Next_2[c] = b		
			}
Content[a] = ""
Content[b] = ""
Content[c] = ""
sa =""
for(j=1;j<=n;j++){ sa += ',' + j}
sa = sa.substring(1,sa.length)
Content[a] = sa
oldContent[1] = Content[1]
oldContent[2] = Content[2]
oldContent[3] = Content[3]
FIRST = a
SECOND = b
TOPS = new Array()
TOPS[a] = 1
TOPS[b] = Infinity
TOPS[c] = Infinity
NUMBERS = new Array(0,n,0,0)
TXT = TXT + '\nInitialization:\nn = ' + n + '\nVersion = "min"\n(2^n)-1 = ' + N + '\nparity = ' + parity+ '\nPattern (smallest piece) = ' + PATTERN + '\nInitial state:\n  Origin:   {' + Content[1] + '}\n  Spare: {' + Content[2] + '}\n  Destination: {' + Content[3] + '}'

if((MAX_REPORT)&&(N>600)){
TXT += '\nSorry, we do not display a report if there are more than 600 moves.'
MAX_REPORT = false
document.forms.max.max_report.checked=false
					}
Comment_Max(TXT) 
}

function Comment_Max(txt){
document.forms.max.max_area.value = txt
}

function Comment_Max_Status(txt){
document.forms.max.max_status.value = txt
}

function DOIT_Max_Min(){
STOP = false
TXT += 'More is coming .......... '
Comment_Max_Status(TXT)
JJ=1
DOIT_Max_Min_now()
}


function Max_Finish(){
Comment_Max_Status("That's it!")
//IDT = setTimeout('Max_Arrange()',2000)
RUNNING = false
}

function Max_Pause(){
if(1 == document.forms.max.max_pause.selectedIndex){PAUSE = true;return}
PAUSE = false

if(Mode_max == "min") {DOIT_Max_Min()} else {DOIT_Max_Max_now()}
}

function Report_Max(j,p,f,t){
var txt = '\nIteration no. ' + j +  ': Move ' + p + ' from ' + PLATFORMS_MAX[f] + ' to ' + PLATFORMS_MAX[t]+'.'
TXT += txt
document.forms.max.max_area.value = TXT
}



function DOIT_Max_Min_now(){
if(PAUSE == true){return}
if(JJ > N){Max_Finish();return}
jj=JJ
oldContent[1] = Content[1]
oldContent[2] = Content[2]
oldContent[3] = Content[3]
	if(1 == jj%2){Move_Max_Min_First(jj) }
	else{Move_Max_Min_Second(jj)}
	document.forms.max.max_status.value= 'Iteration no. ' + jj + ' out of ' + N
if(jj>N){
	document.forms.max.max_status.value= 'Idle!'
	return}
if(STOP){
	STOP=false
	document.forms.max.max_status.value="Stopped!"
	return}
JJ += 1
ID_doit=setTimeout('DOIT_Max_Min_now()',1000*Delay_max)
}

function Move_Max_Min_First(j){
var piece = 1
var from = PLATFORMS_MAX[FIRST]
too = Next_1[FIRST]
var to = PLATFORMS_MAX[too]
fro = FIRST
TOPS[too]= 1
FIRST = too
Move_Max_Min_FromTo(j,piece,fro,too)
return
}

function Move_Max_Min_Second(j){
var compl = Complement[FIRST]
var ac = compl[0]
var bc = compl[1]
var mintop = ac
if(TOPS[bc] < TOPS[ac] ){mintop = bc}
SECOND = mintop
var k = j
var piece = TOPS[SECOND]
var from = PLATFORMS_MAX[SECOND]
var too = NOT[FIRST][SECOND]
var to = PLATFORMS_MAX[too]
TOPS[too]=1*piece
Move_Max_Min_FromTo(j,piece,SECOND,too)
return
}

function Move_Max_Min_FromTo(j,p,f,t){
var sfrom = Content[f]
if(sfrom == ""){newfrom = ""}
	else {var i = sfrom.indexOf(',')
		if(i==-1){newfrom=""} 
	else{newfrom = sfrom.substring(i+1,sfrom.length)} 
		}
Content[f] = newfrom
if(newfrom == ""){ftop = Infinity}
	else {var i = newfrom.indexOf(',')
		if(i==-1){ftop=1*newfrom} 
	else{ ftop = 1*newfrom.substring(0,i)} 
		}
TOPS[f] = ftop
if(Content[t] == ""){Content[t] ="" + p}
else {Content[t] = "" + p + ',' + Content[t]}

Move_Piece_Max(j,p,f,t)


//if(Mode == "Terse"){Report_Max(j,p,f,t)}
if(MAX_REPORT){Report_Max(j,p,f,t)}
}


function Move_Piece_Max(j,p,f,t){
eval('document.images.gold_' + f + '_' + (12- NUMBERS[f]+1) + '.src=Gold_Blank.src')
eval('document.images.gold_' + t + '_' + (12 - NUMBERS[t]) + '.src=Gold_' + p + '.src')
NUMBERS[f] -= 1
NUMBERS[t] += 1
}

function Max_Reset(){
document.forms.max.reset()
var idt = setTimeout('Max_Accept()',500)
idt = setTimeout('Max_Arrange()',1000)
idt = setTimeout("document.forms.max.max_status.value= 'Idle'",1500)
}

function Solve_Max_Max(){
Initialize_Max_Max()
DOIT_Max_Max()
}

function Initialize_Max_Max(){
N = Math.pow(3,n) -1
TXT =""	
a = 1
A =PLATFORMS_MAX[a]
b = 3
B = PLATFORMS_MAX[b]
c = 2
C = PLATFORMS_MAX[c]
n2 = n%2
if(n2==0 ){parity="Even"} else{parity="Odd"}

Content[a] = ""
Content[b] = ""
Content[c] = ""
sa =""
for(j=1;j<=n;j++){ sa += ',' + j}
sa = sa.substring(1,sa.length)
Content[a] = sa
oldContent[1] = Content[1]
oldContent[2] = Content[2]
oldContent[3] = Content[3]
FIRST = a
SECOND = b
TOPS = new Array()
TOPS[a] = 1
TOPS[b] = Infinity
TOPS[c] = Infinity
NUMBERS = new Array(0,n,0,0)
TXT = TXT + '\nInitialization:\nn = ' + n + '\nVersion = "max"\n(3^n)-1 = ' + N + '\nInitial state:\n  Origin:   {' + Content[1] + '}\n  Spare: {' + Content[2] + '}\n  Destination: {' + Content[3] + '}'


if((MAX_REPORT)&&(N>600)){
TXT += '\nSorry, we do not display a report if there are more than 600 moves.'
MAX_REPORT = false
document.forms.max.max_report.checked=false
					}

Comment_Max(TXT) 

}

function DOIT_Max_Max(){
Max_Pattern = new Array(0,1,2,3,2,1,2)
IFIRST=0
STOP = false
TXT += 'More is coming .......... '
Comment_Max_Status(TXT)
JJ=1
DOIT_Max_Max_now()
}

function DOIT_Max_Max_now(){
if(PAUSE == true){return}
if(JJ > N){Max_Finish();return}
jj=JJ
oldContent[1] = Content[1]
oldContent[2] = Content[2]
oldContent[3] = Content[3]

	if(0 == jj%3){Move_Max_Max_Second(jj)}

else{Move_Max_Max_First(jj) }

document.forms.max.max_status.value= 'Iteration no. ' + jj + ' out of ' + N
if(jj>N){
	document.forms.max.max_status.value= 'Idle!'
	return}
if(STOP){
	STOP=false
	document.forms.max.max_status.value="Stopped!"
	return}
JJ += 1
ID_doit=setTimeout('DOIT_Max_Max_now()',1000*Delay_max)
}

function Move_Max_Max_First(j){
IFIRST = (IFIRST+1)%4 
var piece = 1
var from = PLATFORMS_MAX[FIRST]
var too = Max_Pattern[1+IFIRST%6]
TOPS[too]= 1
to = PLATFORMS[too]
fro = FIRST
FIRST = too
Move_Max_Min_FromTo(j,piece,fro,too)
return
}

function Move_Max_Max_Second(j){
var compl = Complement[FIRST]
var ac = compl[0]
var bc = compl[1]
var mintop = ac
if(TOPS[bc] < TOPS[ac] ){mintop = bc}
SECOND = mintop
var k = j
var piece = TOPS[SECOND]
var from = PLATFORMS_MAX[SECOND]
var too = NOT[FIRST][SECOND]
var to = PLATFORMS_MAX[too]
TOPS[too]=1*piece
Move_Max_Max_FromTo(j,piece,SECOND,too)
return
}

function Move_Max_Max_FromTo(j,p,f,t){
var sfrom = Content[f]
if(sfrom == ""){newfrom = ""}
	else {var i = sfrom.indexOf(',')
		if(i==-1){newfrom=""} 
	else{newfrom = sfrom.substring(i+1,sfrom.length)} 
		}
Content[f] = newfrom
if(newfrom == ""){ftop = Infinity}
	else {var i = newfrom.indexOf(',')
		if(i==-1){ftop=1*newfrom} 
	else{ ftop = 1*newfrom.substring(0,i)} 
		}
TOPS[f] = ftop
if(Content[t] == ""){Content[t] ="" + p}
else {Content[t] = "" + p + ',' + Content[t]}

Move_Piece_Max(j,p,f,t)

if(MAX_REPORT){Report_Max(j,p,f,t)}
}

function Max_Version(){
var m = document.forms.max.max_mode.selectedIndex
if(RUNNING){
	document.forms.max.max_mode.selectedIndex = (m+1)%2
	return}
Max_Resize()
}

function Max_Resize(){
if(RUNNING){
	document.forms.max.max_n.selectedIndex = n-1
	return}
Max_Accept()
Max_Arrange()
PLATFORMS_MAX = new Array("","Origin","Spare","Destination")
TXT =""
if(Mode_max == 'max'){Initialize_Max_Max()}
else{Initialize_Max_Min()}
}



function Max_Accept(){
var m = document.forms.max.max_mode.selectedIndex
Mode_max = "min"
if(m == 1){Mode_max="max"}
n = 1+document.forms.max.max_n.selectedIndex
if(n==1){mmm=3} else {mmm=2}
N = Math.pow(mmm,n)-1
MAX_REPORT = document.forms.max.max_report.checked
Max_Delay()
}

function Max_Delay(){
Delay_max =(1*document.forms.max.max_delay.selectedIndex)/10
}

function Max_Arrange(){
for(j=1;j<=3;j++){
for(i=1;i<=12;i++){
eval('document.images.gold_' + j + '_' + i + '.src=Gold_Blank.src')

document.forms.max.max_status.value="Cleaning images ...."
}}

for(j=1;j<=n;j++){
eval('document.images.gold_1_' + (j+12-n)+ '.src=Gold_'+j + '.src')
}
document.forms.max.max_status.value="Idle"
}

function Compute_np3(){
var thisform = document.forms.max_p3
var m = thisform.max_p3_n.value
if(isNaN(m)){
	thisform.max_p3_p2.value="Invalid value of m!"
	thisform.max_p3_p3.value=""
	return}
thisform.max_p3_p2.value=Math.pow(2,m)
thisform.max_p3_p3.value=Math.pow(3,m)
}


// -->

