function toggle_new_user_password_fields()	{
	$('user_password').value = '';
	Element.toggle('change_password_new');
	$('user_password_confirmation').value = '';
	Element.toggle('change_password_confirmation');
}

function clear_field_if_value_is(target,field)	{
	if	(field.value == target)
		field.value = '';
}
function reset_field_if_value_is_blank(target,field)	{
	if	(field.value == '')
		field.value = target;
}

function toggle_contact_form_fields(type_field)	{
	fields = Array('contact_form_recipient_field', 'contact_form_subject_field')
	if (type_field.value == 'None') {
		for (i in fields) { Element.hide(fields[i]) };
	}
	else	{
		for (i in fields) { Element.show(fields[i]) };
	}
}

function toggle_other_purchase_decision_field(type_field)	{
	if (type_field.value == 'Other') {
		Element.show('other_purchase_decision_field');
	}
	else	{
		Element.hide('other_purchase_decision_field');
	}
}

function remove_new_product_variant_fields(element)	{
	$(element).up('.product_variant').previous('.product_variant').previous('.product_variant').remove();
	$(element).up('.product_variant').previous('.product_variant').remove();
	$(element).up('.product_variant').remove();
}

function hide_product_variant_fields(element)	{
	mark_for_destroy(element);
	$(element).up('.product_variant').previous('.product_variant').previous('.product_variant').hide();
	$(element).up('.product_variant').previous('.product_variant').hide();
	$(element).up('.product_variant').hide();
}

function mark_for_destroy(element)	{
	$(element).next('.should_destroy').value = 1
}
function mark_for_remove(element)	{
	$(element).next('.should_remove_image').value = 1
}


function remove_new_cover_shot_fields(element)	{
	$(element).up('.cover_shot').remove();
}

function hide_cover_shot_fields(element)	{
	mark_for_destroy(element);
	$(element).up('.cover_shot').hide();
}

function hide_cover_panel_image_fields(element)	{
	mark_for_remove(element);
	$(element).up().hide();
}


function store_init_value(e)	{
	var el = Event.element(e);
	var cur_value = $F(el);
	el.init_value = cur_value;
}

function change_cover_type(e)	{
	var el = Event.element(e);
	var selected_class = $F(el);
	var selected_panel = $(selected_class + '_panel_fields');
	if (selected_class == el.init_value) { return };
	var fields_used = false;

	if (!confirm('Changing this value will clear any unsaved panel data. Would you like to continue?')) {
	    el.setValue(el.init_value);
	    e.stop();
	    return;
	}

	$$('.cover_panel_type').each(function(tel) {
	    tel.getElementsBySelector('input', 'textarea', 'select').each(function(fel) {
	        if (!fel.hasClassName('colorpicker')) {
	    		fel.clear();
			}
		});
	});

	$$('.cover_panel_type').each(Element.hide);
	selected_panel.show();
	new Effect.Highlight(selected_panel);
}
