function NetSondage(oMainContainer,oNavBarContainers) {

    //System settings
    this.iQuestionSpacerHeight = 27;
    this.iWidthAvail = 760;
    this.iLoginWidthAvail = 371;
    this.iQuestionWidthAvail = 648;
    this.iImageMaxWidth = 500;
    this.iImageMaxHeight = 500;
    this.sSpacerImg = 'spacer.gif';
    this.sImagesFolder = 'images';
    this.sMediasFolder = 'medias';
    this.sServerCommandPage = 'srvcmd.php';
    this.bASync = false;
    this.bDebugServer = false;
    this.iNBMaxPage = 14;
    this.sQNoPrefix = 'Q';
    this.sTxtCommentPrefix = 'txtComment';
    
    //User settings
    this.bScormEnabled = false;
    this.sServerURL = '';
    this.bSaveParticipation = false;
    this.sQuizIdentifier = '';
    this.displayHiddenQuestion = true;
    
    //Labels & Msgs
    this.sConfirmQuit = '';
    this.sConfirmUnfinishQuit = '';
    this.sConfirmUnload = '';
    this.sPasswordLabel = '';
    this.sKeyLabel = '';
    this.sLoginBoxTitle = '';
    this.sErrorBoxTitle = '';
    this.sLoginBtnOK = '';
    this.sSubmitBtn = '';
   
    //Messages
    this.sErrQuizInactive = '';
    this.sErrQuizDExist = '';
    this.sErrWrongPassword = '';
    this.sErrWrongKey = '';
    this.sErrKeyAlreadyUsed = '';
    this.sErrServerConn = '';
    this.sMsgHiddenQuestion = '';
    this.sMsgQuizEnd = '';
    this.sErrServerURL = '';
    
    //Variables
    this.oMainContainer = oMainContainer;
    this.oNavBarContainers = oNavBarContainers;
    this.oContentElement = null;
    this.iPages = new Array();
    this.oQuestions = new Array();
    this.iCurrPageID = -1;
    this.bChangePage = true;
    this.iParticipantID = -1;
    this.iAccessType = -1;
    this.oTxtLogin = null;
    this.aImages = new Array();
    this.oImgPreloader = getImgPreloader();
    
    //Init
    this.oContentElement = ns_buildHTMLElement('div',{id:'divNSContent'});
    this.oContentElement.style.width = this.iWidthAvail + 'px';
    this.oContentElement.style.textalign = 'left';
    
    this.oMainContainer.appendChild(this.oContentElement);
    
    //Public
    this.addQuestion = function(o){
        var iQuestionID = this.oQuestions.length;
        
        o.oMaster = this;
        o.iQuestionID = iQuestionID
        o.sServerSaveURL = this.sServerURL + '/' + this.sServerSavePage;
        o.bSaveParticipation = this.bSaveParticipation;
        
        this.oQuestions[this.oQuestions.length] = o;
        
        if(this.bChangePage){
            this.iPages[this.iPages.length] = iQuestionID;
            this.bChangePage = false;
        }
    }
    this.addPageSeparator = function(){
        this.bChangePage = true;
    }
    
    this.begin = function(){
        //Hide buttons
        ns_fo('divButtons').style.visibility = 'hidden';
        //Image preloader
        var sImgsToPreload = new Array();
        for(var i = 0;i < this.oQuestions.length;i++){
            sImgsToPreload = sImgsToPreload.concat(this.oQuestions[i].sImgsToPreload);
        }
        
        this.oImgPreloader.sImgs = sImgsToPreload;
        this.oImgPreloader.sFolder = this.sMediasFolder;
        this.oImgPreloader.onFinish = function(){top.ccdmd.netsondage.lauchQuiz();}
        this.oImgPreloader.preload();
    }
    
    this.lauchQuiz = function(){
        if(this.bSaveParticipation){
            if((this.sServerURL.substr(0,7) != 'http://') || (this.sServerURL.length == 0) || (this.sServerURL.replace('http://','').length == 0)){
                alert(this.sErrServerURL);
                return;
            }
        
            var bExist = false;
            var bActive = false;
            var iAccessType = -1;
            
            var oReq = createRequest();
            oReq.open('GET',this.sServerURL + '/' + this.sServerCommandPage + '?cmd=connect&qidentifier=' + this.sQuizIdentifier, false);
            oReq.send(null);

            if(oReq.readyState==4 && oReq.status == 200)
            {
                eval(oReq.responseText);
            }
            else
            {
                alert(this.sErrServerConn);
            }
            
            //Alert if quiz doesn't exist or is inactive
            if(!bExist){
                this.displayAlert(this.sErrorBoxTitle,this.sErrQuizDExist);
            }else if(!bActive){
                this.displayAlert(this.sErrorBoxTitle,this.sErrQuizInactive);
            }else if(iAccessType > -1){
                this.iAccessType = iAccessType;
                this.authParticipant(-1);
            }
         }else{
            ns_fo('divButtons').style.visibility = 'visible';
            this.firstPage();
         }
    }
    
    this.end = function(){
    
    }
    
    this.nextPage = function(){
        this.displayPage(this.iCurrPageID + 1);
    }
    
    this.previousPage = function(){
        this.displayPage(this.iCurrPageID - 1);
    }
    
    this.finalizeAuth = function(){
        var sGivenKey = '';
        var iParticipantID = -1;
        var iServerAnswer = -1; //-1 no answer,0 good to go ,1 quiz doesn't exist, 2 quiz is inactive, 3 wrong key or password, 4 key already used
        
        if(this.iAccessType > 0){
            var sGivenKey = this.oTxtLogin.value;
        }
        
        var oReq = createRequest();
        oReq.open('GET',this.sServerURL + '/' + this.sServerCommandPage + '?cmd=auth&qidentifier=' + this.sQuizIdentifier + '&k=' + sGivenKey, false);
        oReq.send(null);

        if(oReq.readyState==4 && oReq.status == 200)
        {
            eval(oReq.responseText);
        }
        else
        {
            alert();
        }
        
        switch(iServerAnswer){
            case -1:
                alert(this.sErrServerConn);
                break;
            case 0:
                this.iParticipantID = iParticipantID;
                ns_fo('divButtons').style.visibility = 'visible';
                window.onbeforeunload = ns_onbeforeunload;
                this.firstPage();
                break;
            case 1:
                break;
            case 2:
                break;
            case 3: case 4:
                this.authParticipant(iServerAnswer);
                break;
        }
    }
    
    this.firstPage = function(){
        if(this.oQuestions.length > 0){
            this.displayPage(0);
        }
    }
    
    this.submit = function(){
        //Save current page from HTML
        this.saveCurrPage(false);
    
        var bHasAnsweredAll = true;
        var bConfirmed = false;
        var sEmptyQuestion = '';
        
        for(var i = 0;i < this.oQuestions.length;i++){
            if(this.oQuestions[i].condition.validate() && !this.oQuestions[i].isAnswered()){
                sEmptyQuestion += ', Q' + (i + 1);
                bHasAnsweredAll = false;
            }
        }
        
        sEmptyQuestion = sEmptyQuestion.substring(2,sEmptyQuestion.length);
        
        if(bHasAnsweredAll){
            bConfirmed = confirm(this.sConfirmQuit);
        }else{
            bConfirmed = confirm(this.sConfirmUnfinishQuit + sEmptyQuestion + '?');
        }
        
        if(bConfirmed){
            //Submit participation to server
            for(var i = 0;i < this.oQuestions.length;i++){
                if(this.oQuestions[i].condition.validate()){
                    this.oQuestions[i].submit();
                }else{
                    this.saveNAParticipation(this.oQuestions[i].iQuestionID);
                }
            }
            
            var oReq = createRequest();
            oReq.open('GET',this.sServerURL + '/' + this.sServerCommandPage + '?cmd=submit&qidentifier=' + this.sQuizIdentifier + '&pid=' + this.iParticipantID, false);
            oReq.send(null);

            if(oReq.readyState==4 && oReq.status == 200)
            {
                eval(oReq.responseText);
            }
            else
            {
                alert(this.sErrServerConn);
            }
            
            window.onbeforeunload = null;
            window.location = 'end.html';
        }
    }
    
    this.addImage = function(sFileName,iW,iH){
        this.aImages[sFileName] = [iW,iH];
    }
    this.getImageSize = function(sFileName){
        return this.aImages[sFileName];
    }
    
    //Layout
    this.authParticipant = function(iMsg){
        this.resetLayout();
    
        //If no password skip the auth
        if(this.iAccessType == 0){
            this.finalizeAuth();
        }else{
            var oCurrRow = null;
            var oCurrCell = null;
            var oContentElement = null;
            var oTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0',width:this.iLoginWidthAvail});
            oTable.className = 'LoginTable';
            
            //Row 0
            oCurrRow = oTable.insertRow(0);
            //Cell 0
            oCurrCell = oCurrRow.insertCell(0);
            oCurrCell.height = '35';
            oCurrCell.className = 'LoginHeader';
            oCurrCell.innerHTML = this.sLoginBoxTitle;
            
            //Row 1
            oCurrRow = oTable.insertRow(1);
            
            //Cell 0
            oCurrCell = oCurrRow.insertCell(0);
            oCurrCell.align = 'center';
            oCurrCell.vAlign = 'top';
            oCurrCell.className = 'LoginContent';
            oCurrCell.height = '131';
            //Content table
            var oContentTable = this.buildLoginLayout(iMsg);
            var oContentElement = ns_buildHTMLElement('div',{});
            oContentElement.style.paddingTop = '21px';
            oContentElement.appendChild(oContentTable);
            oCurrCell.appendChild(oContentElement);
            
            this.oContentElement.appendChild(oTable);
            this.oTxtLogin.focus();
            this.updateNavBars(false);
        }
    }
    
    this.buildLoginLayout = function(iMsg){
        var sMsg = '&nbsp;';
        
        //dependant du iMsg afficher le bon  msg
        switch(iMsg){
            case 3:
                sMsg = (this.iAccessType == 1 ? this.sErrWrongPassword : this.sErrWrongKey);
                break;
            case 4:
                sMsg = this.sErrKeyAlreadyUsed;
                break;
        }
        
    
        var sLabel = (this.iAccessType == 1 ? this.sPasswordLabel : this.sKeyLabel);
        var oInvisibleSpan = null;
        var oCurrRow = null;
        var oCurrCell = null;
        var oBtnOK = null;
        var oTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0'});
        
        oInvisibleSpan = ns_buildHTMLElement('span',{});
        oInvisibleSpan.className = 'invisible';
        
        //Row 0 
        oCurrRow = oTable.insertRow(0);
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.className = 'LoginLabel';
        oCurrCell.align = 'left';
        oCurrCell.width = '165';
        oCurrCell.innerHTML = sLabel;
        
        oCurrCell = oCurrRow.insertCell(1);
        oCurrCell.width = '165';
        oCurrCell.innerHTML = '&nbsp;';
        
        //Row 1
        oCurrRow = oTable.insertRow(1);
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.align = 'left';
        oCurrCell.vAlign = 'middle';
        this.oTxtLogin = ns_buildHTMLElement('input',{type:'password'});
        this.oTxtLogin.className = 'LoginInput';
        this.oTxtLogin.onkeydown = function(e){exeOnEnterKey(e, finalizeAuth);} 
        oCurrCell.appendChild(this.oTxtLogin);
        
        oCurrCell = oCurrRow.insertCell(1);
        oCurrCell.align = 'right';
        oCurrCell.vAlign = 'middle';
        oBtnOK = ns_buildHTMLElement('a',{href:'javascript:finalizeAuth()',id:'aLoginBtnOK'});
        oBtnOK.className = 'aBtn';
        oBtnOK.innerHTML = this.sLoginBtnOK;
        oCurrCell.appendChild(oBtnOK);
        
        //Row 2
        oCurrRow = oTable.insertRow(2);
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.innerHTML = '&nbsp;';
        
        oCurrCell = oCurrRow.insertCell(1);
        oCurrCell.align = 'right';
        oCurrCell.vAlign = 'top';
        oCurrCell.appendChild(ns_buildHTMLElement('img',{src:this.sImagesFolder + '/btn_shadow_noline.gif'}));
        
        //Row 3
        oCurrRow = oTable.insertRow(3);
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.colSpan = '2';
        oCurrCell.align = 'center';
        oCurrCell.vAlign = 'bottom';
        oCurrCell.height = '33';
        oCurrCell.className = 'LoginMsg';
        oCurrCell.innerHTML = sMsg;
        
        return oTable;
    }
    
    this.displayPage = function(iPageID){
        
        var oContentElement = null;
    
        this.saveCurrPage();
        
        this.resetLayout();
        
        if(iPageID >= 0 && iPageID < this.iPages.length){
            this.iCurrPageID = iPageID;
            var bDone = false;
            var i = this.iPages[iPageID];
            
            while(!bDone){
                if(this.oQuestions[i].condition.validate()){
                    oContentElement = this.buildQuestionLayout(this.oQuestions[i]);
                    this.oQuestions[i].display(oContentElement,this.iQuestionWidthAvail);
                }else{
                    if(this.displayHiddenQuestion){
                        oContentElement = this.buildHiddenQuestionLayout(this.oQuestions[i]);
                    }
                }
                
                this.displaySpacer(this.iQuestionSpacerHeight);
                
                i++;
                
                if(i == this.oQuestions.length || i == this.iPages[(iPageID + 1)]){
                    bDone = true;
                }
            }
        }
        if((iPageID + 1) == this.iPages.length){
            var oCurrRow = null;
            var oCurrCell = null;
            var oTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0'});
        
            oCurrRow = oTable.insertRow(0);
            oCurrCell = oCurrRow.insertCell(0);
            oCurrCell.className = 'QuestionHeaderTitle';
            oCurrCell.innerHTML = this.sMsgQuizEnd;
            
            oCurrCell = oCurrRow.insertCell(1);
            
            oCurrCell.innerHTML = '&nbsp;';
            
            oCurrRow = oTable.insertRow(1);
            oCurrCell = oCurrRow.insertCell(0);
            oCurrCell.colspan = '2';
            oCurrCell.innerHTML = '&nbsp;';
            
            oCurrRow = oTable.insertRow(2);
            oCurrCell = oCurrRow.insertCell(0);
            oCurrCell.colspan = '2';
            oCurrCell.align = 'center';
            var oDiv = ns_buildHTMLElement('div',{style:'width:143px;'});
            var oBtnSubmit = ns_buildHTMLElement('a',{});
            oBtnSubmit.className = 'aBtn';
            oBtnSubmit.onclick = submitSondage;
            oBtnSubmit.innerHTML = this.sSubmitBtn;
            oDiv.appendChild(oBtnSubmit);
            //oDiv.appendChild(ns_buildHTMLElement('img',{src:'images/btn_shadow_noline.gif'}));
            oCurrCell.appendChild(oDiv);
            
            this.oContentElement.appendChild(oTable);
            this.displaySpacer(this.iQuestionSpacerHeight);
        }
        
        this.updateNavBars(true);
    }
    
    this.displayAlert = function(sTitle, sMsg){
        var oCurrRow = null;
        var oCurrCell = null;
        var oContentElement = null;
        var oTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0',width:this.iLoginWidthAvail});
        oTable.className = 'AlertTable';
        
        //Row 0
        oCurrRow = oTable.insertRow(0);
        //Cell 0
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.height = '35';
        oCurrCell.className = 'AlertHeader';
        oCurrCell.innerHTML = sTitle;
        
        //Row 1
        oCurrRow = oTable.insertRow(1);
        
        //Cell 0
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.align = 'center';
        oCurrCell.vAlign = 'top';
        oCurrCell.className = 'AlertContent';
        oCurrCell.height = '131';
        //Content table
        var oContentElement = ns_buildHTMLElement('div',{});
        oContentElement.style.paddingTop = '21px';
        oContentElement.align = 'center';
        oContentElement.innerHTML = sMsg;
        //oContentElement.appendChild(oContentTable);
        oCurrCell.appendChild(oContentElement);
        
        this.oContentElement.appendChild(oTable);
        this.resetNavBar();
    }
    
    this.updateNavBars = function(bEnabled){
        this.resetNavBar();
    
        for(var i = 0;i < this.oNavBarContainers.length;i++){
            this.oNavBarContainers[i].appendChild(this.buildNavBar(bEnabled));
        }
    }
    
    this.buildNavBar = function(bEnabled){ 
        var bDone = false;
        var iCurrPage = null;
        var iPageCount = 0;
        var oTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0'});
        var oCurrRow = oTable.insertRow(0);
        var oCurrCell = null;
        var oInvisibleSpan = null;
        var oLink = null;
        var oImg = null;
        
        oInvisibleSpan = ns_buildHTMLElement('span',{});
        oInvisibleSpan.className = 'invisible';
        
        if(this.iPages.length == 1){
            oTable.insertRow(0).insertCell(0).innerHTML = '&nbsp;';
            
            return oTable;
        }
        
        if(this.iPages.length > this.iNBMaxPage){
            if((this.iCurrPageID + 1) < (this.iNBMaxPage / 2)){
                iCurrPage = 1;
            }else if((this.iCurrPageID + 1) > ((this.iPages.length + 1) - (this.iNBMaxPage / 2))){
                iCurrPage = (this.iPages.length + 1) - this.iNBMaxPage;
            }else{
                iCurrPage = (this.iCurrPageID + 1) - (this.iNBMaxPage / 2);
            }
        }else{
            iCurrPage = 1;
        }
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.width = '20';
        oCurrCell.height = '14';
        
        if(this.iCurrPageID > 0 && bEnabled){
            //oLink = ns_buildHTMLElement('a',{href:'javascript:previousPage()',id:'aNavBarPrevious'});
            //oLink = ns_buildHTMLElement('a',{href:'javascript:previousPage()'});
            oLink = ns_buildHTMLElement('a',{href:'#',onclick:'previousPage()'});
            oLink.className = 'aNavBarPrevious';
            oLink.appendChild(oInvisibleSpan);
            
            oCurrCell.appendChild(oLink);
        }else{
            oImg = ns_buildHTMLElement('img',{src:this.sImagesFolder + '/btn_back_off.gif'});
            
            oCurrCell.appendChild(oImg);
        }
        
        while(!bDone){
            oCurrCell = oCurrRow.insertCell((iPageCount+1));
            oCurrCell.width = '20';
            
            if(!bEnabled){
                oCurrCell.className = 'NavBarLinkOff';
                oCurrCell.innerHTML = String(iCurrPage);
            }else if((iCurrPage - 1) == this.iCurrPageID){
                oCurrCell.className = 'NavBarLinkSel';
                oCurrCell.innerHTML = String(iCurrPage);
            }else{
                //oLink = ns_buildHTMLElement('a',{href:'javascript:displayPage(' + String(iCurrPage - 1) + ')'});
                oLink = ns_buildHTMLElement('a',{href:'#',onclick:'displayPage(' + String(iCurrPage - 1) + ')'});
                oLink.className = 'NavBarLink';
                oLink.innerHTML = String(iCurrPage);
                
                oCurrCell.appendChild(oLink);
            }
            
            if((iCurrPage == this.iPages.length) || (iPageCount == this.iNbMaxPage)){
                bDone = true;
            }
            
            iPageCount++;
            iCurrPage++;
        }
        
        oCurrCell = oCurrRow.insertCell((iPageCount+1));
        oCurrCell.width = '20';
        oCurrCell.height = '14';
        
        if(this.iCurrPageID < (this.iPages.length-1) && bEnabled){
            //oLink = ns_buildHTMLElement('a',{href:'javascript:nextPage()',id:'aNavBarNext'});
            //oLink = ns_buildHTMLElement('a',{href:'javascript:nextPage()'});
            oLink = ns_buildHTMLElement('a',{href:'#',onclick:'nextPage()'});
            oLink.className = 'aNavBarNext';
            oLink.appendChild(oInvisibleSpan);
            
            oCurrCell.appendChild(oLink);
        }else{
            oImg = ns_buildHTMLElement('img',{src:this.sImagesFolder + '/btn_next_off.gif'});
            
            oCurrCell.appendChild(oImg);
        }
        
        return oTable;
    }
    
    this.displaySpacer = function(iHeight){
        this.oContentElement.appendChild(ns_buildHTMLElement('img',{src:this.sImagesFolder + '/' + this.sSpacerImg,height:iHeight,width:this.iWidthAvail}));
        //this.oMainElement.innerHTML += '<img src=\"' + this.sImagesFolder + '/' + this.sSpacerImg + '\" height=\"' + iHeight + '\" width=\"' + this.iWidthAvail + '\" />';
    }
    this.resetLayout = function(){
        this.oContentElement.innerHTML = '';
        window.scrollTo(0,0);
    }
    this.resetNavBar = function(){
        for(var i = 0;i < this.oNavBarContainers.length;i++){
            this.oNavBarContainers[i].innerHTML = '';
        }
    }
    
    this.buildQuestionLayout = function(oQuestion){
        var oCurrRow = null;
        var oCurrCell = null;
        var oContentElement = null;
        var sTitle = oQuestion.sTitle;
        var iNo = oQuestion.iQuestionID;
        var sImageFileName = oQuestion.sImageFileName;
        var sAudioFileName = oQuestion.sAudioFileName;
        var oVideoInfo = oQuestion.oVideoInfo;
        var oTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0',width:this.iWidthAvail});
        oTable.className = 'QuestionTable';
        
        //Row 0
        oCurrRow = oTable.insertRow(0);
        //Cell 0
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.colSpan = '3';
        oCurrCell.width = this.iWidthAvail;
        oCurrCell.height = '35';
        oCurrCell.className = 'QuestionHeader';
        //Header table
        var oHeaderTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0',width:this.iWidthAvail});
        var oHeaderTableRow = oHeaderTable.insertRow(0);
        var oNoCell = oHeaderTableRow.insertCell(0);
        oNoCell.width = '43';
        oNoCell.height = '35';
        oNoCell.align = 'center';
        oNoCell.vAlign = 'middle';
        oNoCell.className = 'QuestionHeaderNo';
        oNoCell.innerHTML = this.sQNoPrefix + (iNo + 1);
        
        var oSpacerCell = oHeaderTableRow.insertCell(1);
        oSpacerCell.width = '16';
        oSpacerCell.appendChild(ns_buildHTMLElement('img',{src:'images/spacer.gif', width:'16', height:'35'}));
        
        var oTitleCell = oHeaderTableRow.insertCell(2);
        oTitleCell.width = (this.iWidthAvail - 43 - 16 - 34);
        oTitleCell.align = 'left';
        oTitleCell.vAlign = 'middle';
        oTitleCell.className = 'QuestionHeaderTitle';
        oTitleCell.innerHTML = sTitle;
        
        var oBtnHelpCell = oHeaderTableRow.insertCell(3);
        oBtnHelpCell.width = '34';
        var oBtnHelp = ns_buildHTMLElement('a',{href:'#', onclick:'ns_showQuestionHelp(\'' + oQuestion.sQuestionType + '\')'});
        oBtnHelp.className = 'aBtnQuestionHelp';
        var oInvisSpan = ns_buildHTMLElement('span',{});
        oInvisSpan.className = 'invisible';
        oBtnHelp.appendChild(oInvisSpan);
        oBtnHelpCell.appendChild(oBtnHelp);
        
        oCurrCell.appendChild(oHeaderTable);
        
        //Row 1
        oCurrRow = oTable.insertRow(1);
        //Cell 0
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.width = '5';
        oCurrCell.className = 'QuestionLBorder';
        oCurrCell.appendChild(ns_buildHTMLElement('img',{src:'images/spacer.gif', width:'5', height:'5'}));
        
        //Cell 1
        oCurrCell = oCurrRow.insertCell(1);
        oCurrCell.width = '750';
        oCurrCell.align = 'center';
        oCurrCell.className = 'QuestionContent';
        //Video
        if(oVideoInfo){
            oCurrCell.appendChild(ns_buildMediaEmbed(this.sMediasFolder + '/' + oVideoInfo.sFileName,oVideoInfo.iWidth,oVideoInfo.iHeight));
            oCurrCell.appendChild(ns_buildHTMLElement('br',{}));
        }
        
        //Audio
        if(sAudioFileName){
            oCurrCell.appendChild(ns_buildAudioEmebed(this.sMediasFolder + '/' + sAudioFileName));
            oCurrCell.appendChild(ns_buildHTMLElement('br',{}));
        }
        
        //Image
        if(sImageFileName){
            oContentElement = ns_buildHTMLElement('div',{style:'padding:10px;width:' + this.iQuestionWidthAvail + 'px;',align:'center'});
            oContentElement.appendChild(ns_buildImageObject(sImageFileName,this.iImageMaxWidth,this.iImageMaxHeight,this.sMediasFolder));
            oCurrCell.appendChild(oContentElement);
        }
        oContentElement = ns_buildHTMLElement('div',{style:'width:' + this.iQuestionWidthAvail + 'px;',align:'left'});
        oCurrCell.appendChild(oContentElement);
        
        
        
        //Cell 2
        oCurrCell = oCurrRow.insertCell(2);
        oCurrCell.width = '5';
        oCurrCell.className = 'QuestionRBorder';
        oCurrCell.appendChild(ns_buildHTMLElement('img',{src:'images/spacer.gif', width:'5', height:'5'}));
        
        //last row
        
        oCurrRow = oTable.insertRow(2);
        //Cell 0
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.width = '5';
        oCurrCell.height = '10';
        oCurrCell.appendChild(ns_buildHTMLElement('img',{src:'images/box_corner_bottom_left.gif', width:'5', height:'10'}));
        
        //Cell 1
        oCurrCell = oCurrRow.insertCell(1);
        oCurrCell.width = '750';
        oCurrCell.height = '10';
        oCurrCell.appendChild(ns_buildHTMLElement('img',{src:'images/box_bottom.gif', width:'750', height:'10'}));
        
        //Cell 2
        oCurrCell = oCurrRow.insertCell(2);
        oCurrCell.width = '5';
        oCurrCell.height = '10';
        oCurrCell.appendChild(ns_buildHTMLElement('img',{src:'images/box_corner_bottom_right.gif', width:'5', height:'10'}));
        
        this.oContentElement.appendChild(oTable);
        return oContentElement;
    }
    this.buildCommentLayout = function(oQuestion){
        //Comment
        var oCommentContainer = ns_buildHTMLElement('span',{style:'visibility:hidden'});
        
        if(oQuestion.sCommentTitle){
            oCommentContainer = ns_buildHTMLElement('div',{style:'width:' + this.iQuestionWidthAvail + 'px;margin-top:15px;',align:'left'});
            oCommentContainer.innerHTML = oQuestion.sCommentTitle + '<br />';
            oCommentField = ns_buildHTMLElement('textarea',{style:'width:' + this.iQuestionWidthAvail + 'px;',rows:'3',id:this.sTxtCommentPrefix + oQuestion.iQuestionID});
            oCommentField.innerHTML = oQuestion.sCommentText;
            oCommentContainer.appendChild(oCommentField);
        }
        
        return oCommentContainer;
    }
    this.buildHiddenQuestionLayout = function(oQuestion){
        var oCurrRow = null;
        var oCurrCell = null;
        var oContentElement = null;
        var sTitle = oQuestion.sTitle;
        var iNo = oQuestion.iQuestionID;
        var oTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0',width:this.iWidthAvail});
        oTable.className = 'QuestionTable';
        
        //Row 0
        oCurrRow = oTable.insertRow(0);
        //Cell 0
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.colSpan = '3';
        oCurrCell.width = this.iWidthAvail;
        oCurrCell.height = '35';
        oCurrCell.className = 'QuestionHeader';
        //Header table
        var oHeaderTable = ns_buildHTMLElement('table',{cellpadding:'0',cellspacing:'0',border:'0',width:this.iWidthAvail});
        var oHeaderTableRow = oHeaderTable.insertRow(0);
        var oNoCell = oHeaderTableRow.insertCell(0);
        oNoCell.width = '43';
        oNoCell.height = '35';
        oNoCell.align = 'center';
        oNoCell.vAlign = 'middle';
        oNoCell.className = 'QuestionHeaderNo';
        oNoCell.innerHTML = this.sQNoPrefix + (iNo + 1);
        
        var oSpacerCell = oHeaderTableRow.insertCell(1);
        oSpacerCell.width = '16';
        oSpacerCell.appendChild(ns_buildHTMLElement('img',{src:'images/spacer.gif', width:'16', height:'35'}));
        
        var oTitleCell = oHeaderTableRow.insertCell(2);
        oTitleCell.width = (this.iWidthAvail - 43 - 16 - 34);
        oTitleCell.align = 'left';
        oTitleCell.vAlign = 'middle';
        oTitleCell.className = 'QuestionHeaderTitle';
        oTitleCell.innerHTML = sTitle;
        
        var oBtnHelpCell = oHeaderTableRow.insertCell(3);
        oBtnHelpCell.width = '34';
        var oBtnHelp = ns_buildHTMLElement('a',{});
        oBtnHelp.className = 'aBtnQuestionHelp';
        //oBtnHelp.href = 'javascript:ns_showQuestionHelp(\'' + oQuestion.sQuestionType + '\')';
        var oInvisSpan = ns_buildHTMLElement('span',{});
        oInvisSpan.className = 'invisible';
        oBtnHelp.appendChild(oInvisSpan);
        oBtnHelpCell.appendChild(oBtnHelp);
        
        oCurrCell.appendChild(oHeaderTable);
        
        //Row 1
        oCurrRow = oTable.insertRow(1);
        //Cell 0
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.width = '5';
        oCurrCell.className = 'QuestionLBorder';
        oCurrCell.appendChild(ns_buildHTMLElement('img',{src:'images/spacer.gif', width:'5', height:'5'}));
        
        //Cell 1
        oCurrCell = oCurrRow.insertCell(1);
        oCurrCell.width = '750';
        oCurrCell.align = 'center';
        oCurrCell.className = 'QuestionContent';
       
        oContentElement = ns_buildHTMLElement('div',{style:'width:' + this.iQuestionWidthAvail + 'px;',align:'left'});
        oContentElement.innerHTML = this.sMsgHiddenQuestion;
        oCurrCell.appendChild(oContentElement);
        
        //Cell 2
        oCurrCell = oCurrRow.insertCell(2);
        oCurrCell.width = '5';
        oCurrCell.className = 'QuestionRBorder';
        oCurrCell.appendChild(ns_buildHTMLElement('img',{src:'images/spacer.gif', width:'5', height:'5'}));
        
        //Row 2
        oCurrRow = oTable.insertRow(2);
        //Cell 0
        oCurrCell = oCurrRow.insertCell(0);
        oCurrCell.width = '5';
        oCurrCell.height = '10';
        oCurrCell.appendChild(ns_buildHTMLElement('img',{src:'images/box_corner_bottom_left.gif', width:'5', height:'10'}));
        
        //Cell 1
        oCurrCell = oCurrRow.insertCell(1);
        oCurrCell.width = '750';
        oCurrCell.height = '10';
        oCurrCell.appendChild(ns_buildHTMLElement('img',{src:'images/box_bottom.gif', width:'750', height:'10'}));
        
        //Cell 2
        oCurrCell = oCurrRow.insertCell(2);
        oCurrCell.width = '5';
        oCurrCell.height = '10';
        oCurrCell.appendChild(ns_buildHTMLElement('img',{src:'images/box_corner_bottom_right.gif', width:'5', height:'10'}));
        
        this.oContentElement.appendChild(oTable);
        return oContentElement;
    }
    
    //Data
    this.saveCurrPage = function(bCallHide){
        if(typeof bCallHide == 'undefined'){
            bCallHide = true;
        }
    
        if(this.iCurrPageID >= 0 && this.iCurrPageID < this.iPages.length){
            var bDone = false;
            var i = this.iPages[this.iCurrPageID];
            
            while(!bDone){
                if(this.oQuestions[i].condition.validate()){
                    this.oQuestions[i].save();
                    if(bCallHide)
                        this.oQuestions[i].hide();
                }else{
                    this.saveNAParticipation(this.oQuestions[i].iQuestionID);
                }
                i++;
                
                if(i == this.oQuestions.length || i == this.iPages[(this.iCurrPageID + 1)]){
                    bDone = true;
                }
            }
        }
    }
    this.saveParticipation = function(iQID, iSNb, sValue){
        if(this.bSaveParticipation){
            var oReq = createRequest();
            oReq.open('POST',this.sServerURL + '/' + this.sServerCommandPage + '?cmd=save&pid=' + this.iParticipantID + '&qnb=' + iQID + '&snb=' + iSNb, this.bASync);
            oReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            oReq.send('v=' + URLEncode(sValue));

            if(!this.bASync && this.bDebugServer){
                if(oReq.readyState==4 && oReq.status == 200)
                {
                    eval(oReq.responseText);
                }
                else
                {
                    alert(this.sErrServerConn);
                }
            }
        }
    }
    
    this.saveNAParticipation = function(iQID){
        if(this.bSaveParticipation){
            var oReq = createRequest();
            oReq.open('POST',this.sServerURL + '/' + this.sServerCommandPage + '?cmd=savena&pid=' + this.iParticipantID + '&qnb=' + iQID, this.bASync);
            oReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            oReq.send(null);

            if(!this.bASync && this.bDebugServer){
                if(oReq.readyState==4 && oReq.status == 200)
                {
                    eval(oReq.responseText);
                }
                else
                {
                    alert(this.sErrServerConn);
                }
            }
        }
    }
    this.saveComment = function(iQID,sValue){
        if(this.bSaveParticipation){
            var oReq = createRequest();
            oReq.open('POST',this.sServerURL + '/' + this.sServerCommandPage + '?cmd=savecomment&pid=' + this.iParticipantID + '&qnb=' + iQID, this.bASync);
            oReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            oReq.send('v=' + URLEncode(sValue));

            if(!this.bASync && this.bDebugServer){
                if(oReq.readyState==4 && oReq.status == 200)
                {
                    eval(oReq.responseText);
                }
                else
                {
                    alert(this.sErrServerConn);
                }
            }
        }
    }
    this.showQuestionHelp = function(sQuestionType){
        var width = 371;
	    var height = 200;
	    var winl = (screen.width-width)/2;
	    var wint = (screen.height-height)/2 - 50;
	    if (winl < 0) winl = 0;
	    if (wint < 0) wint = 0;
    	
	    var oWindow = window.open('help.html?qt=' + sQuestionType,'help','top='+wint+',left='+winl+',width='+width+',height='+height+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0');
	    
    }
    this.onBeforeUnload = function(){
        return this.sConfirmUnload;
    }
}

function getNewNetSondage(oMainContainer,oNavBarContainers){
    if (top.ccdmd == null) top.ccdmd = {};
    top.ccdmd.netsondage = new NetSondage(oMainContainer,oNavBarContainers);
    return top.ccdmd.netsondage;
}

function ns_buildHTMLElement(sTagName,aAtts){
    var oElement = null;

    try{
        var sElementHTML = '<' + sTagName;
        for(var sAtt in aAtts){
            if(aAtts[sAtt] || typeof aAtts[sAtt] != 'object'){
                sElementHTML += ' ' + sAtt + '=\"' + aAtts[sAtt] + '\"';
            }
        }
        sElementHTML += ">";
        
        oElement = document.createElement(sElementHTML);
    }catch(e){
        oElement = document.createElement(sTagName.toUpperCase());
        
        for(var sAtt in aAtts){
            if(aAtts[sAtt] || typeof aAtts[sAtt] != 'object'){
                oElement.setAttribute(sAtt,aAtts[sAtt]);
            }
        }
    }
    
    return oElement;
}
function ns_getShuffledOrder(N) {
	var J, K, Q = new Array(N);
	for (J = 0; J < N; J++) {
		K = ns_Random(J + 1);
		Q[J] = Q[K];
		Q[K] = J;
	}
	return Q;
}
function ns_Random(N) {
	return Math.floor(N * (Math.random() % 1));
}
function ns_copyArray(from){
	var toReturn = new Array();

	for(var i = 0;i < from.length;i++){
		toReturn[i] = from[i];
	}
	
	return toReturn;
}
function ns_buildImageObject(sFileName,iMaxWidth,iMaxHeight,sImgFolder){
    var iNewWidth = 0;
    var iNewHeight = 0;
    var sInnerHTML = "";

    var sImgSrc = sImgFolder + '/' + sFileName;
    var oImg = new Image();
    oImg.src = sImgSrc;
    
    if(iMaxWidth && oImg.width > iMaxWidth){
        iNewWidth = iMaxWidth;
        iNewHeight = ns_b2(oImg.width,oImg.height,iMaxWidth);
    }else{
        iNewWidth = oImg.width;
        iNewHeight = oImg.height;
    }
    
    if(iMaxHeight && iNewHeight > iMaxHeight){
        iNewWidth = ns_b2(iNewHeight,iNewWidth,iMaxHeight);
        iNewHeight = iMaxHeight;
    }
    
    iNewWidth = Math.round(iNewWidth);
    iNewHeight = Math.round(iNewHeight);
    
    return ns_buildHTMLElement('img',{src:sImgSrc, width:iNewWidth, height:iNewHeight});
}
function ns_b2(a1,a2,b1){
	return (a2 * b1) / a1;
}
var ns_sLetters = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");

function ns_getLetter(i){
	var sLetter = "";
	
	if(i < 27){
		sLetter = ns_sLetters[i - 1];
	}else if((i % 26) == 0) {
		sLetter = ns_sLetters[Math.floor(i  / 26) - 2] + ns_getLetter(26);
	}else{
		sLetter = ns_sLetters[Math.floor(i  / 26) - 1] + ns_getLetter(i % 26);
	}
	
	return sLetter;
}

function ns_buildMediaEmbed(sFilePath,iWidth,iHeight){
    //Settings
    var bAutoPlay = false;
    var sClassid = 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B';
    var sCodebase = 'http://www.apple.com/qtactivex/qtplugin.cab';
    var sPluginspage = 'http://www.apple.com/quicktime/download/';
    
    sFilePath = './' + sFilePath;
    
    var oObject = ns_buildHTMLElement('object',{classid:sClassid,width:iWidth,height:iHeight,codebase:sCodebase});
    oObject.appendChild(ns_buildHTMLElement('param',{name:'src',value:sFilePath}));
    oObject.appendChild(ns_buildHTMLElement('param',{name:'autoplay',value:bAutoPlay}));
    oObject.appendChild(ns_buildHTMLElement('param',{name:'controller',value:'true'}));
    oObject.appendChild(ns_buildHTMLElement('embed',{autoplay:bAutoPlay,src:sFilePath,width:iWidth,height:iHeight,controller:'true',pluginspage:sPluginspage}));
    
    return oObject;
}
function ns_buildAudioEmebed(sFilePath){
    var iWidth = 220;
    var iHeight = 20;
    
    return ns_buildMediaEmbed(sFilePath,iWidth,iHeight);
}
function ns_showQuestionHelp(sQuestionType){
    top.ccdmd.netsondage.showQuestionHelp(sQuestionType);
}
function ns_onbeforeunload(){
    return top.ccdmd.netsondage.onBeforeUnload();
}

function ns_fo(theObj, theDoc)
{
    var p, i, foundObj;

    if(!theDoc)theDoc = document;
    if( (p = theObj.indexOf('?')) > 0 && parent.frames.length)
    {
        theDoc = parent.frames[theObj.substring(p+1)].document;
        theObj = theObj.substring(0,p);
    }
    if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
    
    for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
    
    for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = fo(theObj,theDoc.layers[i].document);
    
    if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

    return foundObj;
}
function ns_openLink(sURL) {
    var iWidth = 900;
    var iHeight = 600;
    var iWindowLeft = (screen.width - iWidth) / 2;
    var iWindowTop = (screen.height - iHeight) / 2 - 50;
    if (iWindowLeft < 0) iWindowLeft = 0;
    if (iWindowTop < 0) iWindowTop = 0;
    var settings = "status,scrollbars,menubar,resizable,width="+iWidth+",height="+iHeight+",top="+iWindowTop+",left="+iWindowLeft;
    window.open(sURL, "ns_link", settings).focus();
}

function ns_scrollTop(){
    window.scrollTo(0,0);
}

