<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile: rnmc_stdCrossword.xml $
$Revision: 938 $

last change: $Date: 2009-02-06 13:34:59 +0300 (Пт, 06 фев 2009) $
             $Author: toha $

  Lacerta Project
  version 1.0.0.1
  Copyright (C) 2008 RNMC
-->
<composition name="rnmc_Crossword" class="rnmc_stdMediaObject">
<script> <![CDATA[
  this.type = "rnmc_Crossword";
  this.id = "";
  this.visibility = OBJECT_VISIBILITY_FALSE;

//  проверка сразу
  this.checkImmediately = true;
//  автоматический переход к следующей ячейке при вводе символа
  this.autoSkip = false;
//  текущее направление заполнения (для автоперехода)
//  CROSSWORD_AUTOSKIP_RIGHT = 0 - вправо
//  CROSSWORD_AUTOSKIP_DOWN = 1 - вниз
  this.fillDirection = -1;

  this.crosswordComplete = false;

//  устанавливать фокус на ячейку при наведении на неё мыши
  this.setFocusOnRollover = false;
//  автоматический подгон размеров ячейки под стиль текста в ней 
  this.autoFitStyle = false;

//  приемлмые таблицы символов
  this.rusSymbolTable = "1234567890АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя";
  this.engSymbolTable = "1234567890AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
  this.rusengSymbolTable = "1234567890АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯяAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
  this.customSymbolTable = "";
  this.currentSymbolTable = this.rusSymbolTable;

//  действия на правильно введённое слово
  this.onWordCompleteActions = null;
//  действия на неправильно введённое слово
  this.onWordCompleteWrongActions = null;
//  действия на правильно заполненный кроссворд
  this.onCrosswordCompleteActions = null;
//  действия на НЕправильно заполненный кроссворд
  this.onCrosswordWrongActions = null;
  this.onShowActions = null;

  this.cellWidthNormal = 20;
  this.cellWidthActive = 20;
  this.cellWidthDisabled = 20;
  this.cellHeightNormal = 20;
  this.cellHeightActive = 20;
  this.cellHeightDisabled = 20;
  this.cellStyleNormal = null;
  this.cellStyleActive = null;
  this.cellStyleDisabled = null;
  this.cellBorderNormal = 1;
  this.cellBorderActive = 1;
  this.cellBorderDisabled = 1;
  this.cellBgColorNormal = "#FFFFFF";
  this.cellBgColorActive = "#FFFFFF";
  this.cellBgColorDisabled = "#FFFFFF";
  this.cellBorderColorNormal = "#000000";
  this.cellBorderColorActive = "#FF0000";
  this.cellBorderColorDisabled = "#000000";

  this.indexStyle = null;
  this.cellSpacing = 2;
  this.lineSpacing = 0;

  this.cellObjects = null;
  this.currentCellId = 0;

  this.inputBox = null;

  this.timer_id = 0;

// Параметры для подсчета результатов.
  this.resultsParam = null;

  function initFromNode(srcNode, useDelayLoad){
    var xmlNode = null;
    var xmlAttributeMap = null;
    var xmlAttribute = null;

    this.cellObjects = new Array();
    this.cellMap = new Array();
	
// Параметры для подсчета результатов.
	this.resultsParam = {
		M: 0,          // число попыток
		P: "unknown",  // число всех вариантов
		N: 0,          // число всех правильных ответов
		n: 0,          // число выбранных правильных ответов
		k: 0,          // число выбранных неправильных ответов
		t: 0           // время выполнения задания
//    ------------------- вспопогательные объекты -------------		
//    this.resultsParam.begin = new Date(); // время начала выполнения задания	
	};
    //  считывание настроек по умолчанию

    /*
    var str = "#FF0000scene.defaultSettings.stdCrossword: ";
    for (var k in scene.defaultSettings.stdCrossword){
      str += k+"="+scene.defaultSettings.stdCrossword[k]+"; ";
    }
    trace(str);
    */
    
    if(scene.defaultSettings && scene.defaultSettings.stdCrossword){
      if (scene.defaultSettings.stdCrossword.cellWidthNormal)
        this.cellWidthNormal = scene.defaultSettings.stdCrossword.cellWidthNormal;
      if (scene.defaultSettings.stdCrossword.cellWidthActive)
        this.cellWidthActive = scene.defaultSettings.stdCrossword.cellWidthActive;
      if (scene.defaultSettings.stdCrossword.cellWidthDisabled)
        this.cellWidthDisabled = scene.defaultSettings.stdCrossword.cellWidthDisabled;
      if (scene.defaultSettings.stdCrossword.cellHeightNormal)
        this.cellHeightNormal = scene.defaultSettings.stdCrossword.cellHeightNormal;
      if (scene.defaultSettings.stdCrossword.cellHeightActive)
        this.cellHeightActive = scene.defaultSettings.stdCrossword.cellHeightActive;
      if (scene.defaultSettings.stdCrossword.cellHeightDisabled)
        this.cellHeightDisabled = scene.defaultSettings.stdCrossword.cellHeightDisabled;
      if (scene.defaultSettings.stdCrossword.cellStyleNormal)
        this.cellStyleNormal = scene.defaultSettings.stdCrossword.cellStyleNormal;
      if (scene.defaultSettings.stdCrossword.cellStyleActive)
        this.cellStyleActive = scene.defaultSettings.stdCrossword.cellStyleActive;
      if (scene.defaultSettings.stdCrossword.cellStyleDisabled)
        this.cellStyleDisabled = scene.defaultSettings.stdCrossword.cellStyleDisabled;
      if (scene.defaultSettings.stdCrossword.cellBorderNormal)
        this.cellBorderNormal = scene.defaultSettings.stdCrossword.cellBorderNormal;
      if (scene.defaultSettings.stdCrossword.cellBorderActive)
        this.cellBorderActive = scene.defaultSettings.stdCrossword.cellBorderActive;
      if (scene.defaultSettings.stdCrossword.cellBorderDisabled)
        this.cellBorderDisabled = scene.defaultSettings.stdCrossword.cellBorderDisabled;
      if (scene.defaultSettings.stdCrossword.cellBgColorNormal)
        this.cellBgColorNormal = scene.defaultSettings.stdCrossword.cellBgColorNormal;
      if (scene.defaultSettings.stdCrossword.cellBgColorActive)
        this.cellBgColorActive = scene.defaultSettings.stdCrossword.cellBgColorActive;
      if (scene.defaultSettings.stdCrossword.cellBgColorDisabled)
        this.cellBgColorDisabled = scene.defaultSettings.stdCrossword.cellBgColorDisabled;
      if (scene.defaultSettings.stdCrossword.cellBorderColorNormal)
        this.cellBorderColorNormal = scene.defaultSettings.stdCrossword.cellBorderColorNormal;
      if (scene.defaultSettings.stdCrossword.cellBorderColorActive)
        this.cellBorderColorActive = scene.defaultSettings.stdCrossword.cellBorderColorActive;
      if (scene.defaultSettings.stdCrossword.cellBorderColorDisabled)
        this.cellBorderColorDisabled = scene.defaultSettings.stdCrossword.cellBorderColorDisabled;
      if (scene.defaultSettings.stdCrossword.indexStyle)
        this.indexStyle = scene.defaultSettings.stdCrossword.indexStyle;
      if (scene.defaultSettings.stdCrossword.cellSpacing)
        this.cellSpacing = scene.defaultSettings.stdCrossword.cellSpacing;
      if (scene.defaultSettings.stdCrossword.lineSpacing)
        this.lineSpacing = scene.defaultSettings.stdCrossword.lineSpacing;
      if (scene.defaultSettings.stdCrossword.checkImmediately)
        this.checkImmediately = scene.defaultSettings.stdCrossword.checkImmediately;
      if (scene.defaultSettings.stdCrossword.autoSkip)
        this.autoSkip = scene.defaultSettings.stdCrossword.autoSkip;
      if (scene.defaultSettings.stdCrossword.setFocusOnRollover)
        this.setFocusOnRollover = scene.defaultSettings.stdCrossword.setFocusOnRollover;
      if (scene.defaultSettings.stdCrossword.autoFitStyle)
        this.autoFitStyle = scene.defaultSettings.stdCrossword.autoFitStyle;
      if (scene.defaultSettings.stdCrossword.currentSymbolTable)
        this.currentSymbolTable = scene.defaultSettings.stdCrossword.currentSymbolTable;
    }
    //

    xmlAttributeMap = srcNode.attributes;
    if (xmlAttributeMap){
      xmlAttribute = xmlAttributeMap.getNamedItem("id");
      if (xmlAttribute != null && xmlAttribute.specified)
        this.id = xmlAttribute.value;
      xmlAttribute = xmlAttributeMap.getNamedItem("visible");
      if (xmlAttribute != null && xmlAttribute.specified){
        if(xmlAttribute.value == "true")
          this.visibility = OBJECT_VISIBILITY_TRUE;
        else if(xmlAttribute.value == "false")
          this.visibility = OBJECT_VISIBILITY_FALSE;
      }
      xmlAttribute = xmlAttributeMap.getNamedItem("enabled");
      if (xmlAttribute != null && xmlAttribute.specified
        && xmlAttribute.value.toLowerCase() == "false")
        this.disabled = true;
    }

    xmlNode = srcNode.firstChild;
    while(xmlNode){
      if(xmlNode.nodeName == "param"){
        parseParamNode(xmlNode);
        
        xmlAttributeMap = xmlNode.attributes;
        if (xmlAttributeMap){
/*
          xmlAttribute =  xmlAttributeMap.getNamedItem("startCell");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.objectY = parseInt(xmlAttribute.value);
*/
          xmlAttribute =  xmlAttributeMap.getNamedItem("checkImmediately");
          if (xmlAttribute != null && xmlAttribute.specified){
            if(xmlAttribute.value.toLowerCase() == "true")
              this.checkImmediately = true;
            else if(xmlAttribute.value.toLowerCase() == "false")
              this.checkImmediately = false;
          }
          xmlAttribute =  xmlAttributeMap.getNamedItem("checkAlgorithm");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.crAlgorithm = xmlAttribute.value.toLowerCase();
          xmlAttribute =  xmlAttributeMap.getNamedItem("setFocusWithRollover");
          if (xmlAttribute != null && xmlAttribute.specified){
            if(xmlAttribute.value == "true")
              this.setFocusOnRollover = true;
            else if(xmlAttribute.value == "false")
              this.setFocusOnRollover = false;
          }
          xmlAttribute =  xmlAttributeMap.getNamedItem("autoSkip");
          if (xmlAttribute != null && xmlAttribute.specified){
            if(xmlAttribute.value == "true")
              this.autoSkip = true;
            else if(xmlAttribute.value == "false")
              this.autoSkip = false;
          }
          xmlAttribute =  xmlAttributeMap.getNamedItem("depth");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.objectDepth = parseInt(xmlAttribute.value);
        }
      } else if(xmlNode.nodeName == "layout"){
        xmlAttributeMap = xmlNode.attributes;
        if (xmlAttributeMap){
          xmlAttribute =  xmlAttributeMap.getNamedItem("styleNormal");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.cellStyleNormal = xmlAttribute.value;
          xmlAttribute =  xmlAttributeMap.getNamedItem("styleActive");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.cellStyleActive = xmlAttribute.value;
          xmlAttribute =  xmlAttributeMap.getNamedItem("styleDisabled");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.cellStyleDisabled = xmlAttribute.value;
          xmlAttribute =  xmlAttributeMap.getNamedItem("autoFitStyle");
          if (xmlAttribute != null && xmlAttribute.specified){
            if(xmlAttribute.value.toLowerCase() == "true"){
              this.autoFitStyle = true;
              //  вычисляем размеры клеток в соответствии со стилем текста
              var maxCellSize = 0;
              var tempTextField = new Text();
              tempTextField.adjustHeight = true;
              tempTextField.visible = false;
              tempTextField.parent = this;
              // для русской буквы "Ж"
              if(this.cellStyleNormal && scene.StyleManager.styleExists(this.cellStyleNormal)){
                tempTextField.style = this.cellStyleNormal;
                tempTextField.width = 0;
                tempTextField.height = 0;
                tempTextField.value = "Ж";
                var newCellSize = (tempTextField.width > tempTextField.height) ? tempTextField.width : tempTextField.height;
                if(newCellSize > maxCellSize)
                  maxCellSize = newCellSize;
                this.cellWidthNormal = maxCellSize + 6;
                this.cellHeightNormal = maxCellSize + 6;
              }
              // для английской буквы "М"
              if(this.cellStyleNormal && scene.StyleManager.styleExists(this.cellStyleNormal)){
                tempTextField.style = this.cellStyleNormal;
                tempTextField.width = 0;
                tempTextField.height = 0;
                tempTextField.value = "M";
                var newCellSize = (tempTextField.width > tempTextField.height) ? tempTextField.width : tempTextField.height;
                if(newCellSize > maxCellSize)
                  maxCellSize = newCellSize;
                this.cellWidthNormal = maxCellSize + 6;
                this.cellHeightNormal = maxCellSize + 6;
              }
              // для русской буквы "Ж"
              if(this.cellStyleActive && scene.StyleManager.styleExists(this.cellStyleActive)){
                tempTextField.style = this.cellStyleActive;
                tempTextField.width = 0;
                tempTextField.height = 0;
                tempTextField.value = "Ж";
                var newCellSize = (tempTextField.width > tempTextField.height) ? tempTextField.width : tempTextField.height;
                if(newCellSize > maxCellSize)
                  maxCellSize = newCellSize;
                this.cellWidthActive = maxCellSize + 6;
                this.cellHeightActive = maxCellSize + 6;
              }
              // для английской буквы "М"
              if(this.cellStyleActive && scene.StyleManager.styleExists(this.cellStyleActive)){
                tempTextField.style = this.cellStyleActive;
                tempTextField.width = 0;
                tempTextField.height = 0;
                tempTextField.value = "M";
                var newCellSize = (tempTextField.width > tempTextField.height) ? tempTextField.width : tempTextField.height;
                if(newCellSize > maxCellSize)
                  maxCellSize = newCellSize;
                this.cellWidthActive = maxCellSize + 6;
                this.cellHeightActive = maxCellSize + 6;
              }
              // для русской буквы "Ж"
              if(this.cellStyleDisabled && scene.StyleManager.styleExists(this.cellStyleDisabled)){
                tempTextField.style = this.cellStyleDisabled;
                tempTextField.width = 0;
                tempTextField.height = 0;
                tempTextField.value = "Ж";
                var newCellSize = (tempTextField.width > tempTextField.height) ? tempTextField.width : tempTextField.height;
                if(newCellSize > maxCellSize)
                  maxCellSize = newCellSize;
                this.cellWidthDisabled = maxCellSize + 6;
                this.cellHeightDisabled = maxCellSize + 6;
              }
              // для английской буквы "М"
              if(this.cellStyleDisabled && scene.StyleManager.styleExists(this.cellStyleDisabled)){
                tempTextField.style = this.cellStyleDisabled;
                tempTextField.width = 0;
                tempTextField.height = 0;
                tempTextField.value = "M";
                var newCellSize = (tempTextField.width > tempTextField.height) ? tempTextField.width : tempTextField.height;
                if(newCellSize > maxCellSize)
                  maxCellSize = newCellSize;
                this.cellWidthDisabled = maxCellSize + 6;
                this.cellHeightDisabled = maxCellSize + 6;
              }
              tempTextField.parent = null;
              tempTextField = null;
            } else if(xmlAttribute.value == "false"){
              this.autoFitStyle = false;
            }
          }
          xmlAttribute =  xmlAttributeMap.getNamedItem("borderNormal");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.cellBorderNormal = parseInt(xmlAttribute.value);
          xmlAttribute =  xmlAttributeMap.getNamedItem("borderActive");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.cellBorderActive = parseInt(xmlAttribute.value);
          xmlAttribute =  xmlAttributeMap.getNamedItem("borderDisabled");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.cellBorderDisabled = parseInt(xmlAttribute.value);
          xmlAttribute =  xmlAttributeMap.getNamedItem("cellSpacing");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.cellSpacing = parseInt(xmlAttribute.value);
          xmlAttribute =  xmlAttributeMap.getNamedItem("lineSpacing");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.lineSpacing = parseInt(xmlAttribute.value);
          xmlAttribute =  xmlAttributeMap.getNamedItem("indexStyle");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.indexStyle = xmlAttribute.value;
          xmlAttribute =  xmlAttributeMap.getNamedItem("cellWidthNormal");
          if (xmlAttribute != null && xmlAttribute.specified && !this.autoFitStyle){
            this.cellWidthNormal = parseInt(xmlAttribute.value);
          }
          xmlAttribute =  xmlAttributeMap.getNamedItem("cellWidthActive");
          if (xmlAttribute != null && xmlAttribute.specified && !this.autoFitStyle){
            this.cellWidthActive = parseInt(xmlAttribute.value);
          }
          xmlAttribute =  xmlAttributeMap.getNamedItem("cellWidthDisabled");
          if (xmlAttribute != null && xmlAttribute.specified && !this.autoFitStyle){
            this.cellWidthDisabled = parseInt(xmlAttribute.value);
          }
          xmlAttribute =  xmlAttributeMap.getNamedItem("cellHeightNormal");
          if (xmlAttribute != null && xmlAttribute.specified && !this.autoFitStyle){
            this.cellHeightNormal = parseInt(xmlAttribute.value);
          }
          xmlAttribute =  xmlAttributeMap.getNamedItem("cellHeightActive");
          if (xmlAttribute != null && xmlAttribute.specified && !this.autoFitStyle){
            this.cellHeightActive = parseInt(xmlAttribute.value);
          }
          xmlAttribute =  xmlAttributeMap.getNamedItem("cellHeightDisabled");
          if (xmlAttribute != null && xmlAttribute.specified && !this.autoFitStyle){
            this.cellHeightDisabled = parseInt(xmlAttribute.value);
          }
          xmlAttribute =  xmlAttributeMap.getNamedItem("bgColorNormal");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.cellBgColorNormal = xmlAttribute.value;
          xmlAttribute =  xmlAttributeMap.getNamedItem("bgColorActive");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.cellBgColorActive = xmlAttribute.value;
          xmlAttribute =  xmlAttributeMap.getNamedItem("bgColorDisabled");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.cellBgColorDisabled = xmlAttribute.value;
          xmlAttribute =  xmlAttributeMap.getNamedItem("borderColorNormal");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.cellBorderColorNormal = xmlAttribute.value;
          xmlAttribute =  xmlAttributeMap.getNamedItem("borderColorActive");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.cellBorderColorActive = xmlAttribute.value;
          xmlAttribute =  xmlAttributeMap.getNamedItem("borderColorDisabled");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.cellBorderColorDisabled = xmlAttribute.value;
        }
      } else if(xmlNode.nodeName == "langsettings"){
        xmlAttributeMap = xmlNode.attributes;
        if (xmlAttributeMap){
          xmlAttribute =  xmlAttributeMap.getNamedItem("symbols");
          if (xmlAttribute != null && xmlAttribute.specified){
            if(xmlAttribute.value.indexOf(":") >= 0){
            //  для custom набора символов (если необходимо ограничить
            //  вводимые символы как-то конкретно)
            } else {
              switch(xmlAttribute.value){
              case "RUS":
                this.currentSymbolTable = this.rusSymbolTable;
                break;
              case "RUS_ENG":
                this.currentSymbolTable = this.rusengSymbolTable;
                break;
              case "ENG":
                this.currentSymbolTable = this.engSymbolTable;
                break;
              }
            }
          } else {
            this.currentSymbolTable = this.rusSymbolTable;
          }
        }
      } else if(xmlNode.nodeName == "data"){
        var dataNode = xmlNode.firstChild;
        var horzIndex = 0;
        var vertIndex = 0;
        var horzOffset = 0;
        var vertOffset = 0;
        while(dataNode){
          if(dataNode.nodeName == "tr"){
            var trNode = dataNode.firstChild;
          //  создаём строку в карте
            var mapLine = new Array();
            while(trNode){
              if(trNode.nodeName == "td"){
                if(trNode.textContent && trNode.textContent.length != ""){
                  xmlAttributeMap = trNode.attributes;
                  var newObject = new Composition();
                  newObject._class = "crossword_cell";
                  newObject.parent = this;
                  newObject.objectX = this.objectX + horzOffset;
                  newObject.objectY = this.objectY + vertOffset;
                  newObject.cellWidthNormal = this.cellWidthNormal;
                  newObject.cellWidthActive = this.cellWidthActive;
                  newObject.cellWidthDisabled = this.cellWidthDisabled;
                  newObject.cellHeightNormal = this.cellHeightNormal;
                  newObject.cellHeightActive = this.cellHeightActive;
                  newObject.cellHeightDisabled = this.cellHeightDisabled;
                  newObject.cellStyleNormal = this.cellStyleNormal;
                  newObject.cellStyleActive = this.cellStyleActive;
                  newObject.cellStyleDisabled = this.cellStyleDisabled;
                  newObject.cellBorderNormal = this.cellBorderNormal;
                  newObject.cellBorderActive = this.cellBorderActive;
                  newObject.cellBorderDisabled = this.cellBorderDisabled;
                  newObject.cellBgColorNormal = this.cellBgColorNormal;
                  newObject.cellBgColorActive = this.cellBgColorActive;
                  newObject.cellBgColorDisabled = this.cellBgColorDisabled;
                  newObject.cellBorderColorNormal = this.cellBorderColorNormal;
                  newObject.cellBorderColorActive = this.cellBorderColorActive;
                  newObject.cellBorderColorDisabled = this.cellBorderColorDisabled;
                  newObject.indexStyle = this.indexStyle;
                  newObject.setFocusOnRollover = this.setFocusOnRollover;

                  if (xmlAttributeMap){
                    xmlAttribute =  xmlAttributeMap.getNamedItem("hId");
                    if (xmlAttribute != null && xmlAttribute.specified)
                      newObject.hWordId = parseInt(xmlAttribute.value);
                    xmlAttribute =  xmlAttributeMap.getNamedItem("vId");
                    if (xmlAttribute != null && xmlAttribute.specified)
                      newObject.vWordId = parseInt(xmlAttribute.value);
                    xmlAttribute =  xmlAttributeMap.getNamedItem("wordIndex");
                    if (xmlAttribute != null && xmlAttribute.specified)
                      newObject.cellScreenIndex = parseInt(xmlAttribute.value);
                  }

                  newObject.horizontalIndex = horzIndex;
                  newObject.verticalIndex = vertIndex;
                  newObject.rightChar = (trNode.textContent).toUpperCase();
                  var cellId = this.cellObjects.length;
                  mapLine.push(cellId);
                  newObject.id = cellId;
                  this.cellObjects.push(newObject);
                } else {
                  mapLine.push(-1);
                }
                horzOffset += (this.cellWidthNormal + this.cellSpacing);
                horzIndex++;
              };
              trNode = trNode.nextSibling;
            }
            horzIndex = 0;
            horzOffset = 0;
            vertIndex++;
            vertOffset += (this.cellHeightNormal + this.cellSpacing + this.lineSpacing);
            this.cellMap.push(mapLine);
          };
          dataNode = dataNode.nextSibling;
        }
      } else if(xmlNode.nodeName == "actions"){
        this.onWordCompleteActions      = scene.Utils.parseActionsNode(xmlNode, "onWordComplete");
        this.onWordCompleteWrongActions = scene.Utils.parseActionsNode(xmlNode, "onWordCompleteWrong");
        this.onCrosswordCompleteActions = scene.Utils.parseActionsNode(xmlNode, "onCrosswordComplete");
        this.onCrosswordWrongActions    = scene.Utils.parseActionsNode(xmlNode, "onCrosswordWrong");
        this.onShowActions              = scene.Utils.parseActionsNode(xmlNode, "onShow");
      }
      xmlNode = xmlNode.nextSibling;
    };

  //  массив, облегчающий проверку всего кроссворда по требованию
    this.wordsStartCells = new Array();

  //  проходим карту и записываем индексы соседей
    for(var i = 0; i < this.cellMap.length; i++){
      for(var j = 0; j < this.cellMap[i].length; j++){
        if(this.cellMap[i][j] >= 0){
          var cellIndex = this.cellMap[i][j];
          var leftCell = -1;
          var topCell = -1;
          var rightCell = -1;
          var bottomCell = -1;
          if( j > 0 && this.cellMap[i][j-1] >= 0){
            leftCell = this.cellMap[i][j-1];
          }
          if(i > 0 && this.cellMap[i-1][j] >= 0){
            topCell = this.cellMap[i-1][j];
          }
          if(j < (this.cellMap[i].length - 1) && this.cellMap[i][j+1] && this.cellMap[i][j+1] >= 0){
            rightCell = this.cellMap[i][j+1];
          }
          if(i < (this.cellMap.length - 1) && this.cellMap[i+1][j] >= 0){
            bottomCell = this.cellMap[i+1][j];
          }
          if(leftCell >= 0 || rightCell >= 0){
            if(leftCell == - 1 && rightCell >= 0){
              this.cellObjects[cellIndex].horizontalWordComponent = CROSSWORD_H_START;
              ++this.resultsParam.N; // увеличиваем счетчик правильных ответов (слов) в задании
              if(this.wordsStartCells.indexOf(cellIndex) < 0)
                this.wordsStartCells.push(cellIndex);
            } else if(leftCell >= 0 && rightCell == -1){
              this.cellObjects[cellIndex].horizontalWordComponent = CROSSWORD_H_END;
            } else if(leftCell >= 0 && rightCell >= 0){
              this.cellObjects[cellIndex].horizontalWordComponent = CROSSWORD_H_MIDDLE;
            }
          } else {
            this.cellObjects[cellIndex].horizontalWordComponent = -1;
          }
          if(topCell >= 0 || bottomCell >= 0){
            if(topCell == - 1 && bottomCell >= 0){
              this.cellObjects[cellIndex].verticalWordComponent = CROSSWORD_V_START;
              ++this.resultsParam.N; // увеличиваем счетчик правильных ответов (слов) в задании
              if(this.wordsStartCells.indexOf(cellIndex) < 0)
                this.wordsStartCells.push(cellIndex);
            } else if(topCell >= 0 && bottomCell == -1){
              this.cellObjects[cellIndex].verticalWordComponent = CROSSWORD_V_END;
            } else if(topCell >= 0 && bottomCell >= 0){
              this.cellObjects[cellIndex].verticalWordComponent = CROSSWORD_V_MIDDLE;
            }
          } else {
            this.cellObjects[cellIndex].verticalWordComponent = -1;
          }

          this.cellObjects[cellIndex].previousHorizontalCell = leftCell;
          this.cellObjects[cellIndex].nextHorizontalCell = rightCell;
          this.cellObjects[cellIndex].previousVerticalCell = topCell;
          this.cellObjects[cellIndex].nextVerticalCell = bottomCell;
        }
      }
    }
    return true;
  };

  function showObject(){
    for(var i = 0; i < this.cellObjects.length; i++){	
      this.cellObjects[i].showObject();
    }
    this.depth = this.objectDepth;

    if(!this.inputBox){
      this.inputBox = new Text(); //Input();
      this.inputBox.visible = false;
      this.inputBox.width = 1;
      this.inputBox.height = 1;
      this.inputBox.depth = -5;
      this.inputBox.parent = this;
      if(this.cellBgColor)
        this.inputBox.bkgColor = this.cellBgColorNormal;
      this.inputBox.onKeyDown = this.onKeyDownHandlerAlias;
      this.inputBox.onKeyUp = this.onKeyUpHandlerAlias;
      //this.inputBox.visible = true;
      this.inputBox.id = "INPUT_BOX";
      setFocus(this.inputBox);
    }
    this.setInputFocus(this.currentCellId);
    this.visible = true;

    if(this.onShowActions){
      for(var i = 0; i < this.onShowActions.length; i++){
        parent.dispatchAction(this.onShowActions[i]);
      }
    }
  }

  function hideObject(){
    if(this.inputBox){
      this.inputBox.parent = null;
      this.inputBox = null;
    }
    for(var i = 0; i < this.cellObjects.length; i++){
      this.cellObjects[i].hideObject();
    }
    this.visible = false;

    if (this.timer_id){
      clearTimeout(this.timer_id);
      this.timer_id = 0;
    }
  }

  function checkObject(){
    ++this.resultsParam.M; // увеличиваем число попыток
    this.testCrosswordComplete(true);
  }
  
  function resetObject() {
    this.resetCrossword();
    rnmc_stdMediaObject_resetObject();
  }

//  проверяет заполненность всего кроссворда, и если всё заполнено правильно,
//  то выполняет действия onCrosswordCompleteActions
//  Если checkWord == true - выбрасываются сообщения для каждого (не)правльного введеного слова,
//  в противном случае (если false или не определено) - нет
  function testCrosswordComplete(checkWord){
    if (this.crosswordComplete)
      return;
      
    var errCells = 0;
    for(var i = 0; i < this.cellObjects.length; i++){
      if(this.cellObjects[i].currentChar == ""
        || this.cellObjects[i].rightChar.toLowerCase().indexOf(this.cellObjects[i].currentChar.toLowerCase()) == -1)
        errCells++;
    }

    if (checkWord == true)
    {
      var wrongWords = 0;
      for(var i = 0; i < this.cellObjects.length; i++){
        if(this.cellObjects[i].verticalWordComponent == CROSSWORD_V_START ||
          this.cellObjects[i].horizontalWordComponent == CROSSWORD_H_START){
          wrongWords += this.checkWordsWithCell(i);
        }
      }
    }

  // что-бы события выполнялись после отображения, введенного слова
  // запускаем таймер который произведет выполнение этих действий асинхронно
    if(errCells == 0 && !this.crosswordComplete){
      this.crosswordComplete = true;
      if(this.onCrosswordCompleteActions)
        this.timer_id = setTimeout("this.doCompleteActions()", 10);
    }else if (!this.checkImmediately) {//Возникли ошибки
    // если не установлен режим "проверка сразу" (toha)
      if(this.onCrosswordWrongActions)
        this.timer_id = setTimeout("this.doWrongActions()", 10);
    }
  }
 
  function doCompleteActions() {
    clearTimeout(this.timer_id);
    this.timer_id = 0;
    if(this.onCrosswordCompleteActions){
      for(var i = 0; i < this.onCrosswordCompleteActions.length; i++){
        parent.dispatchAction(this.onCrosswordCompleteActions[i]);
      }
    }  
  }

  function doWrongActions() {
    clearTimeout(this.timer_id);
    this.timer_id = 0;
    if(this.onCrosswordWrongActions){
      for(var i = 0; i < this.onCrosswordWrongActions.length; i++){
        parent.dispatchAction(this.onCrosswordWrongActions[i]);
      }
    }  
  }

//  сброс кроссворда
  function resetCrossword(){
	// Сброс результирующих данных
    this.resultsParam = {
		  M: 0,          // число попыток
		  P: "unknown",  // число всех вариантов
		  N: 0,          // число всех правильных ответов
		  n: 0,          // число выбранных правильных ответов
		  k: 0,          // число выбранных неправильных ответов
		  t: 0           // время выполнения задания
		}

    for(var i = 0; i < this.cellObjects.length; i++){
      this.cellObjects[i].inputEnabled = true;
      this.cellObjects[i].resetCell();
    }
    this.crosswordComplete = false;
  }

//  обработчик сообщения от ячейки что по ней щёлкнули
  function notifyCellSelected(cellId){
    this.cellObjects[this.currentCellId].releaseInputFocus();
    this.currentCellId = cellId;
    this.cellObjects[this.currentCellId].setInputFocus();
    this.fillDirection = -1;
    setFocus(this.inputBox);
  }

//  устанавдивает инпут фокус на ячейку с id равным cellId
  function setInputFocus(cellId){
    if(cellId >=0 && cellId < this.cellObjects.length){
      this.cellObjects[cellId].setInputFocus();
    }
  }

  function releaseInputFocus(cellId){
    if(cellId >=0 && cellId < this.cellObjects.length){
      this.cellObjects[cellId].releaseInputFocus();
    }
  }

//  Input box event dispatchers
  function onKeyDownHandlerAlias(){
    onKeyDownHandler();
  }

  function onKeyUpHandlerAlias(){
    onKeyUpHandler();
  }

  function onKeyDownHandler(){
    switch(Key.keyCode){
    case 8:     //  BACKSPACE
    case 46:    //  DELETE
      if(this.cellObjects[this.currentCellId].inputEnabled){
        this.cellObjects[this.currentCellId].setNewChar("");
      }
      break;
    case 13:    //  ENTER
      break;
    case 37:
      //  LEFT ARROW
      if(this.cellObjects[this.currentCellId].previousHorizontalCell >= 0){
        this.releaseInputFocus(this.currentCellId);
        this.currentCellId = this.cellObjects[this.currentCellId].previousHorizontalCell;
        this.setInputFocus(this.currentCellId);
      }
      break;
    case 38:
      //  UP ARROW
      if(this.cellObjects[this.currentCellId].previousVerticalCell >= 0){
        this.releaseInputFocus(this.currentCellId);
        this.currentCellId = this.cellObjects[this.currentCellId].previousVerticalCell;
        this.setInputFocus(this.currentCellId);
      }
      break;
    case 39:
      //  RIGHT ARROW
      if(this.cellObjects[this.currentCellId].nextHorizontalCell >= 0){
        this.releaseInputFocus(this.currentCellId);
        this.currentCellId = this.cellObjects[this.currentCellId].nextHorizontalCell;
        this.setInputFocus(this.currentCellId);
      }
      break;
    case 40:
      //  DOWN ARROW
      if(this.cellObjects[this.currentCellId].nextVerticalCell >= 0){
        this.releaseInputFocus(this.currentCellId);
        this.currentCellId = this.cellObjects[this.currentCellId].nextVerticalCell;
        this.setInputFocus(this.currentCellId);
      }
      break;
    default:
      var curChar = "";
      var unicode_key = Key.getUnicode();
      
      if (unicode_key <= 0)
        break;

      curChar = unescape(scene.Utils.sprintf("%%u%04X",unicode_key));

      this.inputBox.value = curChar;

      if(curChar == "")
        break;
      if(this.currentSymbolTable.indexOf(curChar) < 0)
        break;
      this.cellObjects[this.currentCellId].setNewChar(curChar.toUpperCase());
      //  проверка слова
      if(this.checkImmediately){
        this.checkWordsWithCell(this.currentCellId);
      }
      //  автопереход
      if(this.autoSkip){
        if(this.fillDirection >= 0){
          if(this.fillDirection == CROSSWORD_AUTOSKIP_RIGHT){
            if(this.cellObjects[this.currentCellId].nextHorizontalCell >= 0 &&
              !this.cellObjects[this.cellObjects[this.currentCellId].nextHorizontalCell].horizontalWordChecked){
              this.releaseInputFocus(this.currentCellId);
              this.currentCellId = this.cellObjects[this.currentCellId].nextHorizontalCell;
              this.setInputFocus(this.currentCellId);
            } else if(this.cellObjects[this.currentCellId].nextVerticalCell >= 0 &&
              !this.cellObjects[this.cellObjects[this.currentCellId].nextVerticalCell].verticalWordChecked){
              this.releaseInputFocus(this.currentCellId);
              this.currentCellId = this.cellObjects[this.currentCellId].nextVerticalCell;
              this.setInputFocus(this.currentCellId);
              this.fillDirection = CROSSWORD_AUTOSKIP_DOWN;
            } else {
              this.fillDirection = -1;
            }
          } else if(this.fillDirection == CROSSWORD_AUTOSKIP_DOWN){
            if(this.cellObjects[this.currentCellId].nextVerticalCell >= 0 &&
              !this.cellObjects[this.cellObjects[this.currentCellId].nextVerticalCell].verticalWordChecked){
              this.releaseInputFocus(this.currentCellId);
              this.currentCellId = this.cellObjects[this.currentCellId].nextVerticalCell;
              this.setInputFocus(this.currentCellId);
            } else if(this.cellObjects[this.currentCellId].nextHorizontalCell >= 0 &&
              !this.cellObjects[this.cellObjects[this.currentCellId].nextHorizontalCell].horizontalWordChecked){
              this.releaseInputFocus(this.currentCellId);
              this.currentCellId = this.cellObjects[this.currentCellId].nextHorizontalCell;
              this.setInputFocus(this.currentCellId);
              this.fillDirection = CROSSWORD_AUTOSKIP_RIGHT;
            } else {
              this.fillDirection = -1;
            }
          }
        } else {
          if(this.cellObjects[this.currentCellId].nextHorizontalCell >= 0 &&
              !this.cellObjects[this.cellObjects[this.currentCellId].nextHorizontalCell].horizontalWordChecked){
            this.releaseInputFocus(this.currentCellId);
            this.currentCellId = this.cellObjects[this.currentCellId].nextHorizontalCell;
            this.setInputFocus(this.currentCellId);
            this.fillDirection = CROSSWORD_AUTOSKIP_RIGHT;
          } else if(this.cellObjects[this.currentCellId].nextVerticalCell >= 0 &&
              !this.cellObjects[this.cellObjects[this.currentCellId].nextVerticalCell].verticalWordChecked){
            this.releaseInputFocus(this.currentCellId);
            this.currentCellId = this.cellObjects[this.currentCellId].nextVerticalCell;
            this.setInputFocus(this.currentCellId);
            this.fillDirection = CROSSWORD_AUTOSKIP_DOWN;
          }
        }
      }
      break;
    }
  }

  function onKeyUpHandler(){
  }

//  проверяет слова в которые входит ячкейка с заданным индексом
//  возвращет число неправильных слов, в которые входит эта ячейка (т.е. от 0 до 2 :)))))
  function checkWordsWithCell(memberCellId){
    var currentCellObj = this.cellObjects[memberCellId];
// Количество неправильно заполненых слов - ошибка или незаполнено.
    var wrongWords = 0;
// Количество неправильно введенных полных слов.
	var wrongWordsComplete = 0;
	
    if(currentCellObj.horizontalWordComponent >= 0){
      var wrongCells = 0;
      var notFilledCells = 0;  //  количество незаполненных ячеек
      var wordCells = new Array();
      var previousCell = memberCellId;
      var nextCell = memberCellId;
      var startCellId = null;
      if(this.cellObjects[memberCellId].horizontalWordComponent == CROSSWORD_H_START){
        startCellId = memberCellId;
      }
      wordCells.push(memberCellId);
      if(this.cellObjects[memberCellId].currentChar != ""){
        if(this.cellObjects[memberCellId].rightChar.indexOf(this.cellObjects[memberCellId].currentChar) == -1){
          wrongCells++;
        }
      }else {
        notFilledCells++;
        wrongCells++;
      }      
      while(true){
        if(this.cellObjects[previousCell].previousHorizontalCell >= 0){
          previousCell = this.cellObjects[previousCell].previousHorizontalCell;
        } else {
          break;
        }
        wordCells.push(previousCell)
        if(this.cellObjects[previousCell].horizontalWordComponent == CROSSWORD_H_START){
          startCellId = previousCell;
        }
        if(this.cellObjects[previousCell].currentChar != ""){
          if(this.cellObjects[previousCell].rightChar.indexOf(this.cellObjects[previousCell].currentChar) == -1){
            wrongCells++;
          }
        }else {
          notFilledCells++;
          wrongCells++;
        }
      }
      while(true){
        if(this.cellObjects[nextCell].nextHorizontalCell >= 0){
          nextCell = this.cellObjects[nextCell].nextHorizontalCell;
        } else {
          break;
        }
        wordCells.push(nextCell)
        if(this.cellObjects[nextCell].horizontalWordComponent == CROSSWORD_H_START){
          startCellId = nextCell;
        }
        if(this.cellObjects[nextCell].currentChar != ""){
          if(this.cellObjects[nextCell].rightChar.indexOf(this.cellObjects[nextCell].currentChar) == -1){
            wrongCells++;
          }
        }else {
          notFilledCells++;
          wrongCells++;
        }
      }
      if(wrongCells == 0){
        if(this.cellObjects[memberCellId].horizontalWordChecked == false){
          for(var i = 0; i < wordCells.length; i++){
            this.cellObjects[wordCells[i]].horizontalWordChecked = true;
            this.cellObjects[wordCells[i]].setCellChecked();
          }
          this.cellObjects[this.currentCellId].setInputFocus();

        // вычисляем число правильных ответов
          ++this.resultsParam.n;
          
        //  выкидываем событие составленного слова            
          if(this.cellObjects[startCellId].hWordId && this.onWordCompleteActions){
            for(var i = 0; i < this.onWordCompleteActions.length; i++){
              if(this.onWordCompleteActions[i].eventParam == "all"
                 || this.onWordCompleteActions[i].eventParam == this.cellObjects[startCellId].hWordId){
                parent.dispatchAction(this.onWordCompleteActions[i]);
              }
            }
          }
        }
      } else {

      // Увеличиваем счетчик неверно составленных слов.
        if(notFilledCells == 0 && wrongCells != 0)
          ++wrongWordsComplete;

        if(notFilledCells == 0 && wrongCells != 0 && this.onWordCompleteWrongActions){
          for(var i = 0; i < this.onWordCompleteWrongActions.length; i++){
            if(this.onWordCompleteWrongActions[i].eventParam == this.cellObjects[startCellId].hWordId){
              parent.dispatchAction(this.onWordCompleteWrongActions[i]);
            }
          }
        }
        wrongWords++;
      }
    }
    if(currentCellObj.verticalWordComponent >= 0){
      var wrongCells = 0;
      var notFilledCells = 0;  //  количество незаполненных ячеек
      var wordCells = new Array();
      var previousCell = memberCellId;
      var nextCell = memberCellId;
      var startCellId = null;
      if(this.cellObjects[memberCellId].verticalWordComponent == CROSSWORD_V_START){
        startCellId = memberCellId;
      }
      if(this.cellObjects[memberCellId].currentChar != ""){
        if(this.cellObjects[memberCellId].rightChar.indexOf(this.cellObjects[memberCellId].currentChar) == -1){
          wrongCells++;
        }
      }else {
        notFilledCells++;
        wrongCells++;
      }      
      wordCells.push(memberCellId);
      while(true){
        if(this.cellObjects[previousCell].previousVerticalCell >= 0){
          previousCell = this.cellObjects[previousCell].previousVerticalCell;
        } else {
          break;
        }
        wordCells.push(previousCell)
        if(this.cellObjects[previousCell].verticalWordComponent == CROSSWORD_V_START){
          startCellId = previousCell;
        }
        if(this.cellObjects[previousCell].currentChar != ""){
          if(this.cellObjects[previousCell].rightChar.indexOf(this.cellObjects[previousCell].currentChar) == -1){
            wrongCells++;
          }
        } else {
          notFilledCells++;
          wrongCells++;
        }
      }
      while(true){
        if(this.cellObjects[nextCell].nextVerticalCell >= 0){
          nextCell = this.cellObjects[nextCell].nextVerticalCell;
        } else {
          break;
        }
        wordCells.push(nextCell)
        if(this.cellObjects[nextCell].verticalWordComponent == CROSSWORD_V_START){
          startCellId = nextCell;
        }
        if(this.cellObjects[nextCell].currentChar != ""){
          if(this.cellObjects[nextCell].rightChar.indexOf(this.cellObjects[nextCell].currentChar) == -1){
            wrongCells++;
          }
        }else {
          notFilledCells++;
          wrongCells++;
        }
      }
      if(wrongCells == 0){
        if(this.cellObjects[memberCellId].verticalWordChecked == false){
          for(var i = 0; i < wordCells.length; i++){
            this.cellObjects[wordCells[i]].verticalWordChecked = true;
            this.cellObjects[wordCells[i]].setCellChecked();
          }
          this.cellObjects[this.currentCellId].setInputFocus();

        // вычисляем число правильных ответов
          ++this.resultsParam.n;
          
          //  выкидываем событие составленного слова
          if(this.cellObjects[startCellId].vWordId && onWordCompleteActions){
            for(var i = 0; i < this.onWordCompleteActions.length; i++){
              if(this.onWordCompleteActions[i].eventParam == "all"
                || this.onWordCompleteActions[i].eventParam == this.cellObjects[startCellId].vWordId){
                parent.dispatchAction(this.onWordCompleteActions[i]);
              }
            }
          }
        }
      } else {
        // Увеличиваем счетчик неверно составленных слов.
        if(notFilledCells == 0 && wrongCells != 0)
          ++wrongWordsComplete;

        if(notFilledCells == 0 && wrongCells != 0 && this.onWordCompleteWrongActions){
          for(var i = 0; i < this.onWordCompleteWrongActions.length; i++){
            if(this.onWordCompleteWrongActions[i].eventParam == this.cellObjects[startCellId].vWordId){
              parent.dispatchAction(this.onWordCompleteWrongActions[i]);
            }
          }
        }
        wrongWords++;
      }
    }
    
  // увеличиваем число неправильных ответов
    this.resultsParam.k += wrongWordsComplete;
	
  // увеличиваем количество попыток (по словам)	
	if(this.checkImmediately)
		this.resultsParam.M += wrongWordsComplete

    if (wrongWords == 0)
      this.testCrosswordComplete();
/*
	var str = "this.resultsParam dump == {";
	for (var k in this.resultsParam){
		str += k;
		str += "=";
		str += this.resultsParam[k];
		str += "; ";
	}
	str += "}"
trace(str);
*/
    return wrongWords;
  }

  function getResult(resultsArray){
    var results;
    results = new scene.Utils.resultParam();
    results.init();
    
    results.rightElements = this.resultsParam.n;
    results.allRightElements = this.resultsParam.N;
    results.wrongElements = this.resultsParam.k;
    results.allWrongElements = "unknown";
    results.allElements = "unknown";
    results.isTimeout = this.isOnTimeout;
    
    results.countResult(this.crAlgorithm);
    
    var str = "results = {";
    for (var k in results)
      str += k + "=" + results[k] + "; ";
    trace("#FF0000"+str);
    
    this.objectResult = results.objectResult;
    if(resultsArray && this.crAlgorithm != "none"){
      var resultString = this.objectResult + ";" + this.objectiveWeight;
      resultsArray.push(resultString);
    }
  }
  
  function setObjects(del_x,del_y){
  this.objectX=this.objectX+del_x;
  this.objectY=this.objectY+del_y;
     for(var i = 0; i < this.cellObjects.length; i++){
		this.cellObjects[i].objectX = this.cellObjects[i].objectX + del_x;
        this.cellObjects[i].objectY = this.cellObjects[i].objectY + del_y;	
    }
  }
]]></script>
</composition>

