﻿// JScript File
/************************************************************************************* 
-  JScriptDYNSurveyObjects  This file contains JavaScript objects that 
-       facilitate dynamic survey implementation.
**************************************************************************************/
/************************************************************************************* 
-  Related Jscript files   
-       JScriptDOMUtils.  This is REQUIRED in order to facilitate cross browser DOM
-                         manipulation.
**************************************************************************************/
/* *********************************************************************************** 
-  Class: DYNSurveyObjectManager   
-  Purpose: Edits and records survey information.  This class represents a question 
-           and answer collection for a survey. It encapsulates question/answer
-           functionality.  
-  Date:  12/15/2006
-  Mods:
-     
************************************************************************************ */
function DYNSurveyObjectManager(thisEvent)
{
// Constructor
     this.Init = Init(thisEvent);
      
// Public Function Declarations ////////////////////////
     this.EditSurvey = EditSurvey;
     this.ClearSurvey = ClearSurvey;
     this.ProcessEvent = ProcessEvent;
     this.SaveSurvey = SaveSurvey;
// Public Property Declarations ////////////////////////
// Property Getters
     //GetIsProceed - Flag that indicates if we should proceed with edits/submit.
     this.GetIsProceed = GetIsProceed; 
     function GetIsProceed()
        {
            return _isProceed;
        }
        
                        
// Private Variable Declarations ////////////////////////
     var _SurveyId;             //Numeric representation of this survey.
     var _ErrMsg;               //General edit error message   
     var _ErrObjID;             //Client HTML tag that defines where the error message goes.
     var _ErrSubmitID;          //Client HTML tag ID of the survey submit button.      
     var _ErrClearID;           //Client HTML tag ID of the survey clear button.
     var _isProceed;            //See GetIsProceed prop.
     var _AssocObservationPK;   //Primary key of the observation associated with this survey.
     var _ObservationID         //Observation number associated with this survey. 
     //Collections
     var _SurveyQuestObjColl;   //Raw question objects from server.
     var _SurveyQuestObjArray;  //Question Object array of Javascript obects.
     var _ErrArray = new Array;
     //Objects
     var _thisEvent;            //Event that initiated this process.
     var _DynS;                 //Server Survey manager object.
     var _DOMUtil;              //Browser specific Services Utility.  
     var _ErrHandler;           //Error handler.
      
////////////////////////////////////////////////////////
// Public Functions ////////////////////////////////////
/* *********************************************************************************** 
-  Function: Init  
-  Purpose: Constructor sets up any metadata for this question.  
-             
-  Parameters: thisEvnt - The event that initiated this class usually the submit button
-                         click.  We also could be processing a clear button.   
-  Date:  01/08/2007
-  Mods:
-     
************************************************************************************ */
    function Init(thisEvnt)
        { 
           //Declare error handler
           _ErrHandler = new CommonErrorHandler();  
           //Save the initiating event 
            _thisEvent = thisEvnt;        
           //Get server Survey Manager object           
           var _DynS = AjaxProxy.ClientGetSurveyMgr(); 
           //Get browser specific Utility object... 
           var DOMobjFact = new DOMObjFactory();
           //This object provides browser specific services.  
           _DOMUtil = DOMobjFact.CreateDOMUtilObject();
           
           //Check if we got the Dynamic Survey object
           if(_DynS.value == null)
           {
                _ErrHandler.HandelClientSideErr("No Survey data was found - check Database error log.");
                return;
           }
              
           //See if the initiating event is 'registered' i.e. known to be a survey related event.    
           if(_DOMUtil.GetSrcElementId(_thisEvent) == _DynS.value.ClientSubmitID || _DOMUtil.GetSrcElementId(_thisEvent) == _DynS.value.ClientClearID)
           {
                //We recognize the event set up to process it....
                _ErrMsg = _DynS.value.ErrorText;
                _ErrObjID = _DynS.value.ErrorClientID;
                _ErrSubmitID = _DynS.value.ClientSubmitID;
                _ErrClearID = _DynS.value.ClientClearID;
                _SurveyID = _DynS.value.SurveyID;
                _SurveyQuestObjColl = _DynS.value.QuestionsColl;
                SurveyQuestObjectFactory("SurveyQuestions");
               _isProceed = true;
               
           }
           else
           {
             //Don't bother it's not one of ours.
              _isProceed = false;
           }

        }//End Init
/* *********************************************************************************** 
-  Function: ProcessEvent  
-  Purpose: Directs processing to either clear or process survey. 
-  Parameters: isEditDone - A boolean flag that indicates if the edits are done. 
-  Date:  01/08/2007
-  Mods:
-     
************************************************************************************ */
    function ProcessEvent(isEditDone)
        {
         //Clear survey      
            if(_DOMUtil.GetSrcElementId(_thisEvent) == _ErrClearID)
              {
                ClearSurvey();
              }   
        //Submit survey.  First edit then if edits pass submit and save survey.
            if(_DOMUtil.GetSrcElementId(_thisEvent) == _ErrSubmitID)
              {
                if(!isEditDone)
                  {
                     EditSurvey();
                  }
                else
                  {       
                     SaveSurvey();
                  }
                   
              }
                     
        }        
/* *********************************************************************************** 
-  Function: EditSurvey  
-  Purpose: Performs edits.  Iterate thru the question collection and let each question
-                            object edit itself.  
-  Parameters: None. 
-  Date:  01/08/2007
-  Mods:
-     
************************************************************************************ */
    function EditSurvey()
        { 
            var DynObj;
            var wkObj;
            var ErrObj;
            
            //Iterate thru all question objects and call the ApplyEdits method on each one.
            for(var i = 0; i < _SurveyQuestObjArray.length; i++)
            {
                DynObj = _SurveyQuestObjArray[i];
                DynObj.ApplyEdits();
                //Check error flag and set _isProceed flag to false if we find an error.
                if(DynObj.GetErrFlag())
                {                   
                    _isProceed = false;
                   
                }
               
            }
            //Found error(s) - set error message and cancel the event.
            if(!_isProceed)
            {
                 ErrObj = document.getElementById(_ErrObjID);
                 ErrObj.innerHTML = _ErrMsg
                 _DOMUtil.CancelEvent(_thisEvent);
                 _DOMUtil = null;
                return false;
            }
            else
            {
                //Allz well...
                return true;
            }
            
                
        } //End EditSurvey
/* *********************************************************************************** 
-  Function: ClearSurvey  
-  Purpose: Clears answers and any highliting/error messages. 
-  Parameters: None. 
-  Date:  01/08/2007
-  Mods:
-     
************************************************************************************ */
    function ClearSurvey()
        { 
            var DynObj;
            var wkObj;
            var ErrObj;
            
            //Iterate thru question objects and call the ClearQuestion method on each of them.
            for(var i = 0; i < _SurveyQuestObjArray.length; i++)
            {
                DynObj = _SurveyQuestObjArray[i];
                DynObj.ClearQuestion();
                           
                            
            }
         //Clear error message   
         ErrObj = document.getElementById(_ErrObjID);
         ErrObj.innerHTML = ""; 
         _isProceed = false;   
                
        } //End ClearSurvey 

/* *********************************************************************************** 
-  Function: SaveSurvey   
-  Purpose: Iterates thru a question collection and collects question/answer data, then
-           calls the server-side method to insert data to database. 
-  Parameters: None. 
-  Date:  01/08/2007
-  Mods:
-     
************************************************************************************ */
    function SaveSurvey()
        { 
            var DynQuestObj;
            var DynAnsObj;
            var AnsObjArray;
            var QuestPK;
            var AnsPK;
            var AnsData;
            var AnsText;
            var QstText;
            var AnsQVA;
            var QstQVA;
            var splitName;
            var ArrLth;
            var checKobj;
             
           /*************************************************************************************
           - Get the observation primary key that is associated with this survey.  Get it from 
           - splitting the HTML tag ID which is in the form yyyy_xxx where xxx is the observation
           - number.  Then call the server GitObservationID method to get the Observation PK.
           **************************************************************************************/ 
           splitName = _DOMUtil.GetSrcElementId(_thisEvent).split("_"); 
           ArrLth = splitName.length - 1;   
           //See if we have any data. 
           if(splitName[ArrLth] == null || splitName[ArrLth] == "")
             {
                throw "Invalid Object Name -" +  splitName +"- Observation Code Does Not Exist.";
             }
            //See if the last node is a number  
           if(isNaN(splitName[ArrLth]))
            {
                 throw "Invalid Object Name -" +  splitName +"- no Observation Code embedded.";
            
            }
            //Get Observation PK 
            _ObservationID = AjaxProxy.GitObservationID(splitName[ArrLth]);
            
            //Iterate thru question collection and call server side to insert data
            for(var i = 0; i < _SurveyQuestObjArray.length; i++)
            {
               DynQuestObj = _SurveyQuestObjArray[i];
              checKobj = document.getElementById(DynQuestObj.GetQuestionID());
             //Do we have the object on this page???
             if(checKobj != null)
             {
               // DynQuestObj = _SurveyQuestObjArray[i];
                if(DynQuestObj.IsQuestionAnswered())
                {
                        AnsObjArray = DynQuestObj.GetAnsObjColl();
                        //Iterate thru associated answer collection and get data if answer data is 
                        //present.  If the question is NOT answered, insert a 'No Answer' row.
                        for(var ii = 0; ii < AnsObjArray.length; ii++)
                         {
                            DynAnsObj = AnsObjArray[ii];
                            if(DynAnsObj.GetIsData())
                              {
                              try
                                {
                                    QuestPK = DynQuestObj.GetQuestionPK();
                                    AnsPK = DynAnsObj.GetAnsPK();
                                    AnsData = DynAnsObj.GetAnswerData();
                                    AnsText = DynAnsObj.GetAnsText();
                                    AnsQVA = DynAnsObj.GetAnsQVA();
                                    QstText = DynQuestObj.GetQuestionText();
                                    QstQVA = DynQuestObj.GetQuestionQVA();
                                    
                                    AjaxProxy.ClientInsertSurvey(sessionId
                                    ,0
                                    ,QuestPK
                                    ,AnsPK
                                    ,AnsData
                                    ,0
                                    ,_ObservationID.value
                                    ,_SurveyQuestObjArray.length
                                    ,i+1
                                    ,AnsText
                                    ,QstText
                                    ,AnsQVA
                                    ,QstQVA
                                    );
                                }  
                                catch(e)
                                    {
                                        alert("Error -" +  e);
                                    }    
                              }
                           
                        }
                    }
                    else
                    {
                        try
                                {
                                    QuestPK = DynQuestObj.GetQuestionPK();
                                    AnsObjArray = DynQuestObj.GetAnsObjColl();
                                    //This is a no answer so find the no answer answer
                                    // and get the proper QVC etc... 
                                     for(var iii = 0; iii < AnsObjArray.length; iii++)
                                        {
                                            DynAnsObj = AnsObjArray[iii];
                                            if(DynAnsObj.GetNoAns())
                                                {   
                                                    AnsPK = DynAnsObj.GetAnsPK();                                             
                                                    AnsData = DynAnsObj.GetAnswerData();
                                                    AnsText = DynAnsObj.GetAnsText();
                                                    AnsQVA = DynAnsObj.GetAnsQVA();
                                                 }
                                         }
                                    QstText = DynQuestObj.GetQuestionText();
                                    QstQVA = DynQuestObj.GetQuestionQVA();
                                    
                                    AjaxProxy.ClientInsertSurvey(sessionId
                                    ,0
                                    ,QuestPK
                                    ,AnsPK
                                    ,AnsText
                                    ,0
                                    ,_ObservationID.value
                                    ,_SurveyQuestObjArray.length
                                    ,i+1
                                    ,AnsText
                                    ,QstText
                                    ,AnsQVA
                                    ,QstQVA
                                    );
                                }  
                                catch(e)
                                    {
                                        alert("Error -" +  e);
                                    }    
                    
                    
                    }
                }
              }  
                                 
        
        }
/* *********************************************************************************** 
-  Function: SurveyQuestObjectFactory   
-  Purpose: Returns a DYNSurveyQuestObj object array with all metadata. 
-  Parameters: SurObjType - The type of object that we want created. 
-  Date:  01/08/2007
-  Mods:
-     
************************************************************************************ */
    function SurveyQuestObjectFactory(SurObjType)
        {             
            var ObjectArray = new Array();      //Raw object collection from server
            var ResultArray = new Array();      //Javascript object Question objects.
            var DataObj;                        //Individual raw server object
            var SurvObj;                        //Individual Javascript question object
            var Pos = 0;
               
            ObjectArray = _SurveyQuestObjColl
            if(ObjectArray.length == 0)
            {
                return;  
            }
            //For each server question object, create a javascript question object.
            for (i in ObjectArray)
                {        
                    var DataObj = ObjectArray[i];
                    //Eliminate types that we don't want...
                    if(isType(SurObjType, DataObj.__type))
                        {
                            SurvObj = new DYNSurveyQuestObj(DataObj.QuestionPk
                            ,DataObj.AnsCount
                            ,DataObj.QuestClientId
                            ,DataObj.QuestText
                            ,DataObj.AnsType
                            ,DataObj.AnswerObjColl
                            ,DataObj.ValidRulesColl
                            ,DataObj.QuestQVAID 
                            ); 
                            ResultArray[Pos] = SurvObj;
                             
                            Pos ++;
                        }

                }
                //Save all questions in an array
                _SurveyQuestObjArray = ResultArray;
        
        }        
/* *********************************************************************************** 
-  Function: isType   
-  Purpose: Determines the type of an object 
-  Parameters: inTypeName - the value of the type that we are looking for.
-              inType -  The string passed from AjaxPro with the type imbedded.  
-  Date:  01/08/2007
-  Mods:
-     
************************************************************************************ */        
        function isType(inTypeName, inType)
        {   
           var regxx = eval("/" + inTypeName + "/gi");
           var resArray; 
           if(inType != null)
            {
                resArray = inType.match(regxx);
                if(resArray)
                { 
                    return true;
                }
                else
                {    
                    return false;
                }
           }  
       }            
     
                 

}//End  DYNSurveyObjectManager
//*End DYNSurveyObjectManager Class ************************************************************/  



