var top12
var top10
var top8
var top6
var top4
var hAlert
var topScore = 0
var newScore = 0
tpTm4 = 0
tpTm6 = 6
tpTm8 = 8
tpTm10 = 10
tpTm12 = 12
var card4 = new Array(1,2,3,4,4,3,2,1)
var card6 = new Array(1,2,3,4,5,6,6,5,4,3,2,1)
var card8 = new Array(1,2,3,4,5,6,7,8,8,7,6,5,4,3,2,1)
var card10 = new Array(1,2,3,4,5,6,7,8,9,10,10,9,8,7,6,5,4,3,2,1)
var card12 = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,12,11,10,9,8,7,6,5,4,3,2,1)
var tC4
var mtCnt = 4
var matchCount = 0
var vr
var  tC
var v1= "images/back.gif"
var v2= 0
var a1
var a2
var a3
var a4
var a5
var a6
var a7
var a1
var a8
var a9
var a10
var a11
var a12
var a13
var a14
var a15
var a16
var a17
var a18
var a19
var a20
mBord = "yellow"
var cards
function compare4() {return parseInt(Math.random() *9) -1}
function compare6() {return parseInt(Math.random() *13) -1}
function compare8() {return parseInt(Math.random() *17) -1}
function compare10() {return parseInt(Math.random() *21) -1}
function compare12() {return parseInt(Math.random() *26) -1}
function sortIt4(compare4) {tC4 = card4.sort(compare4)}
function sortIt6(compare6) {tC4 = card6.sort(compare6)}
function sortIt8(compare8) {tC4 = card8.sort(compare8)}
function sortIt10(compare10) {tC4 = card10.sort(compare10)}
function sortIt12(compare12) {tC4 = card12.sort(compare12)}

