--- rat/client/parameter.html	2000/12/16 19:51:30	1.6
+++ rat/client/parameter.html	2014/02/26 18:56:58	1.64.2.1
@@ -1,14 +1,41 @@
-<html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <!--
 The LearningOnline Network with CAPA
 Parameter Input Window
-06/16/00,06/17,11/17,11/18,11/23,11/27,11/28,12/15,12/16 Gerd Kortemeyer
+//
+// $Id: parameter.html,v 1.64.2.1 2014/02/26 18:56:58 raeburn Exp $
+//
+// Copyright Michigan State University Board of Trustees
+//
+// This file is part of the LearningOnline Network with CAPA (LON-CAPA).
+//
+// LON-CAPA is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// LON-CAPA is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with LON-CAPA; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+// /home/httpd/html/adm/gpl.txt
+//
+// http://www.lon-capa.org/
+//
 -->
 <head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>LON-CAPA</title>
-</head>
 
-<script>
+<script type="text/javascript">
+// <![CDATA[
 
 var ptype='';
 var pvalue='';
@@ -16,8 +43,13 @@ var preturn='';
 var pcode='';
 var pscat='';
 var pmarker='';
+var pmodal='';
 var pname='';
 
+var defhour=0;
+var defmin=0;
+var defsec=0;
+
 var svalue;
 var stype;
 var smarker;
