//This contains functions that are common to all pages

function commonInit(){
var dotList =  "1,1,2,1,1,2,1,2,3,3,1,1,2,1,2,1,1,3,1,3,1,2,2,1,1,2,1,2,2,3,1,1,1,2,1,3,1,1,1,1,2,0"
/////   1c1a1b2a2b3a3b4a4b5a5b6a6b7a7b8a8b9a9b0a0b1a1b2a2b3a3b4a4b5a5b6a6b7a7b8a8b9a9b0a0b00
//   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
colors2 = new Array(4)

 //colored dot appears in left frame
 eval("dotArray = new Array(" + dotList + ")")
 colors2[1] = "#00FF33"
 colors2[2] = "#00FFFF"
 colors2[3] = "#FF6600"
 if (document.getElementById) {
   docTyp2 = "byID"
  } else 
  if (document.layers) {docTyp2 = "layers"} else {
   docTyp2 = "all" ;
  }
 lessonURL = parent.lesson.location + " "
 if (lessonURL.indexOf("unit") > -1) {
 // chgColor2()
 }
return
}

function chgColor2(){
   if (docTyp=="byID")  {
   document.getElementById('scoreBoxDiv').style.backgroundColor = '#00ff33'  
   } else if ( docTyp ==  "all") { 
   document.all['scoreBoxDiv'].style.backgroundColor = '#00ff33'
   } else if (docTyp == "layers")   { 
   document.layers['scoreBoxDiv'].bgColor = "#00ff33;"
   document.layers['scoreBoxDiv'].bgColor = "#00ff33;"
   }
} 

var docTyp2 = "???";
var oldRandNo = 1000;
//var rpt = true;
var rpt = false;

function buttonSet() {
 for (i=2; i <5; i++){
  eval("nowb = nowBlank_" + i);
  lx = "parent.menu." + nowb + "_stat"
  ly = nowb + "ON"
  eval( lx + " =  \'" + ly + "\'" )
  //alert( lx + " =  \'" + ly + "\'" + "\n" + i)
 }
 parent.menu.toggleCheck(2,'OFF')
 parent.menu.toggleCheck(3,'OFF')
 parent.menu.toggleCheck(4,'OFF')
}

function placeCircleA(person){
// alert(eval(person + "[3]  "))
 if (is.ie) { 
  eval('document.all["selCircleDiv"].style.top  = ' + person + '[3]')
  eval('document.all["selCircleDiv"].style.left = ' + person + '[2]')
  eval('document.all["selCircleDiv"].style.visibility = "visible"')
 }
 else
 {
  eval('document.layers["selCircleDiv"].top  = ' + person + '[3]')
  eval('document.layers["selCircleDiv"].left  = ' + person + '[2]')
  eval('document.layers["selCircleDiv"].visibility = "show"')
  }
}

randPhrases = new Array(15);
randWords = new Array(15);
randWordsChop = new Array(15);

function initPhraseArray(){
 for (i=0; i <= totPhrases+1; i++){
   randPhrases[i] = "";
  }
}

function initWordArray(){
 for (i=0; i <= 15; i++){
   randWords[i] = "";
   randWordsChop[i] = ""
  }
}

function tracker(){
 if ( parent.menu.thisExNo > 0) {
  parent.menu.nowState = "Closed";
  makeReportLine();
 }
 parent.menu.gameName = parent.lesson.gameName;
 parent.menu.nowScore = 0;
 parent.menu.nowState = "Opened"
 makeReportLine();
} //end tracker

function closeWin() {
 makeReportLine()
 return
}

function recordStart(){
 scoreHold = parent.menu.nowScore 
 parent.menu.nowScore = 0
 parent.menu.nowState = "Start game"
 makeReportLine()
 parent.menu.nowScore  = scoreHold
}