function loadGame(cards, img){
document.getElementById("foxEXC").style.left = "-700px"
cards = cards
v2 = "images/"+ img
if (cards == "8"){mtCnt = 4;sortIt4(compare4);loadG(4)}
if (cards == "12"){mtCnt = 6;sortIt6(compare6);loadG(6)}
if (cards == "16"){mtCnt = 8;sortIt8(compare8);loadG('8')}
if (cards == "20"){mtCnt = 10;sortIt10(compare10);loadG(10)}
if (cards == "25"){mtCnt = 12;sortIt12(compare12);loadG(12)}
startCounter()
}
function getA(){
a1 = tC4.slice(0,-7)
a2 = tC4.slice(1,-6)
a3 = tC4.slice(2,-5)
a4 = tC4.slice(3,-4)
a5 = tC4.slice(4,-3)
a6 = tC4.slice(5,-2)
a7 = tC4.slice(6,-1)
a8 = tC4.slice(7)
a9 = tC4.slice(8)
a10 = tC4.slice(9)
a11 = tC4.slice(10)
a12 = tC4.slice(11)
a13 = tC4.slice(12)
a14= tC4.slice(13)
a15 = tC4.slice(14)
a16 = tC4.slice(15)
a17 = tC4.slice(16)
a18= tC4.slice(17)
a19 = tC4.slice(18)
a20 = tC4.slice(19)
a21 = tC4.slice(20)
a22 = tC4.slice(21)
a23 = tC4.slice(22)
a24 = tC4.slice(23)
a25 = tC4.slice(24)
}
function loadG(x){
getA()
tBorder = "border:2pt solid "+ bordColor + "'"
 result = "<DIV STYLE='width:560;height:auto;text-align:center'>"
 result += "<TABLE align=center STYLE='background-color:" + allColor + ";cursor:pointer'>"
 result += "<TR><TD style='"+ tBorder + " ID=T1><IMG ID=iM1 SRC=" + v1 + " onclick=match(this.id,"+ a1 + ")></TD><TD style='"+ tBorder + " ID=T2><IMG ID=iM2 SRC=" + v1 + " onclick=match(this.id,"+ a2 + ")></TD><TD style='"+ tBorder + " ID=T3><IMG ID=iM3 SRC=" + v1 + " onclick=match(this.id,"+ a3 + ")></TD><TD style='"+ tBorder + " ID=T4><IMG ID=iM4 SRC=" + v1 + " onclick=match(this.id,"+ a4 + ")></TD></TR>"
 result += "<TR><TD style='"+ tBorder + " ID=T5><IMG ID=iM5 SRC=" + v1 + " onclick=match(this.id,"+ a5 + ")></TD><TD style='"+ tBorder + " ID=T6><IMG ID=iM6 SRC=" + v1 + " onclick=match(this.id,"+ a6 + ")></TD><TD style='"+ tBorder + " ID=T7><IMG ID=iM7 SRC=" + v1 + " onclick=match(this.id," + a7 + ")></TD><TD style='"+ tBorder + " ID=T8><IMG ID=iM8 SRC=" + v1 + " onclick=match(this.id,"+ a8 + ")></TD></TR>"
if(x == 4){
document.getElementById("tpTm").value = topScore4 ;
document.getElementById("playTable").style.top = 170
}
if(x == 6){
result += "<TR><TD style='"+ tBorder + " ID=T9><IMG ID=iM9 SRC=" + v1 + " onclick=match(this.id,"+ a9 + ")></TD><TD style='"+ tBorder + " ID=T10><IMG ID=iM10 SRC=" + v1 + " onclick=match(this.id,"+ a10 + ")></TD><TD style='"+ tBorder + " ID=T11><IMG ID=iM11 SRC=" + v1 + " onclick=match(this.id," + a11 + ")></TD><TD style='"+ tBorder + " ID=T12><IMG ID=iM12 SRC=" + v1 + " onclick=match(this.id,"+ a12 + ")></TD></TR>"
document.getElementById("tpTm").value = topScore6
document.getElementById("playTable").style.top = 120
}
if(x == 8){
result += "<TR><TD style='"+ tBorder + " ID=T9><IMG ID=iM9 SRC=" + v1 + " onclick=match(this.id,"+ a9 + ")></TD><TD style='"+ tBorder + " ID=T10><IMG ID=iM10 SRC=" + v1 + " onclick=match(this.id,"+ a10 + ")></TD><TD style='"+ tBorder + " ID=T11><IMG ID=iM11 SRC=" + v1 + " onclick=match(this.id," + a11 + ")></TD><TD style='"+ tBorder + " ID=T12><IMG ID=iM12 SRC=" + v1 + " onclick=match(this.id,"+ a12 + ")></TD></TR>"
result += "<TR><TD style='"+ tBorder + " ID=T13><IMG ID=iM13 SRC=" + v1 + " onclick=match(this.id,"+ a13 + ")></TD><TD style='"+ tBorder + " ID=T14><IMG ID=iM14 SRC=" + v1 + " onclick=match(this.id,"+ a14 + ")></TD><TD style='"+ tBorder + " ID=T15><IMG ID=iM15 SRC=" + v1 + " onclick=match(this.id," + a15 + ")></TD><TD style='"+ tBorder + " ID=T16><IMG ID=iM16 SRC=" + v1 + " onclick=match(this.id,"+ a16 + ")></TD></TR>"
document.getElementById("tpTm").value = topScore8
document.getElementById("playTable").style.top = 70
}
 resultx = "<DIV STYLE='width:560;height:auto;'>"
 resultx += "<TABLE align=center STYLE='background-color:" + allColor + ";cursor:pointer'>"
 resultx += "<TR><TD style='"+ tBorder + " ID=T1><IMG ID=iM1 SRC=" + v1 + " onclick=match(this.id,"+ a1 + ")></TD><TD style='"+ tBorder + " ID=T2><IMG ID=iM2 SRC=" + v1 + " onclick=match(this.id,"+ a2 + ")></TD><TD style='"+ tBorder + " ID=T3><IMG ID=iM3 SRC=" + v1 + " onclick=match(this.id,"+ a3 + ")></TD><TD style='"+ tBorder + " ID=T4><IMG ID=iM4 SRC=" + v1 + " onclick=match(this.id,"+ a4 + ")></TD><TD style='"+ tBorder + " ID=T5><IMG ID=iM5 SRC=" + v1 + " onclick=match(this.id,"+ a5 + ")></TD></TR>"
 resultx += "<TR><TD style='"+ tBorder + " ID=T6><IMG ID=iM6 SRC=" + v1 + " onclick=match(this.id,"+ a6 + ")></TD><TD style='"+ tBorder + " ID=T7><IMG ID=iM7 SRC=" + v1 + " onclick=match(this.id," + a7 + ")></TD><TD style='"+ tBorder + " ID=T8><IMG ID=iM8 SRC=" + v1 + " onclick=match(this.id,"+ a8 + ")></TD><TD style='"+ tBorder + " ID=T9><IMG ID=iM9 SRC=" + v1 + " onclick=match(this.id,"+ a9 + ")></TD><TD style='"+ tBorder + " ID=T10><IMG ID=iM10 SRC=" + v1 + " onclick=match(this.id,"+ a10 + ")></TD></TR>"
 resultx += "<TR><TD style='"+ tBorder + " ID=T11><IMG ID=iM11 SRC=" + v1 + " onclick=match(this.id," + a11 + ")></TD><TD style='"+ tBorder + " ID=T12><IMG ID=iM12 SRC=" + v1 + " onclick=match(this.id,"+ a12 + ")></TD><TD style='"+ tBorder + " ID=T13><IMG ID=iM13 SRC=" + v1 + " onclick=match(this.id,"+ a13 + ")></TD><TD style='"+ tBorder + " ID=T14><IMG ID=iM14 SRC=" + v1 + " onclick=match(this.id,"+ a14 + ")></TD><TD style='"+ tBorder + " ID=T15><IMG ID=iM15 SRC=" + v1 + " onclick=match(this.id," + a15 + ")></TD></TR>"
 resultx += "<TR><TD style='"+ tBorder + " ID=T16><IMG ID=iM16 SRC=" + v1 + " onclick=match(this.id,"+ a16 + ")></TD><TD style='"+ tBorder + " ID=T17><IMG ID=iM17 SRC=" + v1 + " onclick=match(this.id,"+ a17 + ")></TD><TD style='"+ tBorder + " ID=T18><IMG ID=iM18 SRC=" + v1 + " onclick=match(this.id,"+ a18 + ")></TD><TD style='"+ tBorder + " ID=T19><IMG ID=iM19 SRC=" + v1 + " onclick=match(this.id,"+ a19 + ")></TD><TD style='"+ tBorder + " ID=T20><IMG ID=iM20 SRC=" + v1 + " onclick=match(this.id,"+ a20 + ")></TD></TR>"
if(x == 10){document.getElementById("tpTm").value = topScore10
document.getElementById("playTable").style.top = 70
result = resultx
}
if(x == 12){document.getElementById("tpTm").value = topScore12
document.getElementById("playTable").style.top = 33
result = resultx
 result += "<TR><TD style='"+ tBorder + " ID=T21><IMG ID=iM21 SRC=" + v1 + " onclick=match(this.id,"+ a21 + ")></TD><TD style='"+ tBorder + " ID=T22><IMG ID=iM22 SRC=" + v1 + " onclick=match(this.id,"+ a22 + ")></TD><TD style='"+ tBorder + " ID=T23><IMG ID=iM23 SRC=" + v1 + " onclick=match(this.id,"+ a23 + ")></TD><TD style='"+ tBorder + " ID=T24><IMG ID=iM24 SRC=" + v1 + " onclick=match(this.id,"+ a24 + ")></TD><TD style='"+ tBorder + " ID=T25><IMG ID=iM25 SRC=" + v1 + " onclick=match(this.id,"+ a25 + ")></TD></TR>"
}
 result += "</TABLE></DIV>"
document.getElementById("playTable").innerHTML= result
}
function hPh(){
loadGame()
}
set = 1
var it
var it1 = 9
var it2 = 10
var itOne
var itTwo
var targ1
var targ2
var matchCount = 0
function match(x,it){
if(set == "2"){
} else {
matchNow(x,it)}
}

