// JavaScript Document myObject.studid="Cliff_K__Whitworth_728893";


function stargateLogin(myform){
  
}

store = "";

function confirmGBA(itemgradebookid,studname){
  if(confirm ("IF YOU DO NOT INTEND TO ENTER A GRADE FOR THIS STUDENT PLEASE CANCEL. If you continue the student will not be able to submit this assignment. You are about to create a record for this user in place of their assignment. The grade of GBA (Graded By Admin) will be visible until a grade is entered.")){
    makeGBARecord(itemgradebookid,studname);
  }else{
    return false;
  }  
}

function makeGBARecord(itemgradebookid,studname){
  qs();
  //alert(qsParm['catnum']+":"+itemgradebookid+":"+studname+":"+qsParm['offering']);  
  var url = urls.plugins+"functions_http.php?menu=createNS&catnum="+qsParm['catnum']+"&itemgradebookid="+itemgradebookid+"&studname="+studname+"&offering="+qsParm['offering'];
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        //alert(modreq.responseText);
        window.open(modreq.responseText);
      }
    }
  }
  modreq.send(null);
}

function gotoGradeBook(catnum,offering,itemgradebookid){
  user = document.getElementById("gotoThisPerson").value;
  //alert(catnum+":"+offering+":"+itemgradebookid+":"+user);
  location.href=urls.index+"courseware.php?manage=grades&func=all&catnum="+catnum+"&offering="+offering+"&itemgradebookid="+itemgradebookid+"#"+user;
}

function checksAll(fields){
  if(document.getElementById("doAll").checked == true){
    for (i = 0; i < fields.length; i++) fields[i].checked = true ;
  }else{  
    for (i = 0; i < fields.length; i++) fields[i].checked = false ;
  }  
}

function showThis(){
  switch(document.getElementById("selectMe").value){
    case "email":
      var url = urls.plugins+"functions_http.php?menu=showEmailForm";
      break;
  }
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        document.getElementById("doDiv").innerHTML = modreq.responseText;
      }
    }
  }
  modreq.send(null);
}

function doThis(fields){
  for(i = 0; i < fields.length; i++){
   if(fields[i].checked == true){
    //alert(fields[i].value);
    var url = urls.plugins+"functions_http.php?menu=sendMail&id="+fields[i].value+"&esubject="+document.getElementById('esubject1').value+"&ebody="+document.getElementById('ebody1').value;
    alert(url);
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        document.getElementById("doDiv").innerHTML = modreq.responseText;
      }
    }
  }
  modreq.send(null);
   }
  }
}  

function closeNucWindow(){
  window.close();
  //if (confirm ("ALERT! Click OK to close this window.")) window.close();
}

function showMe(id){//for wikimedia
  document.getElementById(id+"_block").className == "displayNone"?document.getElementById(id+"_block").className = "displayBlock":document.getElementById(id+"_block").className = "displayNone";
  document.getElementById(id+"_excol").innerHTML == "(click to expand)"?document.getElementById(id+"_excol").innerHTML = "(click to collapse)":document.getElementById(id+"_excol").innerHTML = "(click to expand)";
}

function updateMemberSettings(){
  var url = urls.plugins+"functions_http.php?menu=updateMemberSettings";
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        //document.getElementById("wholePage").innerHTML = modreq.responseText;
        alert(modreq.responseText);
      }
    }
  }
  modreq.send(null);
}

//My Code Begin
misc.alertVar=0;
function endExam(){
 if(misc.alertVar==0){
  var vValue = getRadioValue("q1");
  var nq="q50"
  if(vValue==null) vValue=-1;
  vValue++;
  var insertStr=nq+"_"+vValue;
  var url1 = urls.plugins+"functions_http.php?menu=createOrUpdate&value="+insertStr+"&itemgradebookid="+misc.item;
  //alert(url1);
  var modreq1=getHTTPObject(); 
  modreq1.open("GET", url1, true);
    modreq1.onreadystatechange=function(){
      if (modreq1.readyState==4) {
        if (modreq1.status==200) {
          //alert("time");
          var msgStr = "<h3>Thank you!</h3>";
          document.getElementById("qat_div").innerHTML = msgStr;
          document.getElementById("r2c").className="displayBlock";
          grade1Assgn(); 
        }
      }
    }
  modreq1.send(null);
  } 
  var msgStr = "<h3>Thank you!</h3>";
  document.getElementById("newP").innerHTML = msgStr ;
  document.getElementById("r2c").className="displayBlock";
}

