var selected = '';
var selection = new Array();
var dragging = 0;

var ptiles = new Array();
var btiles = new Array();

var score = new Array();
var thisMove = '';
var curmoveno = 99;
var gameend = 0;
var movenotoshow = 99;

var animateCount = 100;
var curAnimateMove = -1;
var animatedObj;
var animatedObjXStart;
var animatedObjYStart;
var animatedObj2;
var animatedObj2XStart;
var animatedObj2YStart;

var numImages = 87;
var action = '';

var minx = 99, maxx = -99;
var miny = 99, maxy = -99;
var centerx = 0, centery = 0;
var TILESIZE = 40;


function getIndexV(i) {
	if(iam < 0) { 
		return i;
	} else {
		return Math.abs(i - iam);
	}
}
function getCursorPos(myturn,e) {
	var posx = 0;
	var posy = 0;
	var selpos = '';
	if (!e) var e = window.event;
	if (e.clientX || e.clientY) 	{
		posx = e.clientX + (document.documentElement.scrollLeft ?
		   document.documentElement.scrollLeft :
		   document.body.scrollLeft);
		posy = e.clientY + (document.documentElement.scrollTop ?
		   document.documentElement.scrollTop :
		   document.body.scrollTop);
	}
	else if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}

  var fielddiv = document.getElementById('fielddiv');
  var tempX = posx - fielddiv.offsetLeft;
  var tempY = posy - fielddiv.offsetTop;
  
  window.status = '(' + tempX + ',' + tempY + ')';

  if(dragging == 0) {
	  var i = 0;
	  while(i < selection.length) {
		if(tempY >= selection[i][2] && tempY < selection[i][2] + TILESIZE && tempX >= selection[i][3] && tempX < selection[i][3] + TILESIZE) {
		 	if(tempY < selection[i][2] + TILESIZE/2) {
				if(tempX < selection[i][3] + TILESIZE/2) { cr = 'tl';} else { cr = 'tr'; }
			} else {
				cr = 'm';
			}
			selpos = selection[i][0] + ',' + selection[i][1] + ',' + cr;
			i = 999;
		}
		i++;
	  }
  }
  window.status += ' selpos=' + selpos;
  return selpos;
}

function moveImg(myturn,e) {
 	var selpos = '';
 	if(action != '') {
	 	selpos = getCursorPos(myturn,e);
	}
 	var sel = document.getElementById('selector');
	sel.style.visibility = 'hidden';
 	sel = document.getElementById('selector_tl');
	sel.style.visibility = 'hidden';
 	sel = document.getElementById('selector_tr');
	sel.style.visibility = 'hidden';
 	sel = document.getElementById('selector_m');
	sel.style.visibility = 'hidden';
 	sel = document.getElementById('selector0');
	sel.style.visibility = 'hidden';
	if(selpos == '' || action == 'confirm') {
		document.body.style.cursor = 'default';
	} else {
	 	arr = selpos.split(',');
	 	if(action == 'sel') {
	 		sel = document.getElementById('selector_' + arr[2]);
		}
	 	if(action == 'move') {
	 		sel = document.getElementById('selector');
		}
		if(arr[0] < 0) {
			sel.style.left = selection[arr[1]][3];
			sel.style.top = selection[arr[1]][2];
		} else {
			sel.style.left = arr[1] * TILESIZE + 5;
			sel.style.top = getIndexV(arr[0]) * (440 - TILESIZE) + 5;	
		}
		sel.style.visibility = 'visible';
		document.body.style.cursor = 'pointer';
		if(action == 'sel') {
			var sel0 = document.getElementById('selector0');
			sel0.style.left = sel.style.left;
			sel0.style.top = sel.style.top;	
			sel0.style.visibility = sel.style.visibility;
		}
	}
}

function setActionSel() {
 	action = 'sel';
	selection = new Array();
	var x = 0;
	for(var i=0; i<2; i++) {
		for(var j=0; j<=10; j++) {
			if(ptiles[i][j] != '') {
			 	selection[x] = new Array();
			 	selection[x][0] = i;
			 	selection[x][1] = j;
			 	selection[x][2] = 5 + (440 - TILESIZE) * getIndexV(i);
			 	selection[x][3] = 5 + TILESIZE * j;
			 	x++;
			}
		}
	}	
	hideAllBlocks();
	showText('divMove', 'Select tile');
	showBlock('divResignBtn');
	showBlock('divMove');
}

