// JavaScript Document
assgnObj = new Object();
assgnObj.itemgradebookid = 0;
assgnObj.elementCount = 1;
assgnObj.value = "";
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function editField(id,i){
  //document.getElementById(id).focus();
  //document.getElementById('li1_'+i).style.zIndex="-1";
  //document.getElementById('ul1').className="someOtherClass";
}

function assignmentType(id){
  var myOptions = '';
  switch(id){
    case 2:
    case 3:
       myOptions = "<p>* Number of MC/TF Questions: <input type=\"text\" name=\"numofitems\" /></p>";
       myOptions += "<p>* Points Each: <input type=\"text\" name=\"ptsea\" /></p>";
       myOptions += "<p>Time Limit (in minutes): <input type=\"text\" name=\"timed\" /> (Optional)</p>";
       break;
    case 4:
    case 5:
       myOptions = "<p>* Number of multiple choice questions: <input type=\"text\" name=\"numofitems\" /></p>";
       myOptions += "<p>* Points Each: <input type=\"text\" name=\"ptsea\" /></p>";
       myOptions += "<p>* Minimum Grade: <input type=\"text\" name=\"mingrade\" /></p>";
       myOptions += "<p>Time Limit (in minutes): <input type=\"text\" name=\"timed\" /> (Optional)</p>";
       break;   
  }
  document.getElementById('assignmentTypeOptions').innerHTML = myOptions;
}

function countChildElements(parent, child){
  var parent = document.getElementById(parent);
  var childCount = parent.getElementsByTagName(child).length;
  return childCount;
  //alert(childCount);
}

function enrollSMF(myform){
  alert(myform.length);
  var poststr = '';
  for(i=0;i<myform.length;i++){
    poststr += encodeURI(myform[i].name+"="+myform[i].value+"&");
  }
  httpPost = false;
  //alert("catnum="+myObject.catnum+"&id="+myObject.id+"&offering="+myObject.offering);
  url = urls.index+"smf/index.php?action=register2";
  var httpPost=getHTTPObject();
  httpPost.open('POST', url, true);
  httpPost.onreadystatechange=function(){
    if (httpPost.readyState == 4) {
      if (httpPost.status == 200) {
        alert("flippity,floppity");           
      } else {
        alert('There was a problem with makePOSTRequest.');
      }
    }  
  }  
  httpPost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  httpPost.setRequestHeader("Content-length", poststr.length);
  httpPost.setRequestHeader("Connection", "close");
  httpPost.send(poststr);
  alert(poststr);
}

function getModIdFromAssgnId(id){
  var url = urls.plugins+"functions_http.php?menu=getModIdFromAssgnId&id="+id;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {    
        //alert(modreq.responseText);  
        document.getElementById('module').value=modreq.responseText; 
        if(document.getElementById('module').value=="0") document.getElementById('assgnNameSelect').className="displayNone";        
        assgnObj.success=null;     
      }
    }
  }
  modreq.send(null);  
}

function getContentIdFromItemgradebookId(id){
  var url = urls.plugins+"functions_http.php?menu=getContentIdFromItemgradebookId&id="+id;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {    
        //alert(modreq.responseText);    
        //document.getElementById("modContentVal").value = modreq.responseText; 
        //showElementAssignments(modreq.responseText); 
        pageLoadItemgradebookId(modreq.responseText);              
      }
    }
  }
  modreq.send(null);  
}

function pageLoadItemgradebookId(id){
  var url = urls.plugins+"functions_http.php?menu=showElementAssignments&id="+id;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {              
        document.getElementById("showElementAssignments_div").innerHTML = modreq.responseText; 
        document.getElementById("block2").className = "displayBlock";
        document.getElementById("modContentVal").value = id;
        showElements(assgnObj.itemgradebookid);      
      }
    }
  }
  modreq.send(null); 
}  

