function login_form(path, success_page) {
	var url = addParameter(path, "success=" + escape(success_page));
	url = addParameter(url, "path=" + getURLParam(location.href, "path"));
	url = addParameter(url, "query=" + getURLParam(location.href, "query"));
	
	new Ajax.Request(url, {
		method: 'get',
		parameters: { randid: Math.random() },
		onSuccess: function(transport) {
			showLoginModal(transport.responseText);
		}
	});
}

function conditionally_show_login_form(path) {
	var matchingIndex = window.location.href.indexOf('login=t');
	
	if (matchingIndex > -1) {
		login_form(path, '');
	}
}

function change_search_action(path) {
	$('general_site_search').action = path;
	if (path.indexOf("registry")>=0){
		jQuery("#search").unautocomplete();
	} else {
		//autocomplete.installAutocomplete(contextPath+"/views/common/search/solrProxy.jsp","search","autocompleteContainer");
		mcfinaSolrTranslations.installAutocomplete(contextPath+"/views/common/search/autocompleteProxy.jsp")
	}
}

function forgot_password_form(path) {
	new Ajax.Request(path, {
		method: 'get',
		parameters: { randid: Math.random() },
		onSuccess: function(transport) {
			showModalDialog(transport.responseText);
		}
	});
}

function submit_forgot_password_form(servlet) {

	// POST
	new Ajax.Request(servlet, {
		method: 'post',
		parameters: { randid: Math.random() },
		onSuccess: function(transport) {
			showModalDialog(transport.responseText);
		},
		postBody: get_form_values('fp')
	});
}

function go_to_login_page() {
}

function conditionally_show_shipping_info(page) {
	var matchingIndex = window.location.href.indexOf('delivery_info=t');
	
	if (matchingIndex > -1) {
		show_modal(page);
	}
}

function conditionally_show_sales_events(page) {
	var matchingIndex = window.location.href.indexOf('sales_events=t');
	
	if (matchingIndex > -1) {
		var emailIndex = window.location.href.indexOf('email=');
		
		if (emailIndex > -1) {
			$('sales_events_email').value = getURLParameter('email');
		}
		
		sales_events_form(page, 'sales_events_email');
		go_to_top_of_page();
	}
}

function conditionally_show_appt_form(page, product_id) {
	var matchingIndex = window.location.href.indexOf('appt=t');
	
	if (matchingIndex > -1) {
		show_appt_form(page, product_id);
		go_to_top_of_page();
	}
}

// this is only for showing zoomed-in image
function show_image(id, relative_position_id) {
	$(id).style.display = 'block';
	
	if ($(relative_position_id)) {
		$(relative_position_id).style.position = 'relative';
		
		// not working quite right.
		//setTimeout('hide_image(\'' + id + '\', \'' + relative_position_id + '\')', 5000);
	}
}

// this is only for hiding zoomed-in image
function hide_image(id, relative_position_id) {
	$(id).style.display = 'none';
	
	if ($(relative_position_id)) {
		$(relative_position_id).style.position = 'static';
	}
}

// determine which breadcrumb to show ("dynamic" or "static")
function show_product_breadcrumbs() {
	if (product) {
		if (product.catalogs) {
			for (var i = 0; i < product.catalogs.length; i++) {
				if (readCookie('last_cat_id') == product.catalogs[i].id) {
					
					// user has been to one of the categories, show
					// dynamic breadcrumb.
					show_dynamic_product_breadcrumbs();
					return;
				}
			}
			
			// user has not been to one of the categories, show
			// home category breadcrumb.
			show_static_product_breadcrumbs();
		}
	}
}

// show the "static" breadcrumb which is the product's home category.
// "product" is created in template.jsp
function show_static_product_breadcrumbs() {
	new Ajax.Request(contextPath + "/util/breadcrumb.jsp?product_id=" + product.id, {
		method: 'get',
		parameters: { randid: Math.random() },
		onSuccess: function(transport) {
			$('product_breadcrumbs').update(transport.responseText);
		}
	});
}

// shows the "dynamic" breadcrumb which is the path user took.
function show_dynamic_product_breadcrumbs() {
	new Ajax.Request(contextPath + "/util/breadcrumb.jsp?cid=" + readCookie('last_cat_id'), {
		method: 'get',
		parameters: { randid: Math.random() },
		onSuccess: function(transport) {
			$('product_breadcrumbs').update(transport.responseText);
		}
	});
}
