//---------------------------------------------------------------------------------
//  (c) 2007 Guardian Networks, Inc
//---------------------------------------------------------------------------------

GNgui.GNCheckBox = Class.create();
GNgui.GNCheckBox.prototype = 
{
	initialize : function ( parentElement, text, id, state, drawBlackBar, endCheckBox)
	{
	  this.refreshState = false;
	  if (state > 0)
	  {
	    this.state = true;
	  }
	  else
	  {
	    this.state = false;
	  }
	  
	  this.BaseID = id;


	var DataTable = $e(parentElement);
	var row = null;
	var Cell = null;

    if ( drawBlackBar == true )
    {
      row = DataTable.insertRow ( DataTable.rows.length );
      Cell = row.insertCell ( 0 );
      Cell.colspan="3";
      Cell.innerHtml = "<img src='./" + TARGET + "/images/c_div.gif' width='201' height='1' border='0'>"; 
    }

  	row = DataTable.insertRow ( DataTable.rows.length );
  	row.id = "row"+id;
    row.className = "MapOverlayRow";
    var Cell = row.insertCell ();
    Cell.width = "22";
    Cell.innerHTML = "<img src='./" + TARGET + "/images/c_checkbox_off.gif' width='22' height='18' border='0'>";
    Cell.id = id;
    Cell.style.cursor='pointer';
    Event.observe(id, 'click', GNgui.GNCheckBox.prototype.MouseClick.bindAsEventListener(this));

    Cell = row.insertCell ();
    Cell.className = "MapOverlayTextOff";
    Cell.innerText = text;
    Cell.id = "Cell"+id;
    Cell.style.cursor='none';

    if (endCheckBox == true) {
      Cell = row.insertCell ();
      Cell.width = "22";
      Cell.innerHTML = "<img alt='Auto Refresh' src='./" + TARGET + "/images/c_checkbox_on.gif' width='22' height='18' border='0'>";
      Cell.id = "Refresh"+id;
      Cell.style.cursor='pointer';
      this.refreshState = true;

      Event.observe("Refresh"+id, 'click', GNgui.GNCheckBox.prototype.RefreshMouseClick.bindAsEventListener(this));
    }
    else {
      Cell = row.insertCell ();
      Cell.width = "22";
      Cell.innerHTML = "&nbsp;";
      Cell.id = "Refresh"+id;
      Cell.style.cursor='pointer';
    }

    this.ChangeState();
	},
	
	ID : function ()
	{
		return this.newdiv.id;
	},
	
	MouseClick : function ()
	{
	  if (this.state)
	  {
	    if (AvailableAssets > 1)
	    {
	        this.state = false;
            AvailableAssets--;
        }
        else
        {
            alert('You must have at least one Overlay selected.');
            return;
        }
	  }
	  else
	  {
	    this.state = true;
        AvailableAssets++;
	  }
	  
	  this.ChangeState();

	  this.refreshState = this.state;
	  this.RefreshChangeState();

    },

    RefreshMouseClick : function ()
    {
      if (this.refreshState)
      {
	    this.refreshState = false;
      }
      else
      {
	    this.refreshState = true;
      }

	  this.RefreshChangeState();
    },
    
    RefreshChangeState : function ()
    {
      if (this.refreshState)
      {
        $e("Refresh"+this.BaseID).innerHTML = "<img src='./" + TARGET + "/images/c_checkbox_on.gif' width='22' height='18' border='0'>";
      }
      else
      {
        $e("Refresh"+this.BaseID).innerHTML = "<img src='./" + TARGET + "/images/c_checkbox_off.gif' width='22' height='18' border='0'>";
      }
    },

    ChangeState : function ()
    {
      if (this.state)
      {
        $e("row"+this.BaseID).bgColor = "#1d1d1c";
        $e("Cell"+this.BaseID).className = "MapOverlayTextOn";
        $e(this.BaseID).innerHTML = "<img src='./" + TARGET + "/images/c_checkbox_on.gif' width='22' height='18' border='0'>";
      }
      else
      {
        $e("row"+this.BaseID).bgColor = "#292a28";
        $e("Cell"+this.BaseID).className = "MapOverlayTextOff";
        $e(this.BaseID).innerHTML = "<img src='./" + TARGET + "/images/c_checkbox_off.gif' width='22' height='18' border='0'>";
      }
    }
}
