function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100+0.50000000001);
	cents = num % 100;
	num = Math.floor(num / 100).toString();
	
	if(cents<10) cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
		num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - ( 4 * i + 3));
	}
	
	return (((sign) ? '' : '-') + '$' + num);
}
function setLocation(url) 
{
	window.location = url;
}
function purchaseValidateEmail(email) 
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return reg.test(email);
}
function purchaseUpdatePriceTotal() 
{
	var newQty = parseInt($('input[name=qty]').val());
	if(newQty > 10000) {
		$('input[name=qty]').val('10000');
		newQty = 10000;
	}
	var newPerPrice = 25;
	var newTotalPrice = 25;
	if(!isNaN(newQty) && parseInt(newQty) > 0) {
		if(parseInt(newQty) >= 4 && parseInt(newQty) <= 6) newPerPrice = 20;
		if(parseInt(newQty) >= 7) newPerPrice = 15;
		newTotalPrice = newPerPrice * newQty;
	}
	$('span#per-price').text('@$' + newPerPrice + ' each');
	$('span#order-total').text(formatCurrency(newTotalPrice));
}