function leftTime(){ 
   var msg = "<strong style=\"color: red;\">Reminder: You have 2 minutes or less to finish this exam.</strong>";
   document.getElementById("newP").innerHTML = msg;
}

function myretest(){  
  if(document.getElementById("newP")) document.getElementById("newP").innerHTML = '' ;
  if(document.getElementById("qat_div")) document.getElementById("qat_div").innerHTML = "<h3 style=\"color: red;\">Sorry, time has expired.</h3>";
  if(document.getElementById("r2c")) document.getElementById("r2c").className="displayBlock";  
  grade1Assgn();
  misc.alertVar =1;
  setTimeout(endExam,5000);
}

function mytest(newvalue,startTime,newTime,totTime){
  //alert(totTime);
  var totalTime = totTime*60*1000;//60
  //var totalTime = 30*1000;//60
  var twoMin = 2*60*1000;//2
  //var twoMin = 15*1000;//2
  setTimeout(myretest,totalTime);
  setTimeout(leftTime,totalTime-twoMin);
}

function getRadioValue(RadioName){
  var colRadio = document.getElementsByName(RadioName);
  for (var i = 0; i < colRadio.length; i++){
    if (colRadio[i].checked){
      return i;
    }
  } 
  return null;    
}

function grade1Assgn(){
  var url = urls.plugins+"functions_http.php?menu=grade1Assgn&itemgradebookid="+misc.item;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    //if(!ie6){ 
      if(!modreq.getResponseHeader("Date")){
        var cached = modreq;
        modreq = (typeof(XMLHttpRequest) != "undefined") ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
        var ifModifiedSince = cached.getResponseHeader("Last-Modified");
        ifModifiedSince = (ifModifiedSince) ? ifModifiedSince : new Date(0); // January 1, 1970
        modreq.open("GET", url, false);
        modreq.setRequestHeader("If-Modified-Since", ifModifiedSince);
        modreq.send("");
        if(modreq.status == 304)
        {
          modreq = cached;
        }
      }
    //}
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        //document.getElementById("testDiv").innerHTML = modreq.responseText;
        //alert(modreq.responseText);
      }
    }
  }
  modreq.send(null);
}

function getQuestion(nq,item){  
  if(nq.substring(1)==0){
    qs();
    var url = urls.plugins+"functions_http.php?menu=ie6HackforQAT&itemgradebookid="+item+"&offering="+qsParm['offering'];
    var modreq=getHTTPObject(); 
    modreq.open("GET", url, true);
    modreq.onreadystatechange=function(){
      if(ie6)
      { 
        if(!modreq.getResponseHeader("Date"))
        {
          var cached = modreq;
          modreq = (typeof(XMLHttpRequest) != "undefined") ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
          var ifModifiedSince = cached.getResponseHeader("Last-Modified");
          ifModifiedSince = (ifModifiedSince) ? ifModifiedSince : new Date(0); // January 1, 1970
          modreq.open("GET", url, false);
          modreq.setRequestHeader("If-Modified-Since", ifModifiedSince);
          modreq.send("");
          if(modreq.status == 304)
          {
            modreq = cached;
          }
        }
      }
      if (modreq.readyState==4) {
        if (modreq.status==200) {
          //alert(modreq.responseText);
          if(modreq.responseText=="continue"){
            document.getElementById("r2c").className="displayNone";
            createUpdate(nq,item);                         
          }else{
            document.getElementById("qat_div").innerHTML = "It appears you have already taken this test.";
          }  
        }
      }
    }
    modreq.send(null);       
  }else{
    createUpdate(nq,item);
  } 
}

