﻿$(document).ready(function(){
	onResize();
});
$(window).resize(function() {
	onResize();
});

function onResize(){
	var wrapper = $("#wrapper");
	if (!wrapper.length)
		return;
	var className;
	var targetCols;
	if (wrapper.width() < 930) {
		className = "small";
		targetCols = 2;
	} else if (wrapper.width() > 1110) {
		className = "large";
		targetCols = 4;
	} else {
		className = "medium";
		targetCols = 3;
	}
	if (wrapper.attr('class') != className)
		wrapper.attr('class', className);
}

function zoomPicture(file){
	myWin = open('', '', "noresize, height=420, width=420");
	myWin.document.writeln('<html><head><title>Zoom Picture</title></head>');
	myWin.document.writeln('<body style="background:#FFF; margin:0; padding:0">');
	myWin.document.writeln('<table width="100%" height="100%"><tr><td align="center">');
	myWin.document.writeln('<a href="#" onclick="window.close()"><img src="'+file+'" border="0" /></a>');
	myWin.document.writeln('</td></tr></table>');
	myWin.document.writeln('</body></html>');
	myWin.document.close();
}

function zoomImage(id, suffix) {
	zoomPicture("/images/" + id + '_' + suffix + '/huge.jpg');
}

function validateSearch(input) {
	if (!/\S{3,}/.test(input.val())) {
		alert("Keyword should be at least 3 chars long");
		input.focus();
		return false;
	}
	return true;
}

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];
}

// Account Popup Windows

function openForgotPassword() { openPopupWindow(getForgotPasswordUrl(), "ForgotPassword", 400, 350); }
function openOrderStatusExplanation(id) { openPopupWindow(getOrderStatusExplanationUrl(id), 'OrderStatusExplanation', 450, 500); }
function openOrderStatusHistory(id) { openPopupWindow(getOrderStatusHistoryUrl(id), 'OrderStatusHistory', 450, 300); }
function openWishListShare() { openPopupWindow(getWishListShareUrl(), 'WishListShare', 450, 550); }

// Cart Popup Windows

function openCartHelp() { openPopupWindow(getCartHelpUrl(), 'CartHelp', 450, 600); }
function openCookiesHelp() { openPopupWindow(getCookiesHelpUrl(), 'CookiesHelp', 450, 600); }
function openStockStatus() { openPopupWindow(getStockStatusUrl(), 'StockStatus', 450, 500); }

// Checkout Windows

function openSecurityCode() { openPopupWindow(getSecurityCodeUrl(), 'SecurityCode', 450, 600); }
function openRecyclingFee() { openPopupWindow(getRecyclingFeeUrl(), 'RecyclingFee', 600, 230); }
function openTaxExemption() { openPopupWindow(getTaxExemptionUrl(), 'TaxExemption', 450, 410); }
function openExpressHelp() { openPopupWindow(getExpressHelpUrl(), 'ExpressHelp', 450, 500); }

// Product Windows

function openNotifier(id) { openPopupWindow(getNotifierUrl(id), 'Notifier', 400, 400); }
function openWriteReview(id) { openPopupWindow(getWriteReviewUrl(id), 'Review', 600, 750); }
function openRebate(id) { openPopupWindow(getRebateUrl(id), "Rebate", 700, 750); }
function openShippingCalc(id) { openPopupWindow(getShippingCalcUrl(id), 'ShippingCalc', 500, 600); }
function openRecommend(id) { openPopupWindow(getRecommendUrl(id), 'Recommend', 400, 450); }
function openImageGallery(id, image) { openPopupWindow(getImageGalleryUrl(id, image), "ImageGallery", 700, 680); }
function openCantBuy() { openPopupWindow(getCantBuyUrl(), 'CantBuy', 400, 200); }
function openConditions(id) { openPopupWindow(getConditionsUrl(id), 'Conditions', 400, 400); }
function openFreeShipping() { openPopupWindow(getFreeShippingUrl(), 'FreeShipping', 400, 300); }
function openPriceInfo() { openPopupWindow(getPriceInfoUrl(), 'PriceInfo', 450, 600); }
function openProductsCompare(id) { openPopupWindow(getProductsCompareUrl(id), "ProductCompare", 700, 750); }

// External Sites Windows

function openResellerRatingsSurvey() { openPopupWindow(getResellerRatingsSurveyUrl(), 'ResellerRatingsSurvey', 625, 400); }
