function QuestionLikert(){
    this.sQuestionType = 'LIKERT';
    this.HORIZONTAL = 0;
    this.VERTICAL = 1;
    
    this.NONE = 0;
    this.LETTERS = 1;
    this.NUMBERS = 2;
    
    //System settings
    this.iInputCellWidth = 400;
    this.iRowHeight = 30;
    this.iTextCellPadding = 10;
    this.iSegmentPadding = 10;
    this.iHeaderMarginBottom = 5;
    this.sLikertLabelTag = 'strong';
    this.sLabelSuffix = ')&nbsp;&nbsp;';
    
    //Quiz settings
    this.oMaster = null;
    this.sServerSaveURL = '';
    this.bSaveParticipation = false;
    
    //User settings
    this.bDisplayBorder = true;
    this.sBorderColor = 'gray';
    this.iNbValue = 0;
    this.iOrientation = this.HORIZONTAL;
    this.iLabelType = this.NONE;
    this.bShowValue = false;
    
    
    //Variables
    this.sQuestionText = '';
    this.sTitle = null;
    this.sImageFileName = null;
    this.oVideoInfo = null;
    this.sAudioFileName = null;
    this.sLikertLabels = new Array();
    this.sChoicesText = new Array();
    this.oInputElements = new Array();
    this.iCurrChoiceID = new Array();
    this.sImgsToPreload = new Array();
    this.iQuestionID = 0;
    this.condition = new Condition();
    this.sCommentTitle = null;
    this.sCommentText = '';
    
    //Mandatory functions
    this.display = function(oParentElement,iWidthAvail){
        var oTable = null;
        var oCurrRow = null;
        var oCurrCell = null;
        var oChoiceTable = null;
        var oChoiceRow = null;
        var oChoiceCell = null;
        var iInputCellWidth = 0;
        
        //Create p
        var oP = ns_buildHTMLElement('p',{style:'display:inline;'});
        oP.className = 'QuestionText';
        oP.innerHTML = this.sQuestionText;
        oParentElement.appendChild(oP);
        
        if(this.sQuestionText || this.sQuestionText.length > 0){
            oParentElement.appendChild(ns_buildHTMLElement('br',{}));
            oParentElement.appendChild(ns_buildHTMLElement('img',{src:'images/spacer.gif', width:'5', height:'19'}));
            oParentElement.appendChild(ns_buildHTMLElement('br',{}));
            oParentElement.appendChild(ns_buildHTMLElement('img',{src:'images/question_line.gif', width:iWidthAvail, height:'1'}));
            oParentElement.appendChild(ns_buildHTMLElement('br',{}));
            oParentElement.appendChild(ns_buildHTMLElement('img',{src:'images/spacer.gif', width:'5', height:'19'}));
            oParentElement.appendChild(ns_buildHTMLElement('br',{}));
        }
        
        //Create header
        oTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0'});
        oCurrRow = oTable.insertRow(0);
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.width = (this.iOrientation == this.HORIZONTAL ? iWidthAvail - this.iInputCellWidth - (this.iTextCellPadding * 2) : iWidthAvail) ;
        oCurrCell.style.paddingLeft = this.iTextCellPadding + 'px';
        oCurrCell.style.paddingRight = this.iTextCellPadding + 'px';
        oCurrCell.innerHTML = '&nbsp;';
        
        oCurrCell = oCurrRow.insertCell(1);
        oCurrCell.width = this.iInputCellWidth;
        if(this.iOrientation == this.HORIZONTAL){
            oCurrCell.appendChild(this.getLikertHeader(this.iInputCellWidth));
        }
        
        oParentElement.appendChild(oTable);
        
        //Create content
        oTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0'});
        oParentElement.appendChild(oTable);
        
        if(this.bDisplayBorder){ 
            oTable.style.borderTop = 'solid 1px ' + this.sBorderColor;
            oTable.style.borderRight = 'solid 1px ' + this.sBorderColor;
        }
        
        for(var i = 0;i < this.sChoicesText.length;i++){
            oCurrRow = oTable.insertRow(oTable.rows.length);
            //Input
            oCurrCell = oCurrRow.insertCell(0);
            if(this.bDisplayBorder){
                oCurrCell.style.borderLeft = 'solid 1px ' + this.sBorderColor;
                if(this.iOrientation == this.HORIZONTAL){
                    oCurrCell.style.borderBottom = 'solid 1px ' + this.sBorderColor;
                }
            }
            
            oCurrCell.height = this.iRowHeight;
            oCurrCell.align = 'left';
            oCurrCell.style.paddingLeft = this.iTextCellPadding + 'px';
            oCurrCell.style.paddingRight = this.iTextCellPadding + 'px';
            oCurrCell.style.paddingTop = this.iSegmentPadding + 'px';
            oCurrCell.style.paddingBottom = this.iSegmentPadding + 'px';
            
            if(this.iLabelType != this.NONE){
                if(this.iLabelType == this.LETTERS){
                    sLabel = ns_getLetter(i + 1) + this.sLabelSuffix;
                }else if(this.iLabelType == this.NUMBERS){
                    sLabel = (i + 1) + this.sLabelSuffix;
                }
                
                oChoiceTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0'});
                oChoiceRow = oChoiceTable.insertRow(0);
                oChoiceCell = oChoiceRow.insertCell(0);
                oChoiceCell.vAlign = 'top';
                oChoiceCell.width = '25';                
                oChoiceCell.innerHTML = sLabel;
                
                
                oChoiceRow.insertCell(1).innerHTML = this.sChoicesText[i];
                
                oCurrCell.appendChild(oChoiceTable);
            }else{
                oCurrCell.innerHTML = this.sChoicesText[i];
            }
            
            if(this.iOrientation == this.HORIZONTAL){
                iInputCellWidth = this.iInputCellWidth;
                oCurrCell.width = iWidthAvail - this.iInputCellWidth - (this.iTextCellPadding * 2);
                oCurrCell = oCurrRow.insertCell(1);
                oCurrCell.width = iInputCellWidth;
                
            }else{
                iInputCellWidth = iWidthAvail;
                oCurrCell.width = iInputCellWidth;
                oCurrCell.height = this.iRowHeight;
                oCurrRow = oTable.insertRow(oTable.rows.length);
                oCurrCell = oCurrRow.insertCell(0);
                oCurrCell.width = iInputCellWidth;
                oCurrCell.height = this.iRowHeight;
                oCurrCell.appendChild(this.getLikertHeader(iInputCellWidth));
                if(this.bDisplayBorder){
                    oCurrCell.style.borderLeft = 'solid 1px ' + this.sBorderColor;
                    if(this.iOrientation == this.HORIZONTAL){
                        oCurrCell.style.borderBottom = 'solid 1px ' + this.sBorderColor;
                    }
                }
                oCurrRow = oTable.insertRow(oTable.rows.length);
                oCurrCell = oCurrRow.insertCell(0);
                oCurrCell.height = this.iRowHeight;
                oCurrCell.style.paddingBottom = this.iSegmentPadding + 'px';
            }
            
            if(this.bDisplayBorder){
                oCurrCell.style.borderLeft = 'solid 1px ' + this.sBorderColor;
                oCurrCell.style.borderBottom = 'solid 1px ' + this.sBorderColor;
            }
            
            oCurrCell.appendChild(this.getLikertInputs(i,iInputCellWidth));
        }
        oParentElement.appendChild(this.oMaster.buildCommentLayout(this));
    }
    
    this.save = function(){
        for(var i = 0;i < this.oInputElements.length;i++){
            for(var j = 0;j < this.oInputElements[i].length;j++){
                if(this.oInputElements[i][j].checked) {
                    this.iCurrChoiceID[i] = j;
                }
            }
        }
        
        //Comment
        if(this.sCommentTitle){
            this.sCommentText = $(this.oMaster.sTxtCommentPrefix + this.iQuestionID).value;
        }
    }
    this.submit = function(){
        if(this.bSaveParticipation){
            for(var i = 0;i < this.iCurrChoiceID.length;i++){
                this.oMaster.saveParticipation(this.iQuestionID,i,this.iCurrChoiceID[i]);
            }
            
            //Comment
            if(this.sCommentTitle){
                this.oMaster.saveComment(this.iQuestionID,this.sCommentText);
            }
        }
    }
    
    this.isAnswered = function() {
        for(var i = 0;i < this.iCurrChoiceID.length;i++){
            if(this.iCurrChoiceID[i] == null){
                return false;
            }
        }
        
        return true;
    }
    
    this.hide = function(){}
    
    this.setQuestionText = function(s){
        this.sQuestionText = s;
    }
    
    this.setTitle = function(s){
        this.sTitle = s;
    }
    this.setImage = function(s){
        this.sImageFileName = s;
        this.sImgsToPreload[this.sImgsToPreload.length] = s;
    }
    this.setLabelType = function(i){
        this.iLabelType = i;
    }
    this.setVideo = function(s,iWidth,iHeight){
        this.oVideoInfo = {sFileName:'',iWidth:0,iHeight:0};
        this.oVideoInfo.sFileName = s;
        this.oVideoInfo.iWidth = iWidth;
        this.oVideoInfo.iHeight = iHeight;   
    }
    this.setAudio = function(s){
        this.sAudioFileName = s;
    }
    //Question specific functions
    this.addChoice = function(sChoice){
        this.sChoicesText[this.sChoicesText.length] = sChoice;
        this.iCurrChoiceID[this.iCurrChoiceID.length] = null;
    }
    this.addLabel = function(sLabel){
        this.sLikertLabels[this.sLikertLabels.length] = sLabel;
    }
    this.setNbValue = function(iNb){
        this.iNbValue = iNb;
    }
    this.setOrientation = function(i){
        this.iOrientation = i;
    }
    this.getLikertHeader = function(iWidthAvail){
        var oTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0'});
        oTable.style.marginBottom = this.iHeaderMarginBottom + 'px';
        var oCurrRow = oTable.insertRow(0);
        var oCurrCell = null;
        var sCellAlign = '';
        var sLabel = null;
       
        for(var i = 0;i < this.sLikertLabels.length;i++){
            oCurrCell = oCurrRow.insertCell(i);
            if(this.sLikertLabels.length == 1){
                sCellAlign = 'center';
            }else if(i == 0){
                sCellAlign = 'left';
            }else if(i == (this.sLikertLabels.length - 1)){
                sCellAlign = 'right';
            }else{
                sCellAlign = 'center';
            }
            
            oCurrCell.align = sCellAlign;
            oCurrCell.style.paddingLeft = '5px';
            oCurrCell.style.paddingRight = '5px';
            
            sLabel = this.sLikertLabels[i].replace(/ /g,'&nbsp;');
            
            oCurrCell.width = Math.round(iWidthAvail / this.sLikertLabels.length);
            oCurrCell.innerHTML = '<' + this.sLikertLabelTag + '>' + sLabel + '</' + this.sLikertLabelTag + '>';
        }
        
        return oTable;
    }
    this.getLikertInputs = function(iChoiceID,iWidthAvail){
        var oTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0'});
        var oCurrRow = oTable.insertRow(0);
        var oCurrCell = null;
        var oSpanNb = null;
        var sChecked = '';
        this.oInputElements[iChoiceID] = new Array();
        
        for(var i = 0;i < this.iNbValue;i++){
            oCurrCell = oCurrRow.insertCell(i);
            oCurrCell.align = 'center';
            oCurrCell.width = Math.round(iWidthAvail / this.iNbValue);
            sChecked = (i == this.iCurrChoiceID[iChoiceID] ? 'checked' : null);
            this.oInputElements[iChoiceID][i] = ns_buildHTMLElement('input',{type:'radio',name:'rdo-' + this.iQuestionID + '-' + iChoiceID,id:'rdo-' + this.iQuestionID + '-' + iChoiceID + '-' + i,value:i,checked:sChecked}); 
            oCurrCell.appendChild(this.oInputElements[iChoiceID][i]);
            if(this.bShowValue){
                oCurrCell.appendChild(ns_buildHTMLElement('br',{}));
                oSpanNb = ns_buildHTMLElement('span',{});
                oSpanNb.innerHTML = (i + 1);
                oCurrCell.appendChild(oSpanNb);
            }
        }
        
        return oTable;
    }
}
