var disabled_frame_ids = new Array();

var global_print_type = null;
function show_frame_options(print_type, collection, artwork_id, product_select_value, frame_id, search) {
	var product_select_parts = product_select_value.split("_");
	var print_id = product_select_parts[0];

	new Ajax.Updater("frame_options_" + print_type, "/page/get_frame_options/" + collection + "?print_type=" + print_type + "&artpiece=" + artwork_id + "&print_id=" + print_id + "&frame_id=" + frame_id + "&search=" + search, {asynchronous:true, evalScripts:true});

	global_print_type = print_type;

	setTimeout("Effect.SlideDown('frame_div_" + global_print_type + "');", 400);
}

function update_framed_art(frame_id, frame_price, id, artpiece, size, print_id, size_id, print_type, print_price, print_type_section_append) {
	if (frame_price == 0 && frame_id != "none") {
		alert("Please call 800-799-6933 for details.");
		return false;
	}

	num_disabled_frame_ids = disabled_frame_ids.length;
	for (var i = 0; i < num_disabled_frame_ids; i++) {
		if (disabled_frame_ids[i] == frame_id) {
			alert("Please call for details.");
			return false;
		}
	}

	var destination_id = "";
	var frame_input = "";

	var total_price = formatCurrency(print_price + frame_price);

	frame_input = document.getElementById("frame_id_" + print_type_section_append);
	displayed_frame_cell = document.getElementById("displayed_frame_" + print_type_section_append);
	displayed_frame_price_cell = document.getElementById("displayed_frame_price_" + print_type_section_append);

	if (document.getElementById("art_in_frame_Original")) {
		destination_id = "art_in_frame_Original";
	}
	else if (document.getElementById("art_in_frame_Print")) {
		destination_id = "art_in_frame_Print";
	}
	else if (document.getElementById("art_in_frame_Canvas")) {
		destination_id = "art_in_frame_Canvas";
	}


	// update selected frame hidden input
	frame_input.value = frame_id;

	if (frame_id == "none") {
		// update displayed price
		displayed_frame_price_cell.innerHTML = "";

		// update displayed frame corner image
		displayed_frame_cell.innerHTML = "";
	}
	else {
		// update displayed price
		displayed_frame_price_cell.innerHTML = "Total price with frame: " + total_price;
		displayed_frame_price_cell.style.display = "inline";

		// update displayed frame corner image
		displayed_frame_cell.innerHTML = "<a href='#' onclick=\"window.open('/page/show_big_frame/?id=" + frame_id + "', 'Frame Image', 'width=625,height=555,scrollbars=yes')\" style='border: none; text-decoration: none'><img src='/images/frames/corners/" + frame_id + ".jpg' style='border: none; text-decoration: none'></a>";
		//displayed_frame_cell.innerHTML = "<img src='/images/frames/corners/" + frame_id + ".jpg'>";
		displayed_frame_cell.style.display = "inline";
	}

	update_frame_border(frame_id, print_id);

	new Ajax.Updater(destination_id, '/page/update_framed_art/' + id + '?artpiece=' + artpiece + '&frame_id=' + frame_id + '&size=' + size + '&print_id=' + print_id + '&size_id=' + size_id + '&print_type=' + print_type, {asynchronous:true, evalScripts:true});
}


function update_framed_art_search(frame_id, frame_price, id, artpiece, size, print_id, size_id, print_type, print_price, print_type_section_append, search) {
	if (frame_price == 0 && frame_id != "none") {
		alert("Please call 800-799-6933 for details.");
		return false;
	}

	num_disabled_frame_ids = disabled_frame_ids.length;
	for (var i = 0; i < num_disabled_frame_ids; i++) {
		if (disabled_frame_ids[i] == frame_id) {
			alert("Please call for details.");
			return false;
		}
	}

	var destination_id = "";
	var frame_input = "";

	var total_price = formatCurrency(print_price + frame_price);

	frame_input = document.getElementById("frame_id_" + print_type_section_append);
	displayed_frame_cell = document.getElementById("displayed_frame_" + print_type_section_append);
	displayed_frame_price_cell = document.getElementById("displayed_frame_price_" + print_type_section_append);

	if (document.getElementById("art_in_frame_Original")) {
		destination_id = "art_in_frame_Original";
	}
	else if (document.getElementById("art_in_frame_Print")) {
		destination_id = "art_in_frame_Print";
	}
	else if (document.getElementById("art_in_frame_Canvas")) {
		destination_id = "art_in_frame_Canvas";
	}


	// update selected frame hidden input
	frame_input.value = frame_id;

	if (frame_id == "none") {
		// update displayed price
		displayed_frame_price_cell.innerHTML = "";

		// update displayed frame corner image
		displayed_frame_cell.innerHTML = "";
	}
	else {
		// update displayed price
		displayed_frame_price_cell.innerHTML = "Total price with frame: " + total_price;
		displayed_frame_price_cell.style.display = "inline";

		// update displayed frame corner image
		displayed_frame_cell.innerHTML = "<a href='#' onclick=\"window.open('/page/show_big_frame/?id=" + frame_id + "', 'Frame Image', 'width=625,height=555,scrollbars=yes')\" style='border: none; text-decoration: none'><img src='/images/frames/corners/" + frame_id + ".jpg' style='border: none; text-decoration: none'></a>";
		displayed_frame_cell.style.display = "inline";
	}

	update_frame_border(frame_id, print_id);

	new Ajax.Updater(destination_id, '/page/update_framed_art_search/' + id + '?artpiece=' + artpiece + '&frame_id=' + frame_id + '&size=' + size + '&print_id=' + print_id + '&size_id=' + size_id + '&print_type=' + print_type + "&search=" + search, {asynchronous:true, evalScripts:true});
}


// set "selected" border around specified frame, clear all other frame borders
function update_frame_border(frame_id, print_id) {
	var image_tags = document.getElementsByTagName("img");
	var num_image_tags = image_tags.length;

	for (i = 0; i < num_image_tags; i++) {
		if (image_tags[i].id.indexOf("frame_image_" + print_id) != -1) {

			// check for frame that should be selected
			if (image_tags[i].id == ("frame_image_" + print_id + "_" + frame_id)) {
				image_tags[i].border="4";
			}
			// check for frame that should not be selected
			else {
				image_tags[i].border="1";
			}
		}
	}


	var div_tags = document.getElementsByTagName("div");
	var num_div_tags = div_tags.length;

	for (i = 0; i < num_div_tags; i++) {
		if (div_tags[i].id.indexOf("frame_image_" + print_id) != -1) {

			// check for frame that should be selected
			if (div_tags[i].id == ("frame_image_" + print_id + "_" + frame_id)) {
				div_tags[i].style.border="4px";
			}
			// check for frame that should not be selected
			else {
				div_tags[i].style.border="1px";
			}
		}
	}
}