function gotHeading(value){
  document.getElementById('ss_heading').disabled=true;
  document.getElementById('ss_text').disabled=true;  
  document.getElementById('ss_heading_div_text').innerHTML="Heading:"; 
  document.getElementById('ss_text_div_text').innerHTML="Text:";   
  switch(value){
    case "h1":
      document.getElementById('ss_heading').disabled=false;
      break; 
    case "_submitted":
      document.getElementById('ss_heading').disabled=false;
      document.getElementById('ss_heading').value="Submitted";
      break; 
    case "Submit":
      document.getElementById('ss_heading').disabled=false;
      document.getElementById('ss_heading').value="Thanks";      
      break;   
    case "_textboxG":
      document.getElementById('ss_heading').disabled=false;
      document.getElementById('ss_heading').value="grade";
      break;
    case "_textboxT":
      document.getElementById('ss_heading').disabled=false;
      document.getElementById('ss_heading').value="Teacher Comments";
      break;     
    case "_textbox":
      document.getElementById('ss_heading').disabled=false;
      document.getElementById('ss_text').disabled=false;
      document.getElementById('ss_heading_div').className="displayBlock";
      document.getElementById('ss_text_div').className="displayBlock";
      document.getElementById('mySubmit_div').className = "displayBlock";      
      break;
    case "_upload":
    case "submit":
      document.getElementById('ss_heading_div').className = "displayBlock";
      document.getElementById('ss_heading').disabled=false;
      document.getElementById('ss_heading_div_text').innerHTML="Button Value: ";
      document.getElementById('ss_text_div').className = "displayBlock";
      document.getElementById('ss_text').disabled=false;
      document.getElementById('ss_text_div_text').innerHTML="Button Message: ";
      document.getElementById('mySubmit_div').className = "displayBlock";
      break; 
    case "survey_start":      
      document.getElementById('ss_text').disabled=false;
      document.getElementById('ss_text_div').className="displayBlock";
      document.getElementById('ss_text_div_text').innerHTML="Caption:";
      document.getElementById('mySubmit_div').className = "displayBlock";
      break; 
    case "survey_itemHead":      
      document.getElementById('ss_heading').disabled=false;
      document.getElementById('ss_heading_div').className="displayBlock";
      document.getElementById('ss_heading_div_text').innerHTML="Stem Type:";      
      getHeadingType("itemHead");
      //document.getElementById('ss_heading_div_type').className = "displayNone";
      //document.getElementById('ss_heading_div_list').className = "displayBlock";
      document.getElementById('mySubmit_div').className = "displayBlock";
      break;
    case "survey_item":      
      document.getElementById('ss_text').disabled=false;
      document.getElementById('ss_text_div').className="displayBlock";
      document.getElementById('ss_text_div_text').innerHTML="Item:";
      document.getElementById('mySubmit_div').className = "displayBlock";
      break; 
    case "survey_end":      
      document.getElementById('mySubmit_div').className = "displayBlock";
      break; 
    case "tf":      
      document.getElementById('ss_text').disabled=false;
      document.getElementById('ss_text_div').className="displayBlock";
      document.getElementById('ss_text_div_text').innerHTML="Question:";
      document.getElementById('ss_feedback_div_text').className="displayBlock";
      document.getElementById('mySubmit_div').className = "displayBlock";
      break;
    case "confType":      
      document.getElementById('ss_text').disabled=false;
      document.getElementById('ss_text_div').className="displayBlock";
      document.getElementById('ss_text_div_text').innerHTML="Question:";
      document.getElementById('mySubmit_div').className = "displayBlock";
      break;    
    case "radio_begin":      
      document.getElementById('ss_text').disabled=false; 
      document.getElementById('ss_text_div').className="displayBlock";
      document.getElementById('ss_text_div_text').innerHTML="Item:";     
      radioBeginDiv = "<p>First Option: <input type=\"text\" id=\"ss_heading\" name=\"ss_heading\" style=\"width: 400px;\"/></p>";
      document.getElementById('ss_radio_div').innerHTML=radioBeginDiv;
      document.getElementById('ss_feedback_div_text').className="displayBlock";
      document.getElementById('mySubmit_div').className = "displayBlock";
      break; 
    case "radio":           
      radioBeginDiv = "<p>Option: <input type=\"text\" id=\"ss_heading\" name=\"ss_heading\" style=\"width: 400px;\"/></p>";
      document.getElementById('ss_radio_div').innerHTML=radioBeginDiv;
      document.getElementById('ss_feedback_div_text').className="displayBlock";
      document.getElementById('mySubmit_div').className = "displayBlock";
      break;   
    case "match_begin":           
      radioBeginDiv = "<p>Matching group name: <input type=\"text\" id=\"ss_heading\" name=\"ss_heading\" style=\"width: 400px;\"/></p>";
      document.getElementById('ss_radio_div').innerHTML=radioBeginDiv;
      document.getElementById('mySubmit_div').className = "displayBlock";
      break;                     
  }
}