/* *********************************************************************************** 
-  Class: DYNSurveyQuestObj   
-  Purpose: Edits and records survey information.  This class represents a question 
-           and associated answer collection for a survey. It encapsulates question/answer functionality.  
-  Date:  12/15/2006
-  Mods:
-     
************************************************************************************ */
function DYNSurveyQuestObj(QPk,AnsCnt,QClientID,QText,AnsTyp,AnsObjCol,EditColl,QuestQVA)
{
// Constructor
     this.Init = Init(QPk,AnsCnt,QClientID,QText,AnsTyp,AnsObjCol,EditColl,QuestQVA);
      
// Public Function Declarations ////////////////////////
     this.ApplyEdits = ApplyEdits;
     this.ClearQuestion = ClearQuestion; 

// Public Property Declarations ////////////////////////
// Property Getters
// Property GetErrFlag - Gets the edit results
     this.GetErrFlag = GetErrFlag; 
     function GetErrFlag()
        {
            return _ErrFlag;
        }
// Property GetAnswerID -          
     this.GetAnswerID = GetAnswerID; 
     function GetAnswerID()
        {
            return _AnsClientID;
        } 
// Property GetQuestionID -         
     this.GetQuestionID = GetQuestionID; 
     function GetQuestionID()
        {
            return _QuestClientId;
        }
// Property GetQuestionPK -          
     this.GetQuestionPK = GetQuestionPK; 
     function GetQuestionPK()
        {
            return _thisQuestionPk;
        }
// Property GetAnsObjColl -             
     this.GetAnsObjColl = GetAnsObjColl; 
     function GetAnsObjColl()
        {
            return _SurveyAnsObjArray;
        } 
// Property GetQuestionText -                      
     this.GetQuestionText = GetQuestionText; 
     function GetQuestionText()
        {
            return _QuestText;
        }
// Property GetQuestionQVA -         
     this.GetQuestionQVA = GetQuestionQVA; 
     function GetQuestionQVA()
        {
            return _QuestQVA;
        } 
// Property IsQuestionAnswered -         
     this.IsQuestionAnswered = IsQuestionAnswered; 
     function IsQuestionAnswered()
        {
            return _DataExists;
        }                               
                        
// Private Variable Declarations ////////////////////////
     var _thisQuestionPk;       //Question Primary Key.
     var _AnsCount;             //Count of associated answers.
     var _QuestClientId;        //HTML ID of the question on the client.  
     var _QuestText;
     var _QuestQVA;
     var _AnsType;
     var _SurveyAnswerObjColl;  //Raw server answer collection.
     var _SurveyAnsObjArray;
     var _ValidRulesColl;
     
     
     var _Qtext;
     var _QclientID;
     var _AnsText;
     var _AnsClientID;
     var _AnsType;
     var _AnsClientID;
     var _ErrMsg;
     var _ErrFlag = false;
     var _DataExists;
     var _AnswerGroup = new Array;
      
////////////////////////////////////////////////////////
// Public Functions ////////////////////////////////////
/* *********************************************************************************** 
-  Function: Init  
-  Purpose: Constructor sets up the question object.  It populates variables
-           and the associated answer collection    
-  Parameters: QPk - Primary Key of the question object. 
-              AnsCnt - Number of associated answers.  
-              QClientID - HTML ID of the question on the client.  
-              QText - Text of the question.  
-              AnsTyp - Type of answer i.e. radiobutton textbox etc.
-              AnsObjCol - Collection of associated answer objects.  
-              QuestQVA - QVA ID of the question.  
-  Date:  01/08/2007
-  Mods:
-     
************************************************************************************ */
    function Init(QPk,AnsCnt,QClientID,QText,AnsTyp,AnsObjCol,EditColl,QuestQVA)
        {             
           //Set up paivate vars
            _thisQuestionPk = QPk;
            _AnsCount = AnsCnt;
            _QuestClientId = QClientID;
            _QuestText = QText;
            _QuestQVA = QuestQVA;
            _AnsType = AnsTyp;
            _SurveyAnswerObjColl = AnsObjCol;
            _ValidRulesColl = EditColl;
            //Get Javascript object array of answers
            SurveyAnsObjectFactory("SurveyAnswers");

        }//End Init
/* *********************************************************************************** 
-  Function: ApplyEdits  
-  Purpose: For this question iterate thru the answer collection and apply any edits
-           that are indicated ie. required validation etc. 
-  Parameters: None. 
-  Date:  01/09/2007
-  Mods:
-     
************************************************************************************ */
    function ApplyEdits()
        { 
            var checKobj;               //Current question HTML object
            var AnsDynObj;              //Single DYNSurveyAnsObj Javascript object.
            var DataExists = false;
            
            //Get question HTML object
            checKobj = document.getElementById(_QuestClientId);
            //Do we have the object on this page???
           if(checKobj != null)
           {
                    //See if we have any edit criteria to apply
                    if(_ValidRulesColl.length > 0)
                    {
                            //Iterate thru the valid rules collection and apply edits as needed
                            for(var i = 0; i < _ValidRulesColl.length; i++)
                              {
                                 switch(_ValidRulesColl[i])
                                 {
                                    case "default":
                                        DataExists = AnsApplyEdits();
                                         _DataExists = DataExists;
                                        break;
                                   
                                    case "required":
                                        DataExists = AnsApplyEdits();
                                         _DataExists = DataExists;
                                        //If allz well set the question text to base color else high light the
                                        //question text on the client.
                                           if(!DataExists)
                                           {
                                                _ErrFlag = true;
                                                checKobj.style.color = "Red";
                                           }
                                           else
                                           {
                                                 checKobj.style.color = "Black";
                                           }
                                         break;    
                                          
                                   }
                              }
                      }
                      else
                      {
                        //No edit rules, we only need to verify that data exists
                        DataExists = AnsApplyEdits();
                        _DataExists = DataExists;
                      }
              
              }
              
             
 
      } //End ApplyEdits
/* *********************************************************************************** 
-  Function: ClearQuestion  
-  Purpose: Resets any editing highitghting for this question text and clears any
-           answers.  
-  Parameters: None. 
-  Date:  01/09/2007
-  Mods:
-     
************************************************************************************ */ 
    function ClearQuestion()
        { 
            var checKobj;               //Current question HTML object
            var AnsDynObj;              //Single DYNSurveyAnsObj Javascript object.
           
            //Get question HTML object.
            checKobj = document.getElementById(_QuestClientId);
            //Do we have the object on this page???
           if(checKobj != null)
           {
                checKobj.style.color = "Black";
               //Iterate thru answer collection and call the ClearAnswer method
               //on each individual object. 
                for(var i = 0; i < _SurveyAnsObjArray.length; i++)
                {
                    AnsDynObj = _SurveyAnsObjArray[i];
                    AnsDynObj.ClearAnswer();
                
                }
            }
                    
      } //End ClearQuestion
/////////////////////// Private Methods ///////////////////////////////////
/* *********************************************************************************** 
-  Function: AnsApplyEdits
-  Purpose: Returns an associated DYNSurveyAnsObj object array with all metadata. 
-  Parameters: SurObjType - Type name of DYNSurveyAnsObj. 
-  Date:  01/09/2007
-  Mods:
-     
************************************************************************************ */
    function AnsApplyEdits()
        {
            var AnsDynObj;              //Single DYNSurveyAnsObj Javascript object.
            var DataExists = false;
                    
            //Iterate thru answer collection and call the ApplyEdits method
           //on each individual object. 
            for(var i = 0; i < _SurveyAnsObjArray.length; i++)
            {
                AnsDynObj = _SurveyAnsObjArray[i];
                AnsDynObj.ApplyEdits();
                //switch(_AnsType)
                switch(AnsDynObj.GetAnsType())
                {
                     case "radio":
                        if(AnsDynObj.GetIsData())
                        {
                            DataExists = true;
                        }    
                          
                        break;
                     case "checkbox":
                        if(AnsDynObj.GetIsData())
                        {
                            DataExists = true;
                        }    
                          
                        break;   
                 }
       
            }
                       
            
            return DataExists;
        
        
        }      
/* *********************************************************************************** 
-  Function: SurveyAnsObjectFactory  
-  Purpose: Returns an associated DYNSurveyAnsObj object array with all metadata. 
-  Parameters: SurObjType - Type name of DYNSurveyAnsObj. 
-  Date:  01/09/2007
-  Mods:
-     
************************************************************************************ */
    function SurveyAnsObjectFactory(SurObjType)
        {             
            var ObjectArray = new Array();  //Array of raw server answer objects.
            var ResultArray = new Array();  //Array of Javascript DYNSurveyAnsObj
            var ServerAnsObj;               //Individual raw server ass object
            var AnsSurvObj;                 //Individual Ans Javascript object.
            var Pos = 0;
            
            //Get raw server objects   
            ObjectArray = _SurveyAnswerObjColl
            if(ObjectArray.length == 0)
            {
                return;  
            }
            //Iterate thru raw server objects and create answer javascript objects. 
            for (i in ObjectArray)
                {        
                    var ServerAnsObj = ObjectArray[i];
         
                    if(isType(SurObjType, ServerAnsObj.__type))
                        {
                            AnsSurvObj = new DYNSurveyAnsObj(ServerAnsObj.AnsClientID
                            ,ServerAnsObj.AnsClientType
                            ,ServerAnsObj.AnsPk
                            ,ServerAnsObj.AnsErrMsg
                            ,ServerAnsObj.AnsSeq
                            ,ServerAnsObj.IsNoAnswer
                            ,ServerAnsObj.AnsText
                            ,ServerAnsObj.AnsQVAID
                            ); 
                            ResultArray[Pos] = AnsSurvObj;
                             
                            Pos ++;
                        }

                }
                //Save the Javasctipt DYNSurveyAnsObj array.
                _SurveyAnsObjArray = ResultArray;
        
        }   
/* *********************************************************************************** 
-  Function: isType  
-  Purpose: Determines the type of an object 
-  Parameters: inTypeName - the value of the type that we are looking for.
-              inType -  The string passed from AjaxPro with the type imbedded.  
-  Date:  01/09/2007
-  Mods:
-     
************************************************************************************ */        
        function isType(inTypeName, inType)
        {   
           var regxx = eval("/" + inTypeName + "/gi");
           var resArray; 
           if(inType != null)
            {
                resArray = inType.match(regxx);
                if(resArray)
                { 
                    return true;
                }
                else
                {    
                    return false;
                }
           }  
       }            
     
                                    
                 

}//End  DYNSurveyQuestObj
//*End DYNSurveyQuestObj Class ************************************************************/  

