function set_colour(element_name, colour_id) {
	var selObj = document.getElementById(element_name);
	selObj.selectedIndex = colour_id;
	//document.getElementById(element_name).value = selObj.options[selObj.selectedIndex].innerHTML;	
	check_enable_add_to_cart();	
}

var cart_button_enabled = true;

function setAttribute_result(id_field, value) {
	if (typeof(attributes_array) != "undefined") {
		attributes_array[id_field] = value;
	}
	update_price();
	check_enable_add_to_cart();
}

function update_price() {
  orientation_select_name = "id[16]";
  orientation_element = document.getElementById(orientation_select_name);
  additional_cost = 0;
  if (orientation_element != null) {
  	orientation_selected = orientation_element.value;
  	if (orientation_selected != 0) {
		additional_cost = (o_array[orientation_element.value][2]);	
	}
  }
  
  border_select_name = "id[3]";
  border_element = document.getElementById(border_select_name);
  with_border = 1;
  	
	if (border_element != null) {
  	border_option = border_element.value;
  	if ((border_option == 2) || (border_option == 34) || (border_option == 272) || (border_option == 274) || (border_option == 275)) {
  		with_border = 1;
  	}
  	else 
  		if ((border_option == 3) || (border_option == 23) || (border_option == 273)) {
  			with_border = 0;
  		}
  }
  
  	if ((attributes_array[2] != '')&&(attributes_array[2] != '0')) {
		// check if size has without border or with. adjust the price accordingly.
		for (i=0; i<size_array.length; i++) {
			if (typeof(size_array[i]) != 'undefined' && size_array[i][1] == with_border && size_array[attributes_array[2]][0] == size_array[i][0]) {
				document.getElementById('id[200]').value = i;
				old_price = document.getElementById('product_price_container').innerHTML;
				if (old_price.indexOf("VAT") > -1) { additional = ' + VAT'; }
				else { additional = ''; }
				document.getElementById('product_price_container').innerHTML = '&pound;' + Math.round(((additional_cost * 1)+ (size_array[i][2] * 1))*100)/100 + ' each' + additional;
			}	
		}				
	}
}

function choose_message() {
	alert("You must select all options before adding to your basket");
	return false;
	//document.getElementById('btn_add_to_basket').onclick = 'alert("You must select all options before adding to your basket"); return false';		
}

function disable_add_to_cart() {
 	if (cart_button_enabled) {
		new Effect.Opacity('btn_add_to_basket', {
			from: 1,
			to: 0.4
		});
		//document.getElementById('btn_add_to_basket').disabled = true;
		document.getElementById('btn_add_to_basket').onclick = choose_message;
		cart_button_enabled = false;
		return false;
	}
}

function enable_add_to_cart() {
	if (!cart_button_enabled) {
		new Effect.Opacity('btn_add_to_basket', {
			from: 0.4,
			to: 1
		});
		document.getElementById('btn_add_to_basket').onclick = '';
		cart_button_enabled = true;
		return false;
	}
}

function check_enable_add_to_cart() {
	disable_button = false;
	if ( typeof( attributes_array ) != "undefined" ) {
		for (i = 0; i < attributes_array.length; i++) {
			if ((attributes_array[i] == '')||(attributes_array[i] == '0')) {
				disable_button = true;
				disable_add_to_cart();
				break;
			}
		}
		if (!disable_button) {
			enable_add_to_cart();
		}
	} else { enable_add_to_cart(); }
	return false;
}