function isMatch(s1, s2, p11, p12, p21, p22) {
	var m = 0;
	if(s1 != '' && s2 != '') {
	 	m = -99;
		if(s1.substring(p11,p11+1) == s2.substring(p21,p21+1) && s1.substring(p12,p12+1) == s2.substring(p22,p22+1)) { m = 1; }
	}
// 	writeDebug('isMatch ' + s1 + ',' + s2 + ',' + p11 + ',' + p12 + ',' + p21 + ',' + p22 + '  m=' + m);
	return m;
}

function findPossibleMoves(tile) {
// 	writeDebug('findPossibleMoves('+ tile + ')');
	// build empty board
	var b = new Array();
	for(i= minx - 2; i <= maxx + 2; i++) {
		b[i - minx + 2] = new Array();
		for(j = miny - 2; j <= maxy + 2; j++) {
			b[i - minx + 2][j - miny + 2] = '';
		}
	}
	// fill board
	for(i=0; i < btiles.length; i++) {
	 	arr = btiles[i].split(',');
	 	b[arr[1] - minx + 2][arr[2] - miny + 2] = arr[0];
	}
	// scan board
	p = selection.length;
//	writeDebug(minx + ',' + maxx + ' ' + miny + ',' + maxy);
	for(i= minx - 1; i <= maxx + 1; i++) {
		for(j = miny - 1; j <= maxy + 1; j++) {
		 	if(b[i - minx + 2][j - miny + 2] == '') {
//		 	 	writeDebug("TESTING (" + i + "," + j + ")");
				var match = 0;
				match += 10 * isMatch(tile, b[i - minx + 1][j - miny + 2], 0, 1, 3, 2);
				match += 10 * isMatch(tile, b[i - minx + 3][j - miny + 2], 2, 3, 1, 0);
				match += 10 * isMatch(tile, b[i - minx + 2][j - miny + 1], 0, 3, 1, 2);
				match += 10 * isMatch(tile, b[i - minx + 2][j - miny + 3], 1, 2, 0, 3);
				match += isMatch(tile, b[i - minx + 3][j - miny + 1], 3, 3, 1, 1);
				match += isMatch(tile, b[i - minx + 3][j - miny + 3], 2, 2, 0, 0);
				match += isMatch(tile, b[i - minx + 1][j - miny + 1], 0, 0, 2, 2);
				match += isMatch(tile, b[i - minx + 1][j - miny + 3], 1, 1, 3, 3);
//				writeDebug('pos: (' + i + ',' + j + ') match:' + match );
				if(match > 9) {
					selection[p] = new Array();
					selection[p][0] = -1;
					selection[p][1] = p;
					selection[p][2] = (450 - TILESIZE)/2 + TILESIZE * (i - centerx);
					selection[p][3] = (450 - TILESIZE)/2 + TILESIZE * (j - centery);
					selection[p][4] = i;
					selection[p][5] = j;
//					writeDebug('pos: (' + i + ',' + j + ') match:' + match );
					p++;					
				}
			}
		}
	}
	
}

function setPostValues() {
	document.post.move.value = thisMove;
	document.post.gameend.value = gameend;
	document.post.score0.value = score[0];
	document.post.score1.value = score[1];
	var t = '';
	for(var j=0; j<=10; j++) {
		t = t + ptiles[0][j] + ',';
	}
	document.post.tiles0.value = t;	
//	writeDebug('tiles0:' + t);
	var t = '';
	for(var j=0; j<=10; j++) {
		t = t + ptiles[1][j] + ',';
	}
	document.post.tiles1.value = t;
//	writeDebug('tiles1:' + document.post.tiles1.value);
}

function confirmAction() {
	action = 'confirm';
 	hideAllBlocks();
 	if(document.post.moveno.value == '22') {
		gameend = 1;
		showText("divMove", "Game over");
		showBlock('divMove');
	}
 	setPostValues();
	showBlock("divConfirm");
	showBlock('divConfirmBtn');
	showBlock('divResignBtn');					
}

