Index: Dev/trunk/classes/SurveyCreationTool.php
===================================================================
--- Dev/trunk/classes/SurveyCreationTool.php	(revision 35)
+++ Dev/trunk/classes/SurveyCreationTool.php	(revision 36)
@@ -38,17 +38,17 @@
             /* autosave every 3 minutes */
             setTimeout("save('<?php echo $id; ?>')", 180000);
-                                                                                                                                                            
+                                                                                                                                                                            
             var questionCount = 1;          
-                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                    
             function getNewQuestion(title, description)
             {
                 if (title == null)
                     var title = 'Untitled Question';
-                                                                                                
+                                                                                                                
                 if (description != null)
                     var description = description;
                 else
                     var description = 'Write a question description here.';
-                                                                                                                    
+                                                                                                                                    
                 var questionDiv = document.createElement("div");
                 var htmlStr = 
@@ -71,10 +71,10 @@
                     "<div id='answersDiv" + questionCount + "' class='answersDiv'></div>" +
                     "</div>";
-                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                
                 questionDiv.innerHTML = htmlStr;
-                                                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                                                
                 return questionDiv;
             }
-                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                    
             function handleFocus(input)
             {
@@ -91,15 +91,15 @@
                 }
             }
-                                                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                                                    
             function handleBlur(input)
             {        
                 var surveyTitle = document.getElementById('surveyTitle');
                 var surveyDescription = document.getElementById('surveyDescription');
-                                                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                                                    
                 if (input.value == "")
                 {
                     input.style.color = "gray";
                     input.clicked = null;
-                                                                                                                                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                                                                                                                                            
                     if (input == surveyTitle)
                     {
@@ -112,5 +112,5 @@
                 }                           
             }
-                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                                    
             function handleType(select, answers)
             {
@@ -118,7 +118,16 @@
                 var type = select.valueOf().value;
                 var answersDiv = document.getElementById("answersDiv" + numQ );
+                
+                /* When type changes, remove question ID, because question changes */
+                var questionIDInput = document.getElementById("questionID" + numQ);
+                if (questionIDInput != null)
+                {
+                    var questionsDiv = document.getElementById("questionsDiv");
+                    questionsDiv.removeChild(questionIDInput);
+                }
+
                 answersDiv.answerCount = 1;
                 answersDiv.clicked = null;
-                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                        
                 switch (type) {
                     case 'mc':
@@ -133,5 +142,5 @@
                         else
                             addOption(numQ);
-                                                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                                                        
                         break;
                     case 'text':
@@ -140,5 +149,5 @@
                     case 'int':    
                         answersDiv.innerHTML = "";
-                                                                                                
+                                                                                                                
                         //min max
                         if (answers != null)
@@ -172,6 +181,6 @@
 
             }
-                                                                                                                                                                                                                                                                    
-                                                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                            
             function addOption(questionNumber, optionStr)
             {        
@@ -179,14 +188,14 @@
                 var answerCount = answersDiv.answerCount;
                 var answerDiv = document.createElement("div");
-                                
+                                                
                 if (optionStr == null)
                     var optionStr = "Option " + answerCount;
-                                
-                               
+                                                
+                                               
                 answerDiv.className = "answerDiv";
-                                                                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                
                 var htmlStr = "<input type='text' name='q" + 
                     questionNumber + "ans" + answerCount + "' value='" + optionStr + "' />";
-                                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                                        
                 if (answersDiv.clicked == null)
                 {
@@ -194,21 +203,21 @@
                         + " class='surveyButton' onclick='addOption(" + questionNumber + ")' value='Add Option' />" +
                         "<input type='button' class='surveyButton' onclick='removeOption(" + questionNumber + ")' value='x' />";
-                                                                                                                                                                                                            
+                                                                                                                                                                                                                            
                     answersDiv.clicked = true;
                 }
-                                                                                                                                                                                                                                                                       
+                                                                                                                                                                                                                                                                                       
                 answerDiv.innerHTML = htmlStr;
-                                                                                                                                                                                                        
+                                                                                                                                                                                                                        
                 answerDiv.prev = answersDiv.lastAnswer; //singly linked list
                 answersDiv.lastAnswer = answerDiv;
-                                                                                                                                                                                                                                                                       
+                                                                                                                                                                                                                                                                                       
                 answersDiv.appendChild(answerDiv);
                 answersDiv.answerCount++;
             }
-                                                                                                                                                                                                    
+                                                                                                                                                                                                                    
             function removeOption(questionNumber)
             {
                 var answersDiv = document.getElementById("answersDiv" + questionNumber);
-                                                                                                                                                                                                       
+                                                                                                                                                                                                                       
                 if (answersDiv.lastAnswer.prev != null)
                 {
@@ -218,5 +227,5 @@
                 }
             }
-                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                            
             function minMax(questionNumber, min, max)
             {
@@ -225,16 +234,16 @@
                 if (max == null)
                     var max = '';
-                                                                                        
+                                                                                                        
                 var answersDiv = document.getElementById("answersDiv" + questionNumber);
-                                                                                                                                                                                                                               
+                                                                                                                                                                                                                                               
                 var answerDiv = document.createElement("div");
-                                                                                                                                                                                                
+                                                                                                                                                                                                                
                 answerDiv.className = "answerDiv";
                 answerDiv.innerHTML = "<label for='min'>Min</label><input type='text' value='" + min + "' name='q" + questionNumber + "ans1' />" +
                     "<label for='max'>Max</label><input type='text' value='" + max + "' name='q" + questionNumber + "ans2' />";
-                                                                                                                                                                                                                           
+                                                                                                                                                                                                                                           
                 answersDiv.appendChild(answerDiv);
             }  
-                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                            
             function minMaxIncr(questionNumber, left, right, incr)
             {
@@ -245,7 +254,7 @@
                 if (incr == null)
                     var incr = '';
-                                        
+                                                        
                 var answersDiv = document.getElementById("answersDiv" + questionNumber);
-                                                                                                                                                                                                                               
+                                                                                                                                                                                                                                               
                 var answerDiv = document.createElement("div");
                 answerDiv.className = "answerDiv";
@@ -254,14 +263,14 @@
                     "<label>Scale count</label><input type='text' value='" + incr + "' name='q" + questionNumber + "ans3' />" +
                     "<div id='inputCheckFeedback'" + questionNumber + "";
-                                                                                                                                                                                                                           
+                                                                                                                                                                                                                                           
                 answersDiv.appendChild(answerDiv);
             }         
-                                                                                                                                                                                                                                                                                 
-                                                                                                                                                                                                                                                                                         
+                                                                                                                                                                                                                                                                                                 
+                                                                                                                                                                                                                                                                                                         
             function addQuestion(title, description)
             {
                 var questionsDiv = document.getElementById('questionsDiv');
                 var newQuestion = getNewQuestion(title, description);
-                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                        
 
                 newQuestion.prev = document.lastQuestion;
@@ -271,9 +280,9 @@
                 questionCount++;
             }
-                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                    
             function removeLastQuestion()
             {
                 var questionsDiv = document.getElementById('questionsDiv');
-                                                                                                                                                                                                                        
+                                                                                                                                                                                                                                        
                 if (document.lastQuestion.prev != null)
                 {
@@ -287,5 +296,5 @@
                 }               
             }
-                                                                                                                                                                                             
+                                                                                                                                                                                                             
             function save(surveyID)
             {
@@ -293,5 +302,5 @@
                 var questionsDiv = document.getElementById('questionsDiv');
                 form.action = "surveycreation.php";
-                                                                                                                                                                
+                                                                                                                                                                                
                 /* extra time stamp */
                 var date = new Date();
@@ -304,16 +313,16 @@
                 timeStampInput.value = timeStamp;
                 timeStampInput.type = "hidden";
-                                                                                                                    
+                                                                                                                                    
                 var surveyIDInput = document.createElement("input");
                 surveyIDInput.name = "surveyID";
                 surveyIDInput.value = surveyID;
                 surveyIDInput.type = "hidden";
-                                                                                                                                             
+                                                                                                                                                             
                 questionsDiv.appendChild(timeStampInput);
                 questionsDiv.appendChild(surveyIDInput);
                 form.submit();
             }
-                                                                                                                                                                                                                            
-                                                                                                                                                                                                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                                                                                                                                                                                                            
         </script>
         <?php
@@ -370,13 +379,5 @@
             foreach ($this->survey->questions as $numQ => $question) {
                 ?>
-                <script type="text/javascript"> 
-                    var questionIDInput = document.createElement("input");
-                    questionIDInput.name = "questionID<?php echo $numQ; ?>";
-                    questionIDInput.value = "<?php echo $question->id; ?>";
-                    questionIDInput.type = "hidden";
-                                                                                                                                                     
-                    document.getElementById("questionsDiv").appendChild(questionIDInput);
-                                 
-                                                            
+                <script type="text/javascript">
                     var answers = new Array();
                 <?php
@@ -386,7 +387,7 @@
                 }
                 ?>
-                                                                    
+                                                                                                    
                     addQuestion('<?php echo $question->title; ?>', '<?php echo $question->description; ?>');
-                                                                                                                                                                    
+                                                                                                                                                                                                    
                     var select = document.getElementById('<?php echo $numQ; ?>');
                     var type = '<?php echo $question->type; ?>';
@@ -399,5 +400,15 @@
                             break;
                         }
-                    }                                                                                                                    
+                    }      
+                                    
+                                    
+                    /* questionID stuff */
+                    var questionIDInput = document.createElement("input");
+                    questionIDInput.id = "questionID<?php echo $numQ; ?>";
+                    questionIDInput.name = "questionID<?php echo $numQ; ?>";
+                    questionIDInput.value = "<?php echo $question->id; ?>";
+                    questionIDInput.type = "hidden";
+                                                                                                                                                                                     
+                    document.getElementById("questionsDiv").appendChild(questionIDInput);
 
                 </script>