function matchNow(x,it){
if(set == "1"){
match1(x,it)
	} else{
match2(x,it)
	}
}
var objID1
var objID2
function match1(x,it){
objID1 = x	 
document.getElementById(objID1).src = v2 + it + ".gif"
itOne = objID1
it1 = it

document.getElementById("itVa1").value = it1
document.getElementById("itV1").value = itOne
targ1 = "T" + itOne.slice(2)
if(it1 == 13){
document.getElementById(targ1).innerHTML = "<IMG SRC='images/wild.gif'>"
document.getElementById(targ1).style.border = "2pt solid " + mBord
fix1()
}else{
document.getElementById("itV3").value = targ1
set = "0"
	}
}
function match2(x,it){
objID2 = x
document.getElementById(objID2).src = v2 + it + ".gif"
itTwo = objID2
it2 = it
document.getElementById("itVa2").value = it2
document.getElementById("itV2").value = itTwo
targ2 = "T" + itTwo.slice(2)

if(it == 13){
document.getElementById(targ2).innerHTML = "<IMG SRC='images/wild.gif'>"
document.getElementById(targ2).style.border = "2pt solid " + mBord
document.getElementById(objID1).src = v1
fix1()
} else {
document.getElementById("itV4").value = targ2
findmatch()
	}
}
function findmatch(){
if( itTwo == itOne){}else{
if (it1 == it2){
document.getElementById(targ1).style.border = "2pt solid " + mBord
document.getElementById(targ2).style.border = "2pt solid " + mBord
document.getElementById(targ1).innerHTML = "<IMG SRC='"+ v2 + it1 + ".gif'>"
document.getElementById(targ2).innerHTML = "<IMG SRC='"+ v2 + it2 + ".gif'>"
matchCount = matchCount +1
document.getElementById("cont").value = matchCount
set = 1
if(matchCount == mtCnt)
endGame()
}else{
set = 2
setTimeout("clearNomatch()",500)
	}
		}
}
function clearNomatch(){
document.getElementById(objID1).src = v1
document.getElementById(objID2).src = v1
set = "1"
}
function fix1(){
set = "1"
}
function startGame(){
	clearTimeout(timerID)
var cNum = document.getElementById("cardNo").value
var gCards = document.getElementById("gameCards").value
document.getElementById("cont").value = "0"
matchCount = 0
counter = 0
countX10 = 0
cntSec = 0
cntMin = 0
loadGame(cNum,gCards)
}
var counter = 0
var countX10 = 0
var cntSec = 0
var cntMin = 0