function createUpdate(nq,item){
  qs();    
  misc.item=item;
  if(nq.substring(1)!=0){
    var vValue = getRadioValue("q1");
    if(vValue==null) vValue = -1;
    vValue++;
    var insertStr=nq+"_"+vValue;
    var url = urls.plugins+"functions_http.php?menu=createOrUpdate&value="+insertStr+"&itemgradebookid="+item+"&offering="+qsParm['offering'];
    var modreq=getHTTPObject(); 
    modreq.open("GET", url, true);
      modreq.onreadystatechange=function(){
        if (modreq.readyState==4) {
          if (modreq.status==200) {
            //alert(modreq.responseText);
            nxtQuestion(nq,item);
          }
        }
      }
    modreq.send(null);
  }else{
    nxtQuestion(nq,item);
  } 
}

function nxtQuestion(nq,item){
    nq=nq.substring(1); //to get the number of the previous.
    nq++; // increment the number by 1.
    nq="q"+nq; // appending q to form the next question.
    var url = urls.plugins+"functions_http.php?menu=createAssgn&value="+nq+"&itemgradebookid="+item;
    //  alert(url);
    var modreq=getHTTPObject(); 
    modreq.open("GET", url, true);  
    modreq.onreadystatechange=function(){
      if (modreq.readyState==4) {
        if (modreq.status==200) {
          //alert(modreq.responseText);
          document.getElementById("qat_div").innerHTML = modreq.responseText;   
          grade1Assgn();               
        }
      }
    }
    modreq.send(null);
}

function makeSure2(val,name){
  var valu = document.getElementById(val).value;
  switch(val){
  case "deleteMember":    
      if(confirmThis(name)){
        deleteMember(name);
      }else{
        return false;
      }
      break;      
  }  
}

function makeSure(val){
  var valu = document.getElementById(val).value;
  switch(val){
  case "catnumSelect":    
      var url = urls.plugins+"functions_http.php?menu=getCourseName&catnum="+valu;    
      var modreq=getHTTPObject(); 
      modreq.open("GET", url, true);  
      modreq.onreadystatechange=function(){    
        if (modreq.readyState==4) {      
          if (modreq.status == 200) {
            valu2 = modreq.responseText;            
            if (!valu2){
              alert("Please Select a Course");
              return false;
            }else{
              if (confirmThis(valu2)) document.forms[0].submit();
            }              
          }
        }
      }
      modreq.send(null);
      break;
  case "uname":    
      if(confirmThis(valu)){
        return true;
      }else{
        return false;
      }
      break;
  case "deleteMember":    
      if(confirmThis(document.getElementById("uname").value)){
        deleteMember(document.getElementById("uname").value);
      }else{
        return false;
      };
      break; 
  case "editMember":    
      //alert(document.getElementById("uname").value);
      editMyMember(document.getElementById("uname").value);
      break;       
  }  
}

function searchGroups(){
  qs();
  var type = document.getElementById('searchGroup').value; 
  var group = document.getElementById('theAlphabet').value; 
  //alert(type+":"+group);
  if(type){    
    var url = urls.plugins+"functions_http.php?menu=viewGroup&type="+type+"&group="+group+"&skin="+qsParm['skin'];
    var modreq=getHTTPObject(); 
    modreq.open("GET", url, true);  
    modreq.onreadystatechange=function(){
      if (modreq.readyState==4) {
        if (modreq.status == 200) {
          document.getElementById("getMembers").innerHTML = modreq.responseText;
          document.getElementById("getMembersDiv").className = "displayBlock";
          document.getElementById("searchGroup").value = type;
        }
      }
    }
    modreq.send(null);
  }
}


function editMyMember(uname){        
  var url = urls.plugins+"functions_http.php?menu=editMyMember&mname="+uname;   
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status == 200) {          
        document.getElementById("editMyMember").innerHTML=modreq.responseText; 
      }
    }
  }
  modreq.send(null);
}

function deleteMember(uname){        
  var url = urls.plugins+"functions_http.php?menu=deleteMember&mname="+uname;   
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status == 200) {          
        updateSelectedGroup(modreq.responseText);
      }
    }
  }
  modreq.send(null);
}