@@ -39,8 +71,26 @@ function selwrite(text) {
 }
 
 function choicestart() {
-  this.window.choices.document.clear();
-  choicewrite('<html><body bgcolor="#FFFFFF">');
+  this.window.choices.document.open();
+  choicewrite('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
+  choicewrite('<html xmlns="http://www.w3.org/1999/xhtml">');
+  choicewrite('<head>');
+  choicewrite('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
+  choicewrite('<title>LON-CAPA</title>');
+  choicewrite('<style type="text/css">');
+  choicewrite('<!--');
+  choicewrite('body {');
+  choicewrite('font-family: Verdana,Arial,Helvetica,sans-serif;');
+  choicewrite('line-height:130%;');
+  choicewrite('font-size:0.83em;');
+  choicewrite('background: #FFFFFF;');
+  choicewrite('}');
+  choicewrite('table.LC_parmsel_table {font-size: 90%;}');
+  choicewrite('table.LC_parmsel_table tr td { padding: 5px; border: 1px solid #C8C8C8;}');
+  choicewrite('-->');
+  choicewrite('</style>');
+  choicewrite('</head>');
+  choicewrite('<body>');
 }
 
 function choiceend() {
@@ -53,15 +103,23 @@ function choicewrite(text) {
 }
 
 function tablestart(headtext) {
-  choicewrite('<table><tr bgcolor="#AAFFAA"><th colspan=3>'+
+  choicewrite('<table class="LC_parmsel_table"><tr bgcolor="#C5DB99"><th colspan="3">'+
               headtext+'</th></tr>');
 }
 
 function valline(text,id1,id2) {
-  choicewrite('<tr bgcolor="#AAFFAA"><td>'+text+
-              '</td><td><input type=text size=4 name=val'+
-              id1+'></td><td>incl:<input type=checkbox name=val'+
-              id2+'></td></tr>');
+  choicewrite('<tr><td>'+text+
+              '</td><td><input type="text" size="4" name="val'+
+              id1+'" /></td><td>incl:<input type="checkbox" name="val'+
+              id2+'" /></td></tr>');
+}
+
+function escapeHTML(text) {
+  text = text.replace(/&/g, '&amp;');
+  text = text.replace(/"/g, '&quot;');
+  text = text.replace(/</g, '&lt;');
+  text = text.replace(/>/g, '&gt;');
+  return text;
 }
 
 function datecalc() {
@@ -80,11 +138,11 @@ function datecalc() {
 function hour() {
    var thishour=cdate.getHours();
     var i; var j;
-    choicewrite('<select name=hours onChange="parent.datecalc();">');
+    choicewrite('<select name="hours" onchange="parent.datecalc();">');
     for (i=0;i<=23;i++) {
-        choicewrite('<option value='+i);
+        choicewrite('<option value="'+i+'"');
         if (i==thishour) {
-            choicewrite(' selected');
+            choicewrite(' selected="selected"');
         }
         choicewrite('>');
         if (i==12) { choicewrite('noon'); } else {
@@ -104,11 +162,11 @@ function hour() {
 function minute() {
    var thisminutes=cdate.getMinutes();
     var i;
-    choicewrite('<select name=minutes onChange="parent.datecalc();">');
+    choicewrite('<select name="minutes" onchange="parent.datecalc();">');
     for (i=0;i<=59;i++) {
-        choicewrite('<option value='+i);
+        choicewrite('<option value="'+i+'"');
         if (i==thisminutes) {
-            choicewrite(' selected');
+            choicewrite(' selected="selected"');
         }
         choicewrite('>'+i+'</option>');
     }
@@ -118,11 +176,11 @@ function minute() {
 function second() {
    var thisseconds=cdate.getSeconds();
     var i;
-    choicewrite('<select name=seconds onChange="parent.datecalc();">');
+    choicewrite('<select name="seconds" onchange="parent.datecalc();">');
     for (i=0;i<=59;i++) {
-        choicewrite('<option value='+i);
+        choicewrite('<option value="'+i+'"');
         if (i==thisseconds) {
-            choicewrite(' selected');
+            choicewrite(' selected="selected"');
         }
         choicewrite('>'+i+'</option>');
     }
@@ -133,11 +191,11 @@ function second() {
 function date() {
    var thisdate=cdate.getDate();
     var i;
-    choicewrite('<select name=date onChange="parent.datecalc();">');
+    choicewrite('<select name="date" onchange="parent.datecalc();">');
     for (i=1;i<=31;i++) {
-        choicewrite('<option value='+i);
+        choicewrite('<option value="'+i+'"');
         if (i==thisdate) {
-            choicewrite(' selected');
+            choicewrite(' selected="selected"');
         }
         choicewrite('>'+i+'</option>');
     }
@@ -146,12 +204,19 @@ function date() {
 
 function year() {
    var thisyear=cdate.getFullYear();
+   var nowdate=new Date();
+   var nowyear=nowdate.getFullYear();
+   if ( !thisyear ) { thisyear=nowyear; }
+   var loweryear=thisyear-2;
+   var upperyear=thisyear+5;
+   if (thisyear>nowyear) { loweryear=nowyear-2; }
+   if (thisyear<nowyear) { upperyear=nowyear+5; } 
     var i;
-    choicewrite('<select name=year onChange="parent.datecalc();">');
-    for (i=thisyear-25;i<=thisyear+50;i++) {
-        choicewrite('<option value='+i);
+    choicewrite('<select name="year" onchange="parent.datecalc();">');
+    for (i=loweryear;i<=upperyear;i++) {
+        choicewrite('<option value="'+i+'"');
         if (i==thisyear) {
-            choicewrite(' selected');
+            choicewrite(' selected="selected"');
         }
         choicewrite('>'+i+'</option>');
     }
@@ -161,11 +226,11 @@ function year() {
 function month() {
     var thismonth=cdate.getMonth();
     var i;
-    choicewrite('<select name=month onChange="parent.datecalc();">');
+    choicewrite('<select name="month" onchange="parent.datecalc();">');
     for (i=0;i<=11;i++) {
-        choicewrite('<option value='+i);
+        choicewrite('<option value="'+i+'"');
         if (i==thismonth) {
-            choicewrite(' selected');
+            choicewrite(' selected="selected"');
         }
         choicewrite('>'+months[i]+'</option>');
     }
@@ -176,11 +241,11 @@ function month() {
 function intminute() {
    var thisminutes=cmins;
     var i;
-    choicewrite('<select name=minutes onChange="parent.intcalc();">');
+    choicewrite('<select name="minutes" onchange="parent.intcalc();">');
     for (i=0;i<=59;i++) {
-        choicewrite('<option value='+i);
+        choicewrite('<option value="'+i+'"');
         if (i==thisminutes) {
-            choicewrite(' selected');
+            choicewrite(' selected="selected"');
         }
         choicewrite('>'+i+'</option>');
     }
@@ -190,11 +255,11 @@ function intminute() {
 function inthour() {
    var thishours=chours;
     var i;
-    choicewrite('<select name=hours onChange="parent.intcalc();">');
+    choicewrite('<select name="hours" onchange="parent.intcalc();">');
     for (i=0;i<=23;i++) {
-        choicewrite('<option value='+i);
+        choicewrite('<option value="'+i+'"');
         if (i==thishours) {
-            choicewrite(' selected');
+            choicewrite(' selected="selected"');
         }
         choicewrite('>'+i+'</option>');
     }
@@ -204,11 +269,11 @@ function inthour() {
 function intsecond() {
    var thisseconds=csecs;
     var i;
-    choicewrite('<select name=seconds onChange="parent.intcalc();">');
+    choicewrite('<select name="seconds" onchange="parent.intcalc();">');
     for (i=0;i<=59;i++) {
-        choicewrite('<option value='+i);
+        choicewrite('<option value="'+i+'"');
         if (i==thisseconds) {
-            choicewrite(' selected');
+            choicewrite(' selected="selected"');
         }
         choicewrite('>'+i+'</option>');
     }
@@ -219,11 +284,11 @@ function intsecond() {
 function intday() {
    var thisdate=cdays;
     var i;
-    choicewrite('<select name=date onChange="parent.intcalc();">');
+    choicewrite('<select name="date" onchange="parent.intcalc();">');
     for (i=0;i<=31;i++) {
-        choicewrite('<option value='+i);
+        choicewrite('<option value="'+i+'"');
         if (i==thisdate) {
-            choicewrite(' selected');
+            choicewrite(' selected="selected"');
         }
         choicewrite('>'+i+'</option>');
     }
@@ -246,6 +311,13 @@ function integereval() {
    if ((pscat=='pos') && (svalue==0)) {
       svalue='';
    }
+   if (pscat.indexOf('inrange')!=-1) {
+      var rangeparts=new Array;
+      rangeparts=split('_',pscat);
+      rangeparts=split(',',rangeparts[1]);
+      if (svalue<rangeparts[0]) { svalue=rangeparts[0]; }
+      if (svalue>rangeparts[1]) { svalue=rangeparts[1]; }
+   }
    draw();
 }
 
@@ -264,6 +336,17 @@ function stringeval() {
    draw();
 }
 
+function radiostringeval(newval) {
+   svalue=newval;
+   draw();
+}
+
+function callradiostringeval(newval) {
+   return 'onchange="parent.radiostringeval(\''
+          +newval+'\')" onclick="parent.radiostringeval(\''
+          +newval+'\')"';
+}
+
 function intervaldis() {
     csecs=svalue;
     cdays=Math.floor(csecs/86400);
@@ -275,17 +358,26 @@ function intervaldis() {
     choicewrite(cdays+' days '+chours+' hours '
                +cmins+' mins '+csecs+' secs');
 }
-    
-    
-    
-function afterproc() {
-  choicewrite('<tr bgcolor="#AAFFAA"><td colspan=3>Error after rounding: '
-             +'<input type=checkbox name=val1></td></tr>');
+
+function pickcolor(picked) {
+  svalue=picked;
+  draw();
 }
 
+function colorfield(ir,ig,ib) {
+   var col=new Array;
+   col=["00","11","22","44","66","88","AA","CC","DD","EE","FF"];
+   var color='#'+col[ir]+col[ig]+col[ib];
+   var selection="<font color='"+color+"'>X</font>";
+   if (color==svalue) { selection="<font color='#"+col[10-ir]+col[10-ig]+col[10-ib]+"'>X</font>"; }
+   choicewrite('<td bgcolor="'+color+'"><a href="javascript:parent.pickcolor('+"'"+
+               color+"'"+')">'+selection+'</a></td>');
+               
+}    
+
 function draw() {
    choicestart();
-   choicewrite('<form name=sch');
+   choicewrite('<form name="sch"');
    if (ptype=='int') {
       choicewrite(' action="javascript:integereval();"');
    }
@@ -295,23 +387,26 @@ function draw() {
    if (ptype=='string') {
       choicewrite(' action="javascript:stringeval();"');
    }
+   if (ptype != 'int' && ptype != 'float' && ptype != 'string') {
+       choicewrite(' action=""');
+   }
    choicewrite('>');
    if (ptype=='tolerance') {
 // 0: pscat
-// 1: after processing
       if (pscat=='default') {
          tablestart('Use default value or algorithm of resource');
       }
-      if (pscat=='exact') {
-         tablestart('Accept only exact value, zero tolerance');
-         afterproc();
-      }
       if (pscat=='relative_sym') {
 // 2: percentage
 // 3: open
          tablestart('Percentage error, symmetric around value');
          valline('Percentage',2,3);
-         afterproc();
+         if ((svalue!='') && (typeof(svalue)!="undefined")) {
+            choices.document.forms.sch.val2.value=parseInt(svalue);
+            if (svalue.indexOf('+')!=-1) {
+               choices.document.forms.sch.val3.checked=true;
+            }
+         }
       }
       if (pscat=='relative') {
 // 2: left
@@ -321,27 +416,47 @@ function draw() {
          tablestart('Percentage error, asymmetric around value');
          valline('Upper percentage',2,3);
          valline('Lower percentage',4,5);
-         afterproc();
+         var range1=new Array;
+         if ((svalue!='') && (typeof(svalue)!="undefined")) {
+            range1=svalue.split(',');
+            if (typeof(range1[1])=='undefined') { range1[1]=range1[0]; }
+            choices.document.forms.sch.val2.value=parseFloat(range1[0]);
+            if (range1[0].indexOf('+')!=-1) {
+               choices.document.forms.sch.val3.checked=true;
+            }
+            choices.document.forms.sch.val4.value=parseFloat(range1[1]);
+            if (range1[1].indexOf('+')!=-1) {
+               choices.document.forms.sch.val5.checked=true;
+            }
+         }
       }
       if (pscat=='absolute_sym') {
          tablestart('Absolute error, symmetric around value');
          valline('Value',2,3);
-         afterproc();
+         if ((svalue!='') && (typeof(svalue)!="undefined")) {
+            choices.document.forms.sch.val2.value=parseFloat(svalue);
+            if (svalue.indexOf('+')!=-1) {
+               choices.document.forms.sch.val3.checked=true;
+            }
+         }
       }
       if (pscat=='absolute') {
          tablestart('Absolute error, asymmetric around value');
          valline('Upper value',2,3);
          valline('Lower value',4,5);
-         afterproc();
-      }
-      if (pscat=='sigdigits') {
-         tablestart('Agreement on significant digits');
-  choicewrite('<tr bgcolor="#AAFFAA"><td colspan=3>Number of digits: '
-             +'<input type=text size=4 name=val2></td></tr>');
-
-choicewrite('<tr bgcolor="#AAFFAA"><td colspan=3>Accept if more digits given: '
-             +'<input type=checkbox name=val3></td></tr>');
-         
+         var range2=new Array;
+         if ((svalue!='') && (typeof(svalue)!="undefined")) {
+            range=svalue.split(',');
+            if (typeof(range2[1])=='undefined') { range2[1]=range2[0]; }
+            choices.document.forms.sch.val2.value=parseFloat(range2[0]);
+            if (range2[0].indexOf('+')!=-1) {
+               choices.document.forms.sch.val3.checked=true;
+            }
+            choices.document.forms.sch.val4.value=parseFloat(range2[1]);
+            if (range2[1].indexOf('+')!=-1) {
+               choices.document.forms.sch.val5.checked=true;
+            }
+         }
       }
    }
 
@@ -351,28 +466,28 @@ choicewrite('<tr bgcolor="#AAFFAA"><td c
          choicewrite('</table>');
      } else {
       if (pscat=='start') {
-         tablestart('Starting or opening date and time');
+         tablestart('Date and time');
       }
       if (pscat=='end') {
-         tablestart('Ending or closing date and time');
+         tablestart('Date and time');
       }
       if (pscat=='interval') {
          tablestart('Time interval');
-         choicewrite('<tr bgcolor="#AAFFAA"><td colspan=3>');
+         choicewrite('<tr><td colspan="3">');
          intervaldis();
-         choicewrite('</td></tr><tr bgcolor="#AAFFAA"><td>Time:'
-         +'</td><td colspan=2>');
+         choicewrite('</td></tr><tr><td>Time:'
+         +'</td><td colspan="2">');
          intday();choicewrite('days ');
          inthour();choicewrite('hours ');
          intminute(); choicewrite('mins '); intsecond();
          choicewrite('secs</td></tr></table>');         
       } else { 
-         choicewrite('<tr bgcolor="#AAFFAA"><td colspan=3>'
+         choicewrite('<tr><td colspan="3">'
          +cdate.toString()+
-         '</td></tr><tr bgcolor="#AAFFAA"><td>Date:</td><td colspan=2>');
+         '</td></tr><tr><td>Date:</td><td colspan="2">');
          month();date();year();
-         choicewrite('</td></tr><tr bgcolor="#AAFFAA"><td>Time:'
-         +'</td><td colspan=2>');hour();choicewrite('h ');minute();
+         choicewrite('</td></tr><tr><td>Time:'
+         +'</td><td colspan="2">');hour();choicewrite('h ');minute();
          choicewrite('m ');second();
          choicewrite('s</td></tr></table>');
       }
@@ -380,24 +495,49 @@ choicewrite('<tr bgcolor="#AAFFAA"><td c
    }
 
    if (ptype=='int') {
+      var pscatparts=new Array;
+      pscatparts=pscat.split(',');
+      pscat=pscatparts[0];
       if (pscat=='default') {
          tablestart('Default value or none');
-         choicewrite('</table>');         
+         choicewrite('</table>');
       } else {
+       if (pscat=='range') {
+         tablestart('Integer range');      
+         choicewrite('<tr><td>Lower Value:'+
+              '</td><td colspan="2"><input type="text" size="4" name="val2'+
+              '" /></td></tr>');
+         choicewrite('<tr><td>Upper Value:'+
+              '</td><td colspan="2"><input type="text" size="4" name="val4'+
+              '" /></td></tr></table>');
+         var range=new Array;
+         if ((svalue!='') && (typeof(svalue)!="undefined")) {
+            range=svalue.split(',');
+            if (typeof(range[1])=='undefined') { range[1]=range[0]; }
+            choices.document.forms.sch.val2.value=parseInt(range[0]);
+            choices.document.forms.sch.val4.value=parseInt(range[1]);
+         }
+       } else {
         if (pscat=='pos') {
            tablestart('Positive (non-zero) integer');
         }
         if (pscat=='zeropos') {
            tablestart('Positive integer or zero');
         }
+        if (pscat.indexOf('inrange')!=-1) {
+           var rangeparts=new Array;
+           rangeparts=split(',',pscat);
+           tablestart('Integer in the range ['+rangeparts[1]+']');
+        }
         if (pscat=='any') {
            tablestart('Integer');
         }
-        choicewrite('<tr bgcolor="#AAFFAA"><td>Value:</td><td colspan=2>');
-        choicewrite('<input name=intval size=10 value="'+svalue+
-                    '" name=intval onChange="parent.integereval()">');
-        choicewrite('</td></table>');
+        choicewrite('<tr><td>Value:</td><td colspan="2">');
+        choicewrite('<input name="intval" size="10" value="'+escapeHTML(svalue)+
+                    '" onchange="parent.integereval()" />');
+        choicewrite('</td></tr></table>');
       }
+     }
    }
 
    if (ptype=='float') {
@@ -414,36 +554,224 @@ choicewrite('<tr bgcolor="#AAFFAA"><td c
         if (pscat=='any') {
            tablestart('Floating point number');
         }
-        choicewrite('<tr bgcolor="#AAFFAA"><td>Value:</td><td colspan=2>');
-        choicewrite('<input name=floatval size=10 value="'+svalue+
-                    '" name=floatval onChange="parent.floateval()">');
-        choicewrite('</td></table>');
+        choicewrite('<tr><td>Value:</td><td colspan="2">');
+        choicewrite('<input name="floatval" size="10" value="'+escapeHTML(svalue)+
+                    '" onchange="parent.floateval()" />');
+        choicewrite('</td></tr></table>');
       }
    }
 
    if (ptype=='string') {
-      if (pscat=='default') {
-         tablestart('Default value or none');
-         choicewrite('</table>');         
-      } else {
-        if (pscat=='any') {
+        if ((pscat=='any') || (pscat=='') || (pscat=='default') ||  
+            (typeof(pscat)=='undefined')) {
            tablestart('Text');
+           choicewrite('<tr><td>Value:</td><td colspan="2">');
+           choicewrite('<input name="stringval" size="20" value="'+escapeHTML(svalue)+
+                    '" type="text" onchange="parent.stringeval()" />');
+        }
+        if (pscat=='yesno') {
+           tablestart('Yes/No');
+	   choicewrite('<tr><td>Value:</td><td colspan="2">');
+           choicewrite('<label><input name="stringval" value="yes"'+
+                  ' type="radio" '+callradiostringeval('yes'));
+           if (svalue=='yes') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Yes</label><br />');
+           choicewrite('<label><input name="stringval" value="no"'+
+                  ' type="radio" '+callradiostringeval('no'));
+           if (svalue=='no') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> No</label><br />');
+        }
+        if (pscat=='problemstatus') {
+           tablestart('Problem Status');
+	   choicewrite('<tr><td>Value:</td><td colspan="2">');
+           choicewrite('<label><input name="stringval" value="yes"'+
+                  ' type="radio" '+callradiostringeval('yes'));
+           if (svalue=='yes') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Yes</label><br />');
+           choicewrite('<label><input name="stringval" value="answer"'+
+                  ' type="radio" '+callradiostringeval('answer'));
+           if (svalue=='answer') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Yes, and show correct answer if they exceed the maximum number of tries.</label><br />');
+           choicewrite('<label><input name="stringval" value="no"'+
+                  ' type="radio" '+callradiostringeval('no'));
+           if (svalue=='no') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> No, don\'t show correct/incorrect feedback.</label><br />');
+           choicewrite('<label><input name="stringval" value="no_feedback_ever"'+
+                  ' type="radio" '+callradiostringeval('no_feedback_ever'));
+           if (svalue=='no_feedback_ever') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> No, show no feedback at all.</label><br />');
+        }
+        if (pscat=='examtype') {
+           tablestart('Exam Type');
+	   choicewrite('<tr><td>Value:</td><td colspan="2">');
+           choicewrite('<label><input name="stringval" value="online"'+
+                ' type="radio" '+callradiostringeval('online'));
+           if (svalue=='online') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Online</label><br />');
+           choicewrite('<label><input name="stringval" value="checkout"'+
+              ' type="radio" '+callradiostringeval('checkout'));
+           if (svalue=='checkout') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Check out</label><br />');
+       }
+        if (pscat=='questiontype') {
+           tablestart('Question Type');
+	   choicewrite('<tr><td>Value:</td><td colspan="2">');
+           choicewrite('<label><input name="stringval" value="problem"'+
+               ' type="radio" '+callradiostringeval('problem'));
+           if (svalue=='problem') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Standard Problem</label><br />');
+//	   choicewrite('<label><input name="stringval" value="quiz"'+
+//                ' type="radio" '+callradiostringeval('quiz'));
+//         if (svalue=='quiz') { choicewrite(' checked="checked"'); }
+//         choicewrite(' /> Quiz</label><br />');
+           choicewrite('<label><input name="stringval" value="practice"'+
+                  ' type="radio" '+callradiostringeval('practice'));
+           if (svalue=='practice') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Practice</label><br />');
+           choicewrite('<label><input name="stringval" value="exam"'+
+                  ' type="radio" '+callradiostringeval('exam'));
+           if (svalue=='exam') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Exam</label><br />');
+//         choicewrite('<label><input name="stringval" value="assess"'+
+//              ' type="radio" '+callradiostringeval('assess'));
+//         if (svalue=='assess') { choicewrite(' checked="checked"'); }
+//         choicewrite(' /> Assessment</label><br />');
+           choicewrite('<label><input name="stringval" value="survey"'+
+                ' type="radio" '+callradiostringeval('survey'));
+           if (svalue=='survey') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Survey</label><br />');
+//         choicewrite('<label><input name="stringval" value="form"'+
+//                ' type="radio" '+callradiostringeval('form'));
+//         if (svalue=='form') { choicewrite(' checked="checked"'); }
+//         choicewrite('> Input Form</label><br />');
+           choicewrite('<label><input name="stringval" value="surveycred"'+
+                ' type="radio" '+callradiostringeval('surveycred'));
+           if (svalue=='surveycred') { choicewrite(' checked="checked"'); }
+           choicewrite('> Survey (credit for submission)</label><br />');
+           choicewrite('<label><input name="stringval" value="anonsurvey"'+
+                ' type="radio" '+callradiostringeval('anonsurvey'));
+           if (svalue=='anonsurvey') { choicewrite(' checked="checked"'); }
+           choicewrite('> Anonymous Survey</label><br />');
+           choicewrite('<label><input name="stringval" value="anonsurveycred"'+
+                ' type="radio" '+callradiostringeval('anonsurveycred'));
+           if (svalue=='anonsurveycred') { choicewrite(' checked="checked"'); }
+           choicewrite('> Anonymous Survey (credit for submission)</label><br />');
+           choicewrite('<label><input name="stringval" value="randomizetry"'+
+                ' type="radio" '+callradiostringeval('randomizetry'));
+           if (svalue=='randomizetry') { choicewrite(' checked="checked"'); }
+           choicewrite('> New Randomization Each N Tries (default N=1)</label><br />');
+           choicewrite('<label><input name="stringval" value="library"'+
+               ' type="radio" '+callradiostringeval('library'));
+           if (svalue=='library') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Library</label><br />');
+        }
+        if (pscat=='lenient') {
+           tablestart('Lenient Grading (Partial Credit)');
+           choicewrite('<tr><td>Value:</td><td colspan="2">');
+           choicewrite('<label><input name="stringval" value="yes"'+
+                  ' type="radio" '+callradiostringeval('yes'));
+           if (svalue=='yes') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Yes</label><br />');
+           choicewrite('<label><input name="stringval" value="no"'+
+                  ' type="radio" '+callradiostringeval('no'));
+           if (svalue=='no') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> No</label><br />');
+           choicewrite('<label><input name="stringval" value="default"'+
+               ' type="radio" '+callradiostringeval('default'));
+           if (svalue=='default') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Default (only bubblesheet grading is lenient)</label><br />');
+        }
+        if (pscat=='discussvote') {
+           tablestart('Discussion Voting');
+           choicewrite('<tr><td>Value:</td><td colspan="2">');
+           choicewrite('<label><input name="stringval" value="yes"'+
+                  ' type="radio" '+callradiostringeval('yes'));
+           if (svalue=='yes') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Yes</label><br />');
+           choicewrite('<label><input name="stringval" value="notended"'+
+                  ' type="radio" '+callradiostringeval('notended'));
+           if (svalue=='notended') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Yes, unless discussion ended</label><br />');
+           choicewrite('<label><input name="stringval" value="no"'+
+                  ' type="radio" '+callradiostringeval('no'));
+           if (svalue=='no') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> No</label><br />');
+        }
+        if (pscat=='ip') {
+           tablestart('IP Number/Name');
+	   choicewrite('<tr><td>Value:</td><td colspan="2">');
+           choicewrite('<input name="stringval" size="20" value="'+escapeHTML(svalue)+
+                    '" onchange="parent.stringeval()" />');
         }
-        choicewrite('<tr bgcolor="#AAFFAA"><td>Value:</td><td colspan=2>');
-        choicewrite('<input name=intval size=20 value="'+svalue+
-                    '" name=stringval onChange="parent.stringeval()">');
-        choicewrite('</td></table>');
+        if (pscat=='fileext') {
+            tablestart('Allowed File Extensions');
+	   choicewrite('<tr><td>Value:</td><td colspan="2">');
+           choicewrite('<label><input name="radstringval" value="txt"'+
+               ' type="radio" '+callradiostringeval('txt'));
+           if (svalue=='txt') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Plain Text</label><br />');
+           choicewrite('<label><input name="radstringval" value="png,jpg,jpeg,gif"'+
+               ' type="radio" '+callradiostringeval('png,jpg,jpeg,gif'));
+           if (svalue=='png,jpg,jpeg,gif') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Picture File</label><br />');
+           choicewrite('<label><input name="radstringval" value="doc,docx,xls,xlsx,ppt,pptx"'+
+               ' type="radio" '+callradiostringeval('doc,docx,xls,xlsx,ppt,pptx'));
+           if (svalue=='doc,docx,xls,xlsx,ppt,pptx') { choicewrite(' checked="checked"'); }
+           if (svalue=='doc,xls,ppt') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Office Document</label><br />');
+           choicewrite('<input name="stringval" size="20" value="'+escapeHTML(svalue)+
+                    '" onchange="parent.stringeval()" />');
+       }
+       if (pscat=='useslots') {
+           tablestart('Slots control access');
+	   choicewrite('<tr><td>Value:</td><td colspan="2">');
+           choicewrite('<label><input name="stringval" value="no"'+
+                  ' type="radio" '+callradiostringeval('no'));
+           if (svalue=='no') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> No</label><br />');
+           choicewrite('<label><input name="stringval" value="resource"'+
+                  ' type="radio" '+callradiostringeval('resource'));
+           if (svalue=='resource') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Yes, and the scope of student selected slot is a single resource.</label><br />');
+           choicewrite('<label><input name="stringval" value="map"'+
+                  ' type="radio" '+callradiostringeval('map'));
+           if (svalue=='map') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Yes, and the scope of student selected slot is the enclosing map/folder. When checking in, it applies to only one resource.</label><br />');
+           choicewrite('<label><input name="stringval" value="map_map"'+
+                  ' type="radio" '+callradiostringeval('map_map'));
+           if (svalue=='map_map') { choicewrite(' checked="checked"'); }
+           choicewrite(' /> Yes, and the scope of student selected slot is the enclosing map/folder. When checking in, all resources in the map/folder are checked in.</label><br />');
+        choicewrite('</td></tr></table>');
       }
    }
+   
+   if (ptype=='color') {
+      tablestart('Choose a Color');
+      choicewrite('<table>');
+      if (svalue) {
+         choicewrite('<tr><td colspan="9">Current choice:</td><td bgcolor="'+
+                     escapeHTML(svalue)+'" colspan="2">&nbsp;</td></tr>');
+      }
+      for (var ir=0; ir<=10; ir++) {
+          for (var ig=0; ig<=10; ig++) {
+              choicewrite('<tr>');
+              for (var ib=0; ib<=10; ib++) {
+                  colorfield(ir,ig,ib);
+	      }
+              choicewrite('</tr>');
+	  }	      
+      }
+      choicewrite('</table></td></table>');
+   }
 
-   choicewrite('</table></form>');
+   choicewrite('</form>');
    choiceend();
 }
 
 function sopt(va,text) {
    selwrite('<option value="'+va+'"');
    if (va==pscat) {
-     selwrite(' selected');
+     selwrite(' selected="selected"');
    }
    selwrite('>'+text+'</option>');
 }
@@ -456,7 +784,45 @@ function catchange() {
 
 function assemble() {
     if ((ptype=='date') && (pscat!='interval')) {
-        svalue=Math.round(cdate.getTime()/1000);
+        svalue=Math.floor(cdate.getTime()/1000);
+    }
+    if (ptype=='tolerance') {
+       if (pscat=='relative_sym') {
+          svalue=choices.document.forms.sch.val2.value+'%';
+          if (choices.document.forms.sch.val3.checked) {
+             svalue+='+';
+          }
+       }
+       if (pscat=='absolute_sym') {
+          svalue=choices.document.forms.sch.val2.value;
+          if (choices.document.forms.sch.val3.checked) {
+             svalue+='+';
+          }
+       }
+       if (pscat=='absolute') {
+          svalue=choices.document.forms.sch.val2.value;
+          if (choices.document.forms.sch.val3.checked) {
+             svalue+='+';
+          }
+          svalue+=','+choices.document.forms.sch.val4.value;
+          if (choices.document.forms.sch.val5.checked) {
+             svalue+='+';
+          }
+       }
+       if (pscat=='relative') {
+          svalue=choices.document.forms.sch.val2.value+'%';
+          if (choices.document.forms.sch.val3.checked) {
+             svalue+='+';
+          }
+          svalue+=','+choices.document.forms.sch.val4.value+'%';
+          if (choices.document.forms.sch.val5.checked) {
+             svalue+='+';
+          }
+       }
+    }
+    if ((ptype=='int') && (pscat=='range')) {
+          svalue=choices.document.forms.sch.val2.value+','+
+                 choices.document.forms.sch.val4.value;
     }
     if (pscat=='default') { svalue=''; }
     stype=ptype+'_'+pscat;
@@ -476,8 +842,10 @@ function init() {
      if (pair[0]=='type') { subs=pair[1].split('_');
                             ptype=subs[0];
                             pscat=subs[1];
-                            if (subs[2]!=undefined) { pscat+='_'+subs[2]; }
-                            if ((pscat=='') || (pscat==undefined)) { 
+                            if (typeof(subs[2])!="undefined") { 
+                               pscat+='_'+subs[2]; 
+                            }
+                            if ((pscat=='') || (typeof(pscat)=="undefined")) { 
                                pscat='default';
                             }
                            }
@@ -485,36 +853,78 @@ function init() {
      if (pair[0]=='call') { pcode=pair[1]; }
      if (pair[0]=='marker') { pmarker=pair[1]; }
      if (pair[0]=='name') { pname=pair[1]; }
+     if (pair[0]=='modal') { pmodal=pair[1]; }
+     if (pair[0]=='defhour' && pair[1] >= 0 && pair[1] < 24 ) {
+         defhour=pair[1];
+     }
+     if (pair[0]=='defmin' && pair[1] >= 0 && pair[1] < 60) { defmin=pair[1]; }
+     if (pair[0]=='defsec' && pair[1] >= 0 && pair[1] < 60) { defsec=pair[1]; }
   }
 
   svalue=pvalue;
   if (((ptype=='float') || (ptype=='string') || (ptype=='int')) &&
       (pscat=='default') && 
-      (svalue!=undefined) && (svalue!=0) && (svalue!='')) { pscat='any'; }
+      (typeof(svalue)!="undefined") && 
+      (svalue!=0) && (svalue!='')) { pscat='any'; }
 
-  this.window.selector.document.clear();
-  selwrite('<html><body bgcolor="#FFFFFF">');
+  if (ptype=='tolerance') {
+     var tperc=0;
+     var trange=0;
+     if (typeof(svalue)!='undefined') {
+        if (svalue.indexOf('%')!=-1) { tperc=1;  }
+        if (svalue.indexOf(',')!=-1) { trange=1; }
+        if (trange) {
+           if (tperc) { pscat='relative'; } else { pscat='absolute'; }
+        } else {
+           if (tperc) { pscat='relative_sym'; } else { pscat='absolute_sym'; }
+        }
+     }
+  }
+
+  this.window.selector.document.open();
+  selwrite('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
+  selwrite('<html xmlns="http://www.w3.org/1999/xhtml">');
+  selwrite('<head>');
+  selwrite('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
+  selwrite('<title>LON-CAPA</title>');
+  selwrite('<style type="text/css">');
+  selwrite('<!--');
+  selwrite('body {');
+  selwrite('font-family: Verdana,Arial,Helvetica,sans-serif;');
+  selwrite('line-height:130%;');
+  selwrite('font-size:0.83em;');
+  selwrite('background: #FFFFFF;');
+  selwrite('}');
+  selwrite('-->');
+  selwrite('</style>');
+  selwrite('</head>');
+  selwrite('<body>');
+  selwrite('<form name="fsel" action=""><b>'+pname+'</b><br />');
+  selwrite('Format of Value(s): <select name="fcat" onchange="parent.catchange();">');
 
-  selwrite('<form name="fsel"><h2>'+pname+'</h2>');
-  selwrite('<select name="fcat" onChange="parent.catchange();">');
   if (ptype=='tolerance') {
      sopt('default','Default');
-     sopt('exact','Exact Value (no tolerance)');
      sopt('relative_sym','Relative Tolerance, Symmetric (percent)');
      sopt('relative','Relative Tolerance (percentages)');
      sopt('absolute_sym','Absolute Tolerance, Symmetric (value)');
      sopt('absolute','Absolute Tolerance (values)');
-     sopt('sigdigits','Significant Digits (number)');
   }
 
   if (ptype=='date') {
-     sopt('default','Default');
-     sopt('start','Starting Date');
-     sopt('end','Ending Date');
-     sopt('interval','Time Interval');
-     
-     if ((pvalue!='') && (pvalue!=undefined)) {
+     if (pscat != 'interval') {
+         sopt('default','Default');
+	 sopt('start','Starting Date');
+	 sopt('end','Ending Date');
+     } else {
+         sopt('interval','Time Interval');
+     }
+
+     if ((pvalue!='') && (typeof(pvalue)!="undefined")) {
         cdate.setTime(pvalue*1000);
+     } else {        
+        cdate.setSeconds(defsec);
+        cdate.setMinutes(defmin);
+        cdate.setHours(defhour);
      }
  
      months[0]='January';
@@ -535,6 +945,8 @@ function init() {
      sopt('default','Default');
      sopt('pos','Positive Integer, Not Zero');
      sopt('zeropos','Positive Integer or Zero');
+     sopt('inrange','Integer in Range');
+     sopt('range','Range of Integers');
      sopt('any','Integer');
   }
 
@@ -547,66 +959,69 @@ function init() {
   }
 
   if (ptype=='string') {
-     sopt('default','Default');
-     sopt('string','String Value');
+     //sopt('default','Default');
+     if (pscat == 'yesno')        { sopt('yesno','Yes/No'); }
+     else if (pscat == 'problemstatus'){ sopt('problemstatus','Problem Status'); }
+     else if (pscat == 'examtype')     { sopt('examtype','Exam Type'); }
+     else if (pscat == 'questiontype') { sopt('questiontype','Question Type'); }
+     else if (pscat == 'lenient')      { sopt('lenient','Lenient Grading (Partial Credit)'); }
+     else if (pscat == 'discussvote')  { sopt('discussvote','Discussion Voting'); }
+     else if (pscat == 'ip')           { sopt('ip','IP Number/Name'); }
+     else if (pscat == 'fileext')      { sopt('fileext','File Extension'); }
+     else if (pscat == 'useslots')     { sopt('useslots','Slots control access'); }
+     else { pscat = 'any'; }
+     sopt('any','String Value');
   }
 
-  selwrite('</select></form>');
+  if (ptype=='color') {
+     sopt('default','Use Default Color');
+     sopt('custom','Use Custom Color');
+  }
 
+  selwrite('</select></form>');
+  var targ='parent.opener';
+  if (pmodal==1) {
+     targ='parent.parent';
+  }  
   selwrite('<a href="javascript:parent.assemble();');
   if (preturn!='') {
-     selwrite(
-      'parent.opener.document.'+preturn+'_value.value=parent.window.svalue;');
-     selwrite(
-      'parent.opener.document.'+preturn+'_type.value=parent.window.stype;');
+     selwrite(targ+'.document.'+preturn+'_value.value=parent.window.svalue;');
+     selwrite(targ+'.document.'+preturn+'_type.value=parent.window.stype;');
   }
   if (pmarker!='') {
-     selwrite(
-     'parent.opener.document.'+preturn+'_marker.value=parent.window.pmarker;');
+     selwrite(targ+'.document.'+preturn+'_marker.value=parent.window.pmarker;');
   }
   if (pcode!='') {
-     selwrite('parent.opener.'+pcode+'();');
+     selwrite(targ+'.'+pcode+'();');
   }
-  selwrite('">Store</a>&nbsp;&nbsp;');
+  selwrite('">Save</a>&nbsp;&nbsp;');
 
   selwrite('<a href="javascript:');
-     selwrite(
-      'parent.opener.document.'+preturn+'_value.value='+"'';");
+  selwrite(targ+'.document.'+preturn+'_value.value='+"'';");
   if (pmarker!='') {
      selwrite(
-     'parent.opener.document.'+preturn+'_marker.value=parent.window.pmarker;');
+     targ+'.document.'+preturn+'_marker.value=parent.window.pmarker;');
   }
   if (pcode!='') {
-     selwrite('parent.opener.'+pcode+'();');
+     selwrite(targ+'.'+pcode+'();');
   }
   selwrite('">Delete</a>&nbsp;&nbsp;');
  
-  selwrite('<a href="javascript:');
-  if (preturn!='') {
-     selwrite('parent.opener.document.'+preturn+'_value.value='+"'';");
-     selwrite('parent.opener.document.'+preturn+'_type.value='+"'';");
-  }
-  if (pmarker!='') {
-     selwrite('parent.opener.document.'+preturn+'_marker.value='+"'';");
-  }
-  if (pcode!='') {
-     selwrite('parent.opener.'+pcode+'();');
-  }
-  selwrite('">Cancel</a>'); 
- 
   selwrite('</body></html>');
   this.window.selector.document.close();
   draw();
   
 }
 
+// ]]>
 </script>
+</head>
 
-<frameset rows="120,*" onLoad="init();">
-<frame name=selector src="empty.html">
-<frame name=choices src="empty.html">
+<frameset rows="120,*" onload="init();">
+<frame name="selector" src="empty.html" />
+<frame name="choices" src="empty.html" />
 </frameset>
 
 
 
-</html>
\ No newline at end of file
+</html>