function clickImg(myturn,e) {
 	var selpos = '';
 	if(action != '') {
	 	selpos = getCursorPos(myturn,e);
	}
 	if(selpos != '') {
		arr = selpos.split(',');
		if(action == 'move') {
//		 	writeDebug('moving from ' + selected + ' to ' + selpos);
			arr0 = selected.split(',');
			if(arr[0] < 0) {
				thisMove = ptiles[arr0[0]][arr0[1]] + ',' + selection[arr[1]][4] + ',' + selection[arr[1]][5];
				startAnimateMove(99,thisMove);
				doMove(thisMove);
				confirmAction();
			} else {
				startAnimateMove(98, 'sort,' + arr0[0] + ',' + arr0[1] + ',' + arr[0] + ',' + arr[1]);
				var c = ptiles[arr[0]][arr[1]];
				ptiles[arr[0]][arr[1]] = ptiles[arr0[0]][arr0[1]];
				ptiles[arr0[0]][arr0[1]] = c;
				c = playertiles[arr[0]][arr[1]];
				playertiles[arr[0]][arr[1]] = playertiles[arr0[0]][arr0[1]];
				playertiles[arr0[0]][arr0[1]] = c;
				setActionSel();
			}
		} else {
			if(action == 'sel' && (arr[2] == 'tl' || arr[2] == 'tr')) {
				var newtile = '';
				if(arr[2] == 'tl') {
					newtile = ptiles[arr[0]][arr[1]].substring(1,4) + ptiles[arr[0]][arr[1]].substring(0,1);
				} else {
					newtile = ptiles[arr[0]][arr[1]].substring(3,4) + ptiles[arr[0]][arr[1]].substring(0,3);
				}
				if(newtile != ptiles[arr[0]][arr[1]]) {
					var img0 = document.getElementById('tile_' + ptiles[arr[0]][arr[1]]);
					ptiles[arr[0]][arr[1]] = newtile;
					playertiles[arr[0]][arr[1]] = ptiles[arr[0]][arr[1]];
					var img1 = document.getElementById('tile_' + ptiles[arr[0]][arr[1]]);
					img1.style.left = img0.style.left;
					img1.style.top = img0.style.top;
					img1.style.visibility = 'visible';
					img0.style.visibility = 'hidden';
				}
			}
			if(action == 'sel' && arr[2] == 'm') {
			 	selected = selpos;
				selection = new Array();
				for(var j=0; j<=10; j++) {
					selection[j] = new Array();
					selection[j][0] = arr[0];
					selection[j][1] = j;
					selection[j][2] = 5 + (440 - TILESIZE) * getIndexV(arr[0]);
					selection[j][3] = 5 + TILESIZE * j;
				}
	//			add possible placement of selected tile on board
				if(arr[0] != iam) {
					findPossibleMoves(ptiles[arr[0]][arr[1]]);
				}
				action = 'move';
				showText('divMove', 'Select new position for tile');
				if(curmoveno >= 10 && arr[0] != iam) {
					showBlock('divRemoveTile');
				}
				showBlock('divUndo');
			}
		}
	}
}

function compareTiles(tile0, tile1) {
	var c = 0;
	if(tile0 == tile1) { c = 1; }
	var i = 0;
	while(c == 0 && i < 3)	 {
		tile1 = tile1.substring(3,4) + tile1.substring(0,3);
		if(tile0 == tile1) { c = 1; }
		i++;
	}
	return c;	
}

