//Copyright e-Business Systems Limited  www.e-businesssystems.co.uk

var maxcols = 6;
var maxrows = 9;
var button = new Array(maxcols);
var matrix = new Array(maxrows);
var setup_complete = false;

function Set_style(id_name){
	document.getElementById(id_name).style.color = "#C00000";
	document.getElementById(id_name).style.fontSize = "8pt";
	//document.getElementById(id_name).style.fontWeight = "bold";	
	document.getElementById(id_name).style.backgroundColor = "#C0C0C0";
}


function Setup_styles(){
	var i;
	var j;
	for (i = 0; i < maxrows; i++){
		Set_style("ebsl" + (i+10) + "00");
		for (j = 0; j < maxcols; j++){
			Set_style("ebsl" + (i+10) +(j+10));
		}
	}
}

function Setup_buttons(){
	button[0] = new Button_hilo("images/industrial_pesticides_hi.gif","images/industrial_pesticides_lo.gif");
	button[1] = new Button_hilo("images/thamesmead_hi.gif","images/thamesmead_lo.gif");
	button[2] = new Button_hilo("images/ics_hi.gif","images/ics_lo.gif");
	button[3] = new Button_hilo("images/bca_hi.gif","images/bca_lo.gif");
	button[4] = new Button_hilo("images/binding_bazaar_hi.gif","images/binding_bazaar_lo.gif");
	button[5] = new Button_hilo("images/nwi_hi.gif","images/nwi_lo.gif");
}

function Button_hilo(high,low){
	this.hi = high;
	this.lo = low;
	this.hi_img = new Image();
	this.hi_img.src = ebsl_1004 + high;
	this.lo_img = new Image();
	this.lo_img.src = ebsl_1004 + low;
}


function Swap_button(id,on_off){
	var i;
	for (i = 0; (document.images[i] != null); i++){
		//alert(document.images[i].src);	//temp
		if (document.images[i].src.indexOf(((on_off == "on") ? button[id].lo : button[id].hi)) >=0){
			document.images[i].src = ((on_off == "on") ? button[id].hi_img.src : button[id].lo_img.src);
		}
	}
}

function Setup_matrix(){
	var i,j;
	for (i=0; i < maxrows; i++){
		matrix[i] = new Array(maxcols);
		for (j=0; j < maxcols; j++){
			matrix[i][j] = 0;
		}
	}
	matrix[0][0] = 1;
	matrix[0][4] = 1;
	matrix[1][0] = 1;
	matrix[1][1] = 1;
	matrix[1][2] = 1;
	matrix[1][4] = 1;
	//matrix[2][1] = 1;	//thamesmead supplier link
	matrix[3][1] = 1;
	matrix[3][2] = 1;
	matrix[4][0] = 1;
	matrix[4][1] = 1;
	matrix[4][2] = 1;
	matrix[4][3] = 1;
	matrix[4][4] = 1;
	matrix[4][5] = 1;
	matrix[5][0] = 1;
	matrix[5][1] = 1;
	matrix[5][2] = 1;
	matrix[5][4] = 1;
	matrix[6][4] = 1;
	matrix[7][2] = 1;
	matrix[7][5] = 1;
	matrix[8][0] = 1;
	matrix[8][1] = 1;
	matrix[8][2] = 1;
	matrix[8][3] = 1;
	matrix[8][4] = 1;
	matrix[8][5] = 1;
}

function Change_style_attribute(attribute_name,id_name,change_to){
	if ((browsertype.netscape6)||(browsertype.ie5plus)){
		eval("document.getElementById('" + id_name + "').style." + attribute_name + " = change_to");
	}
}

function Highlight_on_cell(i,j){
	var k = "ebsl" + (i+10) + (j + 10);
	if (j < 0){
		k = k + "0";
	}
	Change_style_attribute("color",k,"#006699");
	Change_style_attribute("backgroundColor",k,"#80FFFF");
}


function Highlight_off_cell(i,j){
	var k = "ebsl" + (i+10) + (j + 10);
	if (j < 0){
		k = k + "0";
	}
	Change_style_attribute("color",k,"#C00000");
	Change_style_attribute("backgroundColor",k,"#C0C0C0");
}

function Highlight_toggle(identity,on_off){
	var i;
	var j;
	var k;
	if (identity.indexOf("col") >= 0){
		j = parseInt(identity.substr(3));
		Swap_button(j,on_off);
		for (i=0; i < maxrows; i++){
			if (on_off == "on"){
				Highlight_on_cell(i,j);
			}
			if (on_off == "off"){
				Highlight_off_cell(i,j);
			}
			if (matrix[i][j] == 1){
				if (on_off == "on"){
					Highlight_on_cell(i,-10);
				}
				if (on_off == "off"){
					Highlight_off_cell(i,-10);
				}
			}
		}
	}
	
	if (identity.indexOf("row") >= 0){
		i = parseInt(identity.substr(3));
		if (on_off == "on"){
			Highlight_on_cell(i,-10);
		}
		if (on_off == "off"){
			Highlight_off_cell(i,-10);
		}
		for (j=0; j < maxcols; j++){
			if (matrix[i][j] == 1){
				Swap_button(j,on_off);
				for (k=0; k < maxrows; k++){
					if (on_off == "on"){
						Highlight_on_cell(k,j);
					}
					if (on_off == "off"){
						Highlight_off_cell(k,j);
					}
				}
			}
		}
	}
}	


function Highlight_on(identity){
	if (setup_complete){
		Highlight_toggle(identity,"on")
	}
}

function Highlight_off(identity){
	if (setup_complete){
		Highlight_toggle(identity,"off")
	}
}






function Control_setup(){
	if ((browsertype.netscape6)||(browsertype.ie5plus)){
		Setup_styles();
	}
	Setup_buttons();
	Setup_matrix();
	setup_complete = true;
}



