function build_option_table (name) {
document.writeln ('<table>');
document.writeln ('<thead><tr><td>&nbsp;</td><td>Some options below are limited to certain makes and models</td></tr>');
var optArr = eval (name + "_opt");
for(i=0; i < optArr.length ;i++) 
	{ 
 	opt = optArr[i];
	var imgArr = eval (name + '_' + i + '_img');
	var descArr = eval (name + '_' + i + '_desc');
	var nOpt = descArr.length;
	//picture will have rowspan number Options + 1 for header
	var rSpan = nOpt + 1;
	//find the first picture available if any
	var picIdx=0;
	while (picIdx < nOpt){	
		if (imgArr[picIdx] != '')
				break;
		picIdx++;
		
	}
	document.write ('<tr><td class="leftimg" id="img_'+ i +'" rowspan=' + rSpan + '>');
	if (picIdx < nOpt)
		document.write ('<script>display_image(\''+ name + '\',' + i +',' + picIdx + '); </script>');
	document.writeln('</td><td class="optionHeader"><h2>' + opt +'</h2></td></tr>' );
	for(j=0; j < nOpt ;j++) 
		{ 	
			var imgName = imgArr[j];
			var desc = descArr[j];
			document.write('<tr><td class="option" id="opt_' + i + '_' +j +'">');
			if (imgName == '')
				document.write(desc);
			else 
				document.write('<a href="#" onClick="return display_image(\''+ name + '\',' + i +',' + j + ');">' + desc + '</a>');
			document.writeln('</td></tr>');
		}
 }
document.writeln ('</table>');
}
							   
function display_image (name, id, opt)
{
var imgNames = eval (name + '_' + id + '_img');
var nLinks = imgNames.length;
var src="/utilimaster/product/images/"+ imgNames[opt] +".jpg";
var cell = document.getElementById('img_' + id);
//Check if the image exists
var img = new Image();
img.onload = function () {
	cell.innerHTML = '<img src="'+ src + '" />';
	change_link (id, opt, nLinks);
};
img.onerror = function () {
	cell.innerHTML = "Image not available";
	change_link (id, opt,nLinks);
}
img.src = src;
return false;
}							   
							   
function show_image (name, id, opt)
{
var src="/utilimaster/product/images/"+ name +".jpg";
var cell = document.getElementById('img_' + id);
//Check if the image exists
var img = new Image();
img.onload = function () {
	cell.innerHTML = '<img src="'+ src + '" />';
	change_link (id, opt);
};
img.onerror = function () {
cell.innerHTML = "Image not available";
change_link (id, opt);
}
img.src = src;
return false;
}

function change_link (id, opt, nLinks) {
for(linkIdx=0; linkIdx < nLinks ; linkIdx++) 
{ 
     var textcell = document.getElementById('opt_' + id + "_" + linkIdx);
	 if (textcell==null)
	 	break;
	  if (linkIdx==opt) {
	  	textcell.className = "optionOn";
	  }
	  else
	  	textcell.className = "option";
	}
}