function fps_validateStoreSelections()
{
	if ($('fps_Item3051'))
	{
		if ($F('fps_Item3051') == 0)
			$('Item3058').value = 0;

		if ($F('fps_Item3053') == 0)
			$('Item3059').value = 0;
	}

    var subQuantity = 0;
    $$('select.item.subscription').each(function(sel)
    {
        subQuantity += parseInt($F(sel));
    });
    
    if (subQuantity == 0)
    {
        alert("Please select at least one subscription option.");
        $$('select.item.subscription')[0].focus();
        return false;
    }

	return true;
}

var fps_submitStoreSelections_disabled = false;

function fps_submitStoreSelections()
{
    if (fps_submitStoreSelections_disabled) return;

    fps_submitStoreSelections_disabled = true;   
    if (!fps_validateStoreSelections())
    {
        fps_submitStoreSelections_disabled = false;
        return;
    }
    
    $('fps_StoreForm').submit();
}

function fps_subtotalStoreSelections()
{
	var subtotal = 0;

	var aItems = $$('select.item');
	var aPrices = $$('.price');

	for (var i = 0; i < aItems.length; i++)
	{
		if (typeof aPrices[i].value != 'undefined')
		{
			if (!isFloat($F(aPrices[i])))
				aPrices[i].value = 0;
				
			subtotal += $F(aPrices[i]) * $F(aItems[i]);
		}
		else
			subtotal += aPrices[i].innerHTML * $F(aItems[i]);
	}

	$('fps_Subtotal').innerHTML = formatNumber(subtotal, 2);
}

function fps_calculateShipping()
{
    if ($('fps_InternationalFlag1').checked)
    {
        $('fps_Shipping1').innerHTML = 30;
        $('fps_Shipping2').innerHTML = 30;
    }
}

function fps_InternationalFlag_Change(event)
{
    var checked = Event.element(event).checked;
    $('fps_InternationalFlag1').checked = checked;
    $('fps_InternationalFlag2').checked = checked;
    fps_calculateShipping();
}

Event.observe(window, 'load', function(event)
{
    if (document.cookie.indexOf("Edit=true")) return;

	Event.observe('fps_InternationalFlag1', 'change', fps_InternationalFlag_Change);
	Event.observe('fps_InternationalFlag2', 'change', fps_InternationalFlag_Change);

    if ($('fps_InternationalFlag1').checked || $('fps_InternationalFlag2').checked)
    {
        $('fps_InternationalFlag1').checked = true;
        $('fps_InternationalFlag2').checked = true;
    }

    fps_calculateShipping();
    fps_subtotalStoreSelections();
});
