<!--

theCation="";

theAnion="";

catQuestion = new Array();

anQuestion = new Array();

compQuestion = new Array();

nameQuestion = new Array();

currQuestion=0;

totalQuestions=10;

defaultEmail=email;

correct=0;

graded=false;

gameOver=false;

mailFlag=false;

catColor_old="#00FFFF";

aniColor_old="#00FFFF";

blink=false;

simRunning=false;

simBlinking=false;

randNum_cat_old=0;

randNum_ani_old=0;

score=0;

numScored=0;

scored=true;



Cation = new Array("Mg2+", "Fe3+", "Au1+", "Co2+", "K1+", "Ni2+", "Ra2+", "Ca2+", "Mn3+", "Cu2+", "Rb1+", "Cs1+", "Sr2+", "Cd2+", "Au3+", "Fe2+", "Cu1+", "Cr2+", "Pb2+", "Bi3+", "Mn2+", "Sc3+", "Li1+", "Hg[2]2+", "Co3+", "NH[4]1+", "Hg2+", "Ag1+", "Sn4+", "Cr3+", "Na1+", "Sn2+", "Al3+", "Be2+", "Ba2+", "Pb4+");

Anion = new Array("C[2]H[3]O[2]1-", "N3-", "PO[4]3-", "ClO[3]1-", "I1-", "HCO[3]1-", "NO[2]1-", "PO[3]3-", "SO[4]2-", "ClO[2]1-", "SO[3]2-", "CrO[4]2-", "CN1-", "AsO[4]3-", "IO[3]1-", "C[2]O[4]2-", "BrO[3]1-", "P3-", "HSO[4]1-", "ClO1-", "IO[4]1-", "F1-", "IO[2]1-", "O2-", "NO[3]1-", "CO[3]2-", "BrO[4]1-", "ClO[4]1-", "OH1-", "Cr[2]O[7]2-", "S2-", "H[2]PO[4]1-", "Br1-", "Cl1-", "SCN1-", "MnO[4]1-");



function startSim() {



	whichButton();

	if(gameOver) {



		alert("The game is over!");

		return;



	}

	if(simRunning) return;

	if(simBlinking) return;

	totalQuestions=document.frmChem.hdnQuestions.value;

	sim = setInterval("changeImage()",200);

	simRunning=true;

	graded=false;

	document.frmChem.numWrong.value=0;

	whichButton();



}



var img;

xL=285;

xR=435;

yT=80;

yB=385;

snaptoXani=353;

snaptoXcat=330;

boxXani=462;

boxYani=155;

boxXcat=225;

boxYcat=155;

var DRAG_lastX, DRAG_lastY, DRAG_dragging;





for(i=1;i<=4;i++) {

 for(j=1;j<=4;j++) {

  document["cat"+i+j].captureEvents(Event.MOUSEUP|Event.MOUSEDOWN);

  document["cat"+i+j].onmousedown=DRAG_begindrag;

  document["cat"+i+j].onmouseup=DRAG_enddrag;

  document["ani"+i+j].captureEvents(Event.MOUSEUP|Event.MOUSEDOWN);

  document["ani"+i+j].onmousedown=DRAG_begindrag;

  document["ani"+i+j].onmouseup=DRAG_enddrag;

 }

}



function DRAG_begindrag(e) {

		cX=e.pageX;

        cY=e.pageY;

		for(i=1;i<=4;i++) {

          for(j=1;j<=4;j++) {

  			c=document["cat"+i+j];

			if ((cX>c.left)&&(cX<c.left+c.clip.width)&&(cY>c.top)&&(cY<c.top+c.clip.height)) {

     				img="cat"+i+j;

  			}

			a=document["ani"+i+j];

			if ((cX>a.left)&&(cX<a.left+a.clip.width)&&(cY>a.top)&&(cY<a.top+a.clip.height)) {

     				img="ani"+i+j;

  			}

          }       

		} 

        DRAG_lastX=e.pageX;

        DRAG_lastY=e.pageY;

        DRAG_dragging=true;

        document.captureEvents(Event.MOUSEMOVE);

        document.onmousemove=DRAG_drag;

        return false;

}



function DRAG_enddrag(e) {

    ionTest=img.charAt(0);

    if (ionTest=="a") {

      if (DRAG_lastX>xL && DRAG_lastX<xR && DRAG_lastY>yT && DRAG_lastY<yB) {

        document[img].left=snaptoXani;    

      }

      else {

        document[img].moveTo(boxXani, boxYani);

      }

    }

    else {

      if (DRAG_lastX>xL && DRAG_lastX<xR && DRAG_lastY>yT && DRAG_lastY<yB) {

        document[img].left=snaptoXcat;  

      }

      else {

        document[img].moveTo(boxXcat, boxYcat);

      }

    }

    DRAG_dragging=false;

    document.releaseEvents(Event.MOUSEMOVE);

    document.onmousemove=null

    return false;

}