function fillB(b, p, q, v, w) {
	b[p][q] = w;
 	c = 0;
 	while(c == 0) {
		c = 1;
		for(var i = 0; i < b.length; i++) {
			for(var j = 0; j < b[i].length; j++) {
				if(b[i][j] == w) {
					if(i > 0) { if(b[i-1][j] == v) { b[i-1][j] = w; c = 0; }}
					if(i < b.length - 1) { if(b[i+1][j] == v) { b[i+1][j] = w; c = 0; }}
					if(j > 0) { if(b[i][j-1] == v) { b[i][j-1] = w; c = 0; }}
					if(j < b[i].length - 1) { if(b[i][j+1] == v) { b[i][j+1] = w; c = 0; }}
				}
			}
		}
	}
}
function getScore() {
	var sc = 0;
	var b = new Array();
	var p, q;
	for(var i = 0; i < btiles.length; i++) {
		var arr = btiles[i].split(',');
		p = parseInt(arr[1]) - minx + 1;
		q = parseInt(arr[2]) - miny + 1;
		while(b.length < p*2+2) { b[b.length] = new Array(); }
		b[p*2][q*2] = arr[0].substring(0,1);
		b[p*2][q*2+1] = arr[0].substring(1,2);
		b[p*2+1][q*2+1] = arr[0].substring(2,3);
		b[p*2+1][q*2] = arr[0].substring(3,4);
	}
	if(b[p*2][q*2] > '4') { fillB(b, p*2, q*2, b[p*2][q*2], '1'); }
	if(b[p*2+1][q*2] > '4') { fillB(b, p*2+1, q*2, b[p*2+1][q*2], '2');	}
	if(b[p*2+1][q*2+1] > '3') { fillB(b, p*2+1, q*2+1, b[p*2+1][q*2+1], '3'); }
	if(b[p*2][q*2+1] > '4') { fillB(b, p*2, q*2+1, b[p*2][q*2+1], '4'); }
//	for(var i =0; i<b.length; i++) {
//	 	var s = '';
//		for(var j=0; j<b[i].length; j++) {
//			if(b[i][j] == '' || b[i][j] == null) { s += '.'; } else { s += b[i][j]; }
//		}
//		writeDebug("grid4:" + s);
//	}
	for(var i = 0; i < b.length; i += 2) {
		for(var j = 0; j < b[i].length; j += 2) {
		 	if(i != p*2 || j != q*2) {
				for(var k = 1; k < 5; k++) {
					if(b[i][j] == k || b[i+1][j] == k || b[i+1][j+1] == k || b[i][j+1] == k) { sc++; }
				}
			}
		}
	}
	return sc;	
}

function doMove(xmove) {
// 	writeDebug('doMove ' + xmove);
 	var arr = xmove.split(',');
 	var i = 0;
 	var j = 0;
	var c = 0;
 	while(c == 0) {
		j = 0;
		while(c == 0 && j <= 10) {
			c = compareTiles(ptiles[i][j], arr[0]);
			if(c == 0) { j++; }
		}
		if(c == 0) { i++; }
	}	
//	writeDebug(i + ',' + j);
	if(arr[1] != 'remove') {
		btiles[btiles.length] = xmove;
		score[1-i] += getScore();
	}
	ptiles[i][j] = '';
}

function animateMove(moveno, xmove) {
 	if(curAnimateMove== moveno) {
	 	if(animateCount < 100) {
	 	 	var arr = xmove.split(',');
	 	 	if(arr[1] == 'remove') {
	 	 	 	var o = 100 - animateCount;
				animatedObj.style.opacity = o / 100;
				animatedObj.style.filter = 'alpha(opacity=' + o + ')';				
			} else {
			 	if(arr[0] == 'sort') {
					var ttop = 5 + (440 - TILESIZE) * getIndexV(arr[3]);
					var tleft = 5 + TILESIZE * arr[4];
			 	 	var xdiv = animateCount * (tleft - animatedObjXStart) / 100;
			 	 	var ydiv = animateCount * (ttop - animatedObjYStart) / 100;
					animatedObj.style.left = animatedObjXStart + xdiv;
					animatedObj.style.top = animatedObjYStart + ydiv;
					if(animatedObj2 != null) {
						var ttop = 5 + (440 - TILESIZE) * getIndexV(arr[1]);
						var tleft = 5 + TILESIZE * arr[2];
				 	 	var xdiv = animateCount * (tleft - animatedObj2XStart) / 100;
				 	 	var ydiv = animateCount * (ttop - animatedObj2YStart) / 100;
						animatedObj2.style.left = animatedObj2XStart + xdiv;
						animatedObj2.style.top = animatedObj2YStart + ydiv;						
					}
			 	} else {
					var ttop = (450 - TILESIZE)/2 + TILESIZE * (arr[1] - centerx);
					var tleft = (450 - TILESIZE)/2 + TILESIZE * (arr[2] - centery);
			 	 	var xdiv = animateCount * (tleft - animatedObjXStart) / 100;
			 	 	var ydiv = animateCount * (ttop - animatedObjYStart) / 100;
					animatedObj.style.left = animatedObjXStart + xdiv;
					animatedObj.style.top = animatedObjYStart + ydiv;
				}
			}
//			writeDebug('animateMove count=' + animateCount + ' animatedObj.style.left=' + animatedObj.style.left + ' animatedObjXStart + xdiv=' + (animatedObjXStart + xdiv));
			animateCount+=2;
			setTimeout("animateMove(" + moveno + ", '" + xmove + "')", 10);
	 	} else {
	 	 	stopAnimation(false);
		}
	}
}

