// study panel -------------

var molviewScp="load ether.pdb; wireframe 0.02; spacefill 0.3; delay 1; select carbon; lcaocartoon create sp3a"

// lcaocartoon scale 1.0 create px; delay 1; lcaocartoon delete pz; lcaocartoon scale 1.0 create py; delay 1; lcaocartoon delete py; lcaocartoon scale 1.0 create pz; delay 1; lcaocartoon delete pz;"
var molviewMsg="Test"
var molviewSettings=""

var glcflatScp="load glucose.sdf; wireframe 0.02; spacefill off; font label 16 serif bold; set labelOffset 0 0; label %e;"
var glcflatMsg="Glucose 'Lewis' Projection"

var glc3dScp="load glucose.sdf; wireframe 0.02; spacefill off; font label 16 serif bold; set labelOffset 0 0; label %e; delay 1; set minimizationCriterion 0.001; minimize; moveto 1.0 {-979 -204 20 56.51} 100.0 0.1 0.0  {4.3058 0.0 0.0} 4.4122915 {0.0 0.0 0.0} -46.622135 5.9077997 50.0;"
var glc3dMsg="Glucose 3D Projection"

var glcBSScp="load glucose.mol; wireframe 0.05; spacefill 0.3; font label 16 serif bold; set labelOffset 0 0; label %e; color label [x101010]; moveto 0 {-979 -204 20 56.51} 100.0 0.1 0.0  {4.3058 0.0 0.0} 4.4122915 {0.0 0.0 0.0} -46.622135 5.9077997 50.0;"
var glcBSMsg="Glucose Ball and Stick Projection"
var glcBSSettings="All,Atoms,0.3,Bonds,0.05,Dots,Element"

var glcSFScp="load glucose.mol; wireframe 0.05; spacefill 100%; font label 16 serif bold; set labelOffset 0 0; label %e; color label [x101010]; moveto 0 {-979 -204 20 56.51} 100.0 0.1 0.0  {4.3058 0.0 0.0} 4.4122915 {0.0 0.0 0.0} -46.622135 5.9077997 50.0;"
var glcSFMsg="Glucose Spacefill Projection"
var glcSFSettings="All,Atoms,1.0,Bonds,0.05,Dots,Element"

var glcDtsScp="load glucose.mol; spacefill 0.2; wireframe 0.05; dots 100%; font label 16 serif bold; set labelOffset 0 0; label %e; color label [x101010]; moveto 0 {-979 -204 20 56.51} 100.0 0.1 0.0  {4.3058 0.0 0.0} 4.4122915 {0.0 0.0 0.0} -46.622135 5.9077997 50.0;"
var glcDtsMsg="Glucose Dots Projection"
var glcDtsSettings="All,Atoms,0.2,Bonds,0.05,Dots,100%,Element"

var glcSfcScp="load glucose.mol; wireframe off; spacefill 5%; color atoms gray; isosurface SASURFACE 0.2;  color isosurface translucent white; moveto 0 {-979 -204 20 56.51} 100.0 0.1 0.0  {4.3058 0.0 0.0} 4.4122915 {0.0 0.0 0.0} -46.622135 5.9077997 50.0;";
var glcSfcMsg="Glucose Spacefill Projection";
var glcSfcSettings="All,Atoms,0.05,Bonds,0.05,Dots,|col;Grey;grey|,Element,IsoSurface";

var catalScp="load 7CAT.pdb; hide [HOH]; moveto 0 { -222 -968 120 156.35} 100.0 2.08 9.71   {3.974001 5.938999 12.636498} 47.37117 {0.0 0.0 0.0} 9.346173 16.489847 50.0; wireframe 0.15; spacefill 1.25; select [HEM] OR [NDP]; color atoms CPK; select protein; color atoms amino";
var catalMsg="Catalase";
var catalSettings="All,Atoms,1.25,Bonds,0.15,Dots,|col;Amino acids;Shapely|,Element";

var catalTcScp="load 7CAT.pdb; hide [HOH]; moveto 0 { -222 -968 120 156.35} 100.0 2.08 9.71   {3.974001 5.938999 12.636498} 47.37117 {0.0 0.0 0.0} 9.346173 16.489847 50.0; wireframe 0.15; spacefill 1.25; select [HEM] OR [NDP]; color atoms CPK; select protein; color atoms shapely; select all; for(var i = 1.25; i > 0.25; i = i - 0.1); delay 0.1; spacefill @i; end for; trace 100; color trace gold; select protein";
var catalTcMsg="Catalase";
var catalTcSettings="All,Atoms,0.25,Bonds,0.15,Trace,100,Dots,|col;Amino acids;Shapely|,Element"

var catalHmSettings="All,Atoms,0.25,Bonds,0.15,Trace,100,Dots,|col;Amino acids;Shapely|,Element";
var catalHmAni="select [HEM] OR [NDP]; color atoms CPK; for(var i = 0.25; i <= 2.0; i = i + 0.1); delay 0.1; spacefill @i; end for; select protein";