var timerID
function startCounter(){
countX10 = ++counter/20

	document.getElementById("display").value = countX10
	timerID = setTimeout("startCounter()", 1)
}
function endGame(){
	clearTimeout(timerID)

topScore = document.getElementById("tpTm").value
newScore = document.getElementById("display").value
if(topScore*10 > newScore*10){
document.getElementById("tpTm").value = newScore
if(mtCnt == 4){
topScore4 = newScore
createCookie("tvp4",newScore,365)
	}
if(mtCnt == 6){
topScore6 = newScore
createCookie("tvp6",newScore,365)
	}
if(mtCnt == 8){
topScore8 = newScore
createCookie("tvp8",newScore,365)
	}
if(mtCnt == 10){
topScore10 = newScore
createCookie("tvp10",newScore,365)
	}
if(mtCnt == 12){
topScore12 = newScore
createCookie("tvp12",newScore,365)
	}
mkHigh()
}
if(topScore == 0){
document.getElementById("tpTm").value = newScore
if(mtCnt == 4){
topScore4 = newScore
createCookie("tvp4",newScore,365)
	}
if(mtCnt == 6){
topScore6 = newScore
createCookie("tvp6",newScore,365)
	}
if(mtCnt == 8){
topScore8 = newScore
createCookie("tvp8",newScore,365)
	}
if(mtCnt == 10){
topScore10 = newScore
createCookie("tvp10",newScore,365)
	}
if(mtCnt == 12){
topScore12 = newScore
createCookie("tvp12",newScore,365)
	}
mkHigh()
}
}
function readIt(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return 0;
}

