﻿function formatPrice(value, digits) {
	var price = "";
	var number = formatNumber(value, digits).split(".", 2);
	var len = number[0].length;
	for (var i = 0; i <= len; i++)
		price = (i > 0 && i < len && i % 3 == 0 ? "," : "") + number[0].charAt(len - i) + price;
	return "$" + price + "." + number[1];
}

function mailingSubscribe(form, container, url) {
	form = $(form);
	$(container).attr('class', 'icon icon-loader gray').html('<small>Processing, please wait...</small>');
	$.ajax({
		type: "GET",
		url: url,
		data: form.serialize(),
		dataType: "json",
		cache: false,
		error: function(request) { this.success({ success: false, text: "Unknown error, try again" }); },
		success: function(data) {
			$(container)
				.attr('class', data.success ? "icon icon-check green" : "icon icon-error red")
				.html("<small>" + data.text + "</small>");
		}
	});
	return false;
}

// Account Windows
function openForgotPassword() { openPopupWindow(getForgotPasswordUrl(), "ForgotPassword", 400, 220); }

// Cart & Checkout Windows
function openCookiesHelp() { openPopupWindow(getCookiesHelpUrl(), "CookiesHelp", 500, 550); }
function openSecurityCode() { openPopupWindow(getSecurityCodeUrl(), "SecurityCode", 500, 550); }

// Product Windows
function openRebate(id) { openPopupWindow(getRebateUrl(id), "Rebate", 700, 750); }
function openShipCalc(id) { openPopupWindow(getShippingCalcUrl(id), "ShipCalc", 500, 550); }
function openNotifier(id) { openPopupWindow(getNotifierUrl(id), "Notifier", 450, 350); }
function openRecommend(id) { openPopupWindow(getRecommendUrl(id), "Recommend", 400, 350); }
function openImageGallery(id, image) { openPopupWindow(getImageGalleryUrl(id, image), "ImageGallery", 550, 700); }
function openProductsCompare(id) { openPopupWindow(getProductsCompareUrl(id), "ProductCompare", 700, 750); }