var DNAScp= "load bdna.pdb; moveto 0 { -843 -236 483 106.48} 100.0 0.0 0.0  {-0.07799959 -0.10200024 -0.0050001144} 25.542456  {0.0 0.0 0.0} 0.047034025 -0.07771263 50.0; ribbon 200; color ribbon green; set spin Y 10;spin on; hbonds calculate; hbonds 0.15; color hbonds magenta";
var DNAMsg="DNA Double Helix"
var DNASettings="Atoms,0.4,Bonds,0.15,H-Bonds,0.15,Dots,Ribbon,200,Trace,|mol;Strand;all|,Element,|col;Base;shapely|";



// inquiry panel -------------

var sucrflatScp="load sucrose.sdf; moveto 0 { 128 100 -987 70.45}  100.0 0.0 0.0   {4.93555 0.0 0.0} 5.9158726  {0.0 0.0 0.0} -14.664301 -45.55701 50.0; wireframe 0.02; spacefill off; font label 16 serif bold; set labelOffset 0 0; label %e;"
var sucrflatMsg="Sucrose -- common table sugar"
var sucrSettings="All,Atoms,Bonds,0.02,Dots,Element,|col;Grey;grey|,IsoSurface"; 

var sucrSFScp="load sucrose.mol; moveto 0 { 128 100 -987 70.45}  75.36 0.0 0.0  {4.93555 0.0 0.0} 5.9158726  {0.0 0.0 0.0} -10.993255 -34.151234 50.0; wireframe 0.2; spacefill 0.5; font label 10 serif bold; set labelOffset 0 0; label %e; color label [x101010]"
var sucrSFMsg="Sucrose -- common table sugar"
var sucrSFSettings="All,Atoms,0.5,Bonds,Dots,Element,|col;Grey;grey|,IsoSurface"; 

// 1kb9 is Cytochrome bc1 from yeast -- quartenary structure animation; 
var CytochromeScp = "load 1kb9.pdb; moveto 0 { -999 -26 -26 90.04}  100.0 0.0 0.0  {0.0 0.0 1.1315002} 75.653854 {0.0 0.0 0.0} 4.5437284E-4 0.9572013 50.0; select water; spacefill off; select [HOH],[SMA],[UQ6],[PIE],[CDL],[UMQ],[PCF],[PEF]; spacefill off; wireframe off; select protein; spacefill 400; color atoms chain; wireframe 20; ribbons 200; color ribbon chain; select visible; subset selected; select protein; set atomPicking True;";
var CytochromeMsg = "Yeast Cytochrome bc1";
var CytochromeSettings ="Atoms,1.6,Bonds,0.1,Ribbon,200,Trace,Dots,IsoSurface,Protein,Cofactors,Memb Surface,4o Structure,Element,1o Structure,2o Structure" 


var opnSettings="Atoms,2.0,Bonds,0.3,Dots,Trace,Ribbon,Protein,DNA,White,Element,1o Structure,2o Structure,4o Structure";
var opnScp="load 1osl_modif.mol; select all; spacefill 2.0; wireframe 0.1; color atoms white; moveto 0 1 0 0 100;"; 
var opnMsg="DNA-protein complex"

function showDipole(num1,num2,dpOffSet,dpColor,lblFont){
jmolScriptWait("dipole (atomno="+num1+")(atomno="+num2+"); dipole bonds width 0.06; dipole offsetSide "+dpOffSet+"; color dipoles "+dpColor+"; set labelOffset 0 0; color label [x101010]; font label "+lblFont+" serif; select atomno="+num2+"; label \u03B4 -; select atomno="+num1+"; label \u03B4 +;"); 
}


function showCrbnNum(){
jmolScript("select {@isCarb AND carbon}; set labelOffset 0 0; set labelFront; color label gold; font label 20; label %a; select ALL");
}

var mtchAns="";
function setMtchAnswers(Ans){
	// type of bond type to be described by correct match
mtchAns=Ans;
}

function checkMatch(MtchVal,ctlID){
var corMat="false"
if (mtchVal == mtchAns){
	corMat = "True"
}
evalResponse(corMat,true,ctlID);
}

var inpAnswers=""
function setInpAnswers(inpAns){
inpAnswers=inpAns.split(",");
   //IE wants to send 'enter' keycode to applet which activates zoom
   // this turns off zoom only for IE
if(window.event){     
  runScript('zoom off')
  }
}



function checkInp(e,corAns,inpVal,ctlID) {
	// look for 'enter' key code (13)
var keynum="";
if(window.event){     //IE
  keynum = window.event.keyCode;
  }
else if(e.which) // Netscape/Firefox/Opera
  {
  keynum = e.which;
  }
if (keynum == 13) {
document.getElementById(tallyGroup+"Attempts").value= Number(document.getElementById(tallyGroup+"Attempts").value)+1;
if (inpVal+"" == inpAnswers[corAns-1]){
	document.getElementById(tallyGroup+"Correct").value = Number(document.getElementById(tallyGroup+"Correct").value)+1;
	showMsg("Well done! That is Correct");
	}
else{
	showMsg("Oops! That is incorrect. Try Again.")
	document.getElementById(ctlID).value="";
	}
}
}

