// Copyright 1998 Macromedia, Inc. All rights reserved.
//Constructs a hot area element
function KO_hota(theParent, theName, theInitialValue,
                 theExpectedValue, theIsCorrect, theScore) {
  // properties
  this.initialValue = theInitialValue;
  this.value = '';
  this.disabled = false;

  this.expectedValue = theExpectedValue;
  this.isCorrect = theIsCorrect;
  this.score = theScore;
  this.selected = false;

  this._parent = theParent;
  this._name = theName;
  this._self = theParent._self+".e['"+theName+"']";
  this._obj = '';
	
  this.c = new Array(this); // NOTE: choice info stored on the element.

  // member functions
  this.reset = KO_hotaReset;
  this.init = KO_hotaInit;
  this.initBackdrop = KO_hotaInitBackdrop;
  this.enable = KO_hotaEnable;
  this.disable = KO_hotaDisable;
  this.setDisabled = KO_hotaSetDisabled;
  this.update = KO_hotaUpdate;
  this.validValue = KO_hotaValidValue;
  this.changeValue = KO_hotaChangeValue;
  this.setValue = KO_hotaSetValue;
  this.setSelected = KO_hotaSetSelected;
  
}

//Resets the element
function KO_hotaReset() {
  if (this._obj) with (this) {
    value = initialValue;
    disabled = _parent.disabled;
    validValue();
  }
}

function KO_hotaInit() {
  with (this) {
    _obj = KO_findObject(_parent._self + _name); //find slider layer object
    if (_obj)
      MM_dragLayer(_obj,_obj,0,0,0,0,true,false,0,0,0,0,false,false,0,_self + '.update()',true);
    initBackdrop();
  }
}

function KO_hotaInitBackdrop() {
  var theObj;
  if (this._parent.bdInited == null) with (this) {
    _parent.bdInited = true;
    theObj = KO_findObject(_parent._self + "backdrop"); // find backdrop layer object
    if (theObj) {
      document.allLayers = null;
      MM_dragLayer(theObj,theObj,0,0,0,0,false,false,0,0,0,0,false,false,0,
                   "KO_hotaUpdateBackdrop(" + _parent._self + ")",true);
  } }
}

//Enables the element
function KO_hotaEnable() {
  if (this._obj) with (this) {
    disabled = false;
  }
}

//Disables the element
function KO_hotaDisable() {
  this.disabled = true;
}

//Calls the approppriate disable or enable function
function KO_hotaSetDisabled(theDisabled) {
  if (theDisabled) this.disable();
  else this.enable();
}

//Called by onClick event to update this elements value
function KO_hotaUpdate() {
  if (!this.disabled) with (this) {
    changeValue((_parent.allowMultiSel) ? !value : true);
    _parent.update();  // call the parent's update
  }
}

function KO_hotaValidValue() {
  this.selected = (this.value == this.expectedValue);
  return this.selected;
}

function KO_hotaChangeValue(theValue) {
  var i;
  with (this) {
    if (!_parent.allowMultiSel) {
      value = theValue;
      for (i in _parent.e) if (i != 'length') with (_parent) {
        if (e[i] != this) e[i].value = false;
        e[i].validValue();
      }
    } else {
      value = theValue;
      validValue();
  } }
}

function KO_hotaSetValue(theValue) {
  with (this) {
    changeValue(theValue);
    _parent.update(true); // update int, but don't judge
  }
}

function KO_hotaSetSelected(theSelected) {
  if (theSelected)
    this.setValue(this.expectedValue);
  else
    this.setValue(!this.expectedValue);
}

function KO_hotaUpdateBackdrop(theParent) {
  if (!theParent.allowMultiSel) {
    theParent.resetElems();
    theParent.update();
  }
}