function eraseCookie(name){
	createCookie(name,"",-1);
}
function initGame(){
topScore12 = readIt('tvp12')
topScore10 = readIt('tvp10')
topScore8 = readIt('tvp8')
topScore6 = readIt('tvp6')
topScore4 = readIt('tvp4')
Ixme12 = readIt('xme12')
Ixme10 = readIt('xme10')
Ixme8 = readIt('xme8')
Ixme6 = readIt('xme6')
Ixme4 = readIt('xme4')
document.getElementById("tpTm").value = topScore4
document.getElementById("playerAlert").style.color = fontColor
document.getElementById("playerAlert").style.backgroundColor = allColor
document.getElementById("controls").style.color = fontColor
document.getElementById("controlsT").style.color = fontColor
document.getElementById("controls").style.backgroundColor = allColor
document.getElementById("tpTm").style.color = bordColor
document.getElementById("display").style.color = bordColor
document.getElementById("cont").style.color = bordColor
document.getElementById("tpTm").style.borderColor = bordColor
document.getElementById("display").style.borderColor = bordColor
document.getElementById("cont").style.borderColor = bordColor
document.getElementById("tpTm").style.backgroundColor = allColor
document.getElementById("display").style.backgroundColor = allColor
document.getElementById("cont").style.backgroundColor = allColor
document.getElementById("start").style.color = allColor
document.getElementById("start").style.backgroundColor = bordColor
document.getElementById("highTable").style.borderColor = bordColor
document.getElementById("inputMain").style.backgroundColor = allColor
document.getElementById("inputMain").style.color = fontColor
document.getElementById("ender").style.backgroundColor = allColor
document.getElementById("ender").style.color = fontColor
if(allColor == "yellow"){mBord = "green";}

mkHighA()
}

function mkHigh(){
var hAlert = "Great Going !<BR> You Have the <B>Top Time Score</B><BR>Enter Name <INPUT type=text Id=nameH Maxlength=11 style=background-color:F2F2EE; onchange='nameY = this.value'><BR><BR>"
hAlert  += "<INPUT TYPE='button' VALUE='Save' onclick=mkHighA()>&nbsp;&nbsp;&nbsp;<INPUT TYPE='button' VALUE='cancel' onclick='document.all.playerAlert.style.left = -750'>"
document.getElementById("playerAlert").innerHTML = hAlert
document.getElementById("playerAlert").style.left = 200
}
nameY = 0
Ixme4 = 0
Ixme6 = 0
Ixme8 = 0
Ixme10 = 0
Ixme12 = 0
function mkHighA(){
document.getElementById("playerAlert").style.left = -750
if(mtCnt == 4){
Ixme4 = nameY
createCookie("xme4",Ixme4,365)
	}
if(mtCnt == 6){
Ixme6 = nameY
createCookie("xme6",Ixme6,365)
	}
if(mtCnt == 8){
Ixme8 = nameY
createCookie("xme8",Ixme8,365)
	}
if(mtCnt == 10){
Ixme10 = nameY
createCookie("xme10",Ixme10,365)
	}
if(mtCnt == 12){
Ixme12 = nameY
createCookie("xme12",Ixme12,365)
}
highTab = "<TABLE ID=highTableText1 style=font-size:10><CAPTION ID=highTableText2 style='font-size:14;font-family:"+ sFam +"'>High Scores</CAPTION>"
highTab += "<TR><TD>Cards</TD><TD>Time</TD><TD>Name</TD></TR>"
highTab += "<TR><TD>4</TD><TD>" + topScore4 + "</TD><TD style=width:50;overflow:hidden>" + Ixme4 + "</TD></TR>"
highTab += "<TR><TD>6</TD><TD>" + topScore6 + "</TD><TD style=width:50;overflow:hidden>" + Ixme6 + "</TD></TR>"
highTab += "<TR><TD>8</TD><TD>" + topScore8 + "</TD><TD style=width:50;overflow:hidden>" + Ixme8 + "</TD></TR>"
highTab += "<TR><TD>10</TD><TD>" + topScore10 + "</TD><TD style=width:50;overflow:hidden>" + Ixme10 + "</TD></TR>"
highTab += "<TR><TD>12</TD><TD>" + topScore12 + "</TD><TD style=width:50;overflow:hidden>" + Ixme12 + "</TD></TR>"
highTab += "</TABLE>"
document.getElementById("highTable").innerHTML = highTab
}