function DRAG_drag(e) {

   if (DRAG_dragging) {

      document[img].moveBy(e.pageX-DRAG_lastX, e.pageY-DRAG_lastY);

      DRAG_lastX = e.pageX;

      DRAG_lastY = e.pageY;

      return false;

   }

   else {

      return true;

   }

}









document.frmChem.cmdStart.focus();

document.frmChem.txtCompound.value="Compound";



function configGame() {



	if(simRunning) {

		whichButton();

		return;

	}

	config = open("configIt.htm", "configGame", "toolbar=no,resizable=no,width=370,height=150,left=100,top=100");

	return;



}



function gameHelp() {



	if(simRunning) {

		whichButton();

		return;

	}

	help = open("help.htm", "gameHelp", "toolbar=no,resizeable=no,scrollbars=yes,width=400,height=270,left=100,top=100");

	return;



}



function aboutGame() {



	if(simRunning) {

		whichButton();

		return;

	}

	about = open("splash.htm", "abtGame", "toolbar=no,resizable=no,width=350,height=270,left=100,top=100");

	return;



}

function whichButton() {



	if(simRunning) {

		document.frmChem.cmdEnd.focus();

		return;

	}

	if(gameOver) {

		document.frmChem.cmdSubmit.focus();

		return;

	}

	if(graded) {

		document.frmChem.cmdReset.focus();

		return;

	}

	if(simBlinking) {

		document.frmChem.cmdSeeChems.focus();

		return;

	}

	document.frmChem.cmdStart.focus();



}



function changeImage() {



	document.layers["layer" + randNum_cat_old].bgColor=catColor_old;

	randNum_cat = Math.floor(36*Math.random());

	catColor_old = document.layers["layer" + randNum_cat].bgColor;

	document.layers["layer" + randNum_cat].bgColor="#FFFFFF";	

	theCation=Cation[randNum_cat];

	document.frmChem.txtCation.value=theCation;

	document.frmChem.hdnCation.value=theCation;

	randNum_cat_old=randNum_cat;



	

	document.layers["layer" + randNum_ani_old].bgColor=aniColor_old;

	randNum_ani = (Math.floor(36*Math.random()))+36;

	aniColor_old = document.layers["layer" + randNum_ani].bgColor;

	document.layers["layer" + randNum_ani].bgColor="#FFFFFF";	

	theAnion=Anion[randNum_ani-36];

	document.frmChem.txtAnion.value=theAnion;

	document.frmChem.hdnAnion.value=theAnion;

	randNum_ani_old=randNum_ani;



}



function stopSim() {



	whichButton();

	if(!simRunning) return;

	if(simBlinking) return;

	if(document.frmChem.txtCation.value == "Hg[2]2+") {

		document.layers["layer" + randNum_ani_old].bgColor=aniColor_old;

		randNum_ani = 59;

		aniColor_old = document.layers["layer" + randNum_ani].bgColor;

		document.layers["layer" + randNum_ani].bgColor="#FFFFFF";	

		theAnion=Anion[randNum_ani-36];

		document.frmChem.txtAnion.value=theAnion;

		document.frmChem.hdnAnion.value=theAnion;

		randNum_ani_old=randNum_ani;

	}

	simRunning=false;

	clearInterval(sim);

	currQuestion++;

	document.frmChem.hdnBool.value="false";

	anQuestion[currQuestion] = Anion[randNum_ani-36];

	catQuestion[currQuestion] = Cation[randNum_cat];

	document.frmChem.txtCurProb.value=currQuestion;

	document.frmChem.txtTotProb.value=totalQuestions;

	document.frmChem.txtCompound.select();

	simBlinking=true;

	switchDraggables();

	scored=false;

    	simAns = setInterval("blinkImage()",500);

	whichButton();



}



function blinkImage() {



	if(blink) {

		document.layers["layer" + randNum_cat].bgColor=catColor_old;

		document.layers["layer" + randNum_ani].bgColor=aniColor_old;

		blink = false;

	} else {

		document.layers["layer" + randNum_cat].bgColor="#FFFFFF";

		document.layers["layer" + randNum_ani].bgColor="#FFFFFF";

		blink = true;

	}



}



function switchDraggables() {

  if (document.frmChem.test.value == "false") {

	chemA=theCation;

	chemB=theAnion;



	idx1=chemA.indexOf("+");

	idx2=chemA.indexOf("-");

	if(idx1==-1) { idx1=idx2; }



	idx2=chemB.indexOf("+");

	idx3=chemB.indexOf("-");

	if(idx2==-1) { idx2=idx3; }



	sub1=chemB.charAt(idx2-1);

	sub2=chemA.charAt(idx1-1);	



	for (i=1; i<=4; i++) {

	document["cat"+i+sub2].visibility="show";

	document["cat"+i+sub2].moveTo(boxXcat, boxYcat);

	document["ani"+i+sub1].visibility="show";

	document["ani"+i+sub1].moveTo(boxXani, boxYani);

	}

  }

}



