previous_selected_optionid = ""

function change_option(arg_selectbox,arg_optionid) {
	var src_part, href;
	src_part =  global_Config_StoreFolderName;
	src_part += unescape(global_src_part_Config_ProductPhotosFolder);
	src_part += "/";
	src_part += "options";
	src_part += "/";
	src_part += global_Current_ProductCode + "-";

	//HIDE all previously open spans (if they exist)
	if (document.getElementById("optionimg_" + previous_selected_optionid)) {
		document.getElementById("optionimg_" + previous_selected_optionid).border = "0";
	}
	
	//SHOW the selected SPAN tag + GROUP BY span tag (if they exist)
	if (document.getElementById("optionimg_" + arg_optionid)) {
		change_product_photo(2); // reset selected alternate view back to first view
		document.getElementById("optionimg_" + arg_optionid).border = "1";
		document.getElementById("product_photo").src = src_part + arg_optionid + "-T.jpg"

		href = "javascript:OpenNewWindow(global_SEOImage + '?ShowDesc=N&PhotoURL=' + global_Config_StoreFolderName + global_Config_ProductPhotosFolder + '/options/' + escape(global_Current_ProductCode) + '-" + arg_optionid + ".jpg', 640, 480)";

		if (document.getElementById("product_photo_zoom_url")) {
			document.getElementById("product_photo_zoom_url").href  = href;
		}
		if (document.getElementById("product_photo_zoom_url2")) {
			document.getElementById("product_photo_zoom_url2").href = href;
		}
	}

	//Loop through the dropdown to find and make this OptionID selected
	//Check for select boxes
	if (document.MainForm.elements[arg_selectbox] &&  document.MainForm.elements[arg_selectbox].options && document.MainForm.elements[arg_selectbox].options.length > 0) {
		for (loop=0; loop < document.MainForm.elements[arg_selectbox].options.length; loop++)
		{
			if (document.MainForm.elements[arg_selectbox].options[loop].value == arg_optionid) {
				document.MainForm.elements[arg_selectbox].selectedIndex = loop;
				TCN_reload(document.MainForm.elements[arg_selectbox]);
			}
		}
	}
	//Then check for radio buttons and checkboxes
	else if (document.MainForm.elements[arg_selectbox] && document.MainForm.elements[arg_selectbox].length > 1) {
		for (loop=0; loop < document.MainForm.elements[arg_selectbox].length; loop++) {
			if (document.MainForm.elements[arg_selectbox][loop].value == arg_optionid) {
				document.MainForm.elements[arg_selectbox][loop].checked = true;
				TCN_reload(document.MainForm.elements[arg_selectbox]);
			}
		}
	}
	
	//SAVE the previous span to global variable for next call of this function
	previous_selected_optionid = arg_optionid

}
previous_selected_photo = "";
function change_product_photo(arg_photo_number) {
	var src_part, ext, href;
	var popup = global_Config_EnablePhotosPopup;
	src_part =  global_Config_StoreFolderName;
	src_part += unescape(global_src_part_Config_ProductPhotosFolder);
	src_part += "/";
	src_part += global_Current_ProductCode + "-";

	//HIDE all previously open spans (if they exist)
	if (document.getElementById("alternate_product_photo_" + previous_selected_photo)) {
		document.getElementById("alternate_product_photo_" + previous_selected_photo).border = "1";
	}
	
	//SHOW the selected SPAN tag + GROUP BY span tag (if they exist)
	if (document.getElementById("alternate_product_photo_" + arg_photo_number)) {
		document.getElementById("alternate_product_photo_" + arg_photo_number).border = "2";
		ext = document.getElementById("alternate_product_photo_" + arg_photo_number).src;
		ext = ext.substr(ext.lastIndexOf('.') + 1);
		document.getElementById("product_photo").src = src_part + arg_photo_number + "T." + ext;

		if (popup) {
			href = "javascript:OpenNewWindow(global_SEOImage + '?ShowDesc=N&PhotoNumber=" + arg_photo_number + "&ProductCode=' + escape(global_Current_ProductCode), 640, 480)";
		}
		else {
			href = global_SEOImage_PhotoGallery + "&PhotoNumber=" + arg_photo_number;
		}
		
		if (document.getElementById("product_photo_zoom_url")) {
			document.getElementById("product_photo_zoom_url").href  = href;
		}
		if (document.getElementById("product_photo_zoom_url2")) {
			document.getElementById("product_photo_zoom_url2").href = href;
		}
	}
	
	//SAVE the previous span to global variable for next call of this function
	previous_selected_photo = arg_photo_number

}