function showFeedback(){
  document.getElementById('ss_feedback_div').className == "displayNone"?document.getElementById('ss_feedback_div').className = "displayBlock":document.getElementById('ss_feedback_div').className = "displayNone";
}

function gotFunction(value){
  init_elements(); 
  //document.getElementById('aorder_div').className="displayBlock";
  document.getElementById('assgnProg').className="displayBlock";
  //document.getElementById('assgnNameSelect').className="displayBlock";
  document.getElementById('block2').className="displayBlock"; 
  document.getElementById('block3').className="displayBlock"; 
  switch(value){
    case "csvupdate":
      document.forms[0].ss_type.options[0] = new Option('Update','update');
      //document.forms[0].ss_type.options[1] = new Option('other','other');
      document.getElementById('ss_type_div').className = "displayBlock";      
      break; 
    case "assgnGradeViewBegin":
      document.forms[0].ss_type.options[0] = new Option('Scroll','scroll');
      //document.forms[0].ss_type.options[1] = new Option('other','other');
      document.getElementById('ss_type_div').className = "displayBlock";
      break; 
    case "formStart":
      document.forms[0].ss_type.options[0] = new Option('Submit','submit');
      document.forms[0].ss_type.options[1] = new Option('Upload','upload');
      document.getElementById('ss_type_div').className = "displayBlock";
      break;  
    case "comment":
      document.forms[0].ss_type.options[0] = new Option('Textbox','_textbox');
      document.getElementById('ss_heading_div').className = "displayBlock";
      document.getElementById('ss_heading').disabled=false;
      document.getElementById('ss_text_div').className = "displayBlock";
      document.getElementById('ss_text').disabled=false;
      document.getElementById('mySubmit_div').className = "displayBlock";
      document.getElementById('assgnProg').className="displayBlock"; 
      document.getElementById('ss_heading_div_text').innerHTML="Question Identifier (e.g. Q1): ";
      document.getElementById('ss_text_div_text').innerHTML="Leading Question/Prompt: ";
      break;
    case "survey":
      document.forms[0].ss_type.options[0] = new Option('Please Select...','0');
      document.forms[0].ss_type.options[1] = new Option('Survey Start','survey_start');
      document.forms[0].ss_type.options[2] = new Option('Item Header','survey_itemHead');
      document.forms[0].ss_type.options[3] = new Option('Item','survey_item');
      document.forms[0].ss_type.options[4] = new Option('Survey End','survey_end');      
      document.getElementById('ss_type_div').className = "displayBlock";   
      document.getElementById('assgnProg').className="displayBlock";
      break; 
    case "mc":
      document.forms[0].ss_type.options[0] = new Option('Please Select...','0');
      document.forms[0].ss_type.options[1] = new Option('True/False','tf');
      document.forms[0].ss_type.options[2] = new Option('Radio Begin','radio_begin');
      document.forms[0].ss_type.options[3] = new Option('Radio','radio');
      document.forms[0].ss_type.options[4] = new Option('Conference Type','confType');
      //document.forms[0].ss_type.options[4] = new Option('Radio Other','radio_other');      
      document.getElementById('ss_type_div').className = "displayBlock";   
      break; 
    case "matching":            
      document.forms[0].ss_type.options[0] = new Option('Please Select...','0');
      document.forms[0].ss_type.options[1] = new Option('Matching','match_begin');
      //document.forms[0].ss_type.options[2] = new Option('Matching Item','match_item');
      document.getElementById('ss_type_div').className = "displayBlock";  
      break;     
    case "comments":
      document.forms[0].ss_type.options[0] = new Option('True','true');
      //document.forms[0].ss_type.options[1] = new Option('false','false');
      document.getElementById('ss_type_div').className = "displayBlock";
      break;   
    case "heading":
      document.forms[0].ss_type.options[0] = new Option('h1','h1');
      document.forms[0].ss_type.options[1] = new Option('h2','h2');
      document.forms[0].ss_type.options[2] = new Option('h3','h3');
      document.getElementById('ss_type_div').className = "displayBlock";
      document.getElementById('ss_heading_div').className = "displayBlock";
      document.getElementById('ss_heading').disabled=false;
      document.getElementById('ss_heading').value="";
      break;    
    case "instructions":
      //document.getElementById('ss_function').className = "displayBlock";
      document.getElementById('ss_text').disabled=false;
      document.getElementById('ss_text_div').className = "displayBlock";
      document.getElementById('ss_text_div_text').innerHTML="Text:";
      document.getElementById('mySubmit_div').className = "displayBlock";
      break; 
    case "fieldsetBegin":
      document.getElementById('ss_heading').disabled=false;
      document.getElementById('ss_heading_div').className = "displayBlock";
      document.getElementById('mySubmit_div').className = "displayBlock";
      document.getElementById('ss_heading_div_text').innerHTML="Legend:"
      document.getElementById('ss_heading').value="Reflections";
      break;
    case "upload":
      document.forms[0].ss_type.options[0] = new Option('Upload','_upload');
      document.getElementById('ss_type_div').className = "displayBlock";
      document.getElementById('ss_heading_div').className = "displayBlock";
      document.getElementById('ss_heading').className = "displayNone";
      document.getElementById('ss_heading').value="Document";
      document.getElementById('mySubmit_div').className = "displayBlock";
      break;   
    case "fieldsetEnd":      
      document.getElementById('mySubmit_div').className = "displayBlock";
      break;           
    case "button":
      document.forms[0].ss_type.options[0] = new Option('Please Select...','0');
      document.forms[0].ss_type.options[1] = new Option('Submit','submit');
      document.forms[0].ss_type.options[2] = new Option('Upload Tool','_upload');
      document.getElementById('ss_type_div').className = "displayBlock";  
      break;       
  }
}

