/********1*********2*********3*********4*********5*********6*********7*********8
 * Module:   klQuizTranslators.js Version 1.0
 *******************************************************************************
 * Description: Data translation routines for K&L Quiz.
 *******************************************************************************
 * Requirements: DOM Compliant browser with enabled Javascript.
 *******************************************************************************
 * Copyright (c) 2002, K&L Design Productions, All Rights Reserved.
 *
 * You may not use the code contained in this file without the express written
 * permission of K&L Productions.
 * You may not redistribute, sell, or offer this file for download, in any form
 * or on any medium, without the express written permission of K&L Productions.
 * This includes, but is not limited to, adding it to script archives or
 * bundling and distributing it with other scripts/software.
 * You agree to retain the credits and copyright notice in the source code when
 * including it in your own pages.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHOR OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 ******************************************************************************/ function clearTranslatedDataObjects(){if(window.POINT)delete POINT;if(window.CHOICE)delete CHOICE;if(window.TYPE)delete TYPE;if(window.QUESTION)delete QUESTION;if(window.ANSWER)delete ANSWER;return;}function translateQuizData(){if(window.POINT && window.CHOICE && window.TYPE)return translateSPDataT1(POINT,CHOICE,TYPE);if(window.POINT && window.TYPE)return translateSPDataT2(POINT,TYPE);if(window.QUESTION && window.CHOICE && window.ANSWER)return translateSPDataT3(QUESTION,CHOICE,ANSWER);return null;}function translateSPDataT1(qa,ca,va){var i=0;var j=0;var questions=new Array();for(i=0;i<qa.length;i++){if(qa[i]!=undefined){answers=new Array();choices=ca[i-1].split(',');if(!ca[i-1]){alert('ERROR: CHOICE array missing index: '+i);return null;}if(!va[i]){alert('ERROR: TYPE array missing index: '+i);return null;}correct=va[i].split(',');values=new Array(choices.length);for(j=0;j<values.length;j++)values[j]=0;for(j=0;j<correct.length;j++)values[parseInt(correct[j])-1]=1;for(j=0;j<choices.length;j++){answers.push(new quizAnswer(choices[j],values[j],''))}questions.push(new quizQuestion(qa[i],'',answers,correct.length>1?CA_MULTIPLE:CA_SINGLE));}}klqd=new quizData('',questions,null,0);clearTranslatedDataObjects();return klqd;}function translateSPDataT2(qa,ca){var i=0;var j=0;var questions=new Array();for(i=1;i<qa.length;i++){answers=new Array();for(j=1;j<ca.length;j++){answers.push(new quizAnswer(ca[j],i==j?1:0,''))}questions.push(new quizQuestion(qa[i],'',answers,CA_SINGLE));}klqd=new quizData('',questions,null,0);clearTranslatedDataObjects();return klqd;}function translateSPDataT3(qa,ca,va){var i=0;var j=0;var questions=new Array();for(i=0;i<qa.length;i++){if(qa[i]!=undefined){answers=new Array();choices=ca[i-1].split(',');if(!ca[i-1]){alert('ERROR: CHOICE array missing index: '+i);return null;}if(!va[i]){alert('ERROR: ANSWER array missing index: '+i);return null;}correct=va[i].split(',');values=new Array(choices.length);for(j=0;j<values.length;j++)values[j]=0;for(j=0;j<correct.length;j++)values[parseInt(correct[j])-1]=1;for(j=0;j<choices.length;j++){answers.push(new quizAnswer(choices[j],values[j],''))}questions.push(new quizQuestion(qa[i],'',answers,correct.length>1?CA_MULTIPLE:CA_SINGLE));}}klqd=new quizData('',questions,null,0);clearTranslatedDataObjects();return klqd;}
