Index: Dev/trunk/classes/SurveyCreationTool.php
===================================================================
--- Dev/trunk/classes/SurveyCreationTool.php	(revision 23)
+++ Dev/trunk/classes/SurveyCreationTool.php	(revision 24)
@@ -9,12 +9,11 @@
 class SurveyCreationTool {
 
-    public function __construct() {
+    public function __construct($survey = null, $timeStamp = null) {
         SurveyCreationTool::javascript();
         ?>
 
-        <div id="surveyCreation"><form action="submitsurvey.php" method="post">
+        <div id="surveyCreation"><form id="survey" action="submitsurvey.php" method="post">
                 <?php
-                SurveyCreationTool::titleBox();
-                SurveyCreationTool::descriptionBox();
+                SurveyCreationTool::surveyHead($timeStamp);
                 SurveyCreationTool::questionCreationForm();
                 SurveyCreationTool::addQuestionButton();
@@ -28,6 +27,9 @@
         ?>
         <script type="text/javascript">
-            var questionCount = 1;           
-                                                                                                                    
+            /* autosave every 3 minutes */
+            setTimeout("save()", 180000);
+            
+            var questionCount = 1;          
+                                                                                                                                                    
             function getNewQuestion()
             {
@@ -52,10 +54,10 @@
                     "<div id='answersDiv" + questionCount + "' class='answersDiv'></div>" +
                     "</div>";
-                                                                                                                
+                                                                                                                                                
                 questionDiv.innerHTML = htmlStr;
-                                                                                                                
+                                                                                                                                                
                 return questionDiv;
             }
-                                                                                                                    
+                                                                                                                                                    
             function handleFocus(input)
             {
@@ -67,15 +69,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)
                     {
@@ -88,5 +90,5 @@
                 }                           
             }
-                                                                                                    
+                                                                                                                                    
             function handleType(select)
             {
@@ -95,10 +97,10 @@
                 answersDiv.answerCount = 1;
                 answersDiv.clicked = null;
-                                                        
+                                                                                        
                 switch (type) {
                     case 'mc':
                         answersDiv.innerHTML = "";
                         addOption(select.id);
-                                                                                        
+                                                                                                                        
                         break;
                     case 'text':
@@ -124,6 +126,6 @@
 
             }
-                                                                                    
-                                                                            
+                                                                                                                    
+                                                                                                            
             function addOption(questionNumber)
             {        
@@ -132,8 +134,8 @@
                 var answerDiv = document.createElement("div");
                 answerDiv.className = "answerDiv";
-                                                                                
+                                                                                                                
                 var htmlStr = "<input type='text' name='q" + 
                     questionNumber + "ans" + answerCount + "' value='Option " + answerCount + "' />";
-                                                        
+                                                                                        
                 if (answersDiv.clicked == null)
                 {
@@ -141,21 +143,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)
                 {
@@ -165,22 +167,22 @@
                 }
             }
-                                            
+                                                                            
             function minMax(questionNumber)
             {
                 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' />";
-                                           
+                                                                           
                 answersDiv.appendChild(answerDiv);
             }  
-                                            
+                                                                            
             function minMaxIncr(questionNumber)
             {
                 var answersDiv = document.getElementById("answersDiv" + questionNumber);
-                                               
+                                                                               
                 var answerDiv = document.createElement("div");
                 answerDiv.className = "answerDiv";
@@ -188,14 +190,14 @@
                     "<label>Right label</label><input type='text' name='q" + questionNumber + "ans2' />" +
                     "<label>Scale count</label><input type='text' name='q" + questionNumber + "ans3' />";
-                                           
+                                                                           
                 answersDiv.appendChild(answerDiv);
             }         
-                                                                                                 
-                                                                                                         
+                                                                                                                                 
+                                                                                                                                         
             function addQuestion()
             {
                 var questionsDiv = document.getElementById('questionsDiv');
                 var newQuestion = getNewQuestion();
-                                        
+                                                                        
 
                 newQuestion.prev = document.lastQuestion;
@@ -205,9 +207,9 @@
                 questionCount++;
             }
-                                    
+                                                                    
             function removeLastQuestion()
             {
                 var questionsDiv = document.getElementById('questionsDiv');
-                                        
+                                                                        
                 if (document.lastQuestion.prev != null)
                 {
@@ -221,14 +223,49 @@
                 }               
             }
-                                  
                                             
-                                                                                                                                                                                                                            
+            function save()
+            {
+                var form = document.getElementById('survey');
+                var questionsDiv = document.getElementById('questionsDiv');
+                form.action = "surveycreation.php";
+                
+                /* extra time stamp */
+                var date = new Date();
+                var timeStamp = date.getHours() + ":" + date.getUTCMinutes();
+                var timeStampInput = document.createElement("input");
+                timeStampInput.name = "timeStamp";
+                timeStampInput.value = timeStamp;
+                timeStampInput.type = "hidden";
+                
+                questionsDiv.appendChild(timeStampInput);
+                form.submit();
+            }
+                                                                            
+                                                                                                                                                                                                                                                            
         </script>
         <?php
     }
 
+    private static function surveyHead($timeStamp = null) {
+        ?><div id="surveyHead">
+        <?php
+        SurveyCreationTool::titleBox();
+        SurveyCreationTool::saveSurvey($timeStamp);
+        SurveyCreationTool::descriptionBox();
+        ?></div>
+        <?php
+    }
+
     private static function titleBox() {
         ?>
-        <input type="text" id="surveyTitle" name="surveyTitle" value="Untitled Survey" size="30" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
+        <input type="text" id="surveyTitle" name="surveyTitle" value="Untitled Survey" onblur="handleBlur(this)" onfocus="handleFocus(this)" />
+        <?php
+    }
+
+    private static function saveSurvey($timeStamp = null) {
+        if (isset($timeStamp))
+            echo "<div id='timeStamp'>Last saved " . $timeStamp . '</div>';
+        ?>
+        <input id="surveySaveButton" type="button" onclick="save()" class='surveyButton' value='Save' />
         <?php
     }
@@ -236,5 +273,5 @@
     private static function descriptionBox() {
         ?>
-        <textarea id="surveyDescription" rows="3" cols="80" name="surveyDescription" onblur="handleBlur(this)" onfocus="handleFocus(this)">Write a helpful description for this survey here.</textarea>
+        <textarea id="surveyDescription" name="surveyDescription" onblur="handleBlur(this)" onfocus="handleFocus(this)">Write a helpful description for this survey here.</textarea>
         <?php
     }
