var loggedIn     = false;
var isWholesaler = false;
var wspTier      = '';
var wspType      = '';
var wspAmt       = '';
var wspPric      = '';


/* used on item pages */
function showHideItem()
{
	var itemPit     = document.getElementById( 'item-pit' );
	var itemPitText = document.getElementById( 'item-pit-text' );
	if ( itemPit && itemPitText )
	{
		if ( !loggedIn )
			itemPit.style.display = 'none';
		else
			itemPitText.style.display = 'none';
	}
}

/**
 * calcDiscount()
 * Calculates wholesale discount
 * @param    string   usePrice
 * @param    bool     showPrice    true: price for display, false: price as a discount attribute
 * @param    bool     printPrice   true: document.write(), false: return
 * @return   string                WSP as string if showPrice; WSP as option value if !showPrice
 */
if ( !window.calcDiscount )
{
	function calcDiscount( usePrice, showPrice, printPrice )
	{
		var showPrice   = ( showPrice == null ) ? 0 : 1;
		var printPrice  = ( printPrice == null ) ? 0 : 1;
		var priceFormat = new RegExp( '^\\$(\\d+\\.\\d{2})$' );
		var thisPrice   = priceFormat.exec( usePrice );
		if ( thisPrice == null )
			price = usePrice;
		else
			price = thisPrice[1];
		if ( isNaN( price ) )
			return '';
		if ( isWholesaler )
		{
			if ( wspPricing == 'per' )
				return "View product for wholesale price";
			if ( wspType == 'flat' )
				wsPrice = price - wspAmt;
			else
				wsPrice = price - ( price * ( wspAmt / 100 ) );
		}
		if ( showPrice == 1 )
		{
			if ( price == 0 )
				return '';
			price = price - ( price - wsPrice );
			price = "$" + price.toFixed( 2 );
			if ( printPrice )
				document.write( price );
			else
				return price;
		}
		else
		{
			wsPrice = wsPrice - price;
			return '(' + wsPrice.toFixed( 2 ) + ')';
		}
	}
}