// Include associated libraries ...
include("disclosures.lib.js");
include("events.lib.js");
include("forms.lib.js");
include("image_options.lib.js");
include("scriptaculous_extensions.lib.js");

// Globals for the disclosure triangle images.
var imgDctShow		= '/images/admin/icons/disc_tri_show.png';
var imgDctHide		= '/images/admin/icons/disc_tri_hide.png';

/**
 *	Deletes the specified item.
 *	@param int theID
 *  @param string msg
 *	@param event e
 *	@param string param - the param name we'll use
 */
function confirmDelete(theID, msg, e, param)
{
	if (param == null) {
		param			= 'delete';
	}
	if (confirm(msg)) {
		location.href	= location.href+'&'+param+'='+theID;
	}
	stopEventBubbling(e);
}

/**
 *	Stops the event bubbling and pops up the specified alert.
 *	@param string msg
 *	@param event e
 */
function deadLink(msg, event) 
{ 
	if (msg) { alert(msg); }
	stopEventBubbling(event);
}

/**
 *	Swaps the current product image for the requested one.
 */
function getItemImage()
{
	// If the first item is selected, don't do anything.
	if ($('selItemImage').selectedIndex == 0) { return; }
	// Get the image object.
	imgObject				= eval('img'+$('selItemImage').options[$('selItemImage').selectedIndex].value);
	// Change the small image ...
	$('imgItem').src		= imgObject.smallSrc;
	// And the large image ...
	$('imgItemLarge').src	= imgObject.largeSrc;
	// Now change the product name and caption
	Element.update('dImgItemLargeName', imgObject.name);
	Element.update('dImgItemLargeCaption', imgObject.caption);
}

/**
 *	Includes the specified js library
 *	@param libName
 */
function include(libName) { document.write('<script type="text/javascript" src="/js/'+libName+'"></script>'); }

/**
 *	Stops event bubbling and jumps to the target URL.
 *	@param string target
 *	@param event e
 */
function jumpTo(target, e)
{
	location.href	= target;
	stopEventBubbling(e);
}

/**
 *	Replaces the specified image object with the specified image.
 *	@param string theImage
 *	@param string url
 */
function imgReplace(theImage, url) { Element.setImageSrc($(theImage), url); }