function updateSelectedGroup(resp){ 
  var group = document.getElementById("searchGroup").value;      
  var url = urls.plugins+"functions_http.php?menu=viewGroup&group="+group;   
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status == 200) { 
        document.getElementById("getMembers").innerHTML=modreq.responseText;                 
      }
    }
  }
  modreq.send(null);
}

function confirmThis(val){
  if (confirm ("ALERT! Are you sure you want to delete "+val+"?")) {
    return true;
  }else{
    return false;
  }
}

function gradeSingleAssgn(id){
  var myGrade = document.getElementById('assgnSingleGradeValue').value;  
  if(myGrade){        
    var url = urls.plugins+"functions_http.php?menu=gradeSingleAssgn&value="+myGrade+"&itemassgnid="+id;   
    var modreq=getHTTPObject(); 
    modreq.open("GET", url, true);  
    modreq.onreadystatechange=function(){
      if (modreq.readyState==4) {
        if (modreq.status == 200) {          
          alert(modreq.responseText);          
          window.close();
        }
      }
    }
    modreq.send(null);
  }
}

function searchNames(){
  name = document.getElementById('searchName').value; 
  if(name){    
    var url = urls.plugins+"functions_http.php?menu=searchNames&lname="+name;
    var modreq=getHTTPObject(); 
    modreq.open("GET", url, true);  
    modreq.onreadystatechange=function(){
      if (modreq.readyState==4) {
        if (modreq.status == 200) {
          document.getElementById("myMembers").innerHTML = modreq.responseText;
          document.getElementById("getMembers").className = "displayBlock";
          document.getElementById("getMembersExtra").className = "displayBlock";
          getOfferings(document.getElementById("courses").value);
        }
      }
    }
    modreq.send(null);
  }
}

function getOfferings(catnum){
  qs();
  if(document.getElementById("viewClassMembers")) document.getElementById("viewClassMembers").innerHTML = "";
  if(catnum>0){    
    var url = urls.plugins+"functions_http.php?menu=getOfferings&catnum="+catnum+"&menutype="+qsParm['menu'];
    var modreq=getHTTPObject(); 
    modreq.open("GET", url, true);  
    modreq.onreadystatechange=function(){
      if (modreq.readyState==4) {
        if (modreq.status == 200) {
          document.getElementById("getOfferingsDiv").innerHTML = modreq.responseText;
        }
      }
    }
    modreq.send(null);
  }
}

function viewClassMembers(){
  var url = urls.plugins+"functions_http.php?menu=viewClassMembers&sct="+document.getElementById("offerings").value;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status == 200) {
        document.getElementById("viewClassMembers").innerHTML = modreq.responseText;
      }
    }
  }
  modreq.send(null);
}

function emailClassMembers(){
  alert("Coming Soon");
}

function archiveSection(){
  var url = urls.plugins+"functions_http.php?menu=archiveSection&catnum="+document.getElementById("courses").value+"&sct="+document.getElementById("offerings").value;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status == 200) {
        document.getElementById("archiveSectionDiv").innerHTML = modreq.responseText;
      }
    }
  }
  modreq.send(null);
}

function showAssgnOffering(offering,itemgradebookid,catnum){
  //alert(offering+":"+itemgradebookid+":"+catnum);
  //location.href=urls.index+"courseware.php?manage=grades&func=single_assgn&itemgradebookid="+itemgradebookid+"&offering="+offering+"&catnum="+catnum;
  //return false;
  qsParm['offering'] = null;
  qs();
  if(qsParm['offering']!=offering) location.href=urls.index+"courseware.php?manage=grades&func=single_assgn&itemgradebookid="+itemgradebookid+"&offering="+offering+"&catnum="+catnum;
  if(qsParm['offering']){
    var url = urls.plugins+"functions_http.php?menu=getAssgnGrades&offering="+offering+"&itemgradebookid="+itemgradebookid+"&catnum="+catnum;
    var modreq=getHTTPObject(); 
    modreq.open("GET", url, true);  
    modreq.onreadystatechange=function(){
      if (modreq.readyState==4) {
        if (modreq.status == 200) {
          document.getElementById("gradebookOffering").innerHTML = modreq.responseText;
          getAssgnOffering();
        }
      }
    }
  }  
  if(qsParm['offering']) modreq.send(null);
}