function assgnProgScriptBuild(id){
  //alert(id);
  qs();
  var skin = qsParm['skin'];
  var url = urls.plugins+"functions_http.php?menu=getCatnumModid&id="+id;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {            
        location.href=urls.index+"courseware.php?skin="+skin+"&manage=content_menu&menu=createElementForm"+modreq.responseText;//&catnum="+catnum+"&mod="+modid+"&itemgradebookid="+itemgradebookid;    
      }
    }
  }
  modreq.send(null);
}

function assgnProgScript(id){ 
  if(assgnObj.success){
    //location.href=urls.index+"courseware.php?manage=content_menu&menu=createElementForm&catnum=2&mod=5&itemgradebookid="+id;    
  }else{
    if(assgnObj.itemgradebookid==qsParm['itemgradebookid']) location.href=urls.index+"courseware.php?manage=content_menu&menu=createElementForm&catnum="+assgnObj.catnum+"&mod="+assgnObj.modid+"&itemgradebookid="+id;
  } 
  assgnObj.itemgradebookid = id;
  //document.getElementById('ss_function').value="0";
  document.getElementById('ss_type_div').className = "displayNone";
  document.getElementById('ss_heading_div').className = "displayNone";
  document.getElementById('ss_text_div').className = "displayNone";
  //document.getElementById('assgnNameSelect').className="displayBlock";
  //document.getElementById('block2').className = "displayBlock";
  document.getElementById('assgnProg').className="displayBlock";  
  //var url = urls.plugins+"functions_http.php?menu=assgnProg&studname=xxxx&id="+id;
  var nocache = Math.random();
  var url = urls.plugins+"functions_http.php?menu=buildAssgn&studname=xxxx&itemgradebookid="+id+"&nocache="+nocache;
  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(document.getElementById("footer")) document.getElementById("footer").className = "displayNone";
        //if(document.getElementById("assgnProg")) document.getElementById("assgnProg").innerHTML = modreq.responseText;
        //whatText = "Please select the element/function for this assignment.";          
        //showElements(id);
        getModIdFromAssgnId(id); 
        getContentIdFromItemgradebookId(id);  
        document.getElementById("assgnProg").innerHTML = modreq.responseText.trim();    
      }
    }
  }
  modreq.send(null);  
}

function fillAssgnName(){
  //init_elements();
  if (document.getElementById('assgnNameSelect')) document.getElementById('assgnNameSelect').className="displayBlock";
  var url = urls.plugins+"functions_http.php?menu=fillAssgnName&catnum="+assgnObj.catnum+"&mod="+assgnObj.modid;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        if(document.getElementById("assgnNameSelect")) document.getElementById("assgnNameSelect").innerHTML = modreq.responseText;
        if(assgnObj.itemgradebookid>0 && document.getElementById('assgnNameVal')) document.getElementById('assgnNameVal').value=assgnObj.itemgradebookid;
        if(assgnObj.success=='') document.getElementById('assgnNameVal').value="0";
      }
    }
  }
  modreq.send(null);
}

