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 = '#8DCA19';
    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 AgentCode = ($('agent_code').value=='') ? '' : $('agent_code').value;
    if($(Event.element(event)).readAttribute('id') >= 0) {
//      document.location='http://newstandbycairns.dev/booking?idsupplier='+$('idsupplier').value+'&idproduct='+$(Event.element(event)).readAttribute('idproduct')+'&type=Accommodation&date='+$(Event.element(event)).readAttribute('date')+'&r='+AgentCode;
      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;
    }else {
    	document.location='http://www.standbycairns.com/booking?idproduct='+$(Event.element(event)).readAttribute('idproduct')+'&type=Open&date='+$(Event.element(event)).readAttribute('date')+'&r='+AgentCode;
    }
  },
  handleOnMouseOver: function(event) {
	  
	/** @wayne - buzz (unreliable) - look for a variable in the form */
    var onProd = false; if(document.forms['varform'].prodpage.value == 'true') { onProd = true; }
	
    $A($(this.row).childElements()).each(function(cell) {
			$(cell).setStyle({cursor:'pointer'});			
		    if(cell.readAttribute('soldout')!='true') {
				if(!onProd) { $(cell).setStyle({backgroundImage:'url(../images/grid_blue.gif)', cursor:'pointer'}); }
				$(cell).setStyle({backgroundColor:'#f2d97b'});
			} else {
				$(cell).setStyle({backgroundColor:'#f2eace'});
			}
    });
    ShowDetails(event);
    $('rate_name_'+this.row.readAttribute('idproduct')).setStyle({color:'#000000'});
  },
  handleOnMouseOut: function(event) {
	  
	/** @wayne */
	var onProd = false; if(document.forms['varform'].prodpage.value == 'true') { onProd = true; }
	
    $A($(this.row).childElements()).each(function(cell) {
          if(cell.readAttribute('soldout')!='true') {
			  if(!onProd) { $(cell).setStyle({backgroundImage:'url(../images/grid_green.gif)', cursor:'pointer'}); }
			  $(cell).setStyle({backgroundColor:'#d1eaa3'});
		  } else {
			  $(cell).setStyle({backgroundColor:'#f2f2f2'});
		  }	  
    });
    $('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');
}

