    
  var wordWallList = { };
  var numberOfRows = 4;
  var numberOfColumns = 3;
  var page = "frontpage";

  var queryParamsForWordWall="";

  function fillTable(currentPage) {
    if (currentPage == "assessment" ) {
      numberOfRows = 8;
    } 
    page = currentPage;
    AjaxBean.AjaxGetWordWallList(page, callbackFillTable);
  }  

  var callbackFillTable = function(wordList) {
    var wordBean;
    var wordIndex = 0;
    var o;
    if ( wordList != null ) {
      if ( wordList.length > 0 ){
        o=dwr.util.byId("nextbuttonoffdiv");
        if (o!=null) {
          o.style.display='none';
        }
        o=dwr.util.byId("nextbuttonondiv");
        if (o!=null) {
          o.style.display='inline';
        }
        o=dwr.util.byId("removeAllTD");
        if (o!=null) {
          o.style.display='inline';
        }
        if (page == "assessment" ) {
          if ( wordList.length > 1) {
            dwr.util.setValue("wordWallInstructions", " You currently have<br />("+wordList.length+") words in your<br />Assessment.", { escapeHtml:false });
          }
          else {
            dwr.util.setValue("wordWallInstructions", " You currently have<br />("+wordList.length+") word in your<br />Assessment.", { escapeHtml:false });
          }
        }
        else {
          if ( wordList.length > 1) {
            dwr.util.setValue("wordWallInstructions", " You currently have<br />("+wordList.length+") words in your<br />Word List.", { escapeHtml:false });
          }
          else {
            dwr.util.setValue("wordWallInstructions", " You currently have<br />("+wordList.length+") word in your<br />Word List.", { escapeHtml:false });
          }
        }  
      }
      else {
        dwr.util.setValue("wordWallInstructions", "This is where the<br />words you choose<br />will appear.", { escapeHtml:false });
        o=dwr.util.byId("nextbuttonoffdiv");
        if (o!=null) {
          o.style.display='inline';
        }
        o=dwr.util.byId("nextbuttonondiv");
        if (o!=null) {
          o.style.display='none';
        }
        o=dwr.util.byId("removeAllTD");
        if (o!=null) {
          o.style.display='none';
        }
        
      }
      for (var colIndex = 0; colIndex < numberOfColumns; colIndex++) {
        for (var rowIndex = 0; rowIndex < numberOfRows; rowIndex++) {
          if ( wordIndex < wordList.length ) {
            wordBean = wordList[wordIndex];
            dwr.util.byId("remlink" + colIndex+rowIndex).href= ((page=="assessment")?"assessment.do":"frontpage.do")+"?remword=" + wordBean.wordId +  ((queryParamsForWordWall!='')?"&"+queryParamsForWordWall:"");
            overlayPopup("removeImage" + colIndex+rowIndex, "visible", true);
            dwr.util.setValue("spanWordNameDelete" + colIndex+rowIndex, wordBean.wordName);
            dwr.util.setValue("spanWordName" + colIndex+rowIndex, wordBean.wordName);
            dwr.util.setValue("spanDefinition" + colIndex+rowIndex, wordBean.definition);
            if ( wordBean.imageName != null) {
              dwr.util.setValue("rolloverImageDiv" + colIndex+rowIndex, "<img src='/images/wordimages/"+wordBean.imageName+"'>", { escapeHtml:false });
              overlayPopup("cameraImage" + colIndex+rowIndex, "visible", true);
            }
            else {
              dwr.util.setValue("rolloverImageDiv" + colIndex+rowIndex, "");
              overlayPopup("cameraImage" + colIndex+rowIndex, "hidden", true);
            }          
            dwr.util.setValue("spanPartspeech" + colIndex+rowIndex, wordBean.partspeechMain);
            dwr.util.setValue("spanLevel" + colIndex+rowIndex, wordBean.level);
            dwr.util.setClassName("word_"+wordBean.wordId+wordBean.topicId, 'usedwords');
            dwr.util.setValue("alreadyInWordWall_" + wordBean.wordId + wordBean.topicId, "(already in word list)&nbsp;", { escapeHtml:false });
            wordWallList[colIndex+""+rowIndex] = wordBean;
          }
          else {
            overlayPopup("removeImage" + colIndex+rowIndex, "hidden", true);
            dwr.util.setValue("spanWordNameDelete" + colIndex+rowIndex, "");
            dwr.util.setValue("spanWordName" + colIndex+rowIndex, "");
            dwr.util.setValue("spanDefinition" + colIndex+rowIndex, "");
            dwr.util.setValue("rolloverImageDiv" + colIndex+rowIndex, "");
            overlayPopup("cameraImage" + colIndex+rowIndex, "hidden", true);
            dwr.util.setValue("spanPartspeech" + colIndex+rowIndex, "");
            dwr.util.setValue("spanLevel" + colIndex+rowIndex, "");
            wordWallList[colIndex+""+rowIndex] = null;
          }        
          wordIndex++;
       }
      }
    }
  };
  
  function addToWordWall(wordId, topicId, currentPage) {
     dwr.engine.beginBatch();
     AjaxBean.AjaxAddToWordWall(wordId, topicId, currentPage, function(addSuccessful) {toggleFullMessage(addSuccessful)});
     fillTable(currentPage);
     dwr.engine.endBatch();
    return false;
  }

  function toggleFullMessage(addSuccessful) {
    o=dwr.util.byId("wordListFull");
    if (o!=null) {
      if ( addSuccessful == null || addSuccessful == true ){
        o.style.visibility='hidden';
        o.style.display='none';
      }
      else {
        var browser=navigator.appName;
        o.style.visibility='visible';
        if (browser=="Netscape")  { 
          o.style.display='table-row';
        }
        else {
         o.style.display='block';
        }
      }
    }
  }
  
  function removeFromWordWall(colRowIndex, currentPage) {
    var wordBean = wordWallList[colRowIndex];
      dwr.engine.beginBatch();
      AjaxBean.AjaxRemoveFromWordWall(wordBean.wordId, currentPage);
      fillTable(currentPage);
      toggleFullMessage(true);
      dwr.engine.endBatch();
      dwr.util.setClassName("word_"+wordBean.wordId+wordBean.topicId, 'words');
      dwr.util.setValue("alreadyInWordWall_" + wordBean.wordId+wordBean.topicId);
      return false;
  }
  
  
  var reply0 = function(data)  {
    if (data != null && typeof data == 'object') {
     alert(dwr.util.toDescriptiveString(data, 5));
    }
    else {
      dwr.util.setValue('d0', dwr.util.toDescriptiveString(data, 1));
    }
  }
    
  function debug(idToDebug) {
    alert("The DOM object with id=" + idToDebug + " is defined like this " + dwr.util.toDescriptiveString(dwr.util.byId(idToDebug), 2));
  }
  

  function checkLessonName(lessonName, lessonId) {
     dwr.engine.beginBatch();
     AjaxBean.AjaxValidateLessonName(lessonName, lessonId, function(isValid) {showOverwriteConfirmMessage(isValid,lessonName)});
     dwr.engine.endBatch();
  }  


  function showOverwriteConfirmMessage(isValid,lessonName) {
    var answer = true;
    if ( !isValid ) {
       answer = confirm("This lesson name ["+lessonName+"] already exists. \n\nClick OK to overwrite. Click Cancel to change the name.");
    }
    if ( answer) {
      getObj('formAction').value='Save and Download Lesson';
      getObj('checkoutForm').submit();
    }
  
  }
  
  