function gotCourse(catnum,modid){
  assgnObj.catnum=catnum;
  assgnObj.modid=modid; 
  showContent(modid);
}

function showNextBlock(modid,block,inst){
  //alert(modid+":"+block+":"+inst);
  qs();  
  if(document.getElementById('assgnNameSelect')){  
    gotCourse(document.getElementById('catnumSelect').value,modid);    
  }else if(document.getElementById('showContent_div')){         
    if(qsParm['menu']=="createContentForm"&&qsParm['mod']>0) showContent(modid);        
    if(document.getElementById('block'+block)&&qsParm['mod']>0) document.getElementById('block'+block).className = "displayBlock";    
    fillModContent(modid);       
  }else{  
    if(document.getElementById('showThisModAssignments')) document.getElementById('showThisModAssignments').className = "displayNone";
    if(document.getElementById('showElementAssignments')) document.getElementById('showElementAssignments').className = "displayNone";   
    document.getElementById('block'+block).className = "displayBlock";   
    fillModContent(modid);     
  } 
  if(document.getElementById('module')) document.getElementById('module').value=modid;  
}

function showModules(catnum){
  if(assgnObj.success==''){
    document.getElementById('block2').className="displayNone";
    document.getElementById('assgnProg').className="displayNone";
  } 
  if(catnum > 0){ 
    var url = urls.plugins+"functions_http.php?menu=showModules&catnum="+catnum;
    var modreq=getHTTPObject(); 
    modreq.open("GET", url, true);  
    modreq.onreadystatechange=function(){
      if (modreq.readyState==4) {
        if (modreq.status==200) {
          if(modreq.responseText.length>0){
            nutext = "Existing Modules (<a href=\""+urls.plugins+"functions_edit.php?page=sortMod&catnum="+catnum+"\" target=\"_blank\">edit</a>):<br />" + modreq.responseText;
          }else{
            nutext = "No Existing Modules";
          } 
          document.getElementById('modSelect_div').className = "displayBlock"; 
          document.getElementById('modSelect_div').innerHTML = nutext;
          document.getElementById('block1').className = "displayBlock";
        }
      }
    }
    modreq.send(null);
  }else{
    document.getElementById('modSelect_div').className = "displayNone";
    document.getElementById('block1').className = "displayNone";
  }
}

function getModules(catnum,block,inst){ 
  qs();
  if(document.getElementById('showThisModAssignments')) document.getElementById('showThisModAssignments').className = "displayNone";
  switch(qsParm['menu']){    
    case "createElementForm":
      init_elements();
      break;
  }     
  var url = urls.plugins+"functions_http.php?menu=getModules&catnum="+catnum+"&block="+block+"&inst=1";
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {  
        //alert(modreq.responseText);                    
        document.getElementById("block1").innerHTML = modreq.responseText;
        document.getElementById('block1').className = "displayBlock";                        
        //if(document.getElementById('showAssignments')) showAssignments(catnum);
        if(qsParm['mod']) showNextBlock(qsParm['mod'],2,inst);                        
      }
    }
  }
  modreq.send(null);
}

function init666(catnum, itemgradebookid, modid) {
  //alert(catnum+":"+itemgradebookid+":"+modid); 
  qs(); 
  if(qsParm['success']) assgnObj.success=qsParm['success'];  
  if(catnum>0){  
    gotCourse(catnum,modid);             
    if(document.getElementById('catnumSelect')){
      document.getElementById('catnumSelect').value=catnum;             
      getModules(catnum,1,2);                         
    }else{
      getModules(catnum,1,3);  
    }    
  } 
  if(itemgradebookid>0) assgnProgScript(itemgradebookid);
}

function init_addMod(courseid, contentid) {
  //alert(courseid+":"+contentid);
  if(courseid>0){
    showModules(courseid);
    document.getElementById('catnumSelect').value=courseid;
  }
}

