// © 2004-2007, Applied Geographics, Inc.  All rights reserved.

function StyleOption(groupName, id, postBack, normalClass, overClass, 
    selectedClass, clientScript) {
  this.groupName = groupName;
  this.id = id;
  this.button = document.getElementById(id + "_button");
  
  this.postBack = postBack;
  this.clientScript = clientScript;
  
  this.normalClass = normalClass;
  this.overClass = overClass;
  this.selectedClass = selectedClass;
  
  if (this.isSelected())
    StyleOption.selected[this.groupName] = this;
  else {
    if (StyleOption.selected[this.groupName] == undefined)
      StyleOption.selected[this.groupName] = null;
  }
};

StyleOption.selected = [];

StyleOption.execute = function(clientScript, postBack) {
  if (clientScript != "")
    eval(clientScript);
  if (postBack != "")
    eval(postBack);
};

StyleOption.prototype.isSelected = function() {
  return this.getHiddenField().value == this.id;
};

StyleOption.prototype.getHiddenField = function() {
  var name = "__StyleOption";
  if (this.groupName != "")
    name += "_" + this.groupName;
  return document.getElementById(name);
};

StyleOption.prototype.mouseDown = function() {
  if (!this.isSelected()) {
    this.select();
  }
};

StyleOption.prototype.mouseOut = function() {
  if (!this.isSelected())
    this.button.className = this.normalClass;
};

StyleOption.prototype.mouseOver = function() {
  if (!this.isSelected())
    this.button.className = this.overClass;
};

StyleOption.prototype.select = function() {
  if (!this.isSelected()) {
    if (StyleOption.selected[this.groupName] != null) {
      StyleOption.selected[this.groupName].unselect();
    }
  }
  
  this.getHiddenField().value = this.id;
  StyleOption.selected[this.groupName] = this;
  this.button.className = this.selectedClass;

  setTimeout("StyleOption.execute(\"" + this.clientScript + "\", \"" + this.postBack + "\")", 50);
};

StyleOption.prototype.unselect = function() {
  this.getHiddenField().value = "";
  StyleOption.selected[this.groupName] = null;
  this.button.className = this.normalClass;
};