function startAnimateMove(moveno, xmove) {
 	curAnimateMove = moveno;
 	var arr = xmove.split(',');
 	animateCount = 0;
 	var img2;
 	if(arr[0] == 'sort') {
		i = parseInt(arr[1]);
		j = parseInt(arr[2]);
		img2 = document.getElementById('tile_' + ptiles[i][j]);
		animatedObj2 = null;
		if(ptiles[arr[3]][arr[4]] != '') {
			animatedObj2 = document.getElementById('tile_' + ptiles[arr[3]][arr[4]]);
			animatedObj2.style.zIndex = 3;
		}
		animatedObj2YStart = 5 + (440 - TILESIZE) * getIndexV(arr[3]);
		animatedObj2XStart = 5 + TILESIZE * arr[4];
	} else {
	 	var i = 0;
	 	var j = 0;
		var c = 0;
	 	while(c == 0) {
			j = 0;
			while(c == 0 && j <= 10) {
				c = compareTiles(ptiles[i][j], arr[0]);
				if(c == 0) { j++; }
			}
			if(c == 0) { i++; }
		}	
		img2 = document.getElementById('tile_' + arr[0]);
		if(ptiles[i][j] != arr[0] && arr[1] != 'remove') {
			img = document.getElementById('tile_' + ptiles[i][j]);
			img.style.visibility = 'hidden';
			img2.style.top = img.style.top;
			img2.style.left = img.style.left;
			img2.style.visibility = 'visible';
		}
	}
	animatedObj = img2;
	img2.style.zIndex = 4;
	animatedObjYStart = 5 + (440 - TILESIZE) * getIndexV(i);
	animatedObjXStart = 5 + TILESIZE * j;
	startAnimation();
 	animateMove(moveno, xmove);	
}

function buildFieldUntilMove(moveno) {
	score[0] = 5;
	score[1] = 0;
	
	var i = 1;
	while(i <= moveno && i < move.length) {
	 	doMove(move[i]);
		i++;
	}
}

function clearField() {
 	ptiles = new Array();
 	btiles = new Array();
 	for(var i = 0; i < 2; i++) {
 	 	ptiles[i] = new Array();
		for(var j = 0; j <= 10; j++) {
			ptiles[i][j] = playertiles[i][j];
		}
	}
	btiles[0] = boardtiles[0];
}

function addImage() {
// 	writeDebug('addImage   cntImagesLoaded=' + cntImagesLoaded);
	cntImagesLoaded++;
	showText('divMove', 'Loading images (' + Math.floor(100 * cntImagesLoaded / numImages) + '%)');
	showBlock('divMove');
	if(cntImagesLoaded == numImages && pageLoaded == 1) {
		showGameAtMove(movenotoshow);
	}
}