function init_elements(){
  //document.forms[0].ss_type.options.length = 0;    
  document.getElementById('ss_heading').disabled=true;
  document.getElementById('ss_text').disabled=true;
  if(document.getElementById('addAssgn_div')) document.getElementById('addAssgn_div').className = "displayNone";
  document.getElementById('ss_type_div').className = "displayNone";
  //document.getElementById('aorder_div').className = "displayNone";
  document.getElementById('ss_heading_div').className = "displayNone";
  document.getElementById('ss_text_div').className = "displayNone";
  if(document.getElementById('assgnNameSelect')) document.getElementById('assgnNameSelect').className="displayNone";
  document.getElementById('mySubmit_div').className = "displayNone";
  document.getElementById('block2').className = "displayNone";
  document.getElementById('assgnProg').className="displayNone";  
}

function addCourseMod(id){
  fillModName(id);
  document.getElementById('block1').className = "displayBlock";
}

function addModContent(id){
  fillModContent(id);
  document.getElementById('block1').className = "displayBlock";
}

function showAddAssgn(contentid){  
  qs();
  switch(qsParm['menu']){
  case "createAssignmentForm":
    document.getElementById('addAssgn_div').className = "displayBlock";
    document.getElementById('showThisModAssignments').className = "displayBlock";
    if(document.getElementById('showThisModAssignments')) showThisModAssignments(contentid);
    break;
  case "createElementForm":
    showElementAssignments(contentid);
    break;  
  }
}


function getHeadingType(head){
  var url = urls.plugins+"functions_http.php?menu=getHeadingType&type=survey&head="+head;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        document.getElementById("ss_heading_div_type").innerHTML = modreq.responseText;
      }
    }
  }
  modreq.send(null);
}

function fillModName(catnum){
  var url = urls.plugins+"functions_http.php?menu=fillModName&catnum="+catnum;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        document.getElementById("modSelect_div").innerHTML = modreq.responseText;
      }
    }
  }
  modreq.send(null);
}

function startCourse(catnum){
  location.href=urls.index+"courseware.php?manage=content_menu&menu=createElementForm&catnum="+catnum;
}

function showElements(itemgradebookid){
  var url = urls.plugins+"functions_http.php?menu=showElements&id="+itemgradebookid;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) { 
        document.getElementById("showElements").innerHTML = modreq.responseText; 
        document.getElementById("block3").className = "displayBlock";  
        document.getElementById('moduleAssignments_select').value = assgnObj.itemgradebookid;            
      }
    }
  }
  modreq.send(null);  
}

function showElementAssignments(contentid){
  var url = urls.plugins+"functions_http.php?menu=showElementAssignments&id="+contentid;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {              
        document.getElementById("showElementAssignments_div").innerHTML = modreq.responseText; 
        assgnObj.itemgradebookid = document.getElementById("moduleAssignments_select").value; 
        document.getElementById("block2").className = "displayBlock";
        document.getElementById("modContentVal").value = contentid;
        //showElements(assgnObj.itemgradebookid);
        //assgnProgScript(assgnObj.itemgradebookid);       
      }
    }
  }
  modreq.send(null);  
}

function showThisModAssignments(contentid){
  var url = urls.plugins+"functions_http.php?menu=showThisModAssignments&id="+contentid;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) { 
      //alert(modreq.responseText);
        document.getElementById("showThisModAssignments").innerHTML = modreq.responseText;            
      }
    }
  }
  modreq.send(null);  
}

function showAssignments(itemgradebookid){
  var url = urls.plugins+"functions_http.php?menu=showAssignments&id="+itemgradebookid;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) { 
        document.getElementById("showAssignments").innerHTML = modreq.responseText;             
      }
    }
  }
  modreq.send(null);  
}

function showContent(mod){
  //alert(mod);
  var url = urls.plugins+"functions_http.php?menu=showContent&mod="+mod;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {               
        if(document.getElementById('module')) document.getElementById('module').value = mod;
        fillAssgnName();
      }
    }
  }
  modreq.send(null);
}

function fillModContent(modid){
  var url = urls.plugins+"functions_http.php?menu=fillModContent&mod="+modid;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        if(document.getElementById("modContentSelect_div")) document.getElementById("modContentSelect_div").innerHTML = modreq.responseText; 
        //if(document.getElementById("assgnNameSelect")) document.getElementById("assgnNameSelect").className = "displayBlock"; 
      }
    }
  }
  modreq.send(null);
}

function closeContinue(who){
  switch(who){
    case "plugin_courseware_course_mod":            
      break;
    case "plugin_courseware_course_content":      
      break;  
  }
  //alert(who);
  window.close();
}