function getAssgnOffering(){
  var url = urls.plugins+"functions_http.php?menu=getAssgnOffering";
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status == 200) {
        //document.getElementById("selectOffering").value = modreq.responseText;
      }
    }
  }
  modreq.send(null);
}

function showOffering(offering,catnum,itemgradebookid){
//alert(offering+":"+catnum+":"+itemgradebookid);
  qsParm['offering'] = null;
  qs();
  if(qsParm['offering']!=offering)location.href=urls.index+"courseware.php?skin="+qsParm['skin']+"&manage=grades&func=all&catnum="+catnum+"&offering="+offering+"&itemgradebookid=0";
  if(qsParm['offering']){
    var url = urls.plugins+"functions_http.php?menu=getGrades&offering="+offering+"&catnum="+catnum+"&itemgradebookid="+itemgradebookid;
    var modreq=getHTTPObject(); 
    modreq.open("GET", url, true);  
    modreq.onreadystatechange=function(){
      if (modreq.readyState==4) {
        if (modreq.status == 200) {
          document.getElementById("gradebookOffering").innerHTML = modreq.responseText;
          getOffering();
        }
      }
    }
    modreq.send(null);
  }
}

function getOffering(){
  var url = urls.plugins+"functions_http.php?menu=getOffering";
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status == 200) {
        //alert(modreq.responseText);
        //document.getElementById("selectOffering").value= modreq.responseText;
        //alert("here");
      }
    }
  }
  modreq.send(null);
}

function myStatus(name, offering){
  
  var status = document.getElementById(name+"span").innerHTML;
  var nustatus=(status=="complete")?"incomplete":"complete";
  if(confirm("Are you sure you want to mark this user:offering("+offering+") as "+nustatus+"?")) httpStatus(name,offering,nustatus);
}

function httpStatus(name, offering, nustatus){
  qs();
  var catnum = qsParm['catnum'];
  var url = urls.plugins+"functions_http.php?menu=status&mname="+name+"&offering="+offering+"&nustatus="+nustatus+"&catnum="+catnum;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status == 200) {
       //alert(modreq.responseText);
       document.getElementById(name+"span").innerHTML = modreq.responseText;
      }
    }
  }
  modreq.send(null);
}

function deleteAssgn(id,name){
  if(confirm("Are you sure you want to delete "+name+"'s assignment?")) httpDelAssgn(id);
}

function resubmitAssgn(id,name){
  if(confirm("Are you sure you want to allow "+name+" to resubmit assignment?")) httpResubmitAssgn(id);
}

function httpDelAssgn(id){
  var url = urls.plugins+"functions_http.php?menu=delAssgn&itemassgnid="+id;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status == 200) {
        //alert("Assignment was deleted. Please refresh browser.");
        alert(modreq.responseText);
      }  
    }
  }
  modreq.send(null);
}

function httpResubmitAssgn(id){
  var url = urls.plugins+"functions_http.php?menu=resubmitAssgn&itemassgnid="+id;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status == 200) {
        //alert("Assignment was deleted. Please refresh browser.");
        alert(modreq.responseText);
      }  
    }
  }
  modreq.send(null);
}