function makeReportLine(){
 if( parent.menu.nowState.length > 0) {
 fullDate=Date();
 parent.menu.nowDate=fullDate.substr(0,10);
 parent.menu.nowTime=fullDate.substr(11,5);
 nowX = parent.menu.thisExNo;
 parent.menu.exDone[nowX] = parent.menu.gameName;
 parent.menu.startDate[nowX] = parent.menu.nowDate;
 parent.menu.startTime[nowX] = parent.menu.nowTime;
 parent.menu.finalScore[nowX] = parent.menu.nowScore;
 parent.menu.stateAry[nowX] = parent.menu.nowState;
 parent.menu.thisExNo++;
 if (rpt) { parent.menu.sendRpt();}
 }
}

var plat = "W"

function BrowserCheck() {
     if (navigator.appVersion.indexOf("Macintosh") > -1) {plat = "M"}
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.plat = navigator.platform
	this.p = this.plat.substr(0,1)
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	//this.ie = (this.b=="ns" && this.v>=5)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.min = (this.ns||this.ie)
//below added to see if this fixes it
     if (this.ie5 > 0) this.b = "ns"; isie5 = true;
     if (this.version.substr(0,3) == "4.0" || (this.ns4 && this.p == "W")) {is40 = true} else {is40 = false}
// alert("This version is " + this.version + "  " + is40 + " " + this.p)
commonInit()
}

function placeCircle(leftx,topx){
// alert("topx=" + topx)
 if (is.ie) { 
  document.all.selCircleDiv.style.top  = topx
  document.all.selCircleDiv.style.left = leftx
  document.all.selCircleDiv.style.visibility = "visible"
 } else {
  document.layers["selCircleDiv"].top  = topx
  document.layers["selCircleDiv"].left  = leftx
  document.layers["selCircleDiv"].visibility = "show"
  }
}


function makeRandPhrases(){
 //Takes the 'keywords' for each sentence and places them in an array in random order
  initPhraseArray();
  for (i=1; i <= totPhrases; i++) {
  nowWordX = phrasesLeft.substr(0,phrasesLeft.indexOf(','));
  phrasesLeft = phrasesLeft.substr(phrasesLeft.indexOf(',')+1);
  randNo = totPhrases+1
  while (randPhrases[randNo].length == 0){
   while (randNo > totPhrases) {
    randNo = Math.floor((100*Math.random())) + 1;
  }
   if (randPhrases[randNo].length == 0) {randPhrases[randNo]= prefix + nowWordX} else {randNo = totPhrases+1};
  }
 }
return
}

function showStatus(stat){
 eval("setTimeout(\"showx('" + stat + "')\",\"50\")");
 eval("setTimeout(\"hidex('" + stat + "')\",\"600\")");
 return;
}

function hidex(layname) {
 // alert("in hidex")
  if (document.all) {
  eval('document.all["' + layname + '"].style.visibility = "hidden"')
  } else {
  eval('document.layers["' + layname + '"].visibility = "hide"')
 }
} //end hidex

function showx(layname) {
 if (document.all) {
  eval('document.all["' + layname + '"].style.visibility = "visible"')
  } else {
  eval('document.layers["' + layname + '"].visibility = "show"')
 }
} //end showx

function fixlen(x) {
if(x != null) {
 lenx = x.length;
 addsp = sp30.substr(0,60-lenx)
 newx = addsp + x;
 return newx
 }
 else {return " "}
}

function showStatLine(loc){
  status=loc; return true
}


function writeScore(n){
   divName2 = "scoreDiv"
  if (is.ns) {
  //nx = "<font class=unitsNS>" + n +    "</font>" 
   nx3 = '<font size=3 face=Helvetica,Verdana,Arial,sans-serif><b>&nbsp;'   + n +    '</b></font>'
    document.layers["scoreDiv"].document.open();
    document.layers['scoreDiv'].document.write(nx3);
    document.layers["scoreDiv"].document.close();
   } else {
    document.all[divName2].innerHTML = "<font class=units>&nbsp;" + n + "</font>";
   } // is.ns
}

function randGen(nt){
 randNo = 1000;
 while (randNo > nt ) {
   randNo = Math.floor((100*Math.random())) + 1;
 }
return randNo
}

function twoDigit(td){
 td = "" + td;
 if (td.length == 1) {td = '0' + td}
 return td
}