function resetIt() {

	scoreIt();

	if(gameOver) {



		if(!mailFlag) {

			if (!document.frmChem.test.value) {

				if(!confirm("Do you want to begin another game?")) {

					alert("Please mail your work!");

					whichButton();

					return;

				}

			}

			else {

				alert("Please mail your work!");

				whichButton();

				return;

			}

		}

		

		mailFlag=false;

		document.frmChem.txtCurProb.value="";

		document.frmChem.txtTotProb.value="";

		document.frmChem.txtScore.value="";

		document.frmChem.hdnBool.value="false";

		document.frmChem.hdnScore.value=0;

		for(i=0;i<totalQuestions;i++) {



			catQuestion[i]="";

			anQuestion[i]="";

			compQuestion[i]="";



		}

		gameOver=false;

		correct=0;

		currQuestion=0;

		score=0;

		numScored=0;

		gameType();

	}



	whichButton();

	if(simRunning) return;

	if(!simBlinking) return;

	if(!graded) return;

	clearInterval(simAns);



	document.layers["layer" + randNum_cat].bgColor=catColor_old;

	document.layers["layer" + randNum_ani].bgColor=aniColor_old;



	document.frmChem.txtAnion.value="";

	document.frmChem.txtCation.value="";

	document.frmChem.txtCompound.value="Compound";

	theCation="";

	theAnion="";

	document.frmChem.hdnCation.value="";

	document.frmChem.hdnAnion.value="";

	simRunning=false;

	simBlinking=false;

	graded=false;

	document.frmChem.numWrong.value=0;

	document.frmChem.formulaCorrect.value=0;

	document.frmChem.nameCorrect.value=0;

	document.frmChem.nameQuestionTemp.value="";

    if (document.frmChem.test.value == "false") {

		for (i=1; i<=4; i++) {

			document["cat"+i+sub2].visibility="hide";

			document["cat"+i+sub2].moveTo(0,0);

			document["ani"+i+sub1].visibility="hide";

			document["ani"+i+sub1].moveTo(0,0);

		}

    }

}



function seeChems() {

	if (document.frmChem.numWrong.value >= document.frmChem.retries.value) alert("Please hit the 'Reset It' button to try another compound");	

	else {

	if(document.frmChem.txtCompound.value=="Compound") {



		document.frmChem.txtCompound.select();

		if(simBlinking) alert("Please enter the compound in the selected field \n at the bottom of the toolbar!");

		whichButton();

		return;



	}

	graded=true;

	whichButton();

	if(currQuestion>=totalQuestions) {

		document.frmChem.cmdSubmit.focus();

		gameOver=true;

	}

	compQuestion[currQuestion]=document.frmChem.txtCompound.value;

	check = open("ns_chem1.htm", "seeChem", "toolbar=no,resizable=no,width=550,height=220,left=100,top=100");

	return;

	}



}



function scoreIt() {

	if (scored) return;

	numScored++;

	if (document.frmChem.formulaCorrect.value==1)  score += 5;

	if (document.frmChem.nameCorrect.value==1)  score += 5;

	document.frmChem.txtScore.value = score;

	document.frmChem.hdnScore.value = score;

	nameQuestion[currQuestion]=document.frmChem.nameQuestionTemp.value;

	scored=true;

}



function gameType() {

     if (email != "") {

	open("gameType.htm", "typeWin", "toolbar=no,resizable=no,width=350,height=100,left=300,top=200");

	return;

     }

}



function mailReset() {

	if(document.frmChem.hdnReset.value=="true") {

		document.frmChem.hdnReset.value="false";

		clearInterval(mReset);

		resetIt();

	}

}





function mailIt() {

	if(!gameOver) {

		alert("Please finish before mailing your score!");

		whichButton();

		return;

	}

	if (document.frmChem.test.value == "false") {

		alert("Emailing results is disabled in practice mode!");

		whichButton();

		return;
	
	}
	
	if (numScored != document.frmChem.txtTotProb.value) {

		scoreIt();

	}

	mailFlag=true;

	catTemp="";

	anTemp="";

	compTemp="";

	nameTemp="";

	for(i=1;i<=totalQuestions;i++) {

		catTemp = catTemp + catQuestion[i] + "|";

		anTemp = anTemp + anQuestion[i] + "|";

		compTemp = compTemp + compQuestion[i] + "|";

		nameTemp = nameTemp + nameQuestion[i] + "|";

	}

	document.frmChem.hdnCatArray.value=catTemp;

	document.frmChem.hdnAnArray.value=anTemp;

	document.frmChem.hdnCompArray.value=compTemp;

	document.frmChem.hdnNameArray.value=nameTemp;

	mReset = setInterval("mailReset()",250);

	mailit = open("mail.htm", "mailit", "toolbar=no,resizable=no,width=420,height=230,left=100,top=100");

	return;



}





//-->