function makeLOCALRequest(localstr,col) {
//See updateLocal.php for adjgrade() and prpgrade($functd)
  httpLocal = false;
  url = urls.plugins+"functions_http.php";
  var httpLocal=getHTTPObject();
  httpLocal.open('POST', url, true);
  httpLocal.onreadystatechange=function(){
    if (httpLocal.readyState == 4) {
      if (httpLocal.status == 200) {
        result = httpLocal.responseText;
        var funct = new Array();
        funct = result.split(":::");
        switch(funct[0]){
          case "adjgrade":
            alert(funct[1]);
            window.location.reload(false);
            break;
          case "prpgrade":
            var setprp = new Array();
            setprp = funct[1].split(":");        
            var eachItem = new Array();
            for(x in setprp){
              eachItem = setprp[x].split("=");
              mycurrArray = setprp[x].substring(0,setprp[x].indexOf("_"));
              if(mycurrArray=="radio"){ 
                document.getElementById(eachItem[1]).checked=true;
              }
            }
            break;
          case "prpvalues":
            var setprp = new Array();
            setprp = funct[1].split(":");        
            var eachItem = new Array();
            for(x in setprp){
              eachItem = setprp[x].split("=");
              mycurrArray = setprp[x].substring(0,setprp[x].indexOf("_"));
              if(mycurrArray=="text") document.getElementById(eachItem[0]).value=eachItem[1];
              if(mycurrArray=="select") document.getElementById(eachItem[0]).value=eachItem[1];
            }
            changeTotalValue(col);
            break;
          default:
            break;  
        }   
                 
      } else {
        alert('There was a problem with makeLocalRequest.');
      }
    }  
  }  
  httpLocal.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  httpLocal.setRequestHeader("Content-length", localstr.length);
  httpLocal.setRequestHeader("Connection", "close");
  httpLocal.send(localstr);
}

function updateGrade(id,value){  
  gradeValue = document.getElementById("grade"+value).value;
  teaCommentValue = document.getElementById("teacomment"+value).value;
  var localstr = encodeURI("menu=itemassgn&");
  localstr += encodeURI("id="+id+"&grade="+gradeValue+"&teacomment="+teaCommentValue);   
  makeLOCALRequest(localstr,0);
}

function openlmsWindow(id){
  window.open ("http://localhost/tcet/home/courses/"+id,
  "mylmswindow","menubar=0,toolbar=0,status=1,directories=0,resizable=1,width=780,scrollbars=1");
}

function openlmsWindowProduction(id,sco){
//http://wcl.ednet10.net/lms-ds/icl/launch.ds?courseNumber=SCBTEST0006&itemIdentifier=Exposure_Control_SCO
  window.open ("http://wcl.ednet10.net/lms-ds/icl/launch.ds?courseNumber="+id+"&itemIdentifier="+sco,
  "mylmswindow","menubar=0,toolbar=0,status=1,directories=0,resizable=1,width=780,scrollbars=1");
}


function gradePropKey(){
  var myGradePropKey = "I = Complete/Incomplete\n # = Numeric Grade\n A = Letter Grade\n NS = Not Submitted";
  myGradePropKey += "\nValue 0 = default value of 100";
  alert(myGradePropKey);
}

function processGradeProp(myform){
alert(myform['function']);
  var poststr = encodeURI("function="+myform['function'].value+"&");
  poststr += encodeURI("catnum="+myform['catnum'].value+"&");
  poststr += encodeURI("sectnum="+myform['sectnum'].value+"&");
  for(i=0;i<myform.length;i++){
    if(myform[i].checked) poststr += encodeURI(myform[i].name+"="+myform[i].id+"&");
    if(myform[i].type=="textarea") poststr += encodeURI(myform[i].name+"="+myform[i].value+"&");
    if(myform[i].type=="text") poststr += encodeURI(myform[i].name+"="+myform[i].value+"&");
    if(myform[i].type=="select-one") poststr += encodeURI(myform[i].name+"="+myform[i].value+"&");
  } 
  makeLOCALRequest(poststr,0);
}

function changeTotalValue(col){
  var totalValue = 0;
  var totalWeight = 0;
  for(var i=0; i<col; i++){
    iv = "text_value" + (i + 2);
    iw = "select_weight" + (i + 2);
    thisTempValue = document.getElementById(iv)?document.getElementById(iv).value:100; 
    thisValue = (thisTempValue==0)?100:thisTempValue;
    totalValue += parseInt(thisValue);
    thisTempWeight = document.getElementById(iw)?document.getElementById(iw).value:0; 
    thisWeight = (thisTempWeight==0)?0:thisTempWeight;
    totalWeight += parseInt(thisWeight);
  }
  if(totalWeight==0) totalWeight=100;
  document.getElementById("texttot_value").value = totalValue;
  document.getElementById("texttot_weight").value = totalWeight;
}

