Index: Dev/trunk/classes/Question.php
===================================================================
--- Dev/trunk/classes/Question.php	(revision 31)
+++ Dev/trunk/classes/Question.php	(revision 32)
@@ -15,5 +15,5 @@
     public $type;
     public $description;
-    public $answers;
+    public $answers; // format answers['#']
     
     public function __construct($title, $type, $description = null)
Index: Dev/trunk/classes/SurveyCreationTool.php
===================================================================
--- Dev/trunk/classes/SurveyCreationTool.php	(revision 31)
+++ Dev/trunk/classes/SurveyCreationTool.php	(revision 32)
@@ -16,5 +16,5 @@
         $this->timeStamp = $timeStamp;
 
-        if( isset($this->survey->id))
+        if (isset($this->survey->id))
             SurveyCreationTool::javascript($this->survey->id);
         else
@@ -38,7 +38,7 @@
             /* autosave every 3 minutes */
             setTimeout("save('<?php echo $id; ?>')", 180000);
-                                                                            
+                                                                                                                                                    
             var questionCount = 1;          
-                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                            
             function getNewQuestion(title, description)
             {
@@ -47,10 +47,10 @@
                 else
                     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 = 
@@ -73,10 +73,10 @@
                     "<div id='answersDiv" + questionCount + "' class='answersDiv'></div>" +
                     "</div>";
-                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                        
                 questionDiv.innerHTML = htmlStr;
-                                                                                                                                                                                                                
+                                                                                                                                                                                                                                                                                        
                 return questionDiv;
             }
-                                                                                                                                                                                                                    
+                                                                                                                                                                                                                                                                                            
             function handleFocus(input)
             {
@@ -88,15 +88,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)
                     {
@@ -109,17 +109,26 @@
                 }                           
             }
