function init() {
  var RG = new kTable();
}

var kTable = Class.create();
kTable.prototype = {
  initialize: function() {
    $A(document.getElementsByTagName('TR')).each(function(row) {
      if($(row).readAttribute('idproduct') > 0){
        RatesRow = new kRow(row);
      }
    });
  }
};

var kRow = Class.create();
kRow.prototype = {
  initialize: function(row) {
    this.row = row;
    this.OverColor = '#CCCCCC';
    this.OffColor = '#eaf5d4';
    this.row.onmouseover = this.handleOnMouseOver.bindAsEventListener(this);
    this.row.onmouseout = this.handleOnMouseOut.bindAsEventListener(this);
    this.row.onclick = this.handleOnClick.bindAsEventListener(this);
  },
  handleOnClick: function(event) {
  	var el = $(Event.element(event));
    if(el.readAttribute('rateSq')=='true') {
    	   //- goto Product page.
    
      var AgentCode = ($('agent_code').value=='') ? 'www.' : $('agent_code').value+'.';
      var target = Event.element(event).up().down().down().down().readAttribute('href');
//      document.location='http://'+AgentCode+'standbycairns.com.dev/'+target;

      document.location='http://'+AgentCode+'standbycairns.com/'+target;

      //document.location='http://'+AgentCode+'standbycairns.com.dev/booking?idsupplier='+$('idsupplier').value+'&idproduct='+$(Event.element(event)).readAttribute('idproduct')+'&type=Accommodation&date='+$(Event.element(event)).readAttribute('date');
      //document.location='https://secure.standbycairns.com/booking?idsupplier='+$('idsupplier').value+'&idproduct='+$(Event.element(event)).readAttribute('idproduct')+'&type=Accommodation&date='+$(Event.element(event)).readAttribute('date')+'&r='+AgentCode;

    }
  },
  handleOnMouseOver: function(event) {
    $A($(this.row).descendants()).each(function(cell) {
      if(cell.readAttribute('rateSq')=='true' && cell.readAttribute('unavailable') != 'true')
		$(cell).setStyle({backgroundImage:'url(../images/grid_blue.gif)', cursor:'pointer'});
		else 
        $(cell).setStyle({cursor:'pointer'});
    });
    ShowDetails(event);
//    $('rate_name_'+this.row.readAttribute('idproduct')).setStyle({fontWeight:'bold',color:'#000'});
   // $(Event.element(event)).up().setStyle({backgroundColor:'#fcffb1'});
  // $(cell).setStyle({backgroundImage:'url(../images/grid_prbl.gif)'});
  },
  handleOnMouseOut: function(event) {
    $A($(this.row).descendants()).each(function(cell) {
      if(cell.readAttribute('rateSq')=='true') {
        if(cell.readAttribute('unavailable')=='true')
          //$(cell).setStyle({backgroundColor:'#ecf6d9'});
		  $(cell).setStyle({backgroundColor:'#eaf5d4'});
        else
		$(cell).setStyle({backgroundImage:'url(../images/grid_green.gif)', cursor:'pointer'});
        
      }
    });
    //$(Event.element(event)).up().setStyle({backgroundColor:'#FFF'});
//    $('rate_name_'+this.row.readAttribute('idproduct')).setStyle({fontWeight:'normal',color:'#6D6D6D'});
    HideDetails();
  }
};

function BookOpen(event) {
   document.location='/booking?idproduct='+$(Event.element(event)).readAttribute('idproduct')+'&type=Open&date='+$(Event.element(event)).readAttribute('date');
}