function changeType(type,id,colCount){
  var lil_id = id.substr(id.lastIndexOf('_')+3,id.length);
  var setV = "td1" + lil_id; 
  var col = colCount-2; 
  var defValue = 0; 
  if(document.getElementById("td11").innerHTML==""){
    totalStr="<p>Total Value:<br /><input type=\"text\" name=\"texttot_value\" id=\"texttot_value\" class=\"weeSmaller\" value=\"loading\" /></p>";
    totalStr+="<p>Total Weight:<br /><input type=\"text\" name=\"texttot_weight\" id=\"texttot_weight\" class=\"weeSmaller\" value=\"100\" /></p>";
    document.getElementById("td11").innerHTML=totalStr;
  }  
  weightStr="<p>Value:<br /><input type=\"text\" name=\"text_value"+lil_id+"\" id=\"text_value"+lil_id+"\" class=\"weeSmaller\" value=\""+defValue+"\" onblur=\"changeTotalValue("+col+");\"/></p>";
  weightStr+="<p>";
  weightStr+="Weight:<br />";
  weightStr+="<select name=\"select_weight"+lil_id+"\" id=\"select_weight"+lil_id+"\">";
  weightStr+="<option value=\"0\">default</option>";
  weightStr+="<option value=\"5\">5%</option>";
  weightStr+="<option value=\"10\">10%</option>";
  weightStr+="<option value=\"15\">15%</option>";
  weightStr+="<option value=\"20\">20%</option>";
  weightStr+="<option value=\"25\">25%</option>";
  weightStr+="<option value=\"30\">30%</option>";
  weightStr+="<option value=\"35\">35%</option>";
  weightStr+="<option value=\"40\">40%</option>";
  weightStr+="<option value=\"45\">45%</option>";
  weightStr+="<option value=\"50\">50%</option>";
  weightStr+="<option value=\"55\">55%</option>";
  weightStr+="<option value=\"60\">60%</option>";
  weightStr+="<option value=\"65\">65%</option>";
  weightStr+="<option value=\"70\">70%</option>";
  weightStr+="<option value=\"75\">75%</option>";
  weightStr+="<option value=\"80\">80%</option>";
  weightStr+="<option value=\"85\">85%</option>";
  weightStr+="<option value=\"90\">90%</option>";
  weightStr+="<option value=\"95\">95%</option>";
  weightStr+="<option value=\"100\">100%</option>";
  weightStr+="</select>";
  weightStr+="</p>";
  document.getElementById(setV).innerHTML=weightStr;
  var changetypestring = encodeURI("function=prpvalues&");
  changetypestring += encodeURI("catnum="+document.getElementById('catnum').value+"&");
  changetypestring += encodeURI("sectnum="+document.getElementById('sectnum').value);
  makeLOCALRequest(changetypestring,col);
}

function setGrade(colCount){
  document.getElementById('setGradeTxt').innerHTML=="Show Grade Properties"?document.getElementById('setGradeTxt').innerHTML="Hide Grade Properties":document.getElementById('setGradeTxt').innerHTML="Show Grade Properties";
  if(document.getElementById('setGradeTxt').innerHTML=="Show Grade Properties") document.getElementById("td11").innerHTML="";
  for(var i=3; i<colCount; i++){
    makeGradePropTxt="";
    mytd = "td"+i;
    mytd1 = "td1"+i;
    makeGradePropTxt="<p>Type:<br />";
    makeGradePropTxt+="<input type=\"radio\" name=\"radio_incomp_"+mytd+"\" id=\"radio_incomp_"+mytd+"i\" value=\"i\" onclick=\"changeType(value,this.name,"+colCount+");\" />I<br />";
    makeGradePropTxt+="<input type=\"radio\" name=\"radio_incomp_"+mytd+"\" id=\"radio_incomp_"+mytd+"n\" value=\"n\" onclick=\"changeType(value,this.name,"+colCount+");\" />#<br />";
    makeGradePropTxt+="<input type=\"radio\" name=\"radio_incomp_"+mytd+"\" id=\"radio_incomp_"+mytd+"a\" value=\"a\" onclick=\"changeType(value,this.name,"+colCount+");\" />A<br />";
    makeGradePropTxt+="</p><span id=\"setValue_"+mytd+"\"></span>";      
    if(document.getElementById('setGradeTxt').innerHTML=="Hide Grade Properties"){
      document.getElementById(mytd).innerHTML=makeGradePropTxt;
    }else{
      document.getElementById(mytd).innerHTML="";
      document.getElementById(mytd1).innerHTML="";
    }
  }
  document.getElementById('setGradeTxt').innerHTML=="Hide Grade Properties"?document.getElementById('gradePropSubmit').innerHTML="<p><input type=\"button\" value=\"Save\" onclick=\"processGradeProp(document.getElementById('gradebookForm'));\" /></p>":document.getElementById('gradePropSubmit').innerHTML="";
}