-                                                                                                                                                                                                    
-            function handleType(select)
-            {
+                                                                                                                                                                                                                                                                            
+            function handleType(select, answers)
+            {
+                var numQ = select.id; // questionNumber
                 var type = select.valueOf().value;
-                var answersDiv = document.getElementById("answersDiv" +  select.id);
+                var answersDiv = document.getElementById("answersDiv" + numQ );
                 answersDiv.answerCount = 1;
                 answersDiv.clicked = null;
-                                                                                                                                                        
+                                                                                                                                                                                                                                
                 switch (type) {
                     case 'mc':
                         answersDiv.innerHTML = "";
-                        addOption(select.id);
-                                                                                                                                                                                        
+                        if (answers != null)
+                        {
+                            for (var i = 1; i < answers.length; i++)
+                            {
+                                addOption(numQ, answers[i]);
+                            }
+                        }
+                        else
+                            addOption(numQ);
+                                                                                                                                                                                                                                                                
                         break;
                     case 'text':
@@ -128,15 +137,30 @@
                     case 'int':    
                         answersDiv.innerHTML = "";
+                                                                                        
                         //min max
-                        minMax(select.id);
+                        if (answers != null)
+                            minMax(numQ, answers[1], answers[2]);
+                        else
+                            minMax(numQ);
                         break;
                     case 'checkboxes':
-                        answersDiv.innerHTML = "";  
-                        addOption(select.id);
+                        answersDiv.innerHTML = "";
+                        if (answers != null)
+                        {
+                            for (var i = 1; i < answers.length; i++)
+                            {
+                                addOption(numQ, answers[i]);
+                            }
+                        }
+                        else
+                            addOption(numQ);
                         break;
                     case 'scale':
                         answersDiv.innerHTML = ""; 
                         //what scale (min max incr)
-                        minMaxIncr(select.id);
+                        if (answers != null)
+                            minMaxIncr(numQ, answers[1], answers[2], answers[3]);
+                        else
+                            minMaxIncr(numQ);
                         break;
                     default:
@@ -145,16 +169,21 @@
 
             }
-                                                                                                                                                                                    
-                                                                                                                                                                            
-            function addOption(questionNumber)
+                                                                                                                                                                                                                                                            
+                                                                                                                                                                                                                                                    
+            function addOption(questionNumber, optionStr)
             {        
                 var answersDiv = document.getElementById("answersDiv" + questionNumber);
                 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='Option " + answerCount + "' />";
-                                                                                                                                                        
+                    questionNumber + "ans" + answerCount + "' value='" + optionStr + "' />";
+                                                                                                                                                                                                                                
                 if (answersDiv.clicked == null)
                 {
@@ -162,21 +191,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)
                 {
@@ -186,38 +215,50 @@
                 }
             }
-                                                                                                                                            
-            function minMax(questionNumber)
-            {
+                                                                                                                                                                                                                    
+            function minMax(questionNumber, min, max)
+            {
+                if (min == null)
+                    var min = '';
+                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' name='q" + questionNumber + "ans1' />" +
-                    "<label for='max'>Max</label><input type='text' name='q" + questionNumber + "ans2' />";
-                                                                                                                                           
+                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)
-            {
+                                                                                                                                                                                                                    
+            function minMaxIncr(questionNumber, left, right, incr)
+            {
+                if (left == null)
+                    var left = '';
+                if (right == null)
+                    var right = '';
+                if (incr == null)
+                    var incr = '';
+                                
                 var answersDiv = document.getElementById("answersDiv" + questionNumber);
-                                                                                                                                               
+                                                                                                                                                                                                                       
                 var answerDiv = document.createElement("div");
                 answerDiv.className = "answerDiv";
-                answerDiv.innerHTML = "<label>Left label</label><input type='text' name='q" + questionNumber + "ans1' />" +
-                    "<label>Right label</label><input type='text' name='q" + questionNumber + "ans2' />" +
-                    "<label>Scale count</label><input type='text' name='q" + questionNumber + "ans3' />" +
+                answerDiv.innerHTML = "<label>Left label</label><input type='text' value='" + left + "' name='q" + questionNumber + "ans1' />" +
+                    "<label>Right label</label><input type='text' value='" + right + "' name='q" + questionNumber + "ans2' />" +
+                    "<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;
@@ -227,9 +268,9 @@
                 questionCount++;
             }
-                                                                                                                                    
+                                                                                                                                                                                                            
             function removeLastQuestion()
             {
                 var questionsDiv = document.getElementById('questionsDiv');
-                                                                                                                                        
+                                                                                                                                                                                                                
                 if (document.lastQuestion.prev != null)
                 {
@@ -243,5 +284,5 @@
                 }               
             }
-                                                                                                             
+                                                                                                                                                                                     
             function save(surveyID)
             {
@@ -249,5 +290,5 @@
                 var questionsDiv = document.getElementById('questionsDiv');
                 form.action = "surveycreation.php";
-                                                                                
+                                                                                                                                                        
                 /* extra time stamp */
                 var date = new Date();
@@ -260,16 +301,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
@@ -324,7 +365,29 @@
         <?php
         if (isset($this->survey)) {
-            foreach ($this->survey->questions as $question) {
+            foreach ($this->survey->questions as $numQ => $question) {
                 ?>
-                <script type="text/javascript"> addQuestion('<?php echo $question->title; ?>', '<?php echo $question->description; ?>');
+                <script type="text/javascript"> 
+                    var answers = new Array();
+                <?php
+                /* Put all answers in js array */
+                foreach ($question->answers as $numA => $answer) {
+                    echo "answers[" . $numA . "] = '" . $answer . "'; ";
+                }
+                ?>
+                                                    
+                    addQuestion('<?php echo $question->title; ?>', '<?php echo $question->description; ?>');
+                                                                                                                                                    
+                    var select = document.getElementById('<?php echo $numQ; ?>');
+                    var type = '<?php echo $question->type; ?>';
+
+                    for (var i = 0; i < select.options.length; i++) {
+                        if (select.options[i].value == type)
+                        {
+                            select.options[i].selected = true;
+                            handleType(select, answers)
+                            break;
+                        }
+                    }                                                                                                                    
+
                 </script>
                 <?php