function sortThis(id,who){
  //alert(id+":"+who);
  var url = urls.plugins+"functions_http.php?menu=sortThis&id="+id+"&who="+who;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        //alert(modreq.responseText);
        document.getElementById('sort_div').innerHTML = modreq.responseText;
      }
    }
  }
  modreq.send(null);
}
  
function sortThisUp(id,who){
  //alert(id+":"+who);
  var url = urls.plugins+"functions_http.php?menu=sortThisUp&id="+id+"&who="+who;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {     
        sortThis(modreq.responseText,who);
      }
    }
  }
  modreq.send(null);
}
  
function sortThisDown(id,who){
  //alert(id+":"+who);
  var url = urls.plugins+"functions_http.php?menu=sortThisDown&id="+id+"&who="+who;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {
        sortThis(modreq.responseText,who);
      }
    }
  }
  modreq.send(null);
}
  
function deleteThisSort(id,type){
  //alert(id+":"+type);
  qs();
  var nutitle = document.getElementById('nutitle'+id).value;
  if (confirm ("Are you sure you want to delete "+nutitle+"?")){
    var url = urls.plugins+"functions_http.php?menu=deleteThisSort&type="+type+"&id="+id;
    var modreq=getHTTPObject(); 
    modreq.open("GET", url, true);  
    modreq.onreadystatechange=function(){
      if (modreq.readyState==4) {
        if (modreq.status==200) {
          document.getElementById('sort_div').innerHTML = modreq.responseText;
        }
      }
    }
    modreq.send(null);
  }
}

function updateThisSort(id,type){ 
  qs();
  var nutitle = escape(document.getElementById('nutitle'+id).value);  
  nutitle = nutitle.replace("\%27","|27");
  var url = urls.plugins+"functions_http.php?menu=updateThisSort&type="+type+"&id="+id+"&value="+nutitle;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {    
        document.getElementById('sort_div').innerHTML = modreq.responseText;
        alert("Content updated");
      }
    }
  }
  modreq.send(null);
}

function initMod(catnum){
  qs();
  var skin = qsParm['skin'];
  location.href=urls.index+"courseware.php?skin="+skin+"&manage=content_menu&menu=createModulesForm&catnum="+catnum;
}

function initAssgn(catnum){
  qs();
  var skin = qsParm['skin'];
  location.href=urls.index+"courseware.php?skin="+skin+"&manage=content_menu&menu=createAssignmentForm&catnum="+catnum;
}

function initElement(catnum){
  qs();
  var skin = qsParm['skin'];
  location.href=urls.index+"courseware.php?skin="+skin+"&manage=content_menu&menu=createElementForm&catnum="+catnum;
}

function initAssgnMod(catnum,itemgradebookid,modid){
  //alert(catnum+":"+itemgradebookid+":"+modid);
  qs();
  var skin = qsParm['skin'];
  switch(qsParm['menu']){
    case "createContentForm":
      //showNextBlock(modid,2,0);
      location.href=urls.index+"courseware.php?skin="+skin+"&manage=content_menu&menu=createContentForm&catnum="+catnum+"&mod="+modid;        
      break; 
    case "createAssignmentForm":      
      location.href=urls.index+"courseware.php?skin="+skin+"&manage=content_menu&menu=createAssignmentForm&catnum="+catnum+"&mod="+modid;
      break; 
    case "createElementForm":
      //showNextBlock(modid,0,0);      
      location.href=urls.index+"courseware.php?skin="+skin+"&manage=content_menu&menu=createElementForm&catnum="+catnum+"&mod="+modid;      
      break; 
    default:
      showNextBlock(catnum,0,0);
      break;
  }
}

function initContent(catnum){
  location.href=urls.index+"courseware.php?manage=content_menu&menu=createContentForm&catnum="+catnum;
}
  
function showInstructions(id){
  switch(id){
    case 0:
      return "Please choose a module.";
      break;
    case 1:
      return "Please provide appropriate information and click submit.";
      break;
    case 2:
      return "Please select the content.";
      break; 
    case 3:
      return "Add another heading, content order, content and click Submit.";
      break;
    case 4:
      return "Please select the course you want to work on.";  
      break;
    case 5:
      return "Please select the module you want to work on.";  
      break; 
    case 6:
      return "Please select the content you want to create an assignment for.";  
      break;       
    default:
      alert("error getting instructions");  
  }
}

function buildAssignment(){
  document.getElementById('assgnSketchBrd').innerHTML='';
}

function assgnitemup(id){
  alert(id);
}