/* *********************************************************************************** 
-  Class: DYNSurveyAnsObj   
-  Purpose: Encapsulates Survey answer functionality.  This class represents an answer
-           to a question for a survey. 
-  Date:  12/15/2006
-  Mods:
-     
************************************************************************************ */
function DYNSurveyAnsObj(AnsClientID,AnsType,AnsPk,ErrMsg,AnsSeq,IsNoAnswer,AnsText,AnsQVA)
{
// Constructor
     this.Init = Init(AnsClientID,AnsType,AnsPk,ErrMsg,AnsSeq,IsNoAnswer,AnsText,AnsQVA);
      
// Public Function Declarations ////////////////////////
     this.ApplyEdits = ApplyEdits;
     this.ClearAnswer = ClearAnswer;

// Public Property Declarations ////////////////////////
// Property Getters
     this.GetAnswerData = GetAnswerData; 
     function GetAnswerData()
        {
            return _AnswerData;
        }
     this.GetErrFlag = GetErrFlag; 
     function GetErrFlag()
        {
            return _ErrFlag;
        }  
     this.GetIsData = GetIsData; 
     function GetIsData()
        {
            return _IsData;
        }             
     this.GetAnsPK = GetAnsPK; 
     function GetAnsPK()
        {
            return _AnsPk;
        }  
     this.GetAnsType = GetAnsType; 
     function GetAnsType()
        {
            return _AnsType;
        }                              
     this.GetAnsText = GetAnsText; 
     function GetAnsText()
        {
            return _AnsText;
        }
     this.GetAnsQVA = GetAnsQVA; 
     function GetAnsQVA()
        {
            return _AnsQVA;
        } 
     this.GetAnsSeq = GetAnsSeq; 
     function GetAnsSeq()
        {
            return _AnsSeq;
        } 
     this.GetNoAns = GetNoAns; 
     function GetNoAns()
        {
            return _IsNoAns;
        }                                                    
                        
// Private Variable Declarations ////////////////////////
    
     var _AnsText;
     var _AnsQVA;
     var _AnsClientID;
     var _AnsType;
     var _AnsClientID;
     var _AnsPk;
     var _ErrMsg;
     var _AnswerData;
     var _ErrFlag;
     var _IsData;
     var _AnsSeq 
     var _IsNoAns
      
////////////////////////////////////////////////////////
// Public Functions ////////////////////////////////////
/* *********************************************************************************** 
-  Function: Init  
-  Purpose: Constructor sets up the answer object.  It populates variables
-           and initializes the associated answer.        
-  Parameters: AnsClientID - ID of the Answer HTML tag. 
-              AnsType - The type of HTML object i.e. radiobutton, textbox etc.   
-              AnsPk - Primary Key of the Answer.  
-              ErrMsg - Associated error message for this answer.  
-              AnsSeq - Numeric position of the answer object.
-              AnsText - Text of the answer.  
-              AnsQVA - QVA number for the answer.    
-  Date:  12/15/2006
-  Mods:
-     
************************************************************************************ */
    function Init(AnsClientID,AnsType,AnsPk,ErrMsg,AnsSeq,IsNoAnswer,AnsText,AnsQVA)
        {             
           //Set up paivate vars
           _AnsClientID = AnsClientID;
           _AnsType = AnsType;
           _AnsClientID = AnsClientID;
           _AnsPk = AnsPk; 
           _ErrMsg = ErrMsg;
           _AnsSeq = AnsSeq;
           _IsNoAns = IsNoAnswer
           _AnsQVA = AnsQVA;
           _AnsText = AnsText;
           _IsData = false; 
           _AnswerData = null;
        }//End Init
/* *********************************************************************************** 
-  Function: ApplyEdits  
-  Purpose: Performs appropriate edits for the answer HTML object. 
-  Parameters: None. 
-  Date:  12/15/2006
-  Mods:
-     
************************************************************************************ */
    function ApplyEdits()
        { 
            var checKobj;               //HTML answer object.
            var objLength;
            var objChecked = false;
            var retval = false;
            var wkObj;
            var objValue;
           
           //Get the HTML answer object
           checKobj = document.getElementById(_AnsClientID);
           //Do we have the object on this page???
           if(checKobj != null)
           {
               //Edit the answer for now check for required....          
                
                switch(_AnsType)
                {
                     case "radio":
                        wkObj = document.getElementsByName(_AnsClientID);
                        if(wkObj[_AnsSeq].checked)
                          {
                            _IsData = true;
                            _AnswerData = "true";
                          }
                          
                          
                        break;
                     case "text":
                          objValue = checKobj.value;
                          if(objValue.length > 0)
                          {
                            objChecked = true;
                          }
                             
                        break;
                     case "checkbox":
                        wkObj = document.getElementsByName(_AnsClientID);
                       
                            if(wkObj[_AnsSeq].checked)
                              {
                                _IsData = true;
                                _AnswerData = "true";
                              }
                          
                            
                        break;   
                           
                 }
             }
                     
                
      } //End ApplyEdits
/* *********************************************************************************** 
-  Function: ClearAnswer  
-  Purpose: Clears the answer radio button checkbox textbox etc. 
-  Parameters: None. 
-  Date:  12/15/2006
-  Mods:
-     
************************************************************************************ */
    function ClearAnswer()
        { 
            var checKobj;
            var wkObj;
            
           //Get the HTML answer object
            checKobj = document.getElementById(_AnsClientID);
            //Do we have the object on this page???
           if(checKobj != null)
           {
                   //Clear the answer.             
                    switch(_AnsType)
                    {
                         case "radio":
                            wkObj = document.getElementsByName(_AnsClientID);
                            for(var i = 0; i < wkObj.length; i++)
                              {
                                wkObj[i].checked = false;
                                  
                              }
                              
                            break;
                         case "text":
                              
                                 
                            break;
                         case "checkbox":
                            wkObj = document.getElementsByName(_AnsClientID);
                            
                                
                            break;   
                               
                     }
             }
                     
                
      } //End ClearAnswer   
                 

}//End  DYNSurveyObject
//*End DYNSurveyObject Class ************************************************************/  