function setPolAnswers(Ans){
	// for amino acid models set sidechain type checkbox values
var aAnswers = window[Ans].split(",");	
for (i=0;i<=aAnswers.length-1;i++){
	document.getElementById("qPol"+(i+5)).value=aAnswers[i];
	}
}

var addBondAnswers=""
function setAddBondAnswers(Ans){
	// for amino acid models set sidechain type checkbox values
addBondAnswers = Ans.split(";");
}

function setBPAnswers(BPType){
	// for base pair models set asnswer checkbox values
var aAnswers = window[BPType+'Ans'].split(",");	
for (i=0;i<=6;i++){
	document.getElementById("qBP"+i).value=aAnswers[i];
	}
for (i=7;i<=11;i++){
	document.getElementById("q2BP"+i).value=aAnswers[i];
	}	
}

function setMutAnswers(MutType){
	// for base pair models set asnswer checkbox values
var aAnswers = window[MutType+'Ans'].split(",");	
for (i=0;i<=8;i++){
	document.getElementById("qMut"+i).value=aAnswers[i];
	}
}

var btypScp=""
function setbtypAnswers(Ans,scrp){
	// for identifying bond types	
btypScp=scrp;	
	//btypScrp holds script that shows bonds
var aAnswers = window[Ans].split(",");	
for (i=0;i<=aAnswers.length-1;i++){
	document.getElementById("btyp"+(i+1)).value=aAnswers[i];
	}
}

function PreEvalResponse(ctlValue,isChecked,ctlID){
evalResponse(ctlValue, isChecked, ctlID)
if (ctlValue == "True"){
	runScript(btypScp)
	}
}

var atmCount=0
var frstAtmNm=0
var frstAtmIdx=0
function IsPickCorrect (id){
	// examine atom selected and determine if it is correct	
document.getElementById(tallyGroup+"Attempts").value= Number(document.getElementById(tallyGroup+"Attempts").value)+1;	
if (toSelect == 'tplB') {
	if (addBondAnswers[1].search(id) != -1){
		runScript ("connect (atomno="+bndAtom1+") (atomno="+bndAtom2+") RADIUS 0.075 TRIPLE MODIFY")
		document.getElementById(tallyGroup+"Correct").value = Number(document.getElementById(tallyGroup+"Correct").value)+1;
		return("Correct! This is the location of a triple bond.");
		} 
	else{
		return("Oops! This is not the location of a triple bond. Try Again.");
		}
	}
if (toSelect == 'dblB') {
	if (addBondAnswers[0].search(id) != -1){
		runScript ("connect (atomno="+bndAtom1+") (atomno="+bndAtom2+") RADIUS 0.075 DOUBLE MODIFY")
		document.getElementById(tallyGroup+"Correct").value = Number(document.getElementById(tallyGroup+"Correct").value)+1;
		return("Correct! This is the location of a double bond.");
		} 
	else{
		return("Oops! This is not the location of a double bond. Try Again.");
		}
	}
	
if (toSelect == 'hexnl') {
	if (id == "1"  || id == "2" ) {
		document.getElementById(tallyGroup+"Correct").value = Number(document.getElementById(tallyGroup+"Correct").value)+1;
		return("Correct! This is a polar bond.");
		} 
	else{
		return("Oops! This is the non-polar region. Try Again.");
		}
	}

if (toSelect == 'ala') {
	if (id == "1" || id == "6" ||id == "7" ||id == "8") {
		document.getElementById(tallyGroup+"Correct").value = Number(document.getElementById(tallyGroup+"Correct").value)+1;
		return("Correct! This is a nonpolar bond.");
		} 
	else{
		return("Oops! This is the polar region. Try Again.");
		}
	}	
	
if (toSelect == 'Hbnd'){

			// this is for nucleotide pairs where students click on the atoms forming H-bonds
			// get the custom typeIndx property of the atom
	var typeIndx=jmolEvaluate("{atomno="+atmNm+"}.property_BPIndx");
	if (typeIndx === 0) {
		return "This atom is not |involved in hydrogen bonding";
		}
	else {
		if (atmCount === 0){		
			atmCount=1;
			frstAtmNm=atmNm;		
			frstAtmIdx=typeIndx;		
			return "Good. Now click on the atom|to which it will bond.";
			}
		else{
			if (atmNm == frstAtmNm){
					return "Click on a different atom.";
				}
			else {
					if(frstAtmIdx == typeIndx){
						jmolScript("select atomno="+frstAtmNm+" OR atomno="+atmNm+"; CONNECT (selected) HBOND; hbond 0.2; color hbonds magenta");
						document.getElementById(tallyGroup+"Correct").value = Number(document.getElementById(tallyGroup+"Correct").value)+1;
						atmCount=0
						return "Correct! These atoms will hydrogen bond.";
						}
					else{
						atmCount=0
						return "Oops! These atoms do not|hydrogen bond.|Start again.";
					}
				}
			}
		}	
	}


}