function showGameAtMove(moveno) {
// 	writeDebug('showGameAtMove(' + moveno + ')   cntImagesLoaded=' + cntImagesLoaded);
 	movenotoshow = moveno;
	if(pageLoaded == 0 && tileorder != '') {
		// order tiles
		for(i=0; i<2; i++) {
			for(j=0; j<=10; j++) {
				xtile = tileorder.substring(i*44+j*4, i*44+j*4+4);
				if(xtile != "    ") {
	//				writeDebug('target ' + i + ',' + j + ' ' + xtile + ' (' + playertiles[i][j] + ')');
					k = 0;
					c = 0;
					while(k <= 10 && c == 0) {
					 	c = compareTiles(xtile, playertiles[i][k]);
					 	if(c == 1) {
							playertiles[i][k] = playertiles[i][j];
							playertiles[i][j] = xtile;
	//						writeDebug('swapping ' + i + ',' + j + '-' + k + ' ' + xtile);
						}
					 	k++;
					}
				}
			}
		}
	}
 	pageLoaded = 1;
 	action = '';
 	if(cntImagesLoaded == numImages) {
 	 	showText('divMove', '');

	 	clearField(); 
	 	if(minx == 99) {
	 	 	minx = 0; maxx = 0; miny = 0; maxy = 0;
			for(i=1; i < move.length; i++) {
				arr = move[i].split(',');
				if(arr[1] < minx) { minx = parseInt(arr[1]); }
				if(arr[1] > maxx) { maxx = parseInt(arr[1]); }
				if(arr[2] < miny) { miny = parseInt(arr[2]); }
				if(arr[2] > maxy) { maxy = parseInt(arr[2]); }
			}
			divy = 40;
			if (maxy > miny) { divy = 450 / (maxy - miny + 3); }
			if(divy < TILESIZE) { TILESIZE = Math.floor(divy); }
			divx = 40;
			if (maxx > minx) { divx = 440 / (maxx - minx + 5); }
			if(divx < TILESIZE) { TILESIZE = Math.floor(divx); }
			if(TILESIZE != 40) {
				//Change the sizes of all images
				for(i=0; i<document.images.length; i++) {
					var img = document.images[i];
					if(img.id.substring(0,5) == 'tile_' || img.id.substring(0,8) == 'selector') {
						img.style.height = TILESIZE;
						img.style.width = TILESIZE;
					}
				}
			}
		}
		
	 	if(moveno == 99) { curmoveno = move.length - 1; } else { curmoveno = moveno; }
	 	xmove = curmoveno - 1;
		buildFieldUntilMove(xmove);
	 	showGame();
	 	if(curmoveno > 0) {
	 		startAnimateMove(curmoveno,move[curmoveno]);
	 	}
	 	if(curmoveno >= 1) {
	 		doMove(move[curmoveno]);
	 	}
		hideAllBlocks();
		if(myturn==1 && moveno==99) {
			setActionSel();
		} else {
			showText('divMove', '');
		} 
		undoing = 1;
	} 
}

function showGame() {
	centerx = (minx + maxx) / 2;
	centery = (miny + maxy) / 2;
//	writeDebug('minx:' + minx + ' maxx:' + maxx + ' miny:' + miny + ' maxy' + maxy + ' centerx:' + centerx + ' centery:' + centery);
    var imga = document.getElementsByTagName('img');
	for(var i = 0; i < imga.length; i++) {
		if(imga[i].id.substring(0,5) == 'tile_') {
			imga[i].style.visibility = 'hidden';
			imga[i].style.opacity = 1;
			imga[i].style.filter = 'alpha(opacity=100)';				
		}
	}
	// show board
	for(i=0; i < btiles.length; i++) {
		arr = btiles[i].split(',');
		var img = document.getElementById('tile_' + arr[0]);
		img.style.top = (450 - TILESIZE)/2 + TILESIZE * (arr[1] - centerx);
		img.style.left = (450 - TILESIZE)/2 + TILESIZE * (arr[2] - centery);
		img.style.visibility = 'visible';
		img.style.zIndex = 2;
	}
	
	// show player tiles
	for(i=0; i<2; i++) {
		for(j=0; j<ptiles[i].length; j++) {
		 	if(ptiles[i][j] != '') {
				var img = document.getElementById('tile_' + ptiles[i][j]);
				img.style.top = 5 + (440 - TILESIZE) * getIndexV(i);
				img.style.left = 5 + TILESIZE * j;
				img.style.visibility = 'visible';
				img.style.zIndex = 2;
			}
		}
	}
	for(var i = 0; i < 2; i++) {
		showText('spanScore' + i, score[i]);		
	} 
}

function clearSelectable() {
	action = '';
}

function removeTile() {
	arr0 = selected.split(',');
	thisMove = ptiles[arr0[0]][arr0[1]] + ',remove';
	startAnimateMove(99,thisMove);
	doMove(thisMove);
	confirmAction();
}

function resignGame() {
	clearSelectable();
	hideAllBlocks();
	document.getElementById('divResign').style.display = 'block';
	document.getElementById('divConfirm').style.display = 'block';
	document.getElementById('divConfirmResign').style.display = 'block';
}

function hideAllBlocks() {
 	if(document.getElementById('divMove')) {
		document.getElementById('divMove').style.display = 'none';
		document.getElementById('divRemoveTile').style.display = 'none';
		document.getElementById('divUndo').style.display = 'none';
		document.getElementById('divConfirm').style.display = 'none';
		document.getElementById('divResign').style.display = 'none';
		document.getElementById('divResignBtn').style.display = 'none';
		document.getElementById('divConfirmBtn').style.display = 'none';
		document.getElementById('divConfirmResign').style.display = 'none';
	}
}