<composition name="crossword_cell">
<script><![CDATA[
//  логическое положение ячейки в кроссворде
  this.rightChar = "";
  this.currentChar = "";

  this.inputEnabled = true;

  this.setFocusOnRollover = false;

  this.cellScreenIndex = -1;
  this.indexStyle = null;
  this.cellIndexObject = null;

  this.hWordId = null;
  this.vWordId = null;

  this.horizontalWordComponent = -1;
  this.verticalWordComponent = -1;

  this.horizontalWordChecked = false;
  this.verticalWordChecked = false;

  this.previousHorizontalCell = -1;
  this.nextHorizontalCell = -1;
  this.previousVerticalCell = -1;
  this.nextVerticalCell = -1;

  this.objectX = 0;
  this.objectY = 0;
  this.cellWidthNormal = 20;
  this.cellWidthActive = 20;
  this.cellWidthDisabled = 20;
  this.cellHeightNormal = 20;
  this.cellHeightActive = 20;
  this.cellHeightDisabled = 20;
  this.cellStyleNormal = null;
  this.cellStyleActive = null;
  this.cellStyleDisabled = null;
  this.cellBorderNormal = 1;
  this.cellBorderActive = 1;
  this.cellBorderDisabled = 1;
  this.cellBgColorNormal = "#FFFFFF";
  this.cellBgColorActive = "#FFFFFF";
  this.cellBgColorDisabled = "#FFFFFF";
  this.cellBorderColorNormal = "#000000";
  this.cellBorderColorActive = "#FF0000";
  this.cellBorderColorDisabled = "#000000";

  this.cellBorderObject = null;

  function showObject(){
    if(!this.objectContent){
      this.objectContent = new Text();
      this.objectContent.bkgColor = this.cellBgColorNormal;
      this.objectContent.adjustHeight = false;
      this.objectContent.x = this.objectX;
      this.objectContent.y = this.objectY;
      this.objectContent.width = this.cellWidthNormal;
      this.objectContent.height = this.cellHeightNormal;
      this.objectContent.depth = 0;
      this.objectContent.style = this.cellStyleNormal;
      this.objectContent.visible = true;
      this.objectContent.parent = this;
      this.objectContent.onPress = this.onPressHandlerAlias;
      if(this.setFocusOnRollover){
        this.objectContent.onRollOver = this.onRollOverHandlerAlias;
      }
      if(this.cellScreenIndex > 0){
        this.cellIndexObject = new Text();
        this.cellIndexObject.adjustHeight = false;
        this.cellIndexObject.x = this.objectContent.x + 2;
        this.cellIndexObject.y = this.objectContent.y + 2;
        this.cellIndexObject.width = this.cellWidthNormal;
        this.cellIndexObject.height = this.cellHeightNormal;
        this.cellIndexObject.enabled = false;
        this.cellIndexObject.depth = -2;
        if(this.indexStyle)
          this.cellIndexObject.style = this.indexStyle;
        this.cellIndexObject.value = this.cellScreenIndex + ".";
        this.cellIndexObject.visible = true;
        this.cellIndexObject.parent = this;
      }
    }
  //  рамка
    if(!this.cellBorderObject){
      this.cellBorderObject = new Text();
      this.cellBorderObject.bkgColor = this.cellBorderColorNormal;
      this.cellBorderObject.adjustHeight = false;
      this.cellBorderObject.x = this.objectX - this.cellBorderNormal;
      this.cellBorderObject.y = this.objectY - this.cellBorderNormal;
      this.cellBorderObject.width = this.cellWidthNormal + (2*this.cellBorderNormal);
      this.cellBorderObject.height = this.cellHeightNormal + (2*this.cellBorderNormal);
      this.cellBorderObject.depth = 5;
      this.cellBorderObject.visible = true;
      this.cellBorderObject.parent = this;
    }
    this.depth = 0;
  }

  function hideObject(){
    if(this.objectContent){
      this.objectContent.parent = null;
      this.objectContent = null;
    }
    if(this.cellBorderObject){
      this.cellBorderObject.parent = null;
      this.cellBorderObject = null;
    }
  }

  function setInputFocus(){
    if(this.inputEnabled){
      if(this.objectContent){
        this.objectContent.bkgColor = this.cellBgColorActive;
        this.objectContent.x = this.objectX
          - parseInt((this.cellWidthActive - this.cellWidthNormal)/2);
        //  BUG в 1-ой версии плеера - при введённом символе надо поднимать на 1 пиксел
        //  во второй этого не надо. Во второй версии появилось свойство Player.version,
        //  проверяя его наличие можно понять какой плеер
        if(this.currentChar != ""){
          if(Player.version){
            this.objectContent.y = this.objectY
              - parseInt((this.cellHeightActive - this.cellHeightNormal)/2);
          } else {
            this.objectContent.y = this.objectY
              - parseInt((this.cellHeightActive - this.cellHeightNormal)/2) - 1;
          }
        } else {
          this.objectContent.y = this.objectY
            - parseInt((this.cellHeightActive - this.cellHeightNormal)/2);
        }
        this.objectContent.width = this.cellWidthActive;
        this.objectContent.height = this.cellHeightActive;
        this.objectContent.style = this.cellStyleActive;
        if(this.cellIndexObject){
          this.cellIndexObject.x = this.objectContent.x + 2;
          this.cellIndexObject.y = this.objectContent.y + 2;
        }
      }
      if(this.cellBorderObject){
        this.cellBorderObject.visible = false;
        this.cellBorderObject.bkgColor = this.cellBorderColorActive;
        this.cellBorderObject.x =
          this.objectX - parseInt((this.cellWidthActive - this.cellWidthNormal)/2)
          - this.cellBorderActive;
        this.cellBorderObject.y =
          this.objectY - parseInt((this.cellHeightActive - this.cellHeightNormal)/2)
          - this.cellBorderActive;
        this.cellBorderObject.width = this.cellWidthActive + (2*this.cellBorderActive);
        this.cellBorderObject.height = this.cellHeightActive + (2*this.cellBorderActive);
        this.cellBorderObject.visible = true;
      }
    } else {
      if(this.objectContent){
        if(this.cellIndexObject){
          this.cellIndexObject.x = this.objectContent.x + 2;
          this.cellIndexObject.y = this.objectContent.y + 2;
        }
      }
      if(this.cellBorderObject){
        this.cellBorderObject.visible = false;
        this.cellBorderObject.bkgColor = this.cellBorderColorActive;
        this.cellBorderObject.x = this.objectX - this.cellBorderActive;
        this.cellBorderObject.y = this.objectY - this.cellBorderActive;
        this.cellBorderObject.width = this.cellWidthDisabled + (2*this.cellBorderActive);
        this.cellBorderObject.height = this.cellWidthDisabled + (2*this.cellBorderActive);
        this.cellBorderObject.visible = true;
      }
    }
    this.depth = -100;
  }

  function releaseInputFocus(){
    if(this.inputEnabled){
      if(this.objectContent){
        this.objectContent.bkgColor = this.cellBgColorNormal;
        this.objectContent.x = this.objectX;
      //  BUG в 1-ой версии плеера - при введённом символе надо поднимать на 1 пиксел
      //  во второй этого не надо. Во второй версии появилось свойство Player.version,
      //  проверяя его наличие можно понять какой плеер
        if(this.currentChar != ""){
          if(Player.version){
            this.objectContent.y = this.objectY;
          } else {
            this.objectContent.y = this.objectY - 1;
          }
        } else {
          this.objectContent.y = this.objectY;
        }
        this.objectContent.width = this.cellWidthNormal;
        this.objectContent.height = this.cellHeightNormal;
        this.objectContent.style = this.cellStyleNormal;
        if(this.cellIndexObject){
          this.cellIndexObject.x = this.objectContent.x + 2;
          this.cellIndexObject.y = this.objectContent.y + 2;
        }
      }
      if(this.cellBorderObject){
        this.cellBorderObject.visible = false;
        this.cellBorderObject.bkgColor = this.cellBorderColorNormal;
        this.cellBorderObject.x = this.objectX - this.cellBorderNormal;
        this.cellBorderObject.y = this.objectY - this.cellBorderNormal;
        this.cellBorderObject.width = this.cellWidthNormal + (2*this.cellBorderNormal);
        this.cellBorderObject.height = this.cellHeightNormal + (2*this.cellBorderNormal);
        this.cellBorderObject.visible = true;
      }
    } else {
      if(this.objectContent){
        this.objectContent.x = this.objectX;
        //  BUG в 1-ой версии плеера - при введённом символе надо поднимать на 1 пиксел
        //  во второй этого не надо. Во второй версии появилось свойство Player.version,
        //  проверяя его наличие можно понять какой плеер
        if(this.currentChar != ""){
          if(Player.version){
            this.objectContent.y = this.objectY;
          } else {
            this.objectContent.y = this.objectY - 1;
          }
        } else {
          this.objectContent.y = this.objectY;
        }
        this.objectContent.width = this.cellWidthDisabled;
        this.objectContent.height = this.cellHeightDisabled;
        this.objectContent.style = this.cellStyleDisabled;
        if(this.cellIndexObject){
          this.cellIndexObject.x = this.objectContent.x + 2;
          this.cellIndexObject.y = this.objectContent.y + 2;
        }
      }
      if(this.cellBorderObject){
        this.cellBorderObject.visible = false;
        this.cellBorderObject.bkgColor = this.cellBorderColorDisabled;
        this.cellBorderObject.x = this.objectX - this.cellBorderDisabled;
        this.cellBorderObject.y = this.objectY - this.cellBorderDisabled;
        this.cellBorderObject.width = this.cellWidthDisabled + (2*this.cellBorderDisabled);
        this.cellBorderObject.height = this.cellHeightDisabled + (2*this.cellBorderDisabled);
        this.cellBorderObject.visible = true;
      }
    }
    this.depth = 0;
  }

  function setNewChar(newChar){
    if(this.inputEnabled){
      this.objectContent.value = newChar;
      this.currentChar = newChar;
      this.objectContent.x = this.objectX
        - parseInt((this.cellWidthActive - this.cellWidthNormal)/2);
      //  BUG в 1-ой версии плеера - при введённом символе надо поднимать на 1 пиксел
      //  во второй этого не надо. Во второй версии появилось свойство Player.version,
      //  проверяя его наличие можно понять какой плеер
      if(this.currentChar != ""){
        if(Player.version){
          this.objectContent.y = this.objectY
            - parseInt((this.cellHeightActive - this.cellHeightNormal)/2);
        } else {
          this.objectContent.y = this.objectY
            - parseInt((this.cellHeightActive - this.cellHeightNormal)/2) - 1;
        }
      } else {
        this.objectContent.y = this.objectY
          - parseInt((this.cellHeightActive - this.cellHeightNormal)/2);
      }
      this.objectContent.width = this.cellWidthActive;
      this.objectContent.height = this.cellHeightActive;
    }
  }

  function resetCell(){
    this.currentChar = "";
    this.horizontalWordChecked = false;
    this.verticalWordChecked = false;
    if(this.objectContent){
      this.objectContent.value = "";
      this.objectContent.bkgColor = this.cellBgColorNormal;
      this.objectContent.x = this.objectX;
      this.objectContent.y = this.objectY;
      this.objectContent.width = this.cellWidthNormal;
      this.objectContent.height = this.cellHeightNormal;
      this.objectContent.style = this.cellStyleNormal;
      this.objectContent.visible = true;
      if(this.cellIndexObject){
        this.cellIndexObject.x = this.objectContent.x + 2;
        this.cellIndexObject.y = this.objectContent.y + 2;
      }
    }
    if(this.cellBorderObject){
      this.cellBorderObject.bkgColor = this.cellBorderColorNormal;
      this.cellBorderObject.x = this.objectX - this.cellBorderNormal;
      this.cellBorderObject.y = this.objectY - this.cellBorderNormal;
      this.cellBorderObject.width = this.cellWidthNormal + (2*this.cellBorderNormal);
      this.cellBorderObject.height = this.cellHeightNormal + (2*this.cellBorderNormal);
      this.cellBorderObject.visible = true;
    }
    this.depth = 0;
  }

  function setCellChecked(){
    this.inputEnabled = false;
    if(this.objectContent){
      this.objectContent.bkgColor = this.cellBgColorDisabled;
      this.objectContent.style = this.cellStyleDisabled;
      
      this.objectContent.x = this.objectX;
    //  BUG в 1-ой версии плеера - при введённом символе надо поднимать на 1 пиксел
    //  во второй этого не надо. Во второй версии появилось свойство Player.version,
    //  проверяя его наличие можно понять какой плеер
      if(this.currentChar != ""){
        if(Player.version){
          this.objectContent.y = this.objectY;
        } else {
          this.objectContent.y = this.objectY - 1;
        }
      } else {
        this.objectContent.y = this.objectY;
      }
      this.objectContent.width = this.cellWidthDisabled;
      this.objectContent.height = this.cellHeightDisabled;
      if(this.cellIndexObject){
        this.cellIndexObject.x = this.objectContent.x + 2;
        this.cellIndexObject.y = this.objectContent.y + 2;
      }
    }
    if(this.cellBorderObject){
      this.cellBorderObject.visible = false;
      this.cellBorderObject.bkgColor = this.cellBorderColorDisabled;
      this.cellBorderObject.x = this.objectX - this.cellBorderDisabled;
      this.cellBorderObject.y = this.objectY - this.cellBorderDisabled;
      this.cellBorderObject.width = this.cellWidthDisabled + (2*this.cellBorderDisabled);
      this.cellBorderObject.height = this.cellHeightDisabled + (2*this.cellBorderDisabled);
      this.cellBorderObject.visible = true;
    }
    this.depth = 0;
  }

  function onPressHandlerAlias(){
    onPressHandler();
  }

  function onPressHandler(){
    parent.notifyCellSelected(this.id);
  }

  function onRollOverHandlerAlias(){
    onRollOverHandler();
  }

  function onRollOverHandler(){
    if(this.setFocusOnRollover){
      parent.notifyCellSelected(this.id);
    }
  }
]]> </script>
</composition>

</rmml>