function assgnitemdel(id){
  alert(id);
}

function assgnitemdown(id){
  alert(id);
}

function addElement(id){
  //alert(id);
  var url = urls.plugins+"functions_http.php?menu=addElement&id="+id;
  var modreq=getHTTPObject(); 
  modreq.open("GET", url, true);  
  modreq.onreadystatechange=function(){
    if (modreq.readyState==4) {
      if (modreq.status==200) {    
        //document.getElementById('inElement_'+assgnObj.elementCount).innerHTML = modreq.responseText;
        document.getElementById('inElement').innerHTML = modreq.responseText;
        if(id=="mc") document.getElementById('addOptionDiv').className = "displayBlock";
        //assgnObj.holdCount = assgnObj.elementCount;
        //assgnObj.elementCount++;
        //document.getElementById('inElement').innerHTML += "<div id=\"inElement_"+assgnObj.elementCount+"\"></div>";
      }
    }
  }
  modreq.send(null);
}

function updateDOM(inputField,id) {
  // if the inputField ID string has been passed in, get the inputField object
  if (typeof inputField == "string") {
      inputField = document.getElementById(inputField);
  }
  if (inputField.type == "select-one") {
    for (var i=0; i<inputField.options.length; i++) {
        if (i == inputField.selectedIndex) {
            inputField.options[inputField.selectedIndex].setAttribute("selected","selected");
        }
    }
  } else if (inputField.type == "text") {
    inputField.setAttribute("value",inputField.value);
  } else if (inputField.type == "textarea") {
    document.getElementById(id).value=inputField.value;
  } else if ((inputField.type == "checkbox") || (inputField.type == "radio")) {
    if (inputField.checked) {
        inputField.setAttribute("checked","checked");
    } else {
        inputField.removeAttribute("checked");
    }
  }
}

function addOption(){
  var txtArray = new Array();
  var elength = document.getElementById('taCount').getElementsByTagName('textarea').length;
  for(i=1;i<=elength;i++){
    txtArray[i]=document.getElementById('x_mcoption'+i).value; 
  }    
  document.getElementById('inOption').innerHTML += "<br /><input type=\"radio\" name=\"nu_radio\" /> <textarea id=\"x_mcoption"+(elength+1)+"\" name=\"x_mcoption[]\" class=\"medTextarea\" onBlur=\"updateDOM(this,this.id)\"></textarea>";
  for(i=1; i<=elength; i++){
    if(txtArray.length>0) document.getElementById('x_mcoption'+i).value = txtArray[i];
  }
}

function doTF(){
  document.getElementById('x_mcoption1').innerHTML = document.getElementById('x_mcoption1').innerHTML == "True"?null:"True";
  document.getElementById('x_mcoption2').innerHTML = document.getElementById('x_mcoption2').innerHTML == "False"?null:"False";
}

function buildAssgn_bt(){
  alert("test for misc variables");
}

function deleteQuizItem(id){
  qs();
  var skin = qsParm['skin'];
  var catnum = qsParm['catnum'];
  var mod = qsParm['mod'];
  var itemgradebookid = qsParm['itemgradebookid'];
  var poststr = "";
  var elength = document.getElementById('li1_'+id).getElementsByTagName('textarea').length;
  for(i=0;i<elength;i++){
    str = document.getElementById('li1_'+id).getElementsByTagName('textarea')[i].name;
    assgnid = str.substring(0,str.indexOf("_"));
    poststr += encodeURI("assgnid[]="+assgnid+"&"); 
  }
  httpPost = false;
  url = urls.plugins+"functions_http.php?menu=delAssgnEl&id="+id;
  var httpPost=getHTTPObject();
  httpPost.open('POST', url, true);
  httpPost.onreadystatechange=function(){
    if (httpPost.readyState == 4) {
      if (httpPost.status == 200) {
        //alert(httpPost.responseText); 
        location.href=urls.index+"courseware.php?skin="+skin+"&manage=content_menu&menu=createElementForm&catnum="+catnum+"&mod="+mod+"&itemgradebookid="+itemgradebookid+"&rnd="+Math.random();           
      } else {
        alert('There was a problem with makePOSTRequest.');
      }
    }  
  }  
  httpPost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  httpPost.setRequestHeader("Content-length", poststr.length);
  httpPost.setRequestHeader("Connection", "close");
  httpPost.send(poststr);
}

