
// © techbuy 2006

// obtain the td objects of the row we want to access
function get_row_tds(img_col_pos)
{

	// search results primary table
	sr = document.getElementById('search_results');

	// loop through the table, get the image object from the provided column position
	obj = sr.getElementsByTagName('TR');

	if(obj.length > 1) {
		var img_objects = new Array();
		var j = 0;

		// skip the first row. we know that its a header
		for(var i = 0; i < obj.length; i++) {

			var img = obj[i].getElementsByTagName('TD');
			img = img[img_col_pos];

			if(img) {
				img_objects[j] = img;
				j++;
			}

		}

		return img_objects;

	}

	return false;

}

// decides if the search product images should be shown or not.
function search_load_images()
{
	//debugger;
	obj = get_row_tds(0);
	if(obj) {
		var display = false;
		c = cookie_get('tb_search_img');
		if(c) display = (c == '1') ? true : false;
		
		_fix_span((display ? 6 : 5));
		// update the checkbox
		document.getElementById('show_images').checked = display;
		// because ie doesnt understand table-row as a display type, need to detect browsers
		for(i = 0; i < obj.length; i++) {
			if(obj[i]) {
				obj[i].style.display = display ? ((document.all) ? 'block' : 'table-cell') : 'none';
			}
		}
	}
}

function set_image_status(show)
{

	// lets set our cookie
	cookie_set('tb_search_img', (show ? '1' : '0'), null, '/');

	search_load_images();

}

function _fix_span(num)
{
	var th = document.getElementById('search_results').getElementsByTagName('th');
	for(var i = 0; i < th.length; i++) {
		if(th[i]) {
			//console.log(th[i].colSpan);
			th[i].colSpan = num;
		}
	}
}