function showHide(colCount){
  var setgradestring = encodeURI("function=prpgrade&");
  setgradestring += encodeURI("catnum="+document.getElementById('catnum').value+"&");
  setgradestring += encodeURI("sectnum="+document.getElementById('sectnum').value);
  makeLOCALRequest(setgradestring,0);
  setGrade(colCount);
}

function showText(id,recid) {
  document.getElementById('commentViewer').innerHTML = document.getElementById(id).value;
  document.getElementById('commentViewer').name = document.getElementById(id).id;
  var myNum = (id)?id.substring(id.indexOf('r')+1, id.indexOf('stucommentq')):0;
  document.getElementById('teacherCommentArea').name="tca"+myNum+"id"+recid;
  //alert(myNum);
  var teacommentid = 'teacomment' + myNum;
  //alert(teacommentid);
  document.getElementById('teacherCommentArea').value = document.getElementById(teacommentid).value;
  var myTable = document.getElementById('gradesTable');
  for (var i=0;i<myTable.rows.length;i++) {
	 myTable.rows[i].className = 'evenOdd0';
  }
  var rowName="row"+parseInt(myNum);
  document.getElementById(rowName).className = 'evenOdd1';
}

function showTeachText(id,recid,value) {
  document.getElementById('teacherCommentArea').name="tca"+value+"id"+recid;
  document.getElementById('teacherCommentArea').value = document.getElementById(id).value;
  var myNum = (id)?id.substring(id.indexOf('teacomment')+10, id.length):0;  
  var myTable = document.getElementById('gradesTable');
  for (var i=0;i<myTable.rows.length;i++) {
	 myTable.rows[i].className = 'evenOdd0';
  }
  var rowName="row"+parseInt(myNum);
  document.getElementById(rowName).className = 'evenOdd1';
}

function showStudent(name, row) { 
  document.getElementById('stuName').innerHTML = "You are viewing the record for " + name;
  myTable = document.getElementById('gradesTable');
	row.style.cursor='hand';
	tempClass = row.className;
	for (var i=0;i<myTable.rows.length;i++) {
		myTable.rows[i].className = 'evenOdd' + (i % 2);
	}
	row.className = 'evenOdd2';
}  

function over(row) {
	var cells = row.cells;
	row.style.cursor='hand';
	if (!cells) return;
	oldCellColor = cells[0].style.backgroundColor;
	for (var i=0;i<cells.length;i++) {
		cells[i].style.backgroundColor='#d9d6cf';
	}
}

function out(row) {
	var cells = row.cells;
	row.style.cursor='';
	if (!cells) return;
	for (var i=0;i<cells.length;i++) {
		cells[i].style.backgroundColor=oldCellColor;
	}
}

function changeText(){ 
  var str = document.getElementById('teacherCommentArea').name; 
  val = str.substring(str.indexOf('tca')+3,str.indexOf('id'));
  recid = str.substring(str.indexOf('id')+2,str.length);  
  myName = document.getElementById('commentViewer').name;
  document.getElementById('teacomment'+val).value = document.getElementById('teacherCommentArea').value;
  if(val) updateGrade(recid,val